/** * 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 { YVAULTS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const CLOSE_PROGRAM_ACCOUNT_DISCRIMINATOR = new Uint8Array([ 245, 14, 192, 211, 99, 42, 170, 187, ]); export function getCloseProgramAccountDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_PROGRAM_ACCOUNT_DISCRIMINATOR, ); } export type CloseProgramAccountInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = string, TAccountProgramData extends string | AccountMeta = string, TAccountClosingAccount extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminAuthority extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdminAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, TAccountProgramData extends string ? ReadonlyAccount : TAccountProgramData, TAccountClosingAccount extends string ? WritableAccount : TAccountClosingAccount, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type CloseProgramAccountInstructionData = { discriminator: ReadonlyUint8Array; }; export type CloseProgramAccountInstructionDataArgs = {}; export function getCloseProgramAccountInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_PROGRAM_ACCOUNT_DISCRIMINATOR, }), ); } export function getCloseProgramAccountInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseProgramAccountInstructionDataCodec(): FixedSizeCodec< CloseProgramAccountInstructionDataArgs, CloseProgramAccountInstructionData > { return combineCodec( getCloseProgramAccountInstructionDataEncoder(), getCloseProgramAccountInstructionDataDecoder(), ); } export type CloseProgramAccountInput< TAccountAdminAuthority extends string = string, TAccountProgram extends string = string, TAccountProgramData extends string = string, TAccountClosingAccount extends string = string, TAccountSystemProgram extends string = string, > = { adminAuthority: TransactionSigner; program: Address; programData: Address; closingAccount: Address; systemProgram?: Address; }; export function getCloseProgramAccountInstruction< TAccountAdminAuthority extends string, TAccountProgram extends string, TAccountProgramData extends string, TAccountClosingAccount extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: CloseProgramAccountInput< TAccountAdminAuthority, TAccountProgram, TAccountProgramData, TAccountClosingAccount, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): CloseProgramAccountInstruction< TProgramAddress, TAccountAdminAuthority, TAccountProgram, TAccountProgramData, TAccountClosingAccount, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: true }, program: { value: input.program ?? null, isWritable: false }, programData: { value: input.programData ?? null, isWritable: false }, closingAccount: { value: input.closingAccount ?? 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.adminAuthority), getAccountMeta(accounts.program), getAccountMeta(accounts.programData), getAccountMeta(accounts.closingAccount), getAccountMeta(accounts.systemProgram), ], data: getCloseProgramAccountInstructionDataEncoder().encode({}), programAddress, } as CloseProgramAccountInstruction< TProgramAddress, TAccountAdminAuthority, TAccountProgram, TAccountProgramData, TAccountClosingAccount, TAccountSystemProgram >); } export type ParsedCloseProgramAccountInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminAuthority: TAccountMetas[0]; program: TAccountMetas[1]; programData: TAccountMetas[2]; closingAccount: TAccountMetas[3]; systemProgram: TAccountMetas[4]; }; data: CloseProgramAccountInstructionData; }; export function parseCloseProgramAccountInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseProgramAccountInstruction { if (instruction.accounts.length < 5) { // 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: { adminAuthority: getNextAccount(), program: getNextAccount(), programData: getNextAccount(), closingAccount: getNextAccount(), systemProgram: getNextAccount(), }, data: getCloseProgramAccountInstructionDataDecoder().decode( instruction.data, ), }; }