/** * 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 AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const CLOSE_MINT_MAP_DISCRIMINATOR = new Uint8Array([ 146, 212, 203, 239, 191, 104, 38, 102, ]); export function getCloseMintMapDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_MINT_MAP_DISCRIMINATOR, ); } export type CloseMintMapInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TAccountMappings extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountConfiguration extends string ? ReadonlyAccount : TAccountConfiguration, TAccountMappings extends string ? WritableAccount : TAccountMappings, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type CloseMintMapInstructionData = { discriminator: ReadonlyUint8Array }; export type CloseMintMapInstructionDataArgs = {}; export function getCloseMintMapInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_MINT_MAP_DISCRIMINATOR }), ); } export function getCloseMintMapInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseMintMapInstructionDataCodec(): FixedSizeCodec< CloseMintMapInstructionDataArgs, CloseMintMapInstructionData > { return combineCodec( getCloseMintMapInstructionDataEncoder(), getCloseMintMapInstructionDataDecoder(), ); } export type CloseMintMapInput< TAccountAdmin extends string = string, TAccountConfiguration extends string = string, TAccountMappings extends string = string, TAccountSystemProgram extends string = string, > = { admin: TransactionSigner; configuration: Address; mappings: Address; systemProgram?: Address; }; export function getCloseMintMapInstruction< TAccountAdmin extends string, TAccountConfiguration extends string, TAccountMappings extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: CloseMintMapInput< TAccountAdmin, TAccountConfiguration, TAccountMappings, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): CloseMintMapInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountMappings, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, configuration: { value: input.configuration ?? null, isWritable: false }, mappings: { value: input.mappings ?? null, isWritable: true }, 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"); return Object.freeze({ accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.configuration), getAccountMeta(accounts.mappings), getAccountMeta(accounts.systemProgram), ], data: getCloseMintMapInstructionDataEncoder().encode({}), programAddress, } as CloseMintMapInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountMappings, TAccountSystemProgram >); } export type ParsedCloseMintMapInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; configuration: TAccountMetas[1]; mappings: TAccountMetas[2]; systemProgram: TAccountMetas[3]; }; data: CloseMintMapInstructionData; }; export function parseCloseMintMapInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseMintMapInstruction { if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { admin: getNextAccount(), configuration: getNextAccount(), mappings: getNextAccount(), systemProgram: getNextAccount(), }, data: getCloseMintMapInstructionDataDecoder().decode(instruction.data), }; }