/** * 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, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, 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, getNonNullResolvedInstructionInput, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; import { getDynamicConfigParametersDecoder, getDynamicConfigParametersEncoder, type DynamicConfigParameters, type DynamicConfigParametersArgs, } from "../types/index.js"; export const CREATE_DYNAMIC_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([81, 251, 122, 78, 66, 57, 208, 82]); export function getCreateDynamicConfigDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CREATE_DYNAMIC_CONFIG_DISCRIMINATOR, ); } export type CreateDynamicConfigInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountConfig extends string | AccountMeta = string, TAccountAdmin extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", 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, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type CreateDynamicConfigInstructionData = { discriminator: ReadonlyUint8Array; index: bigint; configParameters: DynamicConfigParameters; }; export type CreateDynamicConfigInstructionDataArgs = { index: number | bigint; configParameters: DynamicConfigParametersArgs; }; export function getCreateDynamicConfigInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["index", getU64Encoder()], ["configParameters", getDynamicConfigParametersEncoder()], ]), (value) => ({ ...value, discriminator: CREATE_DYNAMIC_CONFIG_DISCRIMINATOR, }), ); } export function getCreateDynamicConfigInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["index", getU64Decoder()], ["configParameters", getDynamicConfigParametersDecoder()], ]); } export function getCreateDynamicConfigInstructionDataCodec(): FixedSizeCodec< CreateDynamicConfigInstructionDataArgs, CreateDynamicConfigInstructionData > { return combineCodec( getCreateDynamicConfigInstructionDataEncoder(), getCreateDynamicConfigInstructionDataDecoder(), ); } export type CreateDynamicConfigAsyncInput< TAccountConfig extends string = string, TAccountAdmin extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { config?: Address; admin: TransactionSigner; systemProgram?: Address; eventAuthority?: Address; program?: Address; index: CreateDynamicConfigInstructionDataArgs["index"]; configParameters: CreateDynamicConfigInstructionDataArgs["configParameters"]; }; export async function getCreateDynamicConfigInstructionAsync< TAccountConfig extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateDynamicConfigAsyncInput< TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CreateDynamicConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, 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 }, systemProgram: { value: input.systemProgram ?? 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.config.value) { accounts.config.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])), getU64Encoder().encode( getNonNullResolvedInstructionInput("index", args.index), ), ], }); } if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreateDynamicConfigInstructionDataEncoder().encode( args as CreateDynamicConfigInstructionDataArgs, ), programAddress, } as CreateDynamicConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type CreateDynamicConfigInput< TAccountConfig extends string = string, TAccountAdmin extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { config: Address; admin: TransactionSigner; systemProgram?: Address; eventAuthority: Address; program?: Address; index: CreateDynamicConfigInstructionDataArgs["index"]; configParameters: CreateDynamicConfigInstructionDataArgs["configParameters"]; }; export function getCreateDynamicConfigInstruction< TAccountConfig extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateDynamicConfigInput< TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CreateDynamicConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, 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 }, systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreateDynamicConfigInstructionDataEncoder().encode( args as CreateDynamicConfigInstructionDataArgs, ), programAddress, } as CreateDynamicConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type ParsedCreateDynamicConfigInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { config: TAccountMetas[0]; admin: TAccountMetas[1]; systemProgram: TAccountMetas[2]; eventAuthority: TAccountMetas[3]; program: TAccountMetas[4]; }; data: CreateDynamicConfigInstructionData; }; export function parseCreateDynamicConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCreateDynamicConfigInstruction { 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(), systemProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getCreateDynamicConfigInstructionDataDecoder().decode( instruction.data, ), }; }