/** * 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 AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, 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 REQUEST_CLOSE_DISCRIMINATOR = 5; export function getRequestCloseDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(REQUEST_CLOSE_DISCRIMINATOR); } export type RequestCloseInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta = string, TAccountChannel extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayer extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPayer, TAccountChannel extends string ? WritableAccount : TAccountChannel, ...TRemainingAccounts, ] >; export type RequestCloseInstructionData = { discriminator: number }; export type RequestCloseInstructionDataArgs = {}; export function getRequestCloseInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ ...value, discriminator: REQUEST_CLOSE_DISCRIMINATOR, })); } export function getRequestCloseInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getRequestCloseInstructionDataCodec(): FixedSizeCodec< RequestCloseInstructionDataArgs, RequestCloseInstructionData > { return combineCodec(getRequestCloseInstructionDataEncoder(), getRequestCloseInstructionDataDecoder()); } export type RequestCloseInput = { payer: TransactionSigner; channel: Address; }; export function getRequestCloseInstruction< TAccountPayer extends string, TAccountChannel extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: RequestCloseInput, config?: { programAddress?: TProgramAddress }, ): RequestCloseInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: false }, channel: { value: input.channel ?? null, isWritable: true }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta('payer', accounts.payer), getAccountMeta('channel', accounts.channel)], data: getRequestCloseInstructionDataEncoder().encode({}), programAddress, } as RequestCloseInstruction); } export type ParsedRequestCloseInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { payer: TAccountMetas[0]; channel: TAccountMetas[1]; }; data: RequestCloseInstructionData; }; export function parseRequestCloseInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRequestCloseInstruction { 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: { payer: getNextAccount(), channel: getNextAccount() }, data: getRequestCloseInstructionDataDecoder().decode(instruction.data), }; }