/** * 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, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, 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, 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 DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR = 21; export function getDecreaseValidatorStakeWithReserveDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode( DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR, ); } export type DecreaseValidatorStakeWithReserveInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountStaker extends string | AccountMeta = string, TAccountWithdrawAuthority extends string | AccountMeta = string, TAccountValidatorList extends string | AccountMeta = string, TAccountReserveStake extends string | AccountMeta = string, TAccountCanonicalStake extends string | AccountMeta = string, TAccountTransientStake extends string | AccountMeta = string, TAccountClockSysvar extends string | AccountMeta = "SysvarC1ock11111111111111111111111111111111", TAccountStakeHistorySysvar extends string | AccountMeta = "SysvarStakeHistory1111111111111111111111111", TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountStakeProgram extends string | AccountMeta = "Stake11111111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? ReadonlyAccount : TAccountStakePool, TAccountStaker extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountStaker, TAccountWithdrawAuthority extends string ? ReadonlyAccount : TAccountWithdrawAuthority, TAccountValidatorList extends string ? WritableAccount : TAccountValidatorList, TAccountReserveStake extends string ? WritableAccount : TAccountReserveStake, TAccountCanonicalStake extends string ? WritableAccount : TAccountCanonicalStake, TAccountTransientStake extends string ? WritableAccount : TAccountTransientStake, TAccountClockSysvar extends string ? ReadonlyAccount : TAccountClockSysvar, TAccountStakeHistorySysvar extends string ? ReadonlyAccount : TAccountStakeHistorySysvar, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountStakeProgram extends string ? ReadonlyAccount : TAccountStakeProgram, ...TRemainingAccounts, ] >; export type DecreaseValidatorStakeWithReserveInstructionData = { discriminator: number; lamports: bigint; transientStakeSeed: bigint; }; export type DecreaseValidatorStakeWithReserveInstructionDataArgs = { lamports: number | bigint; transientStakeSeed: number | bigint; }; export function getDecreaseValidatorStakeWithReserveInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["lamports", getU64Encoder()], ["transientStakeSeed", getU64Encoder()], ]), (value) => ({ ...value, discriminator: DECREASE_VALIDATOR_STAKE_WITH_RESERVE_DISCRIMINATOR, }), ); } export function getDecreaseValidatorStakeWithReserveInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["lamports", getU64Decoder()], ["transientStakeSeed", getU64Decoder()], ]); } export function getDecreaseValidatorStakeWithReserveInstructionDataCodec(): FixedSizeCodec< DecreaseValidatorStakeWithReserveInstructionDataArgs, DecreaseValidatorStakeWithReserveInstructionData > { return combineCodec( getDecreaseValidatorStakeWithReserveInstructionDataEncoder(), getDecreaseValidatorStakeWithReserveInstructionDataDecoder(), ); } export type DecreaseValidatorStakeWithReserveAsyncInput< TAccountStakePool extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountCanonicalStake extends string = string, TAccountTransientStake extends string = string, TAccountClockSysvar extends string = string, TAccountStakeHistorySysvar extends string = string, TAccountSystemProgram extends string = string, TAccountStakeProgram extends string = string, > = { stakePool: Address; staker: TransactionSigner; withdrawAuthority?: Address; validatorList: Address; reserveStake: Address; canonicalStake: Address; transientStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; systemProgram?: Address; stakeProgram?: Address; lamports: DecreaseValidatorStakeWithReserveInstructionDataArgs["lamports"]; transientStakeSeed: DecreaseValidatorStakeWithReserveInstructionDataArgs["transientStakeSeed"]; }; /** * (Staker only) Decrease active stake on a validator, eventually moving it * to the reserve * Internally, this instruction: * * withdraws enough lamports to make the transient account rent-exempt * * splits from a validator stake account into a transient stake account * * deactivates the transient stake account * In order to rebalance the pool without taking custody, the staker needs * a way of reducing the stake on a stake account. This instruction splits * some amount of stake, up to the total activated stake, from the * canonical validator stake account, into its "transient" stake * account. * The instruction only succeeds if the transient stake account does not * exist. The amount of lamports to move must be at least rent-exemption * plus `max(crate::MINIMUM_ACTIVE_STAKE, * solana_program::stake::tools::get_minimum_delegation())`. * 0. `[]` Stake pool * 1. `[s]` Stake pool staker * 2. `[]` Stake pool withdraw authority * 3. `[w]` Validator list * 4. `[w]` Reserve stake account, to fund rent exempt reserve * 5. `[w]` Canonical stake account to split from * 6. `[w]` Transient stake account to receive split * 7. `[]` Clock sysvar * 8. '[]' Stake history sysvar * 9. `[]` System program * 10. `[]` Stake program */ export async function getDecreaseValidatorStakeWithReserveInstructionAsync< TAccountStakePool extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountCanonicalStake extends string, TAccountTransientStake extends string, TAccountClockSysvar extends string, TAccountStakeHistorySysvar extends string, TAccountSystemProgram extends string, TAccountStakeProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: DecreaseValidatorStakeWithReserveAsyncInput< TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< DecreaseValidatorStakeWithReserveInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram > > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: false }, staker: { value: input.staker ?? null, isWritable: false }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, transientStake: { value: input.transientStake ?? null, isWritable: true }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, stakeHistorySysvar: { value: input.stakeHistorySysvar ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("staker", accounts.staker), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("canonicalStake", accounts.canonicalStake), getAccountMeta("transientStake", accounts.transientStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getDecreaseValidatorStakeWithReserveInstructionDataEncoder().encode( args as DecreaseValidatorStakeWithReserveInstructionDataArgs, ), programAddress, } as DecreaseValidatorStakeWithReserveInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >); } export type DecreaseValidatorStakeWithReserveInput< TAccountStakePool extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountCanonicalStake extends string = string, TAccountTransientStake extends string = string, TAccountClockSysvar extends string = string, TAccountStakeHistorySysvar extends string = string, TAccountSystemProgram extends string = string, TAccountStakeProgram extends string = string, > = { stakePool: Address; staker: TransactionSigner; withdrawAuthority: Address; validatorList: Address; reserveStake: Address; canonicalStake: Address; transientStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; systemProgram?: Address; stakeProgram?: Address; lamports: DecreaseValidatorStakeWithReserveInstructionDataArgs["lamports"]; transientStakeSeed: DecreaseValidatorStakeWithReserveInstructionDataArgs["transientStakeSeed"]; }; /** * (Staker only) Decrease active stake on a validator, eventually moving it * to the reserve * Internally, this instruction: * * withdraws enough lamports to make the transient account rent-exempt * * splits from a validator stake account into a transient stake account * * deactivates the transient stake account * In order to rebalance the pool without taking custody, the staker needs * a way of reducing the stake on a stake account. This instruction splits * some amount of stake, up to the total activated stake, from the * canonical validator stake account, into its "transient" stake * account. * The instruction only succeeds if the transient stake account does not * exist. The amount of lamports to move must be at least rent-exemption * plus `max(crate::MINIMUM_ACTIVE_STAKE, * solana_program::stake::tools::get_minimum_delegation())`. * 0. `[]` Stake pool * 1. `[s]` Stake pool staker * 2. `[]` Stake pool withdraw authority * 3. `[w]` Validator list * 4. `[w]` Reserve stake account, to fund rent exempt reserve * 5. `[w]` Canonical stake account to split from * 6. `[w]` Transient stake account to receive split * 7. `[]` Clock sysvar * 8. '[]' Stake history sysvar * 9. `[]` System program * 10. `[]` Stake program */ export function getDecreaseValidatorStakeWithReserveInstruction< TAccountStakePool extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountCanonicalStake extends string, TAccountTransientStake extends string, TAccountClockSysvar extends string, TAccountStakeHistorySysvar extends string, TAccountSystemProgram extends string, TAccountStakeProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: DecreaseValidatorStakeWithReserveInput< TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): DecreaseValidatorStakeWithReserveInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: false }, staker: { value: input.staker ?? null, isWritable: false }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, canonicalStake: { value: input.canonicalStake ?? null, isWritable: true }, transientStake: { value: input.transientStake ?? null, isWritable: true }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, stakeHistorySysvar: { value: input.stakeHistorySysvar ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("staker", accounts.staker), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("canonicalStake", accounts.canonicalStake), getAccountMeta("transientStake", accounts.transientStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getDecreaseValidatorStakeWithReserveInstructionDataEncoder().encode( args as DecreaseValidatorStakeWithReserveInstructionDataArgs, ), programAddress, } as DecreaseValidatorStakeWithReserveInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >); } export type ParsedDecreaseValidatorStakeWithReserveInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { stakePool: TAccountMetas[0]; staker: TAccountMetas[1]; withdrawAuthority: TAccountMetas[2]; validatorList: TAccountMetas[3]; reserveStake: TAccountMetas[4]; canonicalStake: TAccountMetas[5]; transientStake: TAccountMetas[6]; clockSysvar: TAccountMetas[7]; stakeHistorySysvar: TAccountMetas[8]; systemProgram: TAccountMetas[9]; stakeProgram: TAccountMetas[10]; }; data: DecreaseValidatorStakeWithReserveInstructionData; }; export function parseDecreaseValidatorStakeWithReserveInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDecreaseValidatorStakeWithReserveInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), staker: getNextAccount(), withdrawAuthority: getNextAccount(), validatorList: getNextAccount(), reserveStake: getNextAccount(), canonicalStake: getNextAccount(), transientStake: getNextAccount(), clockSysvar: getNextAccount(), stakeHistorySysvar: getNextAccount(), systemProgram: getNextAccount(), stakeProgram: getNextAccount(), }, data: getDecreaseValidatorStakeWithReserveInstructionDataDecoder().decode( instruction.data, ), }; }