/** * 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, 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 { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; import { getFeesDecoder, getFeesEncoder, getLimitDecoder, getLimitEncoder, type Fees, type FeesArgs, type Limit, type LimitArgs, } from "../types"; export const SET_POOL_CONFIG_DISCRIMINATOR = new Uint8Array([ 216, 87, 65, 125, 113, 110, 185, 120, ]); export function getSetPoolConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_POOL_CONFIG_DISCRIMINATOR, ); } export type SetPoolConfigInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TAccountPool extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountPerpetuals extends string ? ReadonlyAccount : TAccountPerpetuals, TAccountPool extends string ? WritableAccount : TAccountPool, ...TRemainingAccounts, ] >; export type SetPoolConfigInstructionData = { discriminator: ReadonlyUint8Array; fees: Fees; limit: Limit; maxRequestExecutionSec: bigint; }; export type SetPoolConfigInstructionDataArgs = { fees: FeesArgs; limit: LimitArgs; maxRequestExecutionSec: number | bigint; }; export function getSetPoolConfigInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["fees", getFeesEncoder()], ["limit", getLimitEncoder()], ["maxRequestExecutionSec", getI64Encoder()], ]), (value) => ({ ...value, discriminator: SET_POOL_CONFIG_DISCRIMINATOR }), ); } export function getSetPoolConfigInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["fees", getFeesDecoder()], ["limit", getLimitDecoder()], ["maxRequestExecutionSec", getI64Decoder()], ]); } export function getSetPoolConfigInstructionDataCodec(): FixedSizeCodec< SetPoolConfigInstructionDataArgs, SetPoolConfigInstructionData > { return combineCodec( getSetPoolConfigInstructionDataEncoder(), getSetPoolConfigInstructionDataDecoder(), ); } export type SetPoolConfigInput< TAccountAdmin extends string = string, TAccountPerpetuals extends string = string, TAccountPool extends string = string, > = { admin: TransactionSigner; perpetuals: Address; pool: Address; fees: SetPoolConfigInstructionDataArgs["fees"]; limit: SetPoolConfigInstructionDataArgs["limit"]; maxRequestExecutionSec: SetPoolConfigInstructionDataArgs["maxRequestExecutionSec"]; }; export function getSetPoolConfigInstruction< TAccountAdmin extends string, TAccountPerpetuals extends string, TAccountPool extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: SetPoolConfigInput, config?: { programAddress?: TProgramAddress }, ): SetPoolConfigInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountPool > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, perpetuals: { value: input.perpetuals ?? null, isWritable: false }, pool: { value: input.pool ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.perpetuals), getAccountMeta(accounts.pool), ], data: getSetPoolConfigInstructionDataEncoder().encode( args as SetPoolConfigInstructionDataArgs, ), programAddress, } as SetPoolConfigInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountPool >); } export type ParsedSetPoolConfigInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; perpetuals: TAccountMetas[1]; pool: TAccountMetas[2]; }; data: SetPoolConfigInstructionData; }; export function parseSetPoolConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetPoolConfigInstruction { if (instruction.accounts.length < 3) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { admin: getNextAccount(), perpetuals: getNextAccount(), pool: getNextAccount(), }, data: getSetPoolConfigInstructionDataDecoder().decode(instruction.data), }; }