/** * 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, getU32Decoder, getU32Encoder, 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"; import { getFeeDecoder, getFeeEncoder, type Fee, type FeeArgs, } from "../types/index.ts"; export const INITIALIZE_DISCRIMINATOR = 0; export function getInitializeDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(INITIALIZE_DISCRIMINATOR); } export type InitializeInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountManager extends string | AccountMeta = string, TAccountStaker extends string | AccountMeta = string, TAccountWithdrawAuthority extends string | AccountMeta = string, TAccountValidatorList extends string | AccountMeta = string, TAccountReserveStake extends string | AccountMeta = string, TAccountPoolMint extends string | AccountMeta = string, TAccountFeeAccount extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountDepositAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountManager extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountManager, TAccountStaker extends string ? ReadonlyAccount : TAccountStaker, TAccountWithdrawAuthority extends string ? ReadonlyAccount : TAccountWithdrawAuthority, TAccountValidatorList extends string ? WritableAccount : TAccountValidatorList, TAccountReserveStake extends string ? ReadonlyAccount : TAccountReserveStake, TAccountPoolMint extends string ? ReadonlyAccount : TAccountPoolMint, TAccountFeeAccount extends string ? ReadonlyAccount : TAccountFeeAccount, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountDepositAuthority extends string ? ReadonlyAccount : TAccountDepositAuthority, ...TRemainingAccounts, ] >; export type InitializeInstructionData = { discriminator: number; fee: Fee; withdrawalFee: Fee; depositFee: Fee; referralFee: number; maxValidators: number; }; export type InitializeInstructionDataArgs = { fee: FeeArgs; withdrawalFee: FeeArgs; depositFee: FeeArgs; referralFee: number; maxValidators: number; }; export function getInitializeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["fee", getFeeEncoder()], ["withdrawalFee", getFeeEncoder()], ["depositFee", getFeeEncoder()], ["referralFee", getU8Encoder()], ["maxValidators", getU32Encoder()], ]), (value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR }), ); } export function getInitializeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["fee", getFeeDecoder()], ["withdrawalFee", getFeeDecoder()], ["depositFee", getFeeDecoder()], ["referralFee", getU8Decoder()], ["maxValidators", getU32Decoder()], ]); } export function getInitializeInstructionDataCodec(): FixedSizeCodec< InitializeInstructionDataArgs, InitializeInstructionData > { return combineCodec( getInitializeInstructionDataEncoder(), getInitializeInstructionDataDecoder(), ); } export type InitializeAsyncInput< TAccountStakePool extends string = string, TAccountManager extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountPoolMint extends string = string, TAccountFeeAccount extends string = string, TAccountTokenProgram extends string = string, TAccountDepositAuthority extends string = string, > = { stakePool: Address; manager: TransactionSigner; staker: Address; withdrawAuthority?: Address; validatorList: Address; reserveStake: Address; poolMint: Address; feeAccount: Address; tokenProgram?: Address; depositAuthority: | Address | TransactionSigner; fee: InitializeInstructionDataArgs["fee"]; withdrawalFee: InitializeInstructionDataArgs["withdrawalFee"]; depositFee: InitializeInstructionDataArgs["depositFee"]; referralFee: InitializeInstructionDataArgs["referralFee"]; maxValidators: InitializeInstructionDataArgs["maxValidators"]; }; /** * Initializes a new `StakePool`. * 0. `[w]` New `StakePool` to create. * 1. `[s]` Manager * 2. `[]` Staker * 3. `[]` Stake pool withdraw authority * 4. `[w]` Uninitialized validator stake list storage account * 5. `[]` Reserve stake account must be initialized, have zero balance, * and staker / withdrawer authority set to pool withdraw authority. * 6. `[]` Pool token mint. Must have zero supply, owned by withdraw * authority. * 7. `[]` Pool account to deposit the generated fee for manager. * 8. `[]` Token program id * 9. `[]` (Optional) Deposit authority that must sign all deposits. * Defaults to the program address generated using * `find_deposit_authority_program_address`, making deposits * permissionless. */ export async function getInitializeInstructionAsync< TAccountStakePool extends string, TAccountManager extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountPoolMint extends string, TAccountFeeAccount extends string, TAccountTokenProgram extends string, TAccountDepositAuthority extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: InitializeAsyncInput< TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, TAccountDepositAuthority >, config?: { programAddress?: TProgramAddress }, ): Promise< InitializeInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, (typeof input)["depositAuthority"] extends TransactionSigner ? ReadonlySignerAccount & AccountSignerMeta : TAccountDepositAuthority > > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, manager: { value: input.manager ?? 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: false }, poolMint: { value: input.poolMint ?? null, isWritable: false }, feeAccount: { value: input.feeAccount ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, depositAuthority: { value: input.depositAuthority ?? 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.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("manager", accounts.manager), getAccountMeta("staker", accounts.staker), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("feeAccount", accounts.feeAccount), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("depositAuthority", accounts.depositAuthority), ], data: getInitializeInstructionDataEncoder().encode( args as InitializeInstructionDataArgs, ), programAddress, } as InitializeInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, (typeof input)["depositAuthority"] extends TransactionSigner ? ReadonlySignerAccount & AccountSignerMeta : TAccountDepositAuthority >); } export type InitializeInput< TAccountStakePool extends string = string, TAccountManager extends string = string, TAccountStaker extends string = string, TAccountWithdrawAuthority extends string = string, TAccountValidatorList extends string = string, TAccountReserveStake extends string = string, TAccountPoolMint extends string = string, TAccountFeeAccount extends string = string, TAccountTokenProgram extends string = string, TAccountDepositAuthority extends string = string, > = { stakePool: Address; manager: TransactionSigner; staker: Address; withdrawAuthority: Address; validatorList: Address; reserveStake: Address; poolMint: Address; feeAccount: Address; tokenProgram?: Address; depositAuthority: | Address | TransactionSigner; fee: InitializeInstructionDataArgs["fee"]; withdrawalFee: InitializeInstructionDataArgs["withdrawalFee"]; depositFee: InitializeInstructionDataArgs["depositFee"]; referralFee: InitializeInstructionDataArgs["referralFee"]; maxValidators: InitializeInstructionDataArgs["maxValidators"]; }; /** * Initializes a new `StakePool`. * 0. `[w]` New `StakePool` to create. * 1. `[s]` Manager * 2. `[]` Staker * 3. `[]` Stake pool withdraw authority * 4. `[w]` Uninitialized validator stake list storage account * 5. `[]` Reserve stake account must be initialized, have zero balance, * and staker / withdrawer authority set to pool withdraw authority. * 6. `[]` Pool token mint. Must have zero supply, owned by withdraw * authority. * 7. `[]` Pool account to deposit the generated fee for manager. * 8. `[]` Token program id * 9. `[]` (Optional) Deposit authority that must sign all deposits. * Defaults to the program address generated using * `find_deposit_authority_program_address`, making deposits * permissionless. */ export function getInitializeInstruction< TAccountStakePool extends string, TAccountManager extends string, TAccountStaker extends string, TAccountWithdrawAuthority extends string, TAccountValidatorList extends string, TAccountReserveStake extends string, TAccountPoolMint extends string, TAccountFeeAccount extends string, TAccountTokenProgram extends string, TAccountDepositAuthority extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: InitializeInput< TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, TAccountDepositAuthority >, config?: { programAddress?: TProgramAddress }, ): InitializeInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, (typeof input)["depositAuthority"] extends TransactionSigner ? ReadonlySignerAccount & AccountSignerMeta : TAccountDepositAuthority > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, manager: { value: input.manager ?? 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: false }, poolMint: { value: input.poolMint ?? null, isWritable: false }, feeAccount: { value: input.feeAccount ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, depositAuthority: { value: input.depositAuthority ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // 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("manager", accounts.manager), getAccountMeta("staker", accounts.staker), getAccountMeta("withdrawAuthority", accounts.withdrawAuthority), getAccountMeta("validatorList", accounts.validatorList), getAccountMeta("reserveStake", accounts.reserveStake), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("feeAccount", accounts.feeAccount), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("depositAuthority", accounts.depositAuthority), ], data: getInitializeInstructionDataEncoder().encode( args as InitializeInstructionDataArgs, ), programAddress, } as InitializeInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountStaker, TAccountWithdrawAuthority, TAccountValidatorList, TAccountReserveStake, TAccountPoolMint, TAccountFeeAccount, TAccountTokenProgram, (typeof input)["depositAuthority"] extends TransactionSigner ? ReadonlySignerAccount & AccountSignerMeta : TAccountDepositAuthority >); } export type ParsedInitializeInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { stakePool: TAccountMetas[0]; manager: TAccountMetas[1]; staker: TAccountMetas[2]; withdrawAuthority: TAccountMetas[3]; validatorList: TAccountMetas[4]; reserveStake: TAccountMetas[5]; poolMint: TAccountMetas[6]; feeAccount: TAccountMetas[7]; tokenProgram: TAccountMetas[8]; depositAuthority: TAccountMetas[9]; }; data: InitializeInstructionData; }; export function parseInitializeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializeInstruction { if (instruction.accounts.length < 10) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 10, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), manager: getNextAccount(), staker: getNextAccount(), withdrawAuthority: getNextAccount(), validatorList: getNextAccount(), reserveStake: getNextAccount(), poolMint: getNextAccount(), feeAccount: getNextAccount(), tokenProgram: getNextAccount(), depositAuthority: getNextAccount(), }, data: getInitializeInstructionDataDecoder().decode(instruction.data), }; }