/** * 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 { assertIsInstructionWithAccounts, containsBytes, extendClient, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, SolanaError, type Address, type ClientWithRpc, type ClientWithTransactionPlanning, type ClientWithTransactionSending, type ExtendedClient, type GetAccountInfoApi, type GetMultipleAccountsApi, type Instruction, type InstructionWithData, type ReadonlyUint8Array, } from '@solana/kit'; import { addSelfFetchFunctions, addSelfPlanAndSendFunctions, type SelfFetchFunctions, type SelfPlanAndSendFunctions, } from '@solana/program-client-core'; import { getChannelCodec, type Channel, type ChannelArgs } from '../accounts/index.js'; import { getDistributeInstructionAsync, getEmitEventInstructionAsync, getOpenInstructionAsync, getReclaimInstruction, getRequestCloseInstruction, getSealInstruction, getSettleAndSealInstruction, getSettleInstruction, getTopUpInstruction, getWithdrawPayerInstruction, parseDistributeInstruction, parseEmitEventInstruction, parseOpenInstruction, parseReclaimInstruction, parseRequestCloseInstruction, parseSealInstruction, parseSettleAndSealInstruction, parseSettleInstruction, parseTopUpInstruction, parseWithdrawPayerInstruction, type DistributeAsyncInput, type EmitEventAsyncInput, type OpenAsyncInput, type ParsedDistributeInstruction, type ParsedEmitEventInstruction, type ParsedOpenInstruction, type ParsedReclaimInstruction, type ParsedRequestCloseInstruction, type ParsedSealInstruction, type ParsedSettleAndSealInstruction, type ParsedSettleInstruction, type ParsedTopUpInstruction, type ParsedWithdrawPayerInstruction, type ReclaimInput, type RequestCloseInput, type SealInput, type SettleAndSealInput, type SettleInput, type TopUpInput, type WithdrawPayerInput, } from '../instructions/index.js'; import { findEventAuthorityPda } from '../pdas/index.js'; export const PAYMENT_CHANNELS_PROGRAM_ADDRESS = 'CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX' as Address<'CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX'>; export enum PaymentChannelsAccount { Channel, } export enum PaymentChannelsInstruction { Open, Settle, TopUp, SettleAndSeal, RequestClose, Seal, Distribute, WithdrawPayer, Reclaim, EmitEvent, } export function identifyPaymentChannelsInstruction( instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): PaymentChannelsInstruction { const data = 'data' in instruction ? instruction.data : instruction; if (containsBytes(data, getU8Encoder().encode(1), 0)) { return PaymentChannelsInstruction.Open; } if (containsBytes(data, getU8Encoder().encode(2), 0)) { return PaymentChannelsInstruction.Settle; } if (containsBytes(data, getU8Encoder().encode(3), 0)) { return PaymentChannelsInstruction.TopUp; } if (containsBytes(data, getU8Encoder().encode(4), 0)) { return PaymentChannelsInstruction.SettleAndSeal; } if (containsBytes(data, getU8Encoder().encode(5), 0)) { return PaymentChannelsInstruction.RequestClose; } if (containsBytes(data, getU8Encoder().encode(6), 0)) { return PaymentChannelsInstruction.Seal; } if (containsBytes(data, getU8Encoder().encode(7), 0)) { return PaymentChannelsInstruction.Distribute; } if (containsBytes(data, getU8Encoder().encode(8), 0)) { return PaymentChannelsInstruction.WithdrawPayer; } if (containsBytes(data, getU8Encoder().encode(9), 0)) { return PaymentChannelsInstruction.Reclaim; } if (containsBytes(data, getU8Encoder().encode(228), 0)) { return PaymentChannelsInstruction.EmitEvent; } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: 'paymentChannels', }); } export type ParsedPaymentChannelsInstruction = | ({ instructionType: PaymentChannelsInstruction.Open; } & ParsedOpenInstruction) | ({ instructionType: PaymentChannelsInstruction.Settle; } & ParsedSettleInstruction) | ({ instructionType: PaymentChannelsInstruction.TopUp; } & ParsedTopUpInstruction) | ({ instructionType: PaymentChannelsInstruction.SettleAndSeal; } & ParsedSettleAndSealInstruction) | ({ instructionType: PaymentChannelsInstruction.RequestClose; } & ParsedRequestCloseInstruction) | ({ instructionType: PaymentChannelsInstruction.Seal; } & ParsedSealInstruction) | ({ instructionType: PaymentChannelsInstruction.Distribute; } & ParsedDistributeInstruction) | ({ instructionType: PaymentChannelsInstruction.WithdrawPayer; } & ParsedWithdrawPayerInstruction) | ({ instructionType: PaymentChannelsInstruction.Reclaim; } & ParsedReclaimInstruction) | ({ instructionType: PaymentChannelsInstruction.EmitEvent; } & ParsedEmitEventInstruction); export function parsePaymentChannelsInstruction( instruction: Instruction & InstructionWithData, ): ParsedPaymentChannelsInstruction { const instructionType = identifyPaymentChannelsInstruction(instruction); switch (instructionType) { case PaymentChannelsInstruction.Open: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.Open, ...parseOpenInstruction(instruction), }; } case PaymentChannelsInstruction.Settle: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.Settle, ...parseSettleInstruction(instruction), }; } case PaymentChannelsInstruction.TopUp: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.TopUp, ...parseTopUpInstruction(instruction), }; } case PaymentChannelsInstruction.SettleAndSeal: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.SettleAndSeal, ...parseSettleAndSealInstruction(instruction), }; } case PaymentChannelsInstruction.RequestClose: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.RequestClose, ...parseRequestCloseInstruction(instruction), }; } case PaymentChannelsInstruction.Seal: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.Seal, ...parseSealInstruction(instruction), }; } case PaymentChannelsInstruction.Distribute: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.Distribute, ...parseDistributeInstruction(instruction), }; } case PaymentChannelsInstruction.WithdrawPayer: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.WithdrawPayer, ...parseWithdrawPayerInstruction(instruction), }; } case PaymentChannelsInstruction.Reclaim: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.Reclaim, ...parseReclaimInstruction(instruction), }; } case PaymentChannelsInstruction.EmitEvent: { assertIsInstructionWithAccounts(instruction); return { instructionType: PaymentChannelsInstruction.EmitEvent, ...parseEmitEventInstruction(instruction), }; } default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: 'paymentChannels', }); } } export type PaymentChannelsPlugin = { accounts: PaymentChannelsPluginAccounts; instructions: PaymentChannelsPluginInstructions; pdas: PaymentChannelsPluginPdas; identifyInstruction: typeof identifyPaymentChannelsInstruction; parseInstruction: typeof parsePaymentChannelsInstruction; }; export type PaymentChannelsPluginAccounts = { channel: ReturnType & SelfFetchFunctions; }; export type PaymentChannelsPluginInstructions = { open: (input: OpenAsyncInput) => ReturnType & SelfPlanAndSendFunctions; settle: (input: SettleInput) => ReturnType & SelfPlanAndSendFunctions; topUp: (input: TopUpInput) => ReturnType & SelfPlanAndSendFunctions; settleAndSeal: ( input: SettleAndSealInput, ) => ReturnType & SelfPlanAndSendFunctions; requestClose: ( input: RequestCloseInput, ) => ReturnType & SelfPlanAndSendFunctions; seal: (input: SealInput) => ReturnType & SelfPlanAndSendFunctions; distribute: ( input: DistributeAsyncInput, ) => ReturnType & SelfPlanAndSendFunctions; withdrawPayer: ( input: WithdrawPayerInput, ) => ReturnType & SelfPlanAndSendFunctions; reclaim: (input: ReclaimInput) => ReturnType & SelfPlanAndSendFunctions; emitEvent: ( input: EmitEventAsyncInput, ) => ReturnType & SelfPlanAndSendFunctions; }; export type PaymentChannelsPluginPdas = { eventAuthority: typeof findEventAuthorityPda; }; export type PaymentChannelsPluginRequirements = ClientWithRpc & ClientWithTransactionPlanning & ClientWithTransactionSending; export function paymentChannelsProgram() { return ( client: T, ): ExtendedClient => { return extendClient(client, { paymentChannels: { accounts: { channel: addSelfFetchFunctions(client, getChannelCodec()) }, instructions: { open: input => addSelfPlanAndSendFunctions(client, getOpenInstructionAsync(input)), settle: input => addSelfPlanAndSendFunctions(client, getSettleInstruction(input)), topUp: input => addSelfPlanAndSendFunctions(client, getTopUpInstruction(input)), settleAndSeal: input => addSelfPlanAndSendFunctions(client, getSettleAndSealInstruction(input)), requestClose: input => addSelfPlanAndSendFunctions(client, getRequestCloseInstruction(input)), seal: input => addSelfPlanAndSendFunctions(client, getSealInstruction(input)), distribute: input => addSelfPlanAndSendFunctions(client, getDistributeInstructionAsync(input)), withdrawPayer: input => addSelfPlanAndSendFunctions(client, getWithdrawPayerInstruction(input)), reclaim: input => addSelfPlanAndSendFunctions(client, getReclaimInstruction(input)), emitEvent: input => addSelfPlanAndSendFunctions(client, getEmitEventInstructionAsync(input)), }, pdas: { eventAuthority: findEventAuthorityPda }, identifyInstruction: identifyPaymentChannelsInstruction, parseInstruction: parsePaymentChannelsInstruction, }, }); }; }