UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

83 lines (63 loc) 6.35 kB
/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU8Decoder, getU8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const SET_REWARD_EMISSIONS_DISCRIMINATOR = new Uint8Array([13, 197, 86, 168, 109, 176, 27, 244]); export function getSetRewardEmissionsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_REWARD_EMISSIONS_DISCRIMINATOR); } export type SetRewardEmissionsInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountRewardAuthority extends string | AccountMeta<string> = string, TAccountRewardVault extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpool extends string ? WritableAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountRewardAuthority extends string ? ReadonlySignerAccount<TAccountRewardAuthority> & AccountSignerMeta<TAccountRewardAuthority> : TAccountRewardAuthority, TAccountRewardVault extends string ? ReadonlyAccount<TAccountRewardVault> : TAccountRewardVault, ...TRemainingAccounts]>; export type SetRewardEmissionsInstructionData = { discriminator: ReadonlyUint8Array; rewardIndex: number; emissionsPerSecondX64: bigint; }; export type SetRewardEmissionsInstructionDataArgs = { rewardIndex: number; emissionsPerSecondX64: number | bigint; }; export function getSetRewardEmissionsInstructionDataEncoder(): FixedSizeEncoder<SetRewardEmissionsInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['rewardIndex', getU8Encoder()], ['emissionsPerSecondX64', getU128Encoder()]]), (value) => ({ ...value, discriminator: SET_REWARD_EMISSIONS_DISCRIMINATOR })); } export function getSetRewardEmissionsInstructionDataDecoder(): FixedSizeDecoder<SetRewardEmissionsInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['rewardIndex', getU8Decoder()], ['emissionsPerSecondX64', getU128Decoder()]]); } export function getSetRewardEmissionsInstructionDataCodec(): FixedSizeCodec<SetRewardEmissionsInstructionDataArgs, SetRewardEmissionsInstructionData> { return combineCodec(getSetRewardEmissionsInstructionDataEncoder(), getSetRewardEmissionsInstructionDataDecoder()); } export type SetRewardEmissionsInput<TAccountWhirlpool extends string = string, TAccountRewardAuthority extends string = string, TAccountRewardVault extends string = string> = { whirlpool: Address<TAccountWhirlpool>; rewardAuthority: TransactionSigner<TAccountRewardAuthority>; rewardVault: Address<TAccountRewardVault>; rewardIndex: SetRewardEmissionsInstructionDataArgs["rewardIndex"]; emissionsPerSecondX64: SetRewardEmissionsInstructionDataArgs["emissionsPerSecondX64"]; } export function getSetRewardEmissionsInstruction<TAccountWhirlpool extends string, TAccountRewardAuthority extends string, TAccountRewardVault extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: SetRewardEmissionsInput<TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault>, config?: { programAddress?: TProgramAddress } ): SetRewardEmissionsInstruction<TProgramAddress, TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: true }, rewardAuthority: { value: input.rewardAuthority ?? null, isWritable: false }, rewardVault: { value: input.rewardVault ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Original args. const args = { ...input, }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.rewardAuthority), getAccountMeta(accounts.rewardVault)], data: getSetRewardEmissionsInstructionDataEncoder().encode(args as SetRewardEmissionsInstructionDataArgs), programAddress } as SetRewardEmissionsInstruction<TProgramAddress, TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault>); } export type ParsedSetRewardEmissionsInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { whirlpool: TAccountMetas[0]; rewardAuthority: TAccountMetas[1]; rewardVault: TAccountMetas[2]; }; data: SetRewardEmissionsInstructionData; }; export function parseSetRewardEmissionsInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetRewardEmissionsInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 3) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; } return { programAddress: instruction.programAddress, accounts: { whirlpool: getNextAccount(), rewardAuthority: getNextAccount(), rewardVault: getNextAccount() }, data: getSetRewardEmissionsInstructionDataDecoder().decode(instruction.data) }; }