/** * 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, 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 COLLECT_PROTOCOL_FEES_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([22, 67, 23, 98, 150, 178, 70, 220]); export function getCollectProtocolFeesDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( COLLECT_PROTOCOL_FEES_DISCRIMINATOR, ); } export type CollectProtocolFeesInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta = string, TAccountWhirlpool extends string | AccountMeta = string, TAccountCollectProtocolFeesAuthority extends string | AccountMeta = string, TAccountTokenVaultA extends string | AccountMeta = string, TAccountTokenVaultB extends string | AccountMeta = string, TAccountTokenDestinationA extends string | AccountMeta = string, TAccountTokenDestinationB extends string | AccountMeta = string, TAccountTokenProgram extends | string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpoolsConfig extends string ? ReadonlyAccount : TAccountWhirlpoolsConfig, TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountCollectProtocolFeesAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA extends string ? WritableAccount : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount : TAccountTokenVaultB, TAccountTokenDestinationA extends string ? WritableAccount : TAccountTokenDestinationA, TAccountTokenDestinationB extends string ? WritableAccount : TAccountTokenDestinationB, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, ...TRemainingAccounts, ] >; export interface CollectProtocolFeesInstructionData { discriminator: ReadonlyUint8Array; } export type CollectProtocolFeesInstructionDataArgs = {}; export function getCollectProtocolFeesInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: COLLECT_PROTOCOL_FEES_DISCRIMINATOR, }), ); } export function getCollectProtocolFeesInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCollectProtocolFeesInstructionDataCodec(): FixedSizeCodec< CollectProtocolFeesInstructionDataArgs, CollectProtocolFeesInstructionData > { return combineCodec( getCollectProtocolFeesInstructionDataEncoder(), getCollectProtocolFeesInstructionDataDecoder(), ); } export interface CollectProtocolFeesInput< TAccountWhirlpoolsConfig extends string = string, TAccountWhirlpool extends string = string, TAccountCollectProtocolFeesAuthority extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountTokenDestinationA extends string = string, TAccountTokenDestinationB extends string = string, TAccountTokenProgram extends string = string, > { whirlpoolsConfig: Address; whirlpool: Address; collectProtocolFeesAuthority: TransactionSigner; tokenVaultA: Address; tokenVaultB: Address; tokenDestinationA: Address; tokenDestinationB: Address; tokenProgram?: Address; } export function getCollectProtocolFeesInstruction< TAccountWhirlpoolsConfig extends string, TAccountWhirlpool extends string, TAccountCollectProtocolFeesAuthority extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountTokenDestinationA extends string, TAccountTokenDestinationB extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: CollectProtocolFeesInput< TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram >, config?: { programAddress?: TProgramAddress }, ): CollectProtocolFeesInstruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false, }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, collectProtocolFeesAuthority: { value: input.collectProtocolFeesAuthority ?? null, isWritable: false, }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, tokenDestinationA: { value: input.tokenDestinationA ?? null, isWritable: true, }, tokenDestinationB: { value: input.tokenDestinationB ?? null, isWritable: true, }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpoolsConfig", accounts.whirlpoolsConfig), getAccountMeta("whirlpool", accounts.whirlpool), getAccountMeta( "collectProtocolFeesAuthority", accounts.collectProtocolFeesAuthority, ), getAccountMeta("tokenVaultA", accounts.tokenVaultA), getAccountMeta("tokenVaultB", accounts.tokenVaultB), getAccountMeta("tokenDestinationA", accounts.tokenDestinationA), getAccountMeta("tokenDestinationB", accounts.tokenDestinationB), getAccountMeta("tokenProgram", accounts.tokenProgram), ], data: getCollectProtocolFeesInstructionDataEncoder().encode({}), programAddress, } as CollectProtocolFeesInstruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram >); } export interface ParsedCollectProtocolFeesInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpoolsConfig: TAccountMetas[0]; whirlpool: TAccountMetas[1]; collectProtocolFeesAuthority: TAccountMetas[2]; tokenVaultA: TAccountMetas[3]; tokenVaultB: TAccountMetas[4]; tokenDestinationA: TAccountMetas[5]; tokenDestinationB: TAccountMetas[6]; tokenProgram: TAccountMetas[7]; }; data: CollectProtocolFeesInstructionData; } export function parseCollectProtocolFeesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCollectProtocolFeesInstruction { if (instruction.accounts.length < 8) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { whirlpoolsConfig: getNextAccount(), whirlpool: getNextAccount(), collectProtocolFeesAuthority: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tokenDestinationA: getNextAccount(), tokenDestinationB: getNextAccount(), tokenProgram: getNextAccount(), }, data: getCollectProtocolFeesInstructionDataDecoder().decode( instruction.data, ), }; }