/** * 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, type WritableSignerAccount, } 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 DEPOSIT_SOL_DISCRIMINATOR = 14; export function getDepositSolDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(DEPOSIT_SOL_DISCRIMINATOR); } export type DepositSolInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountWithdrawAuthority extends string | AccountMeta = string, TAccountReserveStake extends string | AccountMeta = string, TAccountPayer extends string | AccountMeta = string, TAccountUserPoolTokenAccount extends string | AccountMeta = string, TAccountManagerFeeAccount extends string | AccountMeta = string, TAccountReferralPoolAccount extends string | AccountMeta = string, TAccountPoolMint extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountTokenProgram extends string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountDepositAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountWithdrawAuthority extends string ? ReadonlyAccount : TAccountWithdrawAuthority, TAccountReserveStake extends string ? WritableAccount : TAccountReserveStake, TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountUserPoolTokenAccount extends string ? WritableAccount : TAccountUserPoolTokenAccount, TAccountManagerFeeAccount extends string ? WritableAccount : TAccountManagerFeeAccount, TAccountReferralPoolAccount extends string ? WritableAccount : TAccountReferralPoolAccount, TAccountPoolMint extends string ? WritableAccount : TAccountPoolMint, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountDepositAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountDepositAuthority, ...TRemainingAccounts, ] >; export type DepositSolInstructionData = { discriminator: number; args: bigint }; export type DepositSolInstructionDataArgs = { args: number | bigint }; export function getDepositSolInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["args", getU64Encoder()], ]), (value) => ({ ...value, discriminator: DEPOSIT_SOL_DISCRIMINATOR }), ); } export function getDepositSolInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["args", getU64Decoder()], ]); } export function getDepositSolInstructionDataCodec(): FixedSizeCodec< DepositSolInstructionDataArgs, DepositSolInstructionData > { return combineCodec( getDepositSolInstructionDataEncoder(), getDepositSolInstructionDataDecoder(), ); } export type DepositSolAsyncInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountReserveStake extends string = string, TAccountPayer extends string = string, TAccountUserPoolTokenAccount extends string = string, TAccountManagerFeeAccount extends string = string, TAccountReferralPoolAccount extends string = string, TAccountPoolMint extends string = string, TAccountSystemProgram extends string = string, TAccountTokenProgram extends string = string, TAccountDepositAuthority extends string = string, > = { /** Stake pool */ stakePool: Address; /** Stake pool withdraw authority */ withdrawAuthority?: Address; /** Reserve stake account, to deposit SOL */ reserveStake: Address; /** Account providing the lamports to be deposited into the pool */ payer: TransactionSigner; /** User account to receive pool tokens */ userPoolTokenAccount: Address; /** Account to receive fee tokens */ managerFeeAccount: Address; /** Account to receive a portion of fee as referral fees */ referralPoolAccount: Address; /** Pool token mint account */ poolMint: Address; /** System program account */ systemProgram?: Address; /** Token program id */ tokenProgram?: Address; /** (Optional) Stake pool sol deposit authority. */ depositAuthority?: TransactionSigner; args: DepositSolInstructionDataArgs["args"]; }; /** * Deposit SOL directly into the pool's reserve account. The output is a * "pool" token representing ownership into the pool. Inputs are * converted to the current ratio. * 0. `[w]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Reserve stake account, to deposit SOL * 3. `[s]` Account providing the lamports to be deposited into the pool * 4. `[w]` User account to receive pool tokens * 5. `[w]` Account to receive fee tokens * 6. `[w]` Account to receive a portion of fee as referral fees * 7. `[w]` Pool token mint account * 8. `[]` System program account * 9. `[]` Token program id * 10. `[s]` (Optional) Stake pool sol deposit authority. */ export async function getDepositSolInstructionAsync< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountReserveStake extends string, TAccountPayer extends string, TAccountUserPoolTokenAccount extends string, TAccountManagerFeeAccount extends string, TAccountReferralPoolAccount extends string, TAccountPoolMint extends string, TAccountSystemProgram extends string, TAccountTokenProgram extends string, TAccountDepositAuthority extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: DepositSolAsyncInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority >, config?: { programAddress?: TProgramAddress }, ): Promise< DepositSolInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority > > { // 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, }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, userPoolTokenAccount: { value: input.userPoolTokenAccount ?? null, isWritable: true, }, managerFeeAccount: { value: input.managerFeeAccount ?? null, isWritable: true, }, referralPoolAccount: { value: input.referralPoolAccount ?? null, isWritable: true, }, poolMint: { value: input.poolMint ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("reserveStake", accounts.reserveStake), getAccountMeta("payer", accounts.payer), getAccountMeta("userPoolTokenAccount", accounts.userPoolTokenAccount), getAccountMeta("managerFeeAccount", accounts.managerFeeAccount), getAccountMeta("referralPoolAccount", accounts.referralPoolAccount), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("depositAuthority", accounts.depositAuthority), ], data: getDepositSolInstructionDataEncoder().encode( args as DepositSolInstructionDataArgs, ), programAddress, } as DepositSolInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority >); } export type DepositSolInput< TAccountStakePool extends string = string, TAccountWithdrawAuthority extends string = string, TAccountReserveStake extends string = string, TAccountPayer extends string = string, TAccountUserPoolTokenAccount extends string = string, TAccountManagerFeeAccount extends string = string, TAccountReferralPoolAccount extends string = string, TAccountPoolMint extends string = string, TAccountSystemProgram extends string = string, TAccountTokenProgram extends string = string, TAccountDepositAuthority extends string = string, > = { /** Stake pool */ stakePool: Address; /** Stake pool withdraw authority */ withdrawAuthority: Address; /** Reserve stake account, to deposit SOL */ reserveStake: Address; /** Account providing the lamports to be deposited into the pool */ payer: TransactionSigner; /** User account to receive pool tokens */ userPoolTokenAccount: Address; /** Account to receive fee tokens */ managerFeeAccount: Address; /** Account to receive a portion of fee as referral fees */ referralPoolAccount: Address; /** Pool token mint account */ poolMint: Address; /** System program account */ systemProgram?: Address; /** Token program id */ tokenProgram?: Address; /** (Optional) Stake pool sol deposit authority. */ depositAuthority?: TransactionSigner; args: DepositSolInstructionDataArgs["args"]; }; /** * Deposit SOL directly into the pool's reserve account. The output is a * "pool" token representing ownership into the pool. Inputs are * converted to the current ratio. * 0. `[w]` Stake pool * 1. `[]` Stake pool withdraw authority * 2. `[w]` Reserve stake account, to deposit SOL * 3. `[s]` Account providing the lamports to be deposited into the pool * 4. `[w]` User account to receive pool tokens * 5. `[w]` Account to receive fee tokens * 6. `[w]` Account to receive a portion of fee as referral fees * 7. `[w]` Pool token mint account * 8. `[]` System program account * 9. `[]` Token program id * 10. `[s]` (Optional) Stake pool sol deposit authority. */ export function getDepositSolInstruction< TAccountStakePool extends string, TAccountWithdrawAuthority extends string, TAccountReserveStake extends string, TAccountPayer extends string, TAccountUserPoolTokenAccount extends string, TAccountManagerFeeAccount extends string, TAccountReferralPoolAccount extends string, TAccountPoolMint extends string, TAccountSystemProgram extends string, TAccountTokenProgram extends string, TAccountDepositAuthority extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: DepositSolInput< TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority >, config?: { programAddress?: TProgramAddress }, ): DepositSolInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority > { // 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, }, reserveStake: { value: input.reserveStake ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, userPoolTokenAccount: { value: input.userPoolTokenAccount ?? null, isWritable: true, }, managerFeeAccount: { value: input.managerFeeAccount ?? null, isWritable: true, }, referralPoolAccount: { value: input.referralPoolAccount ?? null, isWritable: true, }, poolMint: { value: input.poolMint ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } 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("reserveStake", accounts.reserveStake), getAccountMeta("payer", accounts.payer), getAccountMeta("userPoolTokenAccount", accounts.userPoolTokenAccount), getAccountMeta("managerFeeAccount", accounts.managerFeeAccount), getAccountMeta("referralPoolAccount", accounts.referralPoolAccount), getAccountMeta("poolMint", accounts.poolMint), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("depositAuthority", accounts.depositAuthority), ], data: getDepositSolInstructionDataEncoder().encode( args as DepositSolInstructionDataArgs, ), programAddress, } as DepositSolInstruction< TProgramAddress, TAccountStakePool, TAccountWithdrawAuthority, TAccountReserveStake, TAccountPayer, TAccountUserPoolTokenAccount, TAccountManagerFeeAccount, TAccountReferralPoolAccount, TAccountPoolMint, TAccountSystemProgram, TAccountTokenProgram, TAccountDepositAuthority >); } export type ParsedDepositSolInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Stake pool */ stakePool: TAccountMetas[0]; /** Stake pool withdraw authority */ withdrawAuthority: TAccountMetas[1]; /** Reserve stake account, to deposit SOL */ reserveStake: TAccountMetas[2]; /** Account providing the lamports to be deposited into the pool */ payer: TAccountMetas[3]; /** User account to receive pool tokens */ userPoolTokenAccount: TAccountMetas[4]; /** Account to receive fee tokens */ managerFeeAccount: TAccountMetas[5]; /** Account to receive a portion of fee as referral fees */ referralPoolAccount: TAccountMetas[6]; /** Pool token mint account */ poolMint: TAccountMetas[7]; /** System program account */ systemProgram: TAccountMetas[8]; /** Token program id */ tokenProgram: TAccountMetas[9]; /** (Optional) Stake pool sol deposit authority. */ depositAuthority?: TAccountMetas[10] | undefined; }; data: DepositSolInstructionData; }; export function parseDepositSolInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDepositSolInstruction { 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; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SPL_STAKE_POOL_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), withdrawAuthority: getNextAccount(), reserveStake: getNextAccount(), payer: getNextAccount(), userPoolTokenAccount: getNextAccount(), managerFeeAccount: getNextAccount(), referralPoolAccount: getNextAccount(), poolMint: getNextAccount(), systemProgram: getNextAccount(), tokenProgram: getNextAccount(), depositAuthority: getNextOptionalAccount(), }, data: getDepositSolInstructionDataDecoder().decode(instruction.data), }; }