@ignitionfi/fogo-stake-pool 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19013,7 +19013,7 @@ var solanaStakePool = (function (exports, node_buffer) {
19013
19013
  // Public key that identifies the SPL Stake Pool program.
19014
19014
  const STAKE_POOL_PROGRAM_ID = new PublicKey('SP1s4uFeTAX9jsXXmwyDs1gxYYf7cdDZ8qHUHVxE1yr');
19015
19015
  // Public key that identifies the SPL Stake Pool program deployed to devnet.
19016
- const DEVNET_STAKE_POOL_PROGRAM_ID = new PublicKey('DPoo15wWDqpPJJtS2MUZ49aRxqz5ZaaJCJP4z8bLuib');
19016
+ const DEVNET_STAKE_POOL_PROGRAM_ID = STAKE_POOL_PROGRAM_ID;
19017
19017
  // Maximum number of validators to update during UpdateValidatorListBalance.
19018
19018
  const MAX_VALIDATORS_TO_UPDATE = 4;
19019
19019
  // Seed for ephemeral stake account
@@ -22018,40 +22018,63 @@ var solanaStakePool = (function (exports, node_buffer) {
22018
22018
  }
22019
22019
  const minBalanceForRentExemption = await connection.getMinimumBalanceForRentExemption(StakeProgram.space);
22020
22020
  const minBalance = new BN(minBalanceForRentExemption + MINIMUM_ACTIVE_STAKE);
22021
- let accounts = [];
22022
- // Prepare accounts
22021
+ // First, collect all stake account addresses we need to check
22022
+ const accountsToFetch = [];
22023
22023
  for (const validator of validatorList.validators) {
22024
22024
  if (validator.status !== ValidatorStakeInfoStatus.Active) {
22025
22025
  continue;
22026
22026
  }
22027
22027
  const stakeAccountAddress = await findStakeProgramAddress(stakePoolProgramId, validator.voteAccountAddress, stakePoolAddress);
22028
- // For active stake accounts, subtract the minimum balance that must remain
22029
- // to allow for merges and maintain rent exemption
22030
- const availableActiveLamports = validator.activeStakeLamports.sub(minBalance);
22031
- if (availableActiveLamports.gt(new BN(0))) {
22032
- const isPreferred = (_a = stakePool === null || stakePool === void 0 ? void 0 : stakePool.preferredWithdrawValidatorVoteAddress) === null || _a === void 0 ? void 0 : _a.equals(validator.voteAccountAddress);
22033
- accounts.push({
22028
+ const isPreferred = (_a = stakePool === null || stakePool === void 0 ? void 0 : stakePool.preferredWithdrawValidatorVoteAddress) === null || _a === void 0 ? void 0 : _a.equals(validator.voteAccountAddress);
22029
+ // Add active stake account if validator list indicates it has stake
22030
+ if (validator.activeStakeLamports.gt(new BN(0))) {
22031
+ accountsToFetch.push({
22034
22032
  type: isPreferred ? 'preferred' : 'active',
22035
22033
  voteAddress: validator.voteAccountAddress,
22036
22034
  stakeAddress: stakeAccountAddress,
22037
- lamports: availableActiveLamports,
22038
22035
  });
22039
22036
  }
22040
- const transientStakeLamports = validator.transientStakeLamports.sub(minBalance);
22041
- if (transientStakeLamports.gt(new BN(0))) {
22037
+ // Add transient stake account if validator list indicates it has stake
22038
+ if (validator.transientStakeLamports.gt(new BN(0))) {
22042
22039
  const transientStakeAccountAddress = await findTransientStakeProgramAddress(stakePoolProgramId, validator.voteAccountAddress, stakePoolAddress, validator.transientSeedSuffixStart);
22043
- accounts.push({
22040
+ accountsToFetch.push({
22044
22041
  type: 'transient',
22045
22042
  voteAddress: validator.voteAccountAddress,
22046
22043
  stakeAddress: transientStakeAccountAddress,
22047
- lamports: transientStakeLamports,
22044
+ });
22045
+ }
22046
+ }
22047
+ // Fetch all stake accounts + reserve in one batch call
22048
+ const addressesToFetch = [
22049
+ ...accountsToFetch.map(a => a.stakeAddress),
22050
+ stakePool.reserveStake,
22051
+ ];
22052
+ const accountInfos = await connection.getMultipleAccountsInfo(addressesToFetch);
22053
+ // Build accounts list using actual on-chain balances
22054
+ let accounts = [];
22055
+ for (let i = 0; i < accountsToFetch.length; i++) {
22056
+ const { type, voteAddress, stakeAddress } = accountsToFetch[i];
22057
+ const accountInfo = accountInfos[i];
22058
+ if (!accountInfo) {
22059
+ continue;
22060
+ }
22061
+ // Use actual on-chain balance instead of validator list value
22062
+ const actualLamports = new BN(accountInfo.lamports);
22063
+ const availableLamports = actualLamports.sub(minBalance);
22064
+ if (availableLamports.gt(new BN(0))) {
22065
+ accounts.push({
22066
+ type,
22067
+ voteAddress,
22068
+ stakeAddress,
22069
+ lamports: availableLamports,
22048
22070
  });
22049
22071
  }
22050
22072
  }
22051
22073
  // Sort from highest to lowest balance
22052
22074
  accounts = accounts.sort(compareFn || ((a, b) => b.lamports.sub(a.lamports).toNumber()));
22053
- const reserveStake = await connection.getAccountInfo(stakePool.reserveStake);
22054
- const reserveStakeBalance = new BN(((_b = reserveStake === null || reserveStake === void 0 ? void 0 : reserveStake.lamports) !== null && _b !== void 0 ? _b : 0) - minBalanceForRentExemption);
22075
+ // Add reserve stake using actual balance (last item in batch fetch)
22076
+ const reserveAccountInfo = accountInfos[accountInfos.length - 1];
22077
+ const reserveStakeBalance = new BN(((_b = reserveAccountInfo === null || reserveAccountInfo === void 0 ? void 0 : reserveAccountInfo.lamports) !== null && _b !== void 0 ? _b : 0) - minBalanceForRentExemption);
22055
22078
  if (reserveStakeBalance.gt(new BN(0))) {
22056
22079
  accounts.push({
22057
22080
  type: 'reserve',