/** * 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, getU32Decoder, getU32Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core'; import { LOADER_V3_PROGRAM_ADDRESS } from '../programs'; export const CLOSE_DISCRIMINATOR = 5; export function getCloseDiscriminatorBytes(): ReadonlyUint8Array { return getU32Encoder().encode(CLOSE_DISCRIMINATOR); } export type CloseInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountBufferOrProgramDataAccount extends string | AccountMeta = string, TAccountDestinationAccount extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountProgramAccount extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountBufferOrProgramDataAccount extends string ? WritableAccount : TAccountBufferOrProgramDataAccount, TAccountDestinationAccount extends string ? WritableAccount : TAccountDestinationAccount, TAccountAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAuthority, TAccountProgramAccount extends string ? ReadonlyAccount : TAccountProgramAccount, ...TRemainingAccounts, ] >; export type CloseInstructionData = { discriminator: number }; export type CloseInstructionDataArgs = {}; export function getCloseInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({ ...value, discriminator: CLOSE_DISCRIMINATOR, })); } export function getCloseInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU32Decoder()]]); } export function getCloseInstructionDataCodec(): FixedSizeCodec { return combineCodec(getCloseInstructionDataEncoder(), getCloseInstructionDataDecoder()); } export type CloseInput< TAccountBufferOrProgramDataAccount extends string = string, TAccountDestinationAccount extends string = string, TAccountAuthority extends string = string, TAccountProgramAccount extends string = string, > = { /** Buffer or ProgramData account to close. */ bufferOrProgramDataAccount: Address; /** Destination account for reclaimed lamports. */ destinationAccount: Address; /** Authority (optional). */ authority?: TransactionSigner; /** Program account (optional). */ programAccount?: Address; }; export function getCloseInstruction< TAccountBufferOrProgramDataAccount extends string, TAccountDestinationAccount extends string, TAccountAuthority extends string, TAccountProgramAccount extends string, TProgramAddress extends Address = typeof LOADER_V3_PROGRAM_ADDRESS, >( input: CloseInput< TAccountBufferOrProgramDataAccount, TAccountDestinationAccount, TAccountAuthority, TAccountProgramAccount >, config?: { programAddress?: TProgramAddress }, ): CloseInstruction< TProgramAddress, TAccountBufferOrProgramDataAccount, TAccountDestinationAccount, TAccountAuthority, TAccountProgramAccount > { // Program address. const programAddress = config?.programAddress ?? LOADER_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { bufferOrProgramDataAccount: { value: input.bufferOrProgramDataAccount ?? null, isWritable: true }, destinationAccount: { value: input.destinationAccount ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, programAccount: { value: input.programAccount ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('bufferOrProgramDataAccount', accounts.bufferOrProgramDataAccount), getAccountMeta('destinationAccount', accounts.destinationAccount), getAccountMeta('authority', accounts.authority), getAccountMeta('programAccount', accounts.programAccount), ], data: getCloseInstructionDataEncoder().encode({}), programAddress, } as CloseInstruction< TProgramAddress, TAccountBufferOrProgramDataAccount, TAccountDestinationAccount, TAccountAuthority, TAccountProgramAccount >); } export type ParsedCloseInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Buffer or ProgramData account to close. */ bufferOrProgramDataAccount: TAccountMetas[0]; /** Destination account for reclaimed lamports. */ destinationAccount: TAccountMetas[1]; /** Authority (optional). */ authority?: TAccountMetas[2] | undefined; /** Program account (optional). */ programAccount?: TAccountMetas[3] | undefined; }; data: CloseInstructionData; }; export function parseCloseInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseInstruction { if (instruction.accounts.length < 4) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === LOADER_V3_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { bufferOrProgramDataAccount: getNextAccount(), destinationAccount: getNextAccount(), authority: getNextOptionalAccount(), programAccount: getNextOptionalAccount(), }, data: getCloseInstructionDataDecoder().decode(instruction.data), }; }