/** * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; export const CREATE_CLAIM_FEE_OPERATOR_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([169, 62, 207, 107, 58, 187, 162, 109]); export function getCreateClaimFeeOperatorDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CREATE_CLAIM_FEE_OPERATOR_DISCRIMINATOR, ); } export type CreateClaimFeeOperatorInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountClaimFeeOperator extends string | AccountMeta = string, TAccountOperator 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< [ TAccountClaimFeeOperator extends string ? WritableAccount : TAccountClaimFeeOperator, TAccountOperator extends string ? ReadonlyAccount : TAccountOperator, TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type CreateClaimFeeOperatorInstructionData = { discriminator: ReadonlyUint8Array; }; export type CreateClaimFeeOperatorInstructionDataArgs = {}; export function getCreateClaimFeeOperatorInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CREATE_CLAIM_FEE_OPERATOR_DISCRIMINATOR, }), ); } export function getCreateClaimFeeOperatorInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCreateClaimFeeOperatorInstructionDataCodec(): FixedSizeCodec< CreateClaimFeeOperatorInstructionDataArgs, CreateClaimFeeOperatorInstructionData > { return combineCodec( getCreateClaimFeeOperatorInstructionDataEncoder(), getCreateClaimFeeOperatorInstructionDataDecoder(), ); } export type CreateClaimFeeOperatorAsyncInput< TAccountClaimFeeOperator extends string = string, TAccountOperator extends string = string, TAccountAdmin extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { claimFeeOperator?: Address; operator: Address; admin: TransactionSigner; systemProgram?: Address; eventAuthority?: Address; program?: Address; }; export async function getCreateClaimFeeOperatorInstructionAsync< TAccountClaimFeeOperator extends string, TAccountOperator extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateClaimFeeOperatorAsyncInput< TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CreateClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { claimFeeOperator: { value: input.claimFeeOperator ?? null, isWritable: true, }, operator: { value: input.operator ?? null, isWritable: false }, 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 >; // Resolve default values. if (!accounts.claimFeeOperator.value) { accounts.claimFeeOperator.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([99, 102, 95, 111, 112, 101, 114, 97, 116, 111, 114]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( "operator", accounts.operator.value, ), ), ], }); } 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("claimFeeOperator", accounts.claimFeeOperator), getAccountMeta("operator", accounts.operator), getAccountMeta("admin", accounts.admin), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreateClaimFeeOperatorInstructionDataEncoder().encode({}), programAddress, } as CreateClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type CreateClaimFeeOperatorInput< TAccountClaimFeeOperator extends string = string, TAccountOperator extends string = string, TAccountAdmin extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { claimFeeOperator: Address; operator: Address; admin: TransactionSigner; systemProgram?: Address; eventAuthority: Address; program?: Address; }; export function getCreateClaimFeeOperatorInstruction< TAccountClaimFeeOperator extends string, TAccountOperator extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreateClaimFeeOperatorInput< TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CreateClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { claimFeeOperator: { value: input.claimFeeOperator ?? null, isWritable: true, }, operator: { value: input.operator ?? null, isWritable: false }, 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 >; // 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("claimFeeOperator", accounts.claimFeeOperator), getAccountMeta("operator", accounts.operator), getAccountMeta("admin", accounts.admin), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreateClaimFeeOperatorInstructionDataEncoder().encode({}), programAddress, } as CreateClaimFeeOperatorInstruction< TProgramAddress, TAccountClaimFeeOperator, TAccountOperator, TAccountAdmin, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type ParsedCreateClaimFeeOperatorInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { claimFeeOperator: TAccountMetas[0]; operator: TAccountMetas[1]; admin: TAccountMetas[2]; systemProgram: TAccountMetas[3]; eventAuthority: TAccountMetas[4]; program: TAccountMetas[5]; }; data: CreateClaimFeeOperatorInstructionData; }; export function parseCreateClaimFeeOperatorInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCreateClaimFeeOperatorInstruction { if (instruction.accounts.length < 6) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { claimFeeOperator: getNextAccount(), operator: getNextAccount(), admin: getNextAccount(), systemProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getCreateClaimFeeOperatorInstructionDataDecoder().decode( instruction.data, ), }; }