/** * 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, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type Codec, type Decoder, type Encoder, type ReadonlyUint8Array, } from '@solana/codecs'; import { type IAccountSignerMeta, type TransactionSigner, } from '@solana/signers'; import { POD_COM_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; import type { Address } from '@solana/addresses'; import type { IAccountMeta, IInstruction, IInstructionWithAccounts, IInstructionWithData, } from '../../utils/instruction-compat'; // Define missing types for compatibility type ReadonlyAccount = T; type WritableAccount = T; type WritableSignerAccount = T; export const ADD_PARTICIPANT_DISCRIMINATOR = new Uint8Array([ 201, 23, 89, 155, 12, 47, 199, 233, ]); export function getAddParticipantDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ADD_PARTICIPANT_DISCRIMINATOR ); } export type AddParticipantInstruction< TProgram extends string = typeof POD_COM_PROGRAM_ADDRESS, TAccountChannelAccount extends string | IAccountMeta = string, TAccountAdmin extends string | IAccountMeta = string, TAccountNewParticipant extends string | IAccountMeta = string, TAccountSystemProgram extends | string | IAccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends ReadonlyArray> = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts[]>; export interface AddParticipantInstructionData { discriminator: ReadonlyUint8Array; } export interface AddParticipantInstructionDataArgs {} export function getAddParticipantInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: ADD_PARTICIPANT_DISCRIMINATOR }) ); } export function getAddParticipantInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getAddParticipantInstructionDataCodec(): Codec< AddParticipantInstructionDataArgs, AddParticipantInstructionData > { return combineCodec( getAddParticipantInstructionDataEncoder(), getAddParticipantInstructionDataDecoder() ); } export interface AddParticipantInput< TAccountChannelAccount extends string = string, TAccountAdmin extends string = string, TAccountNewParticipant extends string = string, TAccountSystemProgram extends string = string, > { channelAccount: Address; admin: TransactionSigner; newParticipant: Address; systemProgram?: Address; } export function getAddParticipantInstruction< TAccountChannelAccount extends string, TAccountAdmin extends string, TAccountNewParticipant extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof POD_COM_PROGRAM_ADDRESS, >( input: AddParticipantInput< TAccountChannelAccount, TAccountAdmin, TAccountNewParticipant, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress } ): AddParticipantInstruction< TProgramAddress, TAccountChannelAccount, TAccountAdmin, TAccountNewParticipant, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? POD_COM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { channelAccount: { value: input.channelAccount ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, newParticipant: { value: input.newParticipant ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.channelAccount), getAccountMeta(accounts.admin), getAccountMeta(accounts.newParticipant), getAccountMeta(accounts.systemProgram), ] as any, programAddress, data: new Uint8Array(getAddParticipantInstructionDataEncoder().encode({})), } as AddParticipantInstruction< TProgramAddress, TAccountChannelAccount, TAccountAdmin, TAccountNewParticipant, TAccountSystemProgram >; return instruction; } export interface ParsedAddParticipantInstruction< TProgram extends string = typeof POD_COM_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > { programAddress: Address; accounts: { channelAccount: TAccountMetas[0]; admin: TAccountMetas[1]; newParticipant: TAccountMetas[2]; systemProgram: TAccountMetas[3]; }; data: AddParticipantInstructionData; } export function parseAddParticipantInstruction< TProgram extends string, TAccountMetas extends readonly IAccountMeta[], >( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData ): ParsedAddParticipantInstruction { if (instruction.accounts.length < 4) { // Specific error for instruction validation throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { channelAccount: getNextAccount(), admin: getNextAccount(), newParticipant: getNextAccount(), systemProgram: getNextAccount(), }, data: getAddParticipantInstructionDataDecoder().decode(instruction.data), }; }