/** * 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 ReadonlyAccount, 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'; import { getSettleAndSealArgsDecoder, getSettleAndSealArgsEncoder, type SettleAndSealArgs, type SettleAndSealArgsArgs, } from '../types/index.js'; export const SETTLE_AND_SEAL_DISCRIMINATOR = 4; export function getSettleAndSealDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SETTLE_AND_SEAL_DISCRIMINATOR); } export type SettleAndSealInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountPayee extends string | AccountMeta = string, TAccountChannel extends string | AccountMeta = string, TAccountInstructionsSysvar extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayee extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPayee, TAccountChannel extends string ? WritableAccount : TAccountChannel, TAccountInstructionsSysvar extends string ? ReadonlyAccount : TAccountInstructionsSysvar, ...TRemainingAccounts, ] >; export type SettleAndSealInstructionData = { discriminator: number; settleAndSealArgs: SettleAndSealArgs; }; export type SettleAndSealInstructionDataArgs = { settleAndSealArgs: SettleAndSealArgsArgs; }; export function getSettleAndSealInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', getU8Encoder()], ['settleAndSealArgs', getSettleAndSealArgsEncoder()], ]), value => ({ ...value, discriminator: SETTLE_AND_SEAL_DISCRIMINATOR }), ); } export function getSettleAndSealInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', getU8Decoder()], ['settleAndSealArgs', getSettleAndSealArgsDecoder()], ]); } export function getSettleAndSealInstructionDataCodec(): FixedSizeCodec< SettleAndSealInstructionDataArgs, SettleAndSealInstructionData > { return combineCodec(getSettleAndSealInstructionDataEncoder(), getSettleAndSealInstructionDataDecoder()); } export type SettleAndSealInput< TAccountPayee extends string = string, TAccountChannel extends string = string, TAccountInstructionsSysvar extends string = string, > = { payee: TransactionSigner; channel: Address; instructionsSysvar: Address; settleAndSealArgs: SettleAndSealInstructionDataArgs['settleAndSealArgs']; }; export function getSettleAndSealInstruction< TAccountPayee extends string, TAccountChannel extends string, TAccountInstructionsSysvar extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: SettleAndSealInput, config?: { programAddress?: TProgramAddress }, ): SettleAndSealInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payee: { value: input.payee ?? null, isWritable: false }, channel: { value: input.channel ?? null, isWritable: true }, instructionsSysvar: { value: input.instructionsSysvar ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('payee', accounts.payee), getAccountMeta('channel', accounts.channel), getAccountMeta('instructionsSysvar', accounts.instructionsSysvar), ], data: getSettleAndSealInstructionDataEncoder().encode(args as SettleAndSealInstructionDataArgs), programAddress, } as SettleAndSealInstruction); } export type ParsedSettleAndSealInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { payee: TAccountMetas[0]; channel: TAccountMetas[1]; instructionsSysvar: TAccountMetas[2]; }; data: SettleAndSealInstructionData; }; export function parseSettleAndSealInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSettleAndSealInstruction { if (instruction.accounts.length < 3) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { payee: getNextAccount(), channel: getNextAccount(), instructionsSysvar: getNextAccount(), }, data: getSettleAndSealInstructionDataDecoder().decode(instruction.data), }; }