/** * 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, getU32Decoder, getU32Encoder, 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/kit/program-client-core'; import { LOADER_V3_PROGRAM_ADDRESS } from '../programs'; export const INITIALIZE_BUFFER_DISCRIMINATOR = 0; export function getInitializeBufferDiscriminatorBytes(): ReadonlyUint8Array { return getU32Encoder().encode(INITIALIZE_BUFFER_DISCRIMINATOR); } export type InitializeBufferInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountSourceAccount extends string | AccountMeta = string, TAccountBufferAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountSourceAccount extends string ? WritableAccount : TAccountSourceAccount, TAccountBufferAuthority extends string ? ReadonlyAccount : TAccountBufferAuthority, ...TRemainingAccounts, ] >; export type InitializeBufferInstructionData = { discriminator: number }; export type InitializeBufferInstructionDataArgs = {}; export function getInitializeBufferInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({ ...value, discriminator: INITIALIZE_BUFFER_DISCRIMINATOR, })); } export function getInitializeBufferInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU32Decoder()]]); } export function getInitializeBufferInstructionDataCodec(): FixedSizeCodec< InitializeBufferInstructionDataArgs, InitializeBufferInstructionData > { return combineCodec(getInitializeBufferInstructionDataEncoder(), getInitializeBufferInstructionDataDecoder()); } export type InitializeBufferInput< TAccountSourceAccount extends string = string, TAccountBufferAuthority extends string = string, > = { /** Source account to initialize. */ sourceAccount: Address; /** Buffer authority. */ bufferAuthority: Address; }; export function getInitializeBufferInstruction< TAccountSourceAccount extends string, TAccountBufferAuthority extends string, TProgramAddress extends Address = typeof LOADER_V3_PROGRAM_ADDRESS, >( input: InitializeBufferInput, config?: { programAddress?: TProgramAddress }, ): InitializeBufferInstruction { // Program address. const programAddress = config?.programAddress ?? LOADER_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { sourceAccount: { value: input.sourceAccount ?? null, isWritable: true }, bufferAuthority: { value: input.bufferAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('sourceAccount', accounts.sourceAccount), getAccountMeta('bufferAuthority', accounts.bufferAuthority), ], data: getInitializeBufferInstructionDataEncoder().encode({}), programAddress, } as InitializeBufferInstruction); } export type ParsedInitializeBufferInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Source account to initialize. */ sourceAccount: TAccountMetas[0]; /** Buffer authority. */ bufferAuthority: TAccountMetas[1]; }; data: InitializeBufferInstructionData; }; export function parseInitializeBufferInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializeBufferInstruction { 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: { sourceAccount: getNextAccount(), bufferAuthority: getNextAccount() }, data: getInitializeBufferInstructionDataDecoder().decode(instruction.data), }; }