UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

86 lines (69 loc) 8.09 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, 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 DELETE_POSITION_BUNDLE_DISCRIMINATOR = new Uint8Array([100, 25, 99, 2, 217, 239, 124, 173]); export function getDeletePositionBundleDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(DELETE_POSITION_BUNDLE_DISCRIMINATOR); } export type DeletePositionBundleInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountPositionBundle extends string | AccountMeta<string> = string, TAccountPositionBundleMint extends string | AccountMeta<string> = string, TAccountPositionBundleTokenAccount extends string | AccountMeta<string> = string, TAccountPositionBundleOwner extends string | AccountMeta<string> = string, TAccountReceiver extends string | AccountMeta<string> = string, TAccountTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPositionBundle extends string ? WritableAccount<TAccountPositionBundle> : TAccountPositionBundle, TAccountPositionBundleMint extends string ? WritableAccount<TAccountPositionBundleMint> : TAccountPositionBundleMint, TAccountPositionBundleTokenAccount extends string ? WritableAccount<TAccountPositionBundleTokenAccount> : TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner extends string ? ReadonlySignerAccount<TAccountPositionBundleOwner> & AccountSignerMeta<TAccountPositionBundleOwner> : TAccountPositionBundleOwner, TAccountReceiver extends string ? WritableAccount<TAccountReceiver> : TAccountReceiver, TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram, ...TRemainingAccounts]>; export type DeletePositionBundleInstructionData = { discriminator: ReadonlyUint8Array; }; export type DeletePositionBundleInstructionDataArgs = { }; export function getDeletePositionBundleInstructionDataEncoder(): FixedSizeEncoder<DeletePositionBundleInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: DELETE_POSITION_BUNDLE_DISCRIMINATOR })); } export function getDeletePositionBundleInstructionDataDecoder(): FixedSizeDecoder<DeletePositionBundleInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getDeletePositionBundleInstructionDataCodec(): FixedSizeCodec<DeletePositionBundleInstructionDataArgs, DeletePositionBundleInstructionData> { return combineCodec(getDeletePositionBundleInstructionDataEncoder(), getDeletePositionBundleInstructionDataDecoder()); } export type DeletePositionBundleInput<TAccountPositionBundle extends string = string, TAccountPositionBundleMint extends string = string, TAccountPositionBundleTokenAccount extends string = string, TAccountPositionBundleOwner extends string = string, TAccountReceiver extends string = string, TAccountTokenProgram extends string = string> = { positionBundle: Address<TAccountPositionBundle>; positionBundleMint: Address<TAccountPositionBundleMint>; positionBundleTokenAccount: Address<TAccountPositionBundleTokenAccount>; positionBundleOwner: TransactionSigner<TAccountPositionBundleOwner>; receiver: Address<TAccountReceiver>; tokenProgram?: Address<TAccountTokenProgram>; } export function getDeletePositionBundleInstruction<TAccountPositionBundle extends string, TAccountPositionBundleMint extends string, TAccountPositionBundleTokenAccount extends string, TAccountPositionBundleOwner extends string, TAccountReceiver extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: DeletePositionBundleInput<TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountReceiver, TAccountTokenProgram>, config?: { programAddress?: TProgramAddress } ): DeletePositionBundleInstruction<TProgramAddress, TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountReceiver, TAccountTokenProgram> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { positionBundle: { value: input.positionBundle ?? null, isWritable: true }, positionBundleMint: { value: input.positionBundleMint ?? null, isWritable: true }, positionBundleTokenAccount: { value: input.positionBundleTokenAccount ?? null, isWritable: true }, positionBundleOwner: { value: input.positionBundleOwner ?? null, isWritable: false }, receiver: { value: input.receiver ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.positionBundle), getAccountMeta(accounts.positionBundleMint), getAccountMeta(accounts.positionBundleTokenAccount), getAccountMeta(accounts.positionBundleOwner), getAccountMeta(accounts.receiver), getAccountMeta(accounts.tokenProgram)], data: getDeletePositionBundleInstructionDataEncoder().encode({}), programAddress } as DeletePositionBundleInstruction<TProgramAddress, TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountReceiver, TAccountTokenProgram>); } export type ParsedDeletePositionBundleInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { positionBundle: TAccountMetas[0]; positionBundleMint: TAccountMetas[1]; positionBundleTokenAccount: TAccountMetas[2]; positionBundleOwner: TAccountMetas[3]; receiver: TAccountMetas[4]; tokenProgram: TAccountMetas[5]; }; data: DeletePositionBundleInstructionData; }; export function parseDeletePositionBundleInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedDeletePositionBundleInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 6) { // 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: { positionBundle: getNextAccount(), positionBundleMint: getNextAccount(), positionBundleTokenAccount: getNextAccount(), positionBundleOwner: getNextAccount(), receiver: getNextAccount(), tokenProgram: getNextAccount() }, data: getDeletePositionBundleInstructionDataDecoder().decode(instruction.data) }; }