/** * 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, getU8Decoder, getU8Encoder, 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 SET_POOL_STATUS_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [112, 87, 135, 223, 83, 204, 132, 53], ); export function getSetPoolStatusDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_POOL_STATUS_DISCRIMINATOR, ); } export type SetPoolStatusInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountPool 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< [ TAccountPool extends string ? WritableAccount : TAccountPool, TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type SetPoolStatusInstructionData = { discriminator: ReadonlyUint8Array; status: number; }; export type SetPoolStatusInstructionDataArgs = { status: number }; export function getSetPoolStatusInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["status", getU8Encoder()], ]), (value) => ({ ...value, discriminator: SET_POOL_STATUS_DISCRIMINATOR }), ); } export function getSetPoolStatusInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["status", getU8Decoder()], ]); } export function getSetPoolStatusInstructionDataCodec(): FixedSizeCodec< SetPoolStatusInstructionDataArgs, SetPoolStatusInstructionData > { return combineCodec( getSetPoolStatusInstructionDataEncoder(), getSetPoolStatusInstructionDataDecoder(), ); } export type SetPoolStatusAsyncInput< TAccountPool extends string = string, TAccountAdmin extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; admin: TransactionSigner; eventAuthority?: Address; program?: Address; status: SetPoolStatusInstructionDataArgs["status"]; }; export async function getSetPoolStatusInstructionAsync< TAccountPool extends string, TAccountAdmin extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: SetPoolStatusAsyncInput< TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< SetPoolStatusInstruction< TProgramAddress, TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pool: { value: input.pool ?? 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 >; // Original args. const args = { ...input }; // 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("pool", accounts.pool), getAccountMeta("admin", accounts.admin), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getSetPoolStatusInstructionDataEncoder().encode( args as SetPoolStatusInstructionDataArgs, ), programAddress, } as SetPoolStatusInstruction< TProgramAddress, TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram >); } export type SetPoolStatusInput< TAccountPool extends string = string, TAccountAdmin extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; admin: TransactionSigner; eventAuthority: Address; program?: Address; status: SetPoolStatusInstructionDataArgs["status"]; }; export function getSetPoolStatusInstruction< TAccountPool extends string, TAccountAdmin extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: SetPoolStatusInput< TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): SetPoolStatusInstruction< TProgramAddress, TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pool: { value: input.pool ?? 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 >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.program.value) { accounts.program.value = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG" as Address<"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pool", accounts.pool), getAccountMeta("admin", accounts.admin), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getSetPoolStatusInstructionDataEncoder().encode( args as SetPoolStatusInstructionDataArgs, ), programAddress, } as SetPoolStatusInstruction< TProgramAddress, TAccountPool, TAccountAdmin, TAccountEventAuthority, TAccountProgram >); } export type ParsedSetPoolStatusInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { pool: TAccountMetas[0]; admin: TAccountMetas[1]; eventAuthority: TAccountMetas[2]; program: TAccountMetas[3]; }; data: SetPoolStatusInstructionData; }; export function parseSetPoolStatusInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetPoolStatusInstruction { if (instruction.accounts.length < 4) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { pool: getNextAccount(), admin: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getSetPoolStatusInstructionDataDecoder().decode(instruction.data), }; }