/** * 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, getU64Decoder, getU64Encoder, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, } from "@solana/kit"; import { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const GET_ADD_LIQUIDITY_AMOUNT_AND_FEE_DISCRIMINATOR = new Uint8Array([ 172, 150, 249, 181, 233, 241, 78, 139, ]); export function getGetAddLiquidityAmountAndFeeDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( GET_ADD_LIQUIDITY_AMOUNT_AND_FEE_DISCRIMINATOR, ); } export type GetAddLiquidityAmountAndFeeInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountPerpetuals extends string | AccountMeta = string, TAccountPool extends string | AccountMeta = string, TAccountCustody extends string | AccountMeta = string, TAccountCustodyOracleAccount extends string | AccountMeta = string, TAccountLpTokenMint extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPerpetuals extends string ? ReadonlyAccount : TAccountPerpetuals, TAccountPool extends string ? ReadonlyAccount : TAccountPool, TAccountCustody extends string ? ReadonlyAccount : TAccountCustody, TAccountCustodyOracleAccount extends string ? ReadonlyAccount : TAccountCustodyOracleAccount, TAccountLpTokenMint extends string ? ReadonlyAccount : TAccountLpTokenMint, ...TRemainingAccounts, ] >; export type GetAddLiquidityAmountAndFeeInstructionData = { discriminator: ReadonlyUint8Array; tokenAmountIn: bigint; }; export type GetAddLiquidityAmountAndFeeInstructionDataArgs = { tokenAmountIn: number | bigint; }; export function getGetAddLiquidityAmountAndFeeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["tokenAmountIn", getU64Encoder()], ]), (value) => ({ ...value, discriminator: GET_ADD_LIQUIDITY_AMOUNT_AND_FEE_DISCRIMINATOR, }), ); } export function getGetAddLiquidityAmountAndFeeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["tokenAmountIn", getU64Decoder()], ]); } export function getGetAddLiquidityAmountAndFeeInstructionDataCodec(): FixedSizeCodec< GetAddLiquidityAmountAndFeeInstructionDataArgs, GetAddLiquidityAmountAndFeeInstructionData > { return combineCodec( getGetAddLiquidityAmountAndFeeInstructionDataEncoder(), getGetAddLiquidityAmountAndFeeInstructionDataDecoder(), ); } export type GetAddLiquidityAmountAndFeeInput< TAccountPerpetuals extends string = string, TAccountPool extends string = string, TAccountCustody extends string = string, TAccountCustodyOracleAccount extends string = string, TAccountLpTokenMint extends string = string, > = { perpetuals: Address; pool: Address; custody: Address; custodyOracleAccount: Address; lpTokenMint: Address; tokenAmountIn: GetAddLiquidityAmountAndFeeInstructionDataArgs["tokenAmountIn"]; }; export function getGetAddLiquidityAmountAndFeeInstruction< TAccountPerpetuals extends string, TAccountPool extends string, TAccountCustody extends string, TAccountCustodyOracleAccount extends string, TAccountLpTokenMint extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: GetAddLiquidityAmountAndFeeInput< TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyOracleAccount, TAccountLpTokenMint >, config?: { programAddress?: TProgramAddress }, ): GetAddLiquidityAmountAndFeeInstruction< TProgramAddress, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyOracleAccount, TAccountLpTokenMint > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { perpetuals: { value: input.perpetuals ?? null, isWritable: false }, pool: { value: input.pool ?? null, isWritable: false }, custody: { value: input.custody ?? null, isWritable: false }, custodyOracleAccount: { value: input.custodyOracleAccount ?? null, isWritable: false, }, lpTokenMint: { value: input.lpTokenMint ?? null, isWritable: false }, }; 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.perpetuals), getAccountMeta(accounts.pool), getAccountMeta(accounts.custody), getAccountMeta(accounts.custodyOracleAccount), getAccountMeta(accounts.lpTokenMint), ], data: getGetAddLiquidityAmountAndFeeInstructionDataEncoder().encode( args as GetAddLiquidityAmountAndFeeInstructionDataArgs, ), programAddress, } as GetAddLiquidityAmountAndFeeInstruction< TProgramAddress, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyOracleAccount, TAccountLpTokenMint >); } export type ParsedGetAddLiquidityAmountAndFeeInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { perpetuals: TAccountMetas[0]; pool: TAccountMetas[1]; custody: TAccountMetas[2]; custodyOracleAccount: TAccountMetas[3]; lpTokenMint: TAccountMetas[4]; }; data: GetAddLiquidityAmountAndFeeInstructionData; }; export function parseGetAddLiquidityAmountAndFeeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedGetAddLiquidityAmountAndFeeInstruction { if (instruction.accounts.length < 5) { // 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: { perpetuals: getNextAccount(), pool: getNextAccount(), custody: getNextAccount(), custodyOracleAccount: getNextAccount(), lpTokenMint: getNextAccount(), }, data: getGetAddLiquidityAmountAndFeeInstructionDataDecoder().decode( instruction.data, ), }; }