calcPoolTokensForDeposit static method

BigInt calcPoolTokensForDeposit(
  1. StakePoolAccount stakePoolAccount,
  2. BigInt stakeLamports
)

Calculate the pool tokens that should be minted for a deposit of stakeLamports

Implementation

static BigInt calcPoolTokensForDeposit(
    StakePoolAccount stakePoolAccount, BigInt stakeLamports) {
  if (stakePoolAccount.poolTokenSupply == BigInt.zero ||
      stakePoolAccount.totalLamports == BigInt.zero) {
    return stakeLamports;
  }
  final numerator = stakeLamports * stakePoolAccount.poolTokenSupply;
  if (numerator == BigInt.zero) return BigInt.zero;
  return BigRational(numerator, stakePoolAccount.totalLamports).toBigInt();
}