/** * 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 ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } 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_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 145, 9, 72, 157, 95, 125, 61, 85, ]); export function getCloseConfigDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_CONFIG_DISCRIMINATOR, ); } export type CloseConfigInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountConfig extends string | AccountMeta = string, TAccountAdmin extends string | AccountMeta = string, TAccountRentReceiver extends string | AccountMeta = string, TAccountEventAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountConfig extends string ? WritableAccount : TAccountConfig, TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountRentReceiver extends string ? WritableAccount : TAccountRentReceiver, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type CloseConfigInstructionData = { discriminator: ReadonlyUint8Array }; export type CloseConfigInstructionDataArgs = {}; export function getCloseConfigInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_CONFIG_DISCRIMINATOR }), ); } export function getCloseConfigInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseConfigInstructionDataCodec(): FixedSizeCodec< CloseConfigInstructionDataArgs, CloseConfigInstructionData > { return combineCodec( getCloseConfigInstructionDataEncoder(), getCloseConfigInstructionDataDecoder(), ); } export type CloseConfigAsyncInput< TAccountConfig extends string = string, TAccountAdmin extends string = string, TAccountRentReceiver extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { config: Address; admin: TransactionSigner; rentReceiver: Address; eventAuthority?: Address; program?: Address; }; export async function getCloseConfigInstructionAsync< TAccountConfig extends string, TAccountAdmin extends string, TAccountRentReceiver extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CloseConfigAsyncInput< TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CloseConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { config: { value: input.config ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, rentReceiver: { value: input.rentReceiver ?? null, isWritable: true }, 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("config", accounts.config), getAccountMeta("admin", accounts.admin), getAccountMeta("rentReceiver", accounts.rentReceiver), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCloseConfigInstructionDataEncoder().encode({}), programAddress, } as CloseConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram >); } export type CloseConfigInput< TAccountConfig extends string = string, TAccountAdmin extends string = string, TAccountRentReceiver extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { config: Address; admin: TransactionSigner; rentReceiver: Address; eventAuthority: Address; program?: Address; }; export function getCloseConfigInstruction< TAccountConfig extends string, TAccountAdmin extends string, TAccountRentReceiver extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CloseConfigInput< TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CloseConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { config: { value: input.config ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, rentReceiver: { value: input.rentReceiver ?? null, isWritable: true }, 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("config", accounts.config), getAccountMeta("admin", accounts.admin), getAccountMeta("rentReceiver", accounts.rentReceiver), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCloseConfigInstructionDataEncoder().encode({}), programAddress, } as CloseConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountRentReceiver, TAccountEventAuthority, TAccountProgram >); } export type ParsedCloseConfigInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { config: TAccountMetas[0]; admin: TAccountMetas[1]; rentReceiver: TAccountMetas[2]; eventAuthority: TAccountMetas[3]; program: TAccountMetas[4]; }; data: CloseConfigInstructionData; }; export function parseCloseConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseConfigInstruction { 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: { config: getNextAccount(), admin: getNextAccount(), rentReceiver: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getCloseConfigInstructionDataDecoder().decode(instruction.data), }; }