/** * 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 ClientWithPayer, 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 { getFrequencyAccountCodec, type FrequencyAccount, type FrequencyAccountArgs, } from "../accounts/index.ts"; import { getCreateOrUpdateInstructionAsync, getPuffRuleSetInstruction, getValidateInstruction, getWriteToBufferInstructionAsync, parseCreateOrUpdateInstruction, parsePuffRuleSetInstruction, parseValidateInstruction, parseWriteToBufferInstruction, type CreateOrUpdateAsyncInput, type ParsedCreateOrUpdateInstruction, type ParsedPuffRuleSetInstruction, type ParsedValidateInstruction, type ParsedWriteToBufferInstruction, type PuffRuleSetInput, type ValidateInput, type WriteToBufferAsyncInput, } from "../instructions/index.ts"; import { findRuleSetBufferPda, findRuleSetPda } from "../pdas/index.ts"; export const MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS = "auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg" as Address<"auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg">; const MplTokenAuthRulesAccountLookup = { 0: "FrequencyAccount", FrequencyAccount: 0, } as const; export const MplTokenAuthRulesAccount: Omit< typeof MplTokenAuthRulesAccountLookup, number > = MplTokenAuthRulesAccountLookup; export type MplTokenAuthRulesAccount = (typeof MplTokenAuthRulesAccount)[keyof typeof MplTokenAuthRulesAccount]; const MplTokenAuthRulesInstructionLookup = { 0: "CreateOrUpdate", 1: "Validate", 2: "WriteToBuffer", 3: "PuffRuleSet", CreateOrUpdate: 0, Validate: 1, WriteToBuffer: 2, PuffRuleSet: 3, } as const; export const MplTokenAuthRulesInstruction: Omit< typeof MplTokenAuthRulesInstructionLookup, number > = MplTokenAuthRulesInstructionLookup; export type MplTokenAuthRulesInstruction = (typeof MplTokenAuthRulesInstruction)[keyof typeof MplTokenAuthRulesInstruction]; export function identifyMplTokenAuthRulesInstruction( instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): MplTokenAuthRulesInstruction { const data = "data" in instruction ? instruction.data : instruction; if (containsBytes(data, getU8Encoder().encode(0), 0)) { return MplTokenAuthRulesInstruction.CreateOrUpdate; } if (containsBytes(data, getU8Encoder().encode(1), 0)) { return MplTokenAuthRulesInstruction.Validate; } if (containsBytes(data, getU8Encoder().encode(2), 0)) { return MplTokenAuthRulesInstruction.WriteToBuffer; } if (containsBytes(data, getU8Encoder().encode(3), 0)) { return MplTokenAuthRulesInstruction.PuffRuleSet; } throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "mplTokenAuthRules" }, ); } export type ParsedMplTokenAuthRulesInstruction< TProgram extends string = "auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg", > = | ({ instructionType: typeof MplTokenAuthRulesInstruction.CreateOrUpdate; } & ParsedCreateOrUpdateInstruction) | ({ instructionType: typeof MplTokenAuthRulesInstruction.Validate; } & ParsedValidateInstruction) | ({ instructionType: typeof MplTokenAuthRulesInstruction.WriteToBuffer; } & ParsedWriteToBufferInstruction) | ({ instructionType: typeof MplTokenAuthRulesInstruction.PuffRuleSet; } & ParsedPuffRuleSetInstruction); export function parseMplTokenAuthRulesInstruction( instruction: Instruction & InstructionWithData, ): ParsedMplTokenAuthRulesInstruction { const instructionType = identifyMplTokenAuthRulesInstruction(instruction); switch (instructionType) { case MplTokenAuthRulesInstruction.CreateOrUpdate: { assertIsInstructionWithAccounts(instruction); return { instructionType: MplTokenAuthRulesInstruction.CreateOrUpdate, ...parseCreateOrUpdateInstruction(instruction), }; } case MplTokenAuthRulesInstruction.Validate: { assertIsInstructionWithAccounts(instruction); return { instructionType: MplTokenAuthRulesInstruction.Validate, ...parseValidateInstruction(instruction), }; } case MplTokenAuthRulesInstruction.WriteToBuffer: { assertIsInstructionWithAccounts(instruction); return { instructionType: MplTokenAuthRulesInstruction.WriteToBuffer, ...parseWriteToBufferInstruction(instruction), }; } case MplTokenAuthRulesInstruction.PuffRuleSet: { assertIsInstructionWithAccounts(instruction); return { instructionType: MplTokenAuthRulesInstruction.PuffRuleSet, ...parsePuffRuleSetInstruction(instruction), }; } default: throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "mplTokenAuthRules", }, ); } } export type MplTokenAuthRulesPlugin = { accounts: MplTokenAuthRulesPluginAccounts; instructions: MplTokenAuthRulesPluginInstructions; pdas: MplTokenAuthRulesPluginPdas; identifyInstruction: typeof identifyMplTokenAuthRulesInstruction; parseInstruction: typeof parseMplTokenAuthRulesInstruction; }; export type MplTokenAuthRulesPluginAccounts = { frequencyAccount: ReturnType & SelfFetchFunctions; }; export type MplTokenAuthRulesPluginInstructions = { createOrUpdate: ( input: MakeOptional, ) => ReturnType & SelfPlanAndSendFunctions; validate: ( input: ValidateInput, ) => ReturnType & SelfPlanAndSendFunctions; writeToBuffer: ( input: MakeOptional, ) => ReturnType & SelfPlanAndSendFunctions; puffRuleSet: ( input: MakeOptional, ) => ReturnType & SelfPlanAndSendFunctions; }; export type MplTokenAuthRulesPluginPdas = { ruleSet: typeof findRuleSetPda; ruleSetBuffer: typeof findRuleSetBufferPda; }; export type MplTokenAuthRulesPluginRequirements = ClientWithRpc< GetAccountInfoApi & GetMultipleAccountsApi > & ClientWithPayer & ClientWithTransactionPlanning & ClientWithTransactionSending; export function mplTokenAuthRulesProgram() { return ( client: T, ): ExtendedClient => { return extendClient(client, { mplTokenAuthRules: { accounts: { frequencyAccount: addSelfFetchFunctions( client, getFrequencyAccountCodec(), ), }, instructions: { createOrUpdate: (input) => addSelfPlanAndSendFunctions( client, getCreateOrUpdateInstructionAsync({ ...input, payer: input.payer ?? client.payer, }), ), validate: (input) => addSelfPlanAndSendFunctions(client, getValidateInstruction(input)), writeToBuffer: (input) => addSelfPlanAndSendFunctions( client, getWriteToBufferInstructionAsync({ ...input, payer: input.payer ?? client.payer, }), ), puffRuleSet: (input) => addSelfPlanAndSendFunctions( client, getPuffRuleSetInstruction({ ...input, payer: input.payer ?? client.payer, }), ), }, pdas: { ruleSet: findRuleSetPda, ruleSetBuffer: findRuleSetBufferPda }, identifyInstruction: identifyMplTokenAuthRulesInstruction, parseInstruction: parseMplTokenAuthRulesInstruction, } as MplTokenAuthRulesPlugin, }); }; } type MakeOptional = Omit & Partial>;