/** * 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, 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_STAKE_POOL_BALANCE_DISCRIMINATOR = 7; export function getUpdateStakePoolBalanceDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(UPDATE_STAKE_POOL_BALANCE_DISCRIMINATOR); } export type UpdateStakePoolBalanceInstruction< 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, TAccountFeeAccount extends string | AccountMeta = string, TAccountPoolMint extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountWithdrawAuthority extends string ? ReadonlyAccount : TAccountWithdrawAuthority, TAccountValidatorList extends string ? WritableAccount : TAccountValidatorList, TAccountReserveStake extends string ? ReadonlyAccount : TAccountReserveStake, TAccountFeeAccount extends string ? WritableAccount : TAccountFeeAccount, TAccountPoolMint extends string ? WritableAccount : TAccountPoolMint, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, ...TRemainingAccounts, ] >; export type UpdateStakePoolBalanceInstructionData = { discriminator: number }; export type UpdateStakePoolBalanceInstructionDataArgs = {}; export function getUpdateStakePoolBalanceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", getU8Encoder()]]), (value) => ({ ...value, discriminator: UPDATE_STAKE_POOL_BALANCE_DISCRIMINATOR, }), ); } export function getUpdateStakePoolBalanceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([["discriminator", getU8Decoder()]]); } export function getUpdateStakePoolBalanceInstructionDataCodec(): FixedSizeCodec< UpdateStakePoolBalanceInstructionDataArgs, UpdateStakePoolBalanceInstructionData > { return combineCodec( getUpdateStakePoolBalanceInstructionDataEncoder(), getUpdateStakePoolBalanceInstructionDataDecoder(), ); } export type UpdateStakePoolBalanceAsyncInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountFeeAccount extends string = string, TAccountPoolMint extends string = string, TAccountTokenProgram extends string = string, > = { stakePool: Address; withdrawAuthority?: Address; validatorList: Address; reserveStake: Address; feeAccount: Address; poolMint: Address; tokenProgram?: Address; }; /** * Updates total pool balance based on balances in the reserve and * validator list * 0. `[w]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Validator stake list storage account * 3. `[]` Reserve stake account * 4. `[w]` Account to receive pool fee tokens * 5. `[w]` Pool mint account * 6. `[]` Pool token program */ export async function getUpdateStakePoolBalanceInstructionAsync< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountFeeAccount extends string, TAccountPoolMint extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: UpdateStakePoolBalanceAsyncInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< UpdateStakePoolBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram > > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: false }, feeAccount: { value: input.feeAccount ?? null, isWritable: true }, poolMint: { value: input.poolMint ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.withdrawAuthority.value) { accounts.withdrawAuthority.value = await findWithdrawAuthorityPda( { stakePoolAddress: getAddressFromResolvedInstructionAccount( "stakePool", accounts.stakePool.value, ), }, { programAddress }, ); } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } 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("feeAccount", accounts.feeAccount), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("tokenProgram", accounts.tokenProgram), ], data: getUpdateStakePoolBalanceInstructionDataEncoder().encode({}), programAddress, } as UpdateStakePoolBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram >); } export type UpdateStakePoolBalanceInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountFeeAccount extends string = string, TAccountPoolMint extends string = string, TAccountTokenProgram extends string = string, > = { stakePool: Address; withdrawAuthority: Address; validatorList: Address; reserveStake: Address; feeAccount: Address; poolMint: Address; tokenProgram?: Address; }; /** * Updates total pool balance based on balances in the reserve and * validator list * 0. `[w]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Validator stake list storage account * 3. `[]` Reserve stake account * 4. `[w]` Account to receive pool fee tokens * 5. `[w]` Pool mint account * 6. `[]` Pool token program */ export function getUpdateStakePoolBalanceInstruction< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountFeeAccount extends string, TAccountPoolMint extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: UpdateStakePoolBalanceInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram >, config?: { programAddress?: TProgramAddress }, ): UpdateStakePoolBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, withdrawAuthority: { value: input.withdrawAuthority ?? null, isWritable: false, }, validatorList: { value: input.validatorList ?? null, isWritable: true }, reserveStake: { value: input.reserveStake ?? null, isWritable: false }, feeAccount: { value: input.feeAccount ?? null, isWritable: true }, poolMint: { value: input.poolMint ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } 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("feeAccount", accounts.feeAccount), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("tokenProgram", accounts.tokenProgram), ], data: getUpdateStakePoolBalanceInstructionDataEncoder().encode({}), programAddress, } as UpdateStakePoolBalanceInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountFeeAccount, TAccountPoolMint, TAccountTokenProgram >); } export type ParsedUpdateStakePoolBalanceInstruction< 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]; feeAccount: TAccountMetas[4]; poolMint: TAccountMetas[5]; tokenProgram: TAccountMetas[6]; }; data: UpdateStakePoolBalanceInstructionData; }; export function parseUpdateStakePoolBalanceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdateStakePoolBalanceInstruction { 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(), feeAccount: getNextAccount(), poolMint: getNextAccount(), tokenProgram: getNextAccount(), }, data: getUpdateStakePoolBalanceInstructionDataDecoder().decode( instruction.data, ), }; }