/** * 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 Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS } from "../programs/index.ts"; import { getPuffRuleSetArgsDecoder, getPuffRuleSetArgsEncoder, type PuffRuleSetArgs, type PuffRuleSetArgsArgs, } from "../types/index.ts"; export const PUFF_RULE_SET_DISCRIMINATOR = 3; export function getPuffRuleSetDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(PUFF_RULE_SET_DISCRIMINATOR); } export type PuffRuleSetInstruction< TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta = string, TAccountRuleSetPda extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountRuleSetPda extends string ? WritableAccount : TAccountRuleSetPda, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type PuffRuleSetInstructionData = { discriminator: number; /** Identifies the RuleSet to grow by name. */ puffRuleSetArgs: PuffRuleSetArgs; }; export type PuffRuleSetInstructionDataArgs = { /** Identifies the RuleSet to grow by name. */ puffRuleSetArgs: PuffRuleSetArgsArgs; }; export function getPuffRuleSetInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["puffRuleSetArgs", getPuffRuleSetArgsEncoder()], ]), (value) => ({ ...value, discriminator: PUFF_RULE_SET_DISCRIMINATOR }), ); } export function getPuffRuleSetInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["puffRuleSetArgs", getPuffRuleSetArgsDecoder()], ]); } export function getPuffRuleSetInstructionDataCodec(): Codec< PuffRuleSetInstructionDataArgs, PuffRuleSetInstructionData > { return combineCodec( getPuffRuleSetInstructionDataEncoder(), getPuffRuleSetInstructionDataDecoder(), ); } export type PuffRuleSetInput< TAccountPayer extends string = string, TAccountRuleSetPda extends string = string, TAccountSystemProgram extends string = string, > = { /** Payer and creator of the RuleSet */ payer: TransactionSigner; /** The PDA account where the RuleSet is stored */ ruleSetPda: Address; /** System program */ systemProgram?: Address; puffRuleSetArgs: PuffRuleSetInstructionDataArgs["puffRuleSetArgs"]; }; /** * Grows a RuleSet PDA by reallocating additional space. * * Used to pre-allocate ("puff up") the account to the size a large * RuleSet will need before writing to it, since a single instruction * can only grow an account by a limited amount. */ export function getPuffRuleSetInstruction< TAccountPayer extends string, TAccountRuleSetPda extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, >( input: PuffRuleSetInput< TAccountPayer, TAccountRuleSetPda, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): PuffRuleSetInstruction< TProgramAddress, TAccountPayer, TAccountRuleSetPda, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, ruleSetPda: { value: input.ruleSetPda ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("payer", accounts.payer), getAccountMeta("ruleSetPda", accounts.ruleSetPda), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getPuffRuleSetInstructionDataEncoder().encode( args as PuffRuleSetInstructionDataArgs, ), programAddress, } as PuffRuleSetInstruction< TProgramAddress, TAccountPayer, TAccountRuleSetPda, TAccountSystemProgram >); } export type ParsedPuffRuleSetInstruction< TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Payer and creator of the RuleSet */ payer: TAccountMetas[0]; /** The PDA account where the RuleSet is stored */ ruleSetPda: TAccountMetas[1]; /** System program */ systemProgram: TAccountMetas[2]; }; data: PuffRuleSetInstructionData; }; export function parsePuffRuleSetInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedPuffRuleSetInstruction { if (instruction.accounts.length < 3) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), ruleSetPda: getNextAccount(), systemProgram: getNextAccount(), }, data: getPuffRuleSetInstructionDataDecoder().decode(instruction.data), }; }