@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
77 lines (59 loc) • 5.73 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 AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
import { LB_CLMM_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const CLOSE_PRESET_PARAMETER_DISCRIMINATOR = new Uint8Array([4, 148, 145, 100, 134, 26, 181, 61]);
export function getClosePresetParameterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_PRESET_PARAMETER_DISCRIMINATOR); }
export type ClosePresetParameterInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPresetParameter extends string | AccountMeta<string> = string, TAccountAdmin extends string | AccountMeta<string> = string, TAccountRentReceiver extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPresetParameter extends string ? WritableAccount<TAccountPresetParameter> : TAccountPresetParameter, TAccountAdmin extends string ? WritableSignerAccount<TAccountAdmin> & AccountSignerMeta<TAccountAdmin> : TAccountAdmin, TAccountRentReceiver extends string ? WritableAccount<TAccountRentReceiver> : TAccountRentReceiver, ...TRemainingAccounts]>;
export type ClosePresetParameterInstructionData = { discriminator: ReadonlyUint8Array; };
export type ClosePresetParameterInstructionDataArgs = { };
export function getClosePresetParameterInstructionDataEncoder(): FixedSizeEncoder<ClosePresetParameterInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_PRESET_PARAMETER_DISCRIMINATOR }));
}
export function getClosePresetParameterInstructionDataDecoder(): FixedSizeDecoder<ClosePresetParameterInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getClosePresetParameterInstructionDataCodec(): FixedSizeCodec<ClosePresetParameterInstructionDataArgs, ClosePresetParameterInstructionData> {
return combineCodec(getClosePresetParameterInstructionDataEncoder(), getClosePresetParameterInstructionDataDecoder());
}
export type ClosePresetParameterInput<TAccountPresetParameter extends string = string, TAccountAdmin extends string = string, TAccountRentReceiver extends string = string> = {
presetParameter: Address<TAccountPresetParameter>;
admin: TransactionSigner<TAccountAdmin>;
rentReceiver: Address<TAccountRentReceiver>;
}
export function getClosePresetParameterInstruction<TAccountPresetParameter extends string, TAccountAdmin extends string, TAccountRentReceiver extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: ClosePresetParameterInput<TAccountPresetParameter, TAccountAdmin, TAccountRentReceiver>, config?: { programAddress?: TProgramAddress } ): ClosePresetParameterInstruction<TProgramAddress, TAccountPresetParameter, TAccountAdmin, TAccountRentReceiver> {
// Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { presetParameter: { value: input.presetParameter ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, rentReceiver: { value: input.rentReceiver ?? null, isWritable: true } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.presetParameter), getAccountMeta(accounts.admin), getAccountMeta(accounts.rentReceiver)], data: getClosePresetParameterInstructionDataEncoder().encode({}), programAddress } as ClosePresetParameterInstruction<TProgramAddress, TAccountPresetParameter, TAccountAdmin, TAccountRentReceiver>);
}
export type ParsedClosePresetParameterInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
presetParameter: TAccountMetas[0];
admin: TAccountMetas[1];
rentReceiver: TAccountMetas[2];
};
data: ClosePresetParameterInstructionData; };
export function parseClosePresetParameterInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedClosePresetParameterInstruction<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: { presetParameter: getNextAccount(), admin: getNextAccount(), rentReceiver: getNextAccount() }, data: getClosePresetParameterInstructionDataDecoder().decode(instruction.data) };
}