/** * 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 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 { YVAULTS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const WITHDRAW_FROM_TOPUP_DISCRIMINATOR = new Uint8Array([ 95, 227, 138, 220, 240, 95, 150, 113, ]); export function getWithdrawFromTopupDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( WITHDRAW_FROM_TOPUP_DISCRIMINATOR, ); } export type WithdrawFromTopupInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta = string, TAccountTopupVault extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminAuthority extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdminAuthority, TAccountTopupVault extends string ? WritableAccount : TAccountTopupVault, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, ...TRemainingAccounts, ] >; export type WithdrawFromTopupInstructionData = { discriminator: ReadonlyUint8Array; amount: bigint; }; export type WithdrawFromTopupInstructionDataArgs = { amount: number | bigint }; export function getWithdrawFromTopupInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["amount", getU64Encoder()], ]), (value) => ({ ...value, discriminator: WITHDRAW_FROM_TOPUP_DISCRIMINATOR }), ); } export function getWithdrawFromTopupInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["amount", getU64Decoder()], ]); } export function getWithdrawFromTopupInstructionDataCodec(): FixedSizeCodec< WithdrawFromTopupInstructionDataArgs, WithdrawFromTopupInstructionData > { return combineCodec( getWithdrawFromTopupInstructionDataEncoder(), getWithdrawFromTopupInstructionDataDecoder(), ); } export type WithdrawFromTopupInput< TAccountAdminAuthority extends string = string, TAccountTopupVault extends string = string, TAccountSystem extends string = string, > = { adminAuthority: TransactionSigner; topupVault: Address; system: Address; amount: WithdrawFromTopupInstructionDataArgs["amount"]; }; export function getWithdrawFromTopupInstruction< TAccountAdminAuthority extends string, TAccountTopupVault extends string, TAccountSystem extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: WithdrawFromTopupInput< TAccountAdminAuthority, TAccountTopupVault, TAccountSystem >, config?: { programAddress?: TProgramAddress }, ): WithdrawFromTopupInstruction< TProgramAddress, TAccountAdminAuthority, TAccountTopupVault, TAccountSystem > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: true }, topupVault: { value: input.topupVault ?? null, isWritable: true }, system: { value: input.system ?? 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.adminAuthority), getAccountMeta(accounts.topupVault), getAccountMeta(accounts.system), ], data: getWithdrawFromTopupInstructionDataEncoder().encode( args as WithdrawFromTopupInstructionDataArgs, ), programAddress, } as WithdrawFromTopupInstruction< TProgramAddress, TAccountAdminAuthority, TAccountTopupVault, TAccountSystem >); } export type ParsedWithdrawFromTopupInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminAuthority: TAccountMetas[0]; topupVault: TAccountMetas[1]; system: TAccountMetas[2]; }; data: WithdrawFromTopupInstructionData; }; export function parseWithdrawFromTopupInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedWithdrawFromTopupInstruction { 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: { adminAuthority: getNextAccount(), topupVault: getNextAccount(), system: getNextAccount(), }, data: getWithdrawFromTopupInstructionDataDecoder().decode(instruction.data), }; }