/** * 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, 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"; export const WITHDRAW_FEES_DISCRIMINATOR = new Uint8Array([ 198, 212, 171, 109, 144, 215, 174, 89, ]); export function getWithdrawFeesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( WITHDRAW_FEES_DISCRIMINATOR, ); } export type WithdrawFeesInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountKeeper extends string | AccountMeta = string, TAccountTransferAuthority extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TAccountPool extends string | AccountMeta = string, TAccountCustody extends string | AccountMeta = string, TAccountCustodyTokenAccount extends string | AccountMeta = string, TAccountCustodyOracleAccount extends string | AccountMeta = string, TAccountReceivingTokenAccount extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountKeeper extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountKeeper, TAccountTransferAuthority extends string ? ReadonlyAccount : TAccountTransferAuthority, TAccountPerpetuals extends string ? ReadonlyAccount : TAccountPerpetuals, TAccountPool extends string ? WritableAccount : TAccountPool, TAccountCustody extends string ? WritableAccount : TAccountCustody, TAccountCustodyTokenAccount extends string ? WritableAccount : TAccountCustodyTokenAccount, TAccountCustodyOracleAccount extends string ? ReadonlyAccount : TAccountCustodyOracleAccount, TAccountReceivingTokenAccount extends string ? WritableAccount : TAccountReceivingTokenAccount, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, ...TRemainingAccounts, ] >; export type WithdrawFeesInstructionData = { discriminator: ReadonlyUint8Array }; export type WithdrawFeesInstructionDataArgs = {}; export function getWithdrawFeesInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: WITHDRAW_FEES_DISCRIMINATOR }), ); } export function getWithdrawFeesInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getWithdrawFeesInstructionDataCodec(): FixedSizeCodec< WithdrawFeesInstructionDataArgs, WithdrawFeesInstructionData > { return combineCodec( getWithdrawFeesInstructionDataEncoder(), getWithdrawFeesInstructionDataDecoder(), ); } export type WithdrawFeesInput< TAccountKeeper extends string = string, TAccountTransferAuthority extends string = string, TAccountPerpetuals extends string = string, TAccountPool extends string = string, TAccountCustody extends string = string, TAccountCustodyTokenAccount extends string = string, TAccountCustodyOracleAccount extends string = string, TAccountReceivingTokenAccount extends string = string, TAccountTokenProgram extends string = string, > = { keeper: TransactionSigner; transferAuthority: Address; perpetuals: Address; pool: Address; custody: Address; custodyTokenAccount: Address; custodyOracleAccount: Address; receivingTokenAccount: Address; tokenProgram?: Address; }; export function getWithdrawFeesInstruction< TAccountKeeper extends string, TAccountTransferAuthority extends string, TAccountPerpetuals extends string, TAccountPool extends string, TAccountCustody extends string, TAccountCustodyTokenAccount extends string, TAccountCustodyOracleAccount extends string, TAccountReceivingTokenAccount extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: WithdrawFeesInput< TAccountKeeper, TAccountTransferAuthority, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyTokenAccount, TAccountCustodyOracleAccount, TAccountReceivingTokenAccount, TAccountTokenProgram >, config?: { programAddress?: TProgramAddress }, ): WithdrawFeesInstruction< TProgramAddress, TAccountKeeper, TAccountTransferAuthority, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyTokenAccount, TAccountCustodyOracleAccount, TAccountReceivingTokenAccount, TAccountTokenProgram > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { keeper: { value: input.keeper ?? null, isWritable: false }, transferAuthority: { value: input.transferAuthority ?? null, isWritable: false, }, perpetuals: { value: input.perpetuals ?? null, isWritable: false }, pool: { value: input.pool ?? null, isWritable: true }, custody: { value: input.custody ?? null, isWritable: true }, custodyTokenAccount: { value: input.custodyTokenAccount ?? null, isWritable: true, }, custodyOracleAccount: { value: input.custodyOracleAccount ?? null, isWritable: false, }, receivingTokenAccount: { value: input.receivingTokenAccount ?? null, isWritable: true, }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.keeper), getAccountMeta(accounts.transferAuthority), getAccountMeta(accounts.perpetuals), getAccountMeta(accounts.pool), getAccountMeta(accounts.custody), getAccountMeta(accounts.custodyTokenAccount), getAccountMeta(accounts.custodyOracleAccount), getAccountMeta(accounts.receivingTokenAccount), getAccountMeta(accounts.tokenProgram), ], data: getWithdrawFeesInstructionDataEncoder().encode({}), programAddress, } as WithdrawFeesInstruction< TProgramAddress, TAccountKeeper, TAccountTransferAuthority, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountCustodyTokenAccount, TAccountCustodyOracleAccount, TAccountReceivingTokenAccount, TAccountTokenProgram >); } export type ParsedWithdrawFeesInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { keeper: TAccountMetas[0]; transferAuthority: TAccountMetas[1]; perpetuals: TAccountMetas[2]; pool: TAccountMetas[3]; custody: TAccountMetas[4]; custodyTokenAccount: TAccountMetas[5]; custodyOracleAccount: TAccountMetas[6]; receivingTokenAccount: TAccountMetas[7]; tokenProgram: TAccountMetas[8]; }; data: WithdrawFeesInstructionData; }; export function parseWithdrawFeesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedWithdrawFeesInstruction { if (instruction.accounts.length < 9) { // 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: { keeper: getNextAccount(), transferAuthority: getNextAccount(), perpetuals: getNextAccount(), pool: getNextAccount(), custody: getNextAccount(), custodyTokenAccount: getNextAccount(), custodyOracleAccount: getNextAccount(), receivingTokenAccount: getNextAccount(), tokenProgram: getNextAccount(), }, data: getWithdrawFeesInstructionDataDecoder().decode(instruction.data), }; }