Skip to content

Commit 4b66b3f

Browse files
committed
staking: take into account locked tokens for the delegated capacity
1 parent 9e377a8 commit 4b66b3f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

contracts/staking/Staking.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,10 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
600600
* @return Amount of tokens staked by the indexer
601601
*/
602602
function getIndexerCapacity(address _indexer) public override view returns (uint256) {
603-
Stakes.Indexer storage indexerStake = stakes[_indexer];
603+
Stakes.Indexer memory indexerStake = stakes[_indexer];
604604
uint256 tokensDelegated = delegationPools[_indexer].tokens;
605605

606-
uint256 tokensDelegatedCap = indexerStake.tokensStaked.mul(uint256(delegationRatio));
606+
uint256 tokensDelegatedCap = indexerStake.tokensSecureStake().mul(uint256(delegationRatio));
607607
uint256 tokensDelegatedCapacity = (tokensDelegated < tokensDelegatedCap)
608608
? tokensDelegated
609609
: tokensDelegatedCap;

test/staking/delegation.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,19 @@ describe('Staking::Delegation', () => {
551551
expect(alloc.tokens).eq(tokensToAllocate)
552552
})
553553

554+
it('should account delegation for indexer capacity properly', async function () {
555+
// 1:10 delegation capacity
556+
await staking.connect(governor.signer).setDelegationRatio(10)
557+
558+
// Delegate
559+
await staking.connect(delegator.signer).delegate(indexer.address, tokensToDelegate)
560+
561+
// If we unstake all, the indexer capacity should go to zero
562+
// Should not be able to use delegated tokens
563+
await staking.connect(indexer.signer).unstake(tokensToStake)
564+
expect(await staking.getIndexerCapacity(indexer.address)).eq(0)
565+
})
566+
554567
it('should send delegation cut of query fees to delegation pool', async function () {
555568
// 1:10 delegation capacity
556569
await staking.connect(governor.signer).setDelegationRatio(10)

0 commit comments

Comments
 (0)