Skip to content

Commit bc506ba

Browse files
committed
fix: do not double count tokens when checking minimum stake (OZ M-08)
1 parent 5fcd2dc commit bc506ba

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

contracts/staking/Staking.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,15 @@ abstract contract Staking is StakingV3Storage, GraphUpgradeable, IStakingBase, M
703703
* @param _tokens Amount of tokens to stake
704704
*/
705705
function _stake(address _indexer, uint256 _tokens) internal {
706-
// Deposit tokens into the indexer stake
707-
__stakes[_indexer].deposit(_tokens);
708-
709706
// Ensure minimum stake
710707
require(
711708
__stakes[_indexer].tokensSecureStake().add(_tokens) >= __minimumIndexerStake,
712709
"!minimumIndexerStake"
713710
);
714711

712+
// Deposit tokens into the indexer stake
713+
__stakes[_indexer].deposit(_tokens);
714+
715715
// Initialize the delegation pool the first time
716716
if (__delegationPools[_indexer].updatedAtBlock == 0) {
717717
_setDelegationParameters(_indexer, MAX_PPM, MAX_PPM, __delegationParametersCooldown);

test/staking/staking.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ describe('Staking:Stakes', () => {
115115
})
116116

117117
it('reject stake less than minimum indexer stake', async function () {
118-
expect(toGRT('1')).lte(await staking.minimumIndexerStake())
119-
const tx = staking.connect(indexer.signer).stake(toGRT('1'))
118+
const amount = (await staking.minimumIndexerStake()).sub(toGRT('1'))
119+
const tx = staking.connect(indexer.signer).stake(amount)
120120
await expect(tx).revertedWith('!minimumIndexerStake')
121121
})
122122

0 commit comments

Comments
 (0)