@ignitionfi/fogo-stake-pool 1.0.0 → 1.0.2

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.
@@ -10,4 +10,4 @@ export declare const MAX_VALIDATORS_TO_UPDATE = 4;
10
10
  export declare const EPHEMERAL_STAKE_SEED_PREFIX: Buffer<ArrayBuffer>;
11
11
  export declare const TRANSIENT_STAKE_SEED_PREFIX: Buffer<ArrayBuffer>;
12
12
  export declare const USER_STAKE_SEED_PREFIX: Buffer<ArrayBuffer>;
13
- export declare const MINIMUM_ACTIVE_STAKE = 1000000000;
13
+ export declare const MINIMUM_ACTIVE_STAKE = 1000000;
@@ -446,7 +446,7 @@ const METADATA_MAX_URI_LENGTH = 200;
446
446
  // Public key that identifies the SPL Stake Pool program.
447
447
  const STAKE_POOL_PROGRAM_ID = new web3_js.PublicKey('SP1s4uFeTAX9jsXXmwyDs1gxYYf7cdDZ8qHUHVxE1yr');
448
448
  // Public key that identifies the SPL Stake Pool program deployed to devnet.
449
- const DEVNET_STAKE_POOL_PROGRAM_ID = new web3_js.PublicKey('DPoo15wWDqpPJJtS2MUZ49aRxqz5ZaaJCJP4z8bLuib');
449
+ const DEVNET_STAKE_POOL_PROGRAM_ID = STAKE_POOL_PROGRAM_ID;
450
450
  // Maximum number of validators to update during UpdateValidatorListBalance.
451
451
  const MAX_VALIDATORS_TO_UPDATE = 4;
452
452
  // Seed for ephemeral stake account
@@ -457,7 +457,7 @@ const TRANSIENT_STAKE_SEED_PREFIX = node_buffer.Buffer.from('transient');
457
457
  const USER_STAKE_SEED_PREFIX = node_buffer.Buffer.from('user_stake');
458
458
  // Minimum amount of staked SOL required in a validator stake account to allow
459
459
  // for merges without a mismatch on credits observed
460
- const MINIMUM_ACTIVE_STAKE = web3_js.LAMPORTS_PER_SOL;
460
+ const MINIMUM_ACTIVE_STAKE = 1000000;
461
461
 
462
462
  /**
463
463
  * Populate a buffer of instruction data using an InstructionType
@@ -837,40 +837,63 @@ async function prepareWithdrawAccounts(connection, stakePool, stakePoolAddress,
837
837
  }
838
838
  const minBalanceForRentExemption = await connection.getMinimumBalanceForRentExemption(web3_js.StakeProgram.space);
839
839
  const minBalance = new BN(minBalanceForRentExemption + MINIMUM_ACTIVE_STAKE);
840
- let accounts = [];
841
- // Prepare accounts
840
+ // First, collect all stake account addresses we need to check
841
+ const accountsToFetch = [];
842
842
  for (const validator of validatorList.validators) {
843
843
  if (validator.status !== ValidatorStakeInfoStatus.Active) {
844
844
  continue;
845
845
  }
846
846
  const stakeAccountAddress = await findStakeProgramAddress(stakePoolProgramId, validator.voteAccountAddress, stakePoolAddress);
847
- // For active stake accounts, subtract the minimum balance that must remain
848
- // to allow for merges and maintain rent exemption
849
- const availableActiveLamports = validator.activeStakeLamports.sub(minBalance);
850
- if (availableActiveLamports.gt(new BN(0))) {
851
- const isPreferred = (_a = stakePool === null || stakePool === void 0 ? void 0 : stakePool.preferredWithdrawValidatorVoteAddress) === null || _a === void 0 ? void 0 : _a.equals(validator.voteAccountAddress);
852
- accounts.push({
847
+ const isPreferred = (_a = stakePool === null || stakePool === void 0 ? void 0 : stakePool.preferredWithdrawValidatorVoteAddress) === null || _a === void 0 ? void 0 : _a.equals(validator.voteAccountAddress);
848
+ // Add active stake account if validator list indicates it has stake
849
+ if (validator.activeStakeLamports.gt(new BN(0))) {
850
+ accountsToFetch.push({
853
851
  type: isPreferred ? 'preferred' : 'active',
854
852
  voteAddress: validator.voteAccountAddress,
855
853
  stakeAddress: stakeAccountAddress,
856
- lamports: availableActiveLamports,
857
854
  });
858
855
  }
859
- const transientStakeLamports = validator.transientStakeLamports.sub(minBalance);
860
- if (transientStakeLamports.gt(new BN(0))) {
856
+ // Add transient stake account if validator list indicates it has stake
857
+ if (validator.transientStakeLamports.gt(new BN(0))) {
861
858
  const transientStakeAccountAddress = await findTransientStakeProgramAddress(stakePoolProgramId, validator.voteAccountAddress, stakePoolAddress, validator.transientSeedSuffixStart);
862
- accounts.push({
859
+ accountsToFetch.push({
863
860
  type: 'transient',
864
861
  voteAddress: validator.voteAccountAddress,
865
862
  stakeAddress: transientStakeAccountAddress,
866
- lamports: transientStakeLamports,
863
+ });
864
+ }
865
+ }
866
+ // Fetch all stake accounts + reserve in one batch call
867
+ const addressesToFetch = [
868
+ ...accountsToFetch.map(a => a.stakeAddress),
869
+ stakePool.reserveStake,
870
+ ];
871
+ const accountInfos = await connection.getMultipleAccountsInfo(addressesToFetch);
872
+ // Build accounts list using actual on-chain balances
873
+ let accounts = [];
874
+ for (let i = 0; i < accountsToFetch.length; i++) {
875
+ const { type, voteAddress, stakeAddress } = accountsToFetch[i];
876
+ const accountInfo = accountInfos[i];
877
+ if (!accountInfo) {
878
+ continue;
879
+ }
880
+ // Use actual on-chain balance instead of validator list value
881
+ const actualLamports = new BN(accountInfo.lamports);
882
+ const availableLamports = actualLamports.sub(minBalance);
883
+ if (availableLamports.gt(new BN(0))) {
884
+ accounts.push({
885
+ type,
886
+ voteAddress,
887
+ stakeAddress,
888
+ lamports: availableLamports,
867
889
  });
868
890
  }
869
891
  }
870
892
  // Sort from highest to lowest balance
871
893
  accounts = accounts.sort(compareFn || ((a, b) => b.lamports.sub(a.lamports).toNumber()));
872
- const reserveStake = await connection.getAccountInfo(stakePool.reserveStake);
873
- const reserveStakeBalance = new BN(((_b = reserveStake === null || reserveStake === void 0 ? void 0 : reserveStake.lamports) !== null && _b !== void 0 ? _b : 0) - minBalanceForRentExemption);
894
+ // Add reserve stake using actual balance (last item in batch fetch)
895
+ const reserveAccountInfo = accountInfos[accountInfos.length - 1];
896
+ const reserveStakeBalance = new BN(((_b = reserveAccountInfo === null || reserveAccountInfo === void 0 ? void 0 : reserveAccountInfo.lamports) !== null && _b !== void 0 ? _b : 0) - minBalanceForRentExemption);
874
897
  if (reserveStakeBalance.gt(new BN(0))) {
875
898
  accounts.push({
876
899
  type: 'reserve',