UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

86 lines (66 loc) 6.89 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, getU64Decoder, getU64Encoder, 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 { LB_CLMM_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const SET_LOCK_RELEASE_SLOT_DISCRIMINATOR = new Uint8Array([207, 224, 170, 143, 189, 159, 46, 150]); export function getSetLockReleaseSlotDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_LOCK_RELEASE_SLOT_DISCRIMINATOR); } export type SetLockReleaseSlotInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPosition extends string | AccountMeta<string> = string, TAccountLbPair extends string | AccountMeta<string> = string, TAccountSender extends string | AccountMeta<string> = string, TAccountEventAuthority extends string | AccountMeta<string> = string, TAccountProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountLbPair extends string ? ReadonlyAccount<TAccountLbPair> : TAccountLbPair, TAccountSender extends string ? ReadonlySignerAccount<TAccountSender> & AccountSignerMeta<TAccountSender> : TAccountSender, TAccountEventAuthority extends string ? ReadonlyAccount<TAccountEventAuthority> : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount<TAccountProgram> : TAccountProgram, ...TRemainingAccounts]>; export type SetLockReleaseSlotInstructionData = { discriminator: ReadonlyUint8Array; newLockReleaseSlot: bigint; }; export type SetLockReleaseSlotInstructionDataArgs = { newLockReleaseSlot: number | bigint; }; export function getSetLockReleaseSlotInstructionDataEncoder(): FixedSizeEncoder<SetLockReleaseSlotInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['newLockReleaseSlot', getU64Encoder()]]), (value) => ({ ...value, discriminator: SET_LOCK_RELEASE_SLOT_DISCRIMINATOR })); } export function getSetLockReleaseSlotInstructionDataDecoder(): FixedSizeDecoder<SetLockReleaseSlotInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['newLockReleaseSlot', getU64Decoder()]]); } export function getSetLockReleaseSlotInstructionDataCodec(): FixedSizeCodec<SetLockReleaseSlotInstructionDataArgs, SetLockReleaseSlotInstructionData> { return combineCodec(getSetLockReleaseSlotInstructionDataEncoder(), getSetLockReleaseSlotInstructionDataDecoder()); } export type SetLockReleaseSlotInput<TAccountPosition extends string = string, TAccountLbPair extends string = string, TAccountSender extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string> = { position: Address<TAccountPosition>; lbPair: Address<TAccountLbPair>; sender: TransactionSigner<TAccountSender>; eventAuthority: Address<TAccountEventAuthority>; program: Address<TAccountProgram>; newLockReleaseSlot: SetLockReleaseSlotInstructionDataArgs["newLockReleaseSlot"]; } export function getSetLockReleaseSlotInstruction<TAccountPosition extends string, TAccountLbPair extends string, TAccountSender extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: SetLockReleaseSlotInput<TAccountPosition, TAccountLbPair, TAccountSender, TAccountEventAuthority, TAccountProgram>, config?: { programAddress?: TProgramAddress } ): SetLockReleaseSlotInstruction<TProgramAddress, TAccountPosition, TAccountLbPair, TAccountSender, TAccountEventAuthority, TAccountProgram> { // Program address. const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { position: { value: input.position ?? null, isWritable: true }, lbPair: { value: input.lbPair ?? null, isWritable: false }, sender: { value: input.sender ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? 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.position), getAccountMeta(accounts.lbPair), getAccountMeta(accounts.sender), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getSetLockReleaseSlotInstructionDataEncoder().encode(args as SetLockReleaseSlotInstructionDataArgs), programAddress } as SetLockReleaseSlotInstruction<TProgramAddress, TAccountPosition, TAccountLbPair, TAccountSender, TAccountEventAuthority, TAccountProgram>); } export type ParsedSetLockReleaseSlotInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { position: TAccountMetas[0]; lbPair: TAccountMetas[1]; sender: TAccountMetas[2]; eventAuthority: TAccountMetas[3]; program: TAccountMetas[4]; }; data: SetLockReleaseSlotInstructionData; }; export function parseSetLockReleaseSlotInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetLockReleaseSlotInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 5) { // 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: { position: getNextAccount(), lbPair: getNextAccount(), sender: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getSetLockReleaseSlotInstructionDataDecoder().decode(instruction.data) }; }