/** * 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_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR = 20; export function getDecreaseAdditionalValidatorStakeDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode( DECREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, ); } export type DecreaseAdditionalValidatorStakeInstruction< 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, TAccountEphemeralStake 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, TAccountEphemeralStake extends string ? WritableAccount : TAccountEphemeralStake, 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 DecreaseAdditionalValidatorStakeInstructionData = { discriminator: number; lamports: bigint; transientStakeSeed: bigint; ephemeralStakeSeed: bigint; }; export type DecreaseAdditionalValidatorStakeInstructionDataArgs = { lamports: number | bigint; transientStakeSeed: number | bigint; ephemeralStakeSeed: number | bigint; }; export function getDecreaseAdditionalValidatorStakeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["lamports", getU64Encoder()], ["transientStakeSeed", getU64Encoder()], ["ephemeralStakeSeed", getU64Encoder()], ]), (value) => ({ ...value, discriminator: DECREASE_ADDITIONAL_VALIDATOR_STAKE_DISCRIMINATOR, }), ); } export function getDecreaseAdditionalValidatorStakeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["lamports", getU64Decoder()], ["transientStakeSeed", getU64Decoder()], ["ephemeralStakeSeed", getU64Decoder()], ]); } export function getDecreaseAdditionalValidatorStakeInstructionDataCodec(): FixedSizeCodec< DecreaseAdditionalValidatorStakeInstructionDataArgs, DecreaseAdditionalValidatorStakeInstructionData > { return combineCodec( getDecreaseAdditionalValidatorStakeInstructionDataEncoder(), getDecreaseAdditionalValidatorStakeInstructionDataDecoder(), ); } export type DecreaseAdditionalValidatorStakeAsyncInput< TAccountStakePool extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountCanonicalStake extends string = string, TAccountEphemeralStake 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; ephemeralStake: Address; transientStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; systemProgram?: Address; stakeProgram?: Address; lamports: DecreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; transientStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; ephemeralStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; }; /** * (Staker only) Decrease active stake again from a validator, eventually * moving it to the reserve * Works regardless if the transient stake account already exists. * Internally, this instruction: * * withdraws rent-exempt reserve lamports from the reserve into the * ephemeral stake * * splits a validator stake account into an ephemeral stake account * * deactivates the ephemeral account * * merges or splits the ephemeral account into the transient stake * account delegated to the appropriate validator * The amount of lamports to move must be at least * `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]` Uninitialized ephemeral stake account to receive stake * 7. `[w]` Transient stake account * 8. `[]` Clock sysvar * 9. '[]' Stake history sysvar * 10. `[]` System program * 11. `[]` Stake program */ export async function getDecreaseAdditionalValidatorStakeInstructionAsync< TAccountStakePool extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountCanonicalStake extends string, TAccountEphemeralStake 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: DecreaseAdditionalValidatorStakeAsyncInput< TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< DecreaseAdditionalValidatorStakeInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, 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 }, ephemeralStake: { value: input.ephemeralStake ?? 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("ephemeralStake", accounts.ephemeralStake), getAccountMeta("transientStake", accounts.transientStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getDecreaseAdditionalValidatorStakeInstructionDataEncoder().encode( args as DecreaseAdditionalValidatorStakeInstructionDataArgs, ), programAddress, } as DecreaseAdditionalValidatorStakeInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >); } export type DecreaseAdditionalValidatorStakeInput< TAccountStakePool extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountCanonicalStake extends string = string, TAccountEphemeralStake 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; ephemeralStake: Address; transientStake: Address; clockSysvar?: Address; stakeHistorySysvar?: Address; systemProgram?: Address; stakeProgram?: Address; lamports: DecreaseAdditionalValidatorStakeInstructionDataArgs["lamports"]; transientStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["transientStakeSeed"]; ephemeralStakeSeed: DecreaseAdditionalValidatorStakeInstructionDataArgs["ephemeralStakeSeed"]; }; /** * (Staker only) Decrease active stake again from a validator, eventually * moving it to the reserve * Works regardless if the transient stake account already exists. * Internally, this instruction: * * withdraws rent-exempt reserve lamports from the reserve into the * ephemeral stake * * splits a validator stake account into an ephemeral stake account * * deactivates the ephemeral account * * merges or splits the ephemeral account into the transient stake * account delegated to the appropriate validator * The amount of lamports to move must be at least * `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]` Uninitialized ephemeral stake account to receive stake * 7. `[w]` Transient stake account * 8. `[]` Clock sysvar * 9. '[]' Stake history sysvar * 10. `[]` System program * 11. `[]` Stake program */ export function getDecreaseAdditionalValidatorStakeInstruction< TAccountStakePool extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountCanonicalStake extends string, TAccountEphemeralStake 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: DecreaseAdditionalValidatorStakeInput< TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >, config?: { programAddress?: TProgramAddress }, ): DecreaseAdditionalValidatorStakeInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, 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 }, ephemeralStake: { value: input.ephemeralStake ?? 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("ephemeralStake", accounts.ephemeralStake), getAccountMeta("transientStake", accounts.transientStake), getAccountMeta("clockSysvar", accounts.clockSysvar), getAccountMeta("stakeHistorySysvar", accounts.stakeHistorySysvar), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("stakeProgram", accounts.stakeProgram), ], data: getDecreaseAdditionalValidatorStakeInstructionDataEncoder().encode( args as DecreaseAdditionalValidatorStakeInstructionDataArgs, ), programAddress, } as DecreaseAdditionalValidatorStakeInstruction< TProgramAddress, TAccountStakePool, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountCanonicalStake, TAccountEphemeralStake, TAccountTransientStake, TAccountClockSysvar, TAccountStakeHistorySysvar, TAccountSystemProgram, TAccountStakeProgram >); } export type ParsedDecreaseAdditionalValidatorStakeInstruction< 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]; ephemeralStake: TAccountMetas[6]; transientStake: TAccountMetas[7]; clockSysvar: TAccountMetas[8]; stakeHistorySysvar: TAccountMetas[9]; systemProgram: TAccountMetas[10]; stakeProgram: TAccountMetas[11]; }; data: DecreaseAdditionalValidatorStakeInstructionData; }; export function parseDecreaseAdditionalValidatorStakeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDecreaseAdditionalValidatorStakeInstruction { if (instruction.accounts.length < 12) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 12, }, ); } 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(), ephemeralStake: getNextAccount(), transientStake: getNextAccount(), clockSysvar: getNextAccount(), stakeHistorySysvar: getNextAccount(), systemProgram: getNextAccount(), stakeProgram: getNextAccount(), }, data: getDecreaseAdditionalValidatorStakeInstructionDataDecoder().decode( instruction.data, ), }; }