/** * 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, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyUint8Array, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core'; import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from '../programs/index.js'; export const RECLAIM_DISCRIMINATOR = 9; export function getReclaimDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(RECLAIM_DISCRIMINATOR); } export type ReclaimInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountChannel extends string | AccountMeta = string, TAccountRentPayer extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountChannel extends string ? WritableAccount : TAccountChannel, TAccountRentPayer extends string ? WritableAccount : TAccountRentPayer, ...TRemainingAccounts, ] >; export type ReclaimInstructionData = { discriminator: number }; export type ReclaimInstructionDataArgs = {}; export function getReclaimInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ ...value, discriminator: RECLAIM_DISCRIMINATOR, })); } export function getReclaimInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getReclaimInstructionDataCodec(): FixedSizeCodec { return combineCodec(getReclaimInstructionDataEncoder(), getReclaimInstructionDataDecoder()); } export type ReclaimInput = { channel: Address; rentPayer: Address; }; export function getReclaimInstruction< TAccountChannel extends string, TAccountRentPayer extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: ReclaimInput, config?: { programAddress?: TProgramAddress }, ): ReclaimInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { channel: { value: input.channel ?? null, isWritable: true }, rentPayer: { value: input.rentPayer ?? null, isWritable: true }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta('channel', accounts.channel), getAccountMeta('rentPayer', accounts.rentPayer)], data: getReclaimInstructionDataEncoder().encode({}), programAddress, } as ReclaimInstruction); } export type ParsedReclaimInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { channel: TAccountMetas[0]; rentPayer: TAccountMetas[1]; }; data: ReclaimInstructionData; }; export function parseReclaimInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedReclaimInstruction { if (instruction.accounts.length < 2) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { channel: getNextAccount(), rentPayer: getNextAccount() }, data: getReclaimInstructionDataDecoder().decode(instruction.data), }; }