/** * 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 Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from "@solana/kit"; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.ts"; export const CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR = 8; export function getCleanupRemovedValidatorEntriesDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR); } export type CleanupRemovedValidatorEntriesInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountValidatorList extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? ReadonlyAccount : TAccountStakePool, TAccountValidatorList extends string ? WritableAccount : TAccountValidatorList, ...TRemainingAccounts, ] >; export type CleanupRemovedValidatorEntriesInstructionData = { discriminator: number; }; export type CleanupRemovedValidatorEntriesInstructionDataArgs = {}; export function getCleanupRemovedValidatorEntriesInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", getU8Encoder()]]), (value) => ({ ...value, discriminator: CLEANUP_REMOVED_VALIDATOR_ENTRIES_DISCRIMINATOR, }), ); } export function getCleanupRemovedValidatorEntriesInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([["discriminator", getU8Decoder()]]); } export function getCleanupRemovedValidatorEntriesInstructionDataCodec(): FixedSizeCodec< CleanupRemovedValidatorEntriesInstructionDataArgs, CleanupRemovedValidatorEntriesInstructionData > { return combineCodec( getCleanupRemovedValidatorEntriesInstructionDataEncoder(), getCleanupRemovedValidatorEntriesInstructionDataDecoder(), ); } export type CleanupRemovedValidatorEntriesInput< TAccountStakePool extends string = string, TAccountValidatorList extends string = string, > = { stakePool: Address; validatorList: Address; }; /** * Cleans up validator stake account entries marked as `ReadyForRemoval` * 0. `[]` Stake pool * 1. `[w]` Validator stake list storage account */ export function getCleanupRemovedValidatorEntriesInstruction< TAccountStakePool extends string, TAccountValidatorList extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: CleanupRemovedValidatorEntriesInput< TAccountStakePool, TAccountValidatorList >, config?: { programAddress?: TProgramAddress }, ): CleanupRemovedValidatorEntriesInstruction< TProgramAddress, TAccountStakePool, TAccountValidatorList > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: false }, validatorList: { value: input.validatorList ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("validatorList", accounts.validatorList), ], data: getCleanupRemovedValidatorEntriesInstructionDataEncoder().encode({}), programAddress, } as CleanupRemovedValidatorEntriesInstruction< TProgramAddress, TAccountStakePool, TAccountValidatorList >); } export type ParsedCleanupRemovedValidatorEntriesInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { stakePool: TAccountMetas[0]; validatorList: TAccountMetas[1]; }; data: CleanupRemovedValidatorEntriesInstructionData; }; export function parseCleanupRemovedValidatorEntriesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCleanupRemovedValidatorEntriesInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), validatorList: getNextAccount() }, data: getCleanupRemovedValidatorEntriesInstructionDataDecoder().decode( instruction.data, ), }; }