UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

80 lines (60 loc) 5.32 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, getU8Decoder, getU8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { AMM_V3_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const UPDATE_POOL_STATUS_DISCRIMINATOR = new Uint8Array([130, 87, 108, 6, 46, 224, 117, 123]); export function getUpdatePoolStatusDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_POOL_STATUS_DISCRIMINATOR); } export type UpdatePoolStatusInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountPoolState extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority> : TAccountAuthority, TAccountPoolState extends string ? WritableAccount<TAccountPoolState> : TAccountPoolState, ...TRemainingAccounts]>; export type UpdatePoolStatusInstructionData = { discriminator: ReadonlyUint8Array; status: number; }; export type UpdatePoolStatusInstructionDataArgs = { status: number; }; export function getUpdatePoolStatusInstructionDataEncoder(): FixedSizeEncoder<UpdatePoolStatusInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['status', getU8Encoder()]]), (value) => ({ ...value, discriminator: UPDATE_POOL_STATUS_DISCRIMINATOR })); } export function getUpdatePoolStatusInstructionDataDecoder(): FixedSizeDecoder<UpdatePoolStatusInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['status', getU8Decoder()]]); } export function getUpdatePoolStatusInstructionDataCodec(): FixedSizeCodec<UpdatePoolStatusInstructionDataArgs, UpdatePoolStatusInstructionData> { return combineCodec(getUpdatePoolStatusInstructionDataEncoder(), getUpdatePoolStatusInstructionDataDecoder()); } export type UpdatePoolStatusInput<TAccountAuthority extends string = string, TAccountPoolState extends string = string> = { authority: TransactionSigner<TAccountAuthority>; poolState: Address<TAccountPoolState>; status: UpdatePoolStatusInstructionDataArgs["status"]; } export function getUpdatePoolStatusInstruction<TAccountAuthority extends string, TAccountPoolState extends string, TProgramAddress extends Address = typeof AMM_V3_PROGRAM_ADDRESS>(input: UpdatePoolStatusInput<TAccountAuthority, TAccountPoolState>, config?: { programAddress?: TProgramAddress } ): UpdatePoolStatusInstruction<TProgramAddress, TAccountAuthority, TAccountPoolState> { // Program address. const programAddress = config?.programAddress ?? AMM_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: false }, poolState: { value: input.poolState ?? null, isWritable: true } } 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.authority), getAccountMeta(accounts.poolState)], data: getUpdatePoolStatusInstructionDataEncoder().encode(args as UpdatePoolStatusInstructionDataArgs), programAddress } as UpdatePoolStatusInstruction<TProgramAddress, TAccountAuthority, TAccountPoolState>); } export type ParsedUpdatePoolStatusInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { authority: TAccountMetas[0]; poolState: TAccountMetas[1]; }; data: UpdatePoolStatusInstructionData; }; export function parseUpdatePoolStatusInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdatePoolStatusInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 2) { // 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: { authority: getNextAccount(), poolState: getNextAccount() }, data: getUpdatePoolStatusInstructionDataDecoder().decode(instruction.data) }; }