/** * 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, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core'; import { findEventAuthorityPda } from '../pdas/index.js'; import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from '../programs/index.js'; export const EMIT_EVENT_DISCRIMINATOR = 228; export function getEmitEventDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(EMIT_EVENT_DISCRIMINATOR); } export type EmitEventInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountEventAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountEventAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountEventAuthority, ...TRemainingAccounts, ] >; export type EmitEventInstructionData = { discriminator: number }; export type EmitEventInstructionDataArgs = {}; export function getEmitEventInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ ...value, discriminator: EMIT_EVENT_DISCRIMINATOR, })); } export function getEmitEventInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getEmitEventInstructionDataCodec(): FixedSizeCodec< EmitEventInstructionDataArgs, EmitEventInstructionData > { return combineCodec(getEmitEventInstructionDataEncoder(), getEmitEventInstructionDataDecoder()); } export type EmitEventAsyncInput = { eventAuthority?: TransactionSigner; }; export async function getEmitEventInstructionAsync< TAccountEventAuthority extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: EmitEventAsyncInput, config?: { programAddress?: TProgramAddress }, ): Promise> { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; // Resolve default values. if (!accounts.eventAuthority.value) { accounts.eventAuthority.value = await findEventAuthorityPda(); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta('eventAuthority', accounts.eventAuthority)], data: getEmitEventInstructionDataEncoder().encode({}), programAddress, } as EmitEventInstruction); } export type EmitEventInput = { eventAuthority: TransactionSigner; }; export function getEmitEventInstruction< TAccountEventAuthority extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: EmitEventInput, config?: { programAddress?: TProgramAddress }, ): EmitEventInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta('eventAuthority', accounts.eventAuthority)], data: getEmitEventInstructionDataEncoder().encode({}), programAddress, } as EmitEventInstruction); } export type ParsedEmitEventInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { eventAuthority: TAccountMetas[0]; }; data: EmitEventInstructionData; }; export function parseEmitEventInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedEmitEventInstruction { if (instruction.accounts.length < 1) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 1, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { eventAuthority: getNextAccount() }, data: getEmitEventInstructionDataDecoder().decode(instruction.data), }; }