/** * 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 type { AccountMeta, AccountSignerMeta, Address, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, Instruction, InstructionWithAccounts, InstructionWithData, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, } from "@solana/kit"; import { getAccountMetaFactory } from "@solana/program-client-core"; import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; export const CLOSE_BUNDLED_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([41, 36, 216, 245, 27, 85, 103, 67]); export function getCloseBundledPositionDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_BUNDLED_POSITION_DISCRIMINATOR, ); } export type CloseBundledPositionInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountBundledPosition extends string | AccountMeta = string, TAccountPositionBundle extends string | AccountMeta = string, TAccountPositionBundleTokenAccount extends string | AccountMeta = string, TAccountPositionBundleAuthority extends string | AccountMeta = string, TAccountReceiver extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountBundledPosition extends string ? WritableAccount : TAccountBundledPosition, TAccountPositionBundle extends string ? WritableAccount : TAccountPositionBundle, TAccountPositionBundleTokenAccount extends string ? ReadonlyAccount : TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPositionBundleAuthority, TAccountReceiver extends string ? WritableAccount : TAccountReceiver, ...TRemainingAccounts, ] >; export interface CloseBundledPositionInstructionData { discriminator: ReadonlyUint8Array; bundleIndex: number; } export interface CloseBundledPositionInstructionDataArgs { bundleIndex: number; } export function getCloseBundledPositionInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["bundleIndex", getU16Encoder()], ]), (value) => ({ ...value, discriminator: CLOSE_BUNDLED_POSITION_DISCRIMINATOR, }), ); } export function getCloseBundledPositionInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["bundleIndex", getU16Decoder()], ]); } export function getCloseBundledPositionInstructionDataCodec(): FixedSizeCodec< CloseBundledPositionInstructionDataArgs, CloseBundledPositionInstructionData > { return combineCodec( getCloseBundledPositionInstructionDataEncoder(), getCloseBundledPositionInstructionDataDecoder(), ); } export interface CloseBundledPositionInput< TAccountBundledPosition extends string = string, TAccountPositionBundle extends string = string, TAccountPositionBundleTokenAccount extends string = string, TAccountPositionBundleAuthority extends string = string, TAccountReceiver extends string = string, > { bundledPosition: Address; positionBundle: Address; positionBundleTokenAccount: Address; positionBundleAuthority: TransactionSigner; receiver: Address; bundleIndex: CloseBundledPositionInstructionDataArgs["bundleIndex"]; } export function getCloseBundledPositionInstruction< TAccountBundledPosition extends string, TAccountPositionBundle extends string, TAccountPositionBundleTokenAccount extends string, TAccountPositionBundleAuthority extends string, TAccountReceiver extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: CloseBundledPositionInput< TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountReceiver >, config?: { programAddress?: TProgramAddress }, ): CloseBundledPositionInstruction< TProgramAddress, TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountReceiver > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { bundledPosition: { value: input.bundledPosition ?? null, isWritable: true }, positionBundle: { value: input.positionBundle ?? null, isWritable: true }, positionBundleTokenAccount: { value: input.positionBundleTokenAccount ?? null, isWritable: false, }, positionBundleAuthority: { value: input.positionBundleAuthority ?? null, isWritable: false, }, receiver: { value: input.receiver ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("bundledPosition", accounts.bundledPosition), getAccountMeta("positionBundle", accounts.positionBundle), getAccountMeta( "positionBundleTokenAccount", accounts.positionBundleTokenAccount, ), getAccountMeta( "positionBundleAuthority", accounts.positionBundleAuthority, ), getAccountMeta("receiver", accounts.receiver), ], data: getCloseBundledPositionInstructionDataEncoder().encode( args as CloseBundledPositionInstructionDataArgs, ), programAddress, } as CloseBundledPositionInstruction< TProgramAddress, TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountReceiver >); } export interface ParsedCloseBundledPositionInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { bundledPosition: TAccountMetas[0]; positionBundle: TAccountMetas[1]; positionBundleTokenAccount: TAccountMetas[2]; positionBundleAuthority: TAccountMetas[3]; receiver: TAccountMetas[4]; }; data: CloseBundledPositionInstructionData; } export function parseCloseBundledPositionInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseBundledPositionInstruction { if (instruction.accounts.length < 5) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { bundledPosition: getNextAccount(), positionBundle: getNextAccount(), positionBundleTokenAccount: getNextAccount(), positionBundleAuthority: getNextAccount(), receiver: getNextAccount(), }, data: getCloseBundledPositionInstructionDataDecoder().decode( instruction.data, ), }; }