/** * 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, Codec, Decoder, Encoder, Instruction, InstructionWithAccounts, InstructionWithData, Option, OptionOrNullable, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import type { RemainingAccountsInfo, RemainingAccountsInfoArgs, } from "../types/index.js"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, 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"; import { getRemainingAccountsInfoDecoder, getRemainingAccountsInfoEncoder, } from "../types/index.js"; export const COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([103, 128, 222, 134, 114, 200, 22, 200]); export function getCollectProtocolFeesV2DiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR, ); } export type CollectProtocolFeesV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta = string, TAccountWhirlpool extends string | AccountMeta = string, TAccountCollectProtocolFeesAuthority extends string | AccountMeta = string, TAccountTokenMintA extends string | AccountMeta = string, TAccountTokenMintB extends string | AccountMeta = string, TAccountTokenVaultA extends string | AccountMeta = string, TAccountTokenVaultB extends string | AccountMeta = string, TAccountTokenDestinationA extends string | AccountMeta = string, TAccountTokenDestinationB extends string | AccountMeta = string, TAccountTokenProgramA extends string | AccountMeta = string, TAccountTokenProgramB extends string | AccountMeta = string, TAccountMemoProgram extends | string | AccountMeta = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpoolsConfig extends string ? ReadonlyAccount : TAccountWhirlpoolsConfig, TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountCollectProtocolFeesAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountCollectProtocolFeesAuthority, TAccountTokenMintA extends string ? ReadonlyAccount : TAccountTokenMintA, TAccountTokenMintB extends string ? ReadonlyAccount : TAccountTokenMintB, TAccountTokenVaultA extends string ? WritableAccount : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount : TAccountTokenVaultB, TAccountTokenDestinationA extends string ? WritableAccount : TAccountTokenDestinationA, TAccountTokenDestinationB extends string ? WritableAccount : TAccountTokenDestinationB, TAccountTokenProgramA extends string ? ReadonlyAccount : TAccountTokenProgramA, TAccountTokenProgramB extends string ? ReadonlyAccount : TAccountTokenProgramB, TAccountMemoProgram extends string ? ReadonlyAccount : TAccountMemoProgram, ...TRemainingAccounts, ] >; export interface CollectProtocolFeesV2InstructionData { discriminator: ReadonlyUint8Array; remainingAccountsInfo: Option; } export interface CollectProtocolFeesV2InstructionDataArgs { remainingAccountsInfo: OptionOrNullable; } export function getCollectProtocolFeesV2InstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], [ "remainingAccountsInfo", getOptionEncoder(getRemainingAccountsInfoEncoder()), ], ]), (value) => ({ ...value, discriminator: COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR, }), ); } export function getCollectProtocolFeesV2InstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], [ "remainingAccountsInfo", getOptionDecoder(getRemainingAccountsInfoDecoder()), ], ]); } export function getCollectProtocolFeesV2InstructionDataCodec(): Codec< CollectProtocolFeesV2InstructionDataArgs, CollectProtocolFeesV2InstructionData > { return combineCodec( getCollectProtocolFeesV2InstructionDataEncoder(), getCollectProtocolFeesV2InstructionDataDecoder(), ); } export interface CollectProtocolFeesV2Input< TAccountWhirlpoolsConfig extends string = string, TAccountWhirlpool extends string = string, TAccountCollectProtocolFeesAuthority extends string = string, TAccountTokenMintA extends string = string, TAccountTokenMintB extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountTokenDestinationA extends string = string, TAccountTokenDestinationB extends string = string, TAccountTokenProgramA extends string = string, TAccountTokenProgramB extends string = string, TAccountMemoProgram extends string = string, > { whirlpoolsConfig: Address; whirlpool: Address; collectProtocolFeesAuthority: TransactionSigner; tokenMintA: Address; tokenMintB: Address; tokenVaultA: Address; tokenVaultB: Address; tokenDestinationA: Address; tokenDestinationB: Address; tokenProgramA: Address; tokenProgramB: Address; memoProgram?: Address; remainingAccountsInfo: CollectProtocolFeesV2InstructionDataArgs["remainingAccountsInfo"]; } export function getCollectProtocolFeesV2Instruction< TAccountWhirlpoolsConfig extends string, TAccountWhirlpool extends string, TAccountCollectProtocolFeesAuthority extends string, TAccountTokenMintA extends string, TAccountTokenMintB extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountTokenDestinationA extends string, TAccountTokenDestinationB extends string, TAccountTokenProgramA extends string, TAccountTokenProgramB extends string, TAccountMemoProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: CollectProtocolFeesV2Input< TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram >, config?: { programAddress?: TProgramAddress }, ): CollectProtocolFeesV2Instruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram > { // 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, }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? 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, }, tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.memoProgram.value) { accounts.memoProgram.value = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" as Address<"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpoolsConfig", accounts.whirlpoolsConfig), getAccountMeta("whirlpool", accounts.whirlpool), getAccountMeta( "collectProtocolFeesAuthority", accounts.collectProtocolFeesAuthority, ), getAccountMeta("tokenMintA", accounts.tokenMintA), getAccountMeta("tokenMintB", accounts.tokenMintB), getAccountMeta("tokenVaultA", accounts.tokenVaultA), getAccountMeta("tokenVaultB", accounts.tokenVaultB), getAccountMeta("tokenDestinationA", accounts.tokenDestinationA), getAccountMeta("tokenDestinationB", accounts.tokenDestinationB), getAccountMeta("tokenProgramA", accounts.tokenProgramA), getAccountMeta("tokenProgramB", accounts.tokenProgramB), getAccountMeta("memoProgram", accounts.memoProgram), ], data: getCollectProtocolFeesV2InstructionDataEncoder().encode( args as CollectProtocolFeesV2InstructionDataArgs, ), programAddress, } as CollectProtocolFeesV2Instruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram >); } export interface ParsedCollectProtocolFeesV2Instruction< 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]; tokenMintA: TAccountMetas[3]; tokenMintB: TAccountMetas[4]; tokenVaultA: TAccountMetas[5]; tokenVaultB: TAccountMetas[6]; tokenDestinationA: TAccountMetas[7]; tokenDestinationB: TAccountMetas[8]; tokenProgramA: TAccountMetas[9]; tokenProgramB: TAccountMetas[10]; memoProgram: TAccountMetas[11]; }; data: CollectProtocolFeesV2InstructionData; } export function parseCollectProtocolFeesV2Instruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCollectProtocolFeesV2Instruction { if (instruction.accounts.length < 12) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 12, }, ); } 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(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tokenDestinationA: getNextAccount(), tokenDestinationB: getNextAccount(), tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), memoProgram: getNextAccount(), }, data: getCollectProtocolFeesV2InstructionDataDecoder().decode( instruction.data, ), }; }