/** * 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 Codec, type Decoder, type Encoder, 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 { getStaticConfigParametersDecoder, getStaticConfigParametersEncoder, type StaticConfigParameters, type StaticConfigParametersArgs, } from "../types/index.js"; export const CREATE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 201, 207, 243, 114, 75, 111, 47, 189, ]); export function getCreateConfigDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CREATE_CONFIG_DISCRIMINATOR, ); } export type CreateConfigInstruction< 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 CreateConfigInstructionData = { discriminator: ReadonlyUint8Array; index: bigint; configParameters: StaticConfigParameters; }; export type CreateConfigInstructionDataArgs = { index: number | bigint; configParameters: StaticConfigParametersArgs; }; export function getCreateConfigInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["index", getU64Encoder()], ["configParameters", getStaticConfigParametersEncoder()], ]), (value) => ({ ...value, discriminator: CREATE_CONFIG_DISCRIMINATOR }), ); } export function getCreateConfigInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["index", getU64Decoder()], ["configParameters", getStaticConfigParametersDecoder()], ]); } export function getCreateConfigInstructionDataCodec(): Codec< CreateConfigInstructionDataArgs, CreateConfigInstructionData > { return combineCodec( getCreateConfigInstructionDataEncoder(), getCreateConfigInstructionDataDecoder(), ); } export type CreateConfigAsyncInput< 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: CreateConfigInstructionDataArgs["index"]; configParameters: CreateConfigInstructionDataArgs["configParameters"]; }; /** * ADMIN FUNCTIONS ///// */ export async function getCreateConfigInstructionAsync< TAccountConfig extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateConfigAsyncInput< TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CreateConfigInstruction< 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: getCreateConfigInstructionDataEncoder().encode( args as CreateConfigInstructionDataArgs, ), programAddress, } as CreateConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type CreateConfigInput< 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: CreateConfigInstructionDataArgs["index"]; configParameters: CreateConfigInstructionDataArgs["configParameters"]; }; /** * ADMIN FUNCTIONS ///// */ export function getCreateConfigInstruction< TAccountConfig extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateConfigInput< TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CreateConfigInstruction< 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: getCreateConfigInstructionDataEncoder().encode( args as CreateConfigInstructionDataArgs, ), programAddress, } as CreateConfigInstruction< TProgramAddress, TAccountConfig, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type ParsedCreateConfigInstruction< 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: CreateConfigInstructionData; }; export function parseCreateConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCreateConfigInstruction { 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: getCreateConfigInstructionDataDecoder().decode(instruction.data), }; }