Skip to content

Commit 22e838f

Browse files
committed
fix: enforce a minimum of 1 GRT when delegating to an indexer for the first time
1 parent bf1aa37 commit 22e838f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

contracts/staking/StakingExtension.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
2626

2727
/// @dev 100% in parts per million
2828
uint32 private constant MAX_PPM = 1000000;
29+
/// @dev Minimum delegation for the first delegator of an indexer
30+
uint256 private constant MINIMUM_DELEGATION = 1e18;
2931

3032
/**
3133
* @dev Check if the caller is the slasher.
@@ -544,9 +546,13 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
544546
uint256 delegatedTokens = _tokens.sub(delegationTax);
545547

546548
// Calculate shares to issue
547-
uint256 shares = (pool.tokens == 0)
548-
? delegatedTokens
549-
: delegatedTokens.mul(pool.shares).div(pool.tokens);
549+
uint256 shares;
550+
if (pool.tokens == 0) {
551+
require(_tokens >= MINIMUM_DELEGATION, "!minimum-delegation");
552+
shares = delegatedTokens;
553+
} else {
554+
shares = delegatedTokens.mul(pool.shares).div(pool.tokens);
555+
}
550556
require(shares > 0, "!shares");
551557

552558
// Update the delegation pool

test/staking/delegation.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ describe('Staking::Delegation', () => {
372372
await expect(tx).revertedWith('!tokens')
373373
})
374374

375+
it('reject delegate with less than 1 GRT when the pool is not initialized', async function () {
376+
const tokensToDelegate = toGRT('0.5')
377+
const tx = staking.connect(delegator.signer).delegate(indexer.address, tokensToDelegate)
378+
await expect(tx).revertedWith('!minimum-delegation')
379+
})
380+
381+
it('allows delegating under 1 GRT when the pool is initialized', async function () {
382+
await shouldDelegate(delegator, toGRT('1'))
383+
await shouldDelegate(delegator, toGRT('0.01'))
384+
})
385+
375386
it('reject delegate to empty address', async function () {
376387
const tokensToDelegate = toGRT('100')
377388
const tx = staking.connect(delegator.signer).delegate(AddressZero, tokensToDelegate)

0 commit comments

Comments
 (0)