/** * 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, getU32Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, SolanaError, type Address, type ClientWithTransactionPlanning, type ClientWithTransactionSending, type ExtendedClient, type Instruction, type InstructionWithData, type ReadonlyUint8Array, } from '@solana/kit'; import { addSelfPlanAndSendFunctions, type SelfPlanAndSendFunctions } from '@solana/kit/program-client-core'; import { getCloseInstruction, getDeployWithMaxDataLenInstruction, getExtendProgramInstruction, getInitializeBufferInstruction, getSetAuthorityCheckedInstruction, getSetAuthorityInstruction, getUpgradeInstruction, getWriteInstruction, parseCloseInstruction, parseDeployWithMaxDataLenInstruction, parseExtendProgramInstruction, parseInitializeBufferInstruction, parseSetAuthorityCheckedInstruction, parseSetAuthorityInstruction, parseUpgradeInstruction, parseWriteInstruction, type CloseInput, type DeployWithMaxDataLenInput, type ExtendProgramInput, type InitializeBufferInput, type ParsedCloseInstruction, type ParsedDeployWithMaxDataLenInstruction, type ParsedExtendProgramInstruction, type ParsedInitializeBufferInstruction, type ParsedSetAuthorityCheckedInstruction, type ParsedSetAuthorityInstruction, type ParsedUpgradeInstruction, type ParsedWriteInstruction, type SetAuthorityCheckedInput, type SetAuthorityInput, type UpgradeInput, type WriteInput, } from '../instructions'; export const LOADER_V3_PROGRAM_ADDRESS = 'BPFLoaderUpgradeab1e11111111111111111111111' as Address<'BPFLoaderUpgradeab1e11111111111111111111111'>; export enum LoaderV3Instruction { InitializeBuffer, Write, DeployWithMaxDataLen, Upgrade, SetAuthority, Close, ExtendProgram, SetAuthorityChecked, } export function identifyLoaderV3Instruction( instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): LoaderV3Instruction { const data = 'data' in instruction ? instruction.data : instruction; if (containsBytes(data, getU32Encoder().encode(0), 0)) { return LoaderV3Instruction.InitializeBuffer; } if (containsBytes(data, getU32Encoder().encode(1), 0)) { return LoaderV3Instruction.Write; } if (containsBytes(data, getU32Encoder().encode(2), 0)) { return LoaderV3Instruction.DeployWithMaxDataLen; } if (containsBytes(data, getU32Encoder().encode(3), 0)) { return LoaderV3Instruction.Upgrade; } if (containsBytes(data, getU32Encoder().encode(4), 0)) { return LoaderV3Instruction.SetAuthority; } if (containsBytes(data, getU32Encoder().encode(5), 0)) { return LoaderV3Instruction.Close; } if (containsBytes(data, getU32Encoder().encode(6), 0)) { return LoaderV3Instruction.ExtendProgram; } if (containsBytes(data, getU32Encoder().encode(7), 0)) { return LoaderV3Instruction.SetAuthorityChecked; } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: 'loaderV3', }); } export type ParsedLoaderV3Instruction = | ({ instructionType: LoaderV3Instruction.InitializeBuffer } & ParsedInitializeBufferInstruction) | ({ instructionType: LoaderV3Instruction.Write } & ParsedWriteInstruction) | ({ instructionType: LoaderV3Instruction.DeployWithMaxDataLen } & ParsedDeployWithMaxDataLenInstruction) | ({ instructionType: LoaderV3Instruction.Upgrade } & ParsedUpgradeInstruction) | ({ instructionType: LoaderV3Instruction.SetAuthority } & ParsedSetAuthorityInstruction) | ({ instructionType: LoaderV3Instruction.Close } & ParsedCloseInstruction) | ({ instructionType: LoaderV3Instruction.ExtendProgram } & ParsedExtendProgramInstruction) | ({ instructionType: LoaderV3Instruction.SetAuthorityChecked } & ParsedSetAuthorityCheckedInstruction); export function parseLoaderV3Instruction( instruction: Instruction & InstructionWithData, ): ParsedLoaderV3Instruction { const instructionType = identifyLoaderV3Instruction(instruction); switch (instructionType) { case LoaderV3Instruction.InitializeBuffer: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.InitializeBuffer, ...parseInitializeBufferInstruction(instruction), }; } case LoaderV3Instruction.Write: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.Write, ...parseWriteInstruction(instruction) }; } case LoaderV3Instruction.DeployWithMaxDataLen: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.DeployWithMaxDataLen, ...parseDeployWithMaxDataLenInstruction(instruction), }; } case LoaderV3Instruction.Upgrade: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.Upgrade, ...parseUpgradeInstruction(instruction) }; } case LoaderV3Instruction.SetAuthority: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.SetAuthority, ...parseSetAuthorityInstruction(instruction) }; } case LoaderV3Instruction.Close: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.Close, ...parseCloseInstruction(instruction) }; } case LoaderV3Instruction.ExtendProgram: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.ExtendProgram, ...parseExtendProgramInstruction(instruction), }; } case LoaderV3Instruction.SetAuthorityChecked: { assertIsInstructionWithAccounts(instruction); return { instructionType: LoaderV3Instruction.SetAuthorityChecked, ...parseSetAuthorityCheckedInstruction(instruction), }; } default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: 'loaderV3', }); } } export type LoaderV3Plugin = { instructions: LoaderV3PluginInstructions; identifyInstruction: typeof identifyLoaderV3Instruction; parseInstruction: typeof parseLoaderV3Instruction; }; export type LoaderV3PluginInstructions = { initializeBuffer: ( input: InitializeBufferInput, ) => ReturnType & SelfPlanAndSendFunctions; write: (input: WriteInput) => ReturnType & SelfPlanAndSendFunctions; deployWithMaxDataLen: ( input: DeployWithMaxDataLenInput, ) => ReturnType & SelfPlanAndSendFunctions; upgrade: (input: UpgradeInput) => ReturnType & SelfPlanAndSendFunctions; setAuthority: ( input: SetAuthorityInput, ) => ReturnType & SelfPlanAndSendFunctions; close: (input: CloseInput) => ReturnType & SelfPlanAndSendFunctions; extendProgram: ( input: ExtendProgramInput, ) => ReturnType & SelfPlanAndSendFunctions; setAuthorityChecked: ( input: SetAuthorityCheckedInput, ) => ReturnType & SelfPlanAndSendFunctions; }; export type LoaderV3PluginRequirements = ClientWithTransactionPlanning & ClientWithTransactionSending; export function loaderV3Program() { return (client: T): ExtendedClient => { return extendClient(client, { loaderV3: { instructions: { initializeBuffer: input => addSelfPlanAndSendFunctions(client, getInitializeBufferInstruction(input)), write: input => addSelfPlanAndSendFunctions(client, getWriteInstruction(input)), deployWithMaxDataLen: input => addSelfPlanAndSendFunctions(client, getDeployWithMaxDataLenInstruction(input)), upgrade: input => addSelfPlanAndSendFunctions(client, getUpgradeInstruction(input)), setAuthority: input => addSelfPlanAndSendFunctions(client, getSetAuthorityInstruction(input)), close: input => addSelfPlanAndSendFunctions(client, getCloseInstruction(input)), extendProgram: input => addSelfPlanAndSendFunctions(client, getExtendProgramInstruction(input)), setAuthorityChecked: input => addSelfPlanAndSendFunctions(client, getSetAuthorityCheckedInstruction(input)), }, identifyInstruction: identifyLoaderV3Instruction, parseInstruction: parseLoaderV3Instruction, }, }); }; }