@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.
- package/dist/index.browser.cjs.js +39 -16
- package/dist/index.browser.cjs.js.map +1 -1
- package/dist/index.browser.esm.js +39 -16
- package/dist/index.browser.esm.js.map +1 -1
- package/dist/index.cjs.js +39 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +39 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +39 -16
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/package.json +9 -9
- package/src/constants.ts +1 -1
- package/src/layouts.ts +2 -0
- package/src/utils/stake.ts +50 -21
package/dist/index.cjs.js
CHANGED
|
@@ -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 =
|
|
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
|
|
@@ -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
|
-
|
|
841
|
-
|
|
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
|
-
|
|
848
|
-
//
|
|
849
|
-
|
|
850
|
-
|
|
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
|
-
|
|
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
|
-
|
|
859
|
+
accountsToFetch.push({
|
|
863
860
|
type: 'transient',
|
|
864
861
|
voteAddress: validator.voteAccountAddress,
|
|
865
862
|
stakeAddress: transientStakeAccountAddress,
|
|
866
|
-
|
|
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
|
-
|
|
873
|
-
const
|
|
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',
|