/** * 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 ReadonlyAccount, 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 SETTLE_DISCRIMINATOR = 2; export function getSettleDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SETTLE_DISCRIMINATOR); } export type SettleInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountChannel extends string | AccountMeta = string, TAccountInstructionsSysvar extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountChannel extends string ? WritableAccount : TAccountChannel, TAccountInstructionsSysvar extends string ? ReadonlyAccount : TAccountInstructionsSysvar, ...TRemainingAccounts, ] >; export type SettleInstructionData = { discriminator: number }; export type SettleInstructionDataArgs = {}; export function getSettleInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ ...value, discriminator: SETTLE_DISCRIMINATOR, })); } export function getSettleInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getSettleInstructionDataCodec(): FixedSizeCodec { return combineCodec(getSettleInstructionDataEncoder(), getSettleInstructionDataDecoder()); } export type SettleInput = { channel: Address; instructionsSysvar: Address; }; export function getSettleInstruction< TAccountChannel extends string, TAccountInstructionsSysvar extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: SettleInput, config?: { programAddress?: TProgramAddress }, ): SettleInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { channel: { value: input.channel ?? null, isWritable: true }, instructionsSysvar: { value: input.instructionsSysvar ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('channel', accounts.channel), getAccountMeta('instructionsSysvar', accounts.instructionsSysvar), ], data: getSettleInstructionDataEncoder().encode({}), programAddress, } as SettleInstruction); } export type ParsedSettleInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { channel: TAccountMetas[0]; instructionsSysvar: TAccountMetas[1]; }; data: SettleInstructionData; }; export function parseSettleInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSettleInstruction { 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(), instructionsSysvar: getNextAccount(), }, data: getSettleInstructionDataDecoder().decode(instruction.data), }; }