/** * 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, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, 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 { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; export const CLOSE_CLAIM_FEE_OPERATOR_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([38, 134, 82, 216, 95, 124, 17, 99]); export function getCloseClaimFeeOperatorDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_CLAIM_FEE_OPERATOR_DISCRIMINATOR, ); } export type CloseClaimFeeOperatorInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountClaimFeeOperator extends string | AccountMeta = string, TAccountRentReceiver extends string | AccountMeta = string, TAccountAdmin extends string | AccountMeta = string, TAccountEventAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountClaimFeeOperator extends string ? WritableAccount : TAccountClaimFeeOperator, TAccountRentReceiver extends string ? WritableAccount : TAccountRentReceiver, TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type CloseClaimFeeOperatorInstructionData = { discriminator: ReadonlyUint8Array; }; export type CloseClaimFeeOperatorInstructionDataArgs = {}; export function getCloseClaimFeeOperatorInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_CLAIM_FEE_OPERATOR_DISCRIMINATOR, }), ); } export function getCloseClaimFeeOperatorInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseClaimFeeOperatorInstructionDataCodec(): FixedSizeCodec< CloseClaimFeeOperatorInstructionDataArgs, CloseClaimFeeOperatorInstructionData > { return combineCodec( getCloseClaimFeeOperatorInstructionDataEncoder(), getCloseClaimFeeOperatorInstructionDataDecoder(), ); } export type CloseClaimFeeOperatorAsyncInput< TAccountClaimFeeOperator extends string = string, TAccountRentReceiver extends string = string, TAccountAdmin extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { claimFeeOperator: Address; rentReceiver: Address; admin: TransactionSigner; eventAuthority?: Address; program?: Address; }; export async function getCloseClaimFeeOperatorInstructionAsync< TAccountClaimFeeOperator extends string, TAccountRentReceiver extends string, TAccountAdmin extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CloseClaimFeeOperatorAsyncInput< TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CloseClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { claimFeeOperator: { value: input.claimFeeOperator ?? null, isWritable: true, }, rentReceiver: { value: input.rentReceiver ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.eventAuthority.value) { accounts.eventAuthority.value = await findEventAuthorityPda(); } if (!accounts.program.value) { accounts.program.value = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG" as Address<"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("claimFeeOperator", accounts.claimFeeOperator), getAccountMeta("rentReceiver", accounts.rentReceiver), getAccountMeta("admin", accounts.admin), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCloseClaimFeeOperatorInstructionDataEncoder().encode({}), programAddress, } as CloseClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram >); } export type CloseClaimFeeOperatorInput< TAccountClaimFeeOperator extends string = string, TAccountRentReceiver extends string = string, TAccountAdmin extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { claimFeeOperator: Address; rentReceiver: Address; admin: TransactionSigner; eventAuthority: Address; program?: Address; }; export function getCloseClaimFeeOperatorInstruction< TAccountClaimFeeOperator extends string, TAccountRentReceiver extends string, TAccountAdmin extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CloseClaimFeeOperatorInput< TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CloseClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { claimFeeOperator: { value: input.claimFeeOperator ?? null, isWritable: true, }, rentReceiver: { value: input.rentReceiver ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.program.value) { accounts.program.value = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG" as Address<"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("claimFeeOperator", accounts.claimFeeOperator), getAccountMeta("rentReceiver", accounts.rentReceiver), getAccountMeta("admin", accounts.admin), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCloseClaimFeeOperatorInstructionDataEncoder().encode({}), programAddress, } as CloseClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountRentReceiver, TAccountAdmin, TAccountEventAuthority, TAccountProgram >); } export type ParsedCloseClaimFeeOperatorInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { claimFeeOperator: TAccountMetas[0]; rentReceiver: TAccountMetas[1]; admin: TAccountMetas[2]; eventAuthority: TAccountMetas[3]; program: TAccountMetas[4]; }; data: CloseClaimFeeOperatorInstructionData; }; export function parseCloseClaimFeeOperatorInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseClaimFeeOperatorInstruction { 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: { claimFeeOperator: getNextAccount(), rentReceiver: getNextAccount(), admin: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getCloseClaimFeeOperatorInstructionDataDecoder().decode( instruction.data, ), }; }