/** * 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, getBooleanDecoder, getBooleanEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findWithdrawAuthorityPda } from "../pdas/index.ts"; import { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.ts"; export const UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR = 6; export function getUpdateValidatorListBalanceDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR); } export type UpdateValidatorListBalanceInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountWithdrawAuthority extends string | AccountMeta = string, TAccountValidatorList extends string | AccountMeta = string, TAccountReserveStake extends string | AccountMeta = string, TAccountClockSysvar extends string | AccountMeta = "SysvarC1ock11111111111111111111111111111111", TAccountStakeHistorySysvar extends string | AccountMeta = "SysvarStakeHistory1111111111111111111111111", TAccountStakeProgram extends string | AccountMeta = "Stake11111111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? ReadonlyAccount : TAccountStakePool, TAccountWithdrawAuthority extends string ? ReadonlyAccount : TAccountWithdrawAuthority, TAccountValidatorList extends string ? WritableAccount : TAccountValidatorList, TAccountReserveStake extends string ? WritableAccount : TAccountReserveStake, TAccountClockSysvar extends string ? ReadonlyAccount : TAccountClockSysvar, TAccountStakeHistorySysvar extends string ? ReadonlyAccount : TAccountStakeHistorySysvar, TAccountStakeProgram extends string ? ReadonlyAccount : TAccountStakeProgram, ...TRemainingAccounts, ] >; export type UpdateValidatorListBalanceInstructionData = { discriminator: number; startIndex: number; noMerge: boolean; }; export type UpdateValidatorListBalanceInstructionDataArgs = { startIndex: number; noMerge: boolean; }; export function getUpdateValidatorListBalanceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["startIndex", getU32Encoder()], ["noMerge", getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: UPDATE_VALIDATOR_LIST_BALANCE_DISCRIMINATOR, }), ); } export function getUpdateValidatorListBalanceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["startIndex", getU32Decoder()], ["noMerge", getBooleanDecoder()], ]); } export function getUpdateValidatorListBalanceInstructionDataCodec(): FixedSizeCodec< UpdateValidatorListBalanceInstructionDataArgs, UpdateValidatorListBalanceInstructionData > { return combineCodec( getUpdateValidatorListBalanceInstructionDataEncoder(), getUpdateValidatorListBalanceInstructionDataDecoder(), ); } export type UpdateValidatorListBalanceAsyncInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountClockSysvar extends string = string, TAccountStakeHistorySysvar extends string = string, TAccountStakeProgram extends string = string, > = { stakePool: Address; withdrawAuthority?: Address; validatorList: Address; reserveStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; stakeProgram?: Address; startIndex: UpdateValidatorListBalanceInstructionDataArgs["startIndex"]; noMerge: UpdateValidatorListBalanceInstructionDataArgs["noMerge"]; }; /** * Updates balances of validator and transient stake accounts in the pool * While going through the pairs of validator and transient stake * accounts, if the transient stake is inactive, it is merged into the * reserve stake account. If the transient stake is active and has * matching credits observed, it is merged into the canonical * validator stake account. In all other states, nothing is done, and * the balance is simply added to the canonical stake account balance. * 0. `[]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Validator stake list storage account * 3. `[w]` Reserve stake account * 4. `[]` Sysvar clock * 5. `[]` Sysvar stake history * 6. `[]` Stake program * 7. `..7+2N` [] N pairs of validator and transient stake accounts */ export async function getUpdateValidatorListBalanceInstructionAsync< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountClockSysvar extends string, TAccountStakeHistorySysvar extends string, TAccountStakeProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: UpdateValidatorListBalanceAsyncInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< UpdateValidatorListBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram > > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: false }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, stakeHistorySysvar: { value: input.stakeHistorySysvar ?? null, isWritable: false, }, stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.withdrawAuthority.value) { accounts.withdrawAuthority.value = await findWithdrawAuthorityPda( { stakePoolAddress: getAddressFromResolvedInstructionAccount( "stakePool", accounts.stakePool.value, ), }, { programAddress }, ); } if (!accounts.clockSysvar.value) { accounts.clockSysvar.value = "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; } if (!accounts.stakeHistorySysvar.value) { accounts.stakeHistorySysvar.value = "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; } if (!accounts.stakeProgram.value) { accounts.stakeProgram.value = "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getUpdateValidatorListBalanceInstructionDataEncoder().encode( args as UpdateValidatorListBalanceInstructionDataArgs, ), programAddress, } as UpdateValidatorListBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram >); } export type UpdateValidatorListBalanceInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountClockSysvar extends string = string, TAccountStakeHistorySysvar extends string = string, TAccountStakeProgram extends string = string, > = { stakePool: Address; withdrawAuthority: Address; validatorList: Address; reserveStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; stakeProgram?: Address; startIndex: UpdateValidatorListBalanceInstructionDataArgs["startIndex"]; noMerge: UpdateValidatorListBalanceInstructionDataArgs["noMerge"]; }; /** * Updates balances of validator and transient stake accounts in the pool * While going through the pairs of validator and transient stake * accounts, if the transient stake is inactive, it is merged into the * reserve stake account. If the transient stake is active and has * matching credits observed, it is merged into the canonical * validator stake account. In all other states, nothing is done, and * the balance is simply added to the canonical stake account balance. * 0. `[]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Validator stake list storage account * 3. `[w]` Reserve stake account * 4. `[]` Sysvar clock * 5. `[]` Sysvar stake history * 6. `[]` Stake program * 7. `..7+2N` [] N pairs of validator and transient stake accounts */ export function getUpdateValidatorListBalanceInstruction< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountClockSysvar extends string, TAccountStakeHistorySysvar extends string, TAccountStakeProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: UpdateValidatorListBalanceInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): UpdateValidatorListBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: false }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, stakeHistorySysvar: { value: input.stakeHistorySysvar ?? null, isWritable: false, }, stakeProgram: { value: input.stakeProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.clockSysvar.value) { accounts.clockSysvar.value = "SysvarC1ock11111111111111111111111111111111" as Address<"SysvarC1ock11111111111111111111111111111111">; } if (!accounts.stakeHistorySysvar.value) { accounts.stakeHistorySysvar.value = "SysvarStakeHistory1111111111111111111111111" as Address<"SysvarStakeHistory1111111111111111111111111">; } if (!accounts.stakeProgram.value) { accounts.stakeProgram.value = "Stake11111111111111111111111111111111111111" as Address<"Stake11111111111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getUpdateValidatorListBalanceInstructionDataEncoder().encode( args as UpdateValidatorListBalanceInstructionDataArgs, ), programAddress, } as UpdateValidatorListBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountStakeProgram >); } export type ParsedUpdateValidatorListBalanceInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { stakePool: TAccountMetas[0]; withdrawAuthority: TAccountMetas[1]; validatorList: TAccountMetas[2]; reserveStake: TAccountMetas[3]; clockSysvar: TAccountMetas[4]; stakeHistorySysvar: TAccountMetas[5]; stakeProgram: TAccountMetas[6]; }; data: UpdateValidatorListBalanceInstructionData; }; export function parseUpdateValidatorListBalanceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdateValidatorListBalanceInstruction { if (instruction.accounts.length < 7) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), withdrawAuthority: getNextAccount(), validatorList: getNextAccount(), reserveStake: getNextAccount(), clockSysvar: getNextAccount(), stakeHistorySysvar: getNextAccount(), stakeProgram: getNextAccount(), }, data: getUpdateValidatorListBalanceInstructionDataDecoder().decode( instruction.data, ), }; }