@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
73 lines (55 loc) • 4.37 kB
text/typescript
/**
* 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, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array } from '@solana/kit';
import { LB_CLMM_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const MIGRATE_BIN_ARRAY_DISCRIMINATOR = new Uint8Array([17, 23, 159, 211, 101, 184, 41, 241]);
export function getMigrateBinArrayDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(MIGRATE_BIN_ARRAY_DISCRIMINATOR); }
export type MigrateBinArrayInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountLbPair extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountLbPair extends string ? ReadonlyAccount<TAccountLbPair> : TAccountLbPair, ...TRemainingAccounts]>;
export type MigrateBinArrayInstructionData = { discriminator: ReadonlyUint8Array; };
export type MigrateBinArrayInstructionDataArgs = { };
export function getMigrateBinArrayInstructionDataEncoder(): FixedSizeEncoder<MigrateBinArrayInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: MIGRATE_BIN_ARRAY_DISCRIMINATOR }));
}
export function getMigrateBinArrayInstructionDataDecoder(): FixedSizeDecoder<MigrateBinArrayInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getMigrateBinArrayInstructionDataCodec(): FixedSizeCodec<MigrateBinArrayInstructionDataArgs, MigrateBinArrayInstructionData> {
return combineCodec(getMigrateBinArrayInstructionDataEncoder(), getMigrateBinArrayInstructionDataDecoder());
}
export type MigrateBinArrayInput<TAccountLbPair extends string = string> = {
lbPair: Address<TAccountLbPair>;
}
export function getMigrateBinArrayInstruction<TAccountLbPair extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: MigrateBinArrayInput<TAccountLbPair>, config?: { programAddress?: TProgramAddress } ): MigrateBinArrayInstruction<TProgramAddress, TAccountLbPair> {
// Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { lbPair: { value: input.lbPair ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.lbPair)], data: getMigrateBinArrayInstructionDataEncoder().encode({}), programAddress } as MigrateBinArrayInstruction<TProgramAddress, TAccountLbPair>);
}
export type ParsedMigrateBinArrayInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
lbPair: TAccountMetas[0];
};
data: MigrateBinArrayInstructionData; };
export function parseMigrateBinArrayInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedMigrateBinArrayInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 1) {
// 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: { lbPair: getNextAccount() }, data: getMigrateBinArrayInstructionDataDecoder().decode(instruction.data) };
}