Skip to content

Commit 19513e1

Browse files
committed
staking: set unused Allocation parameters to zero after it is claimed
1 parent 6d1dbd6 commit 19513e1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

cli/defaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export const local = {
99
accountNumber: '0',
1010
}
1111
export const defaultOverrides: Overrides = {
12-
gasPrice: utils.parseUnits('25', 'gwei'), // auto
13-
gasLimit: 2000000, // auto
12+
// gasPrice: utils.parseUnits('25', 'gwei'), // auto
13+
// gasLimit: 2000000, // auto
1414
}
1515

1616
export const cliOpts = {

contracts/staking/Staking.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,15 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
12161216
uint256 delegationRewards = _collectDelegationQueryRewards(alloc.indexer, tokensToClaim);
12171217
tokensToClaim = tokensToClaim.sub(delegationRewards);
12181218

1219-
// Update the allocate state
1219+
// Purge allocation data except for:
1220+
// - indexer: used in disputes and to avoid reusing an allocationID
1221+
// - subgraphDeploymentID: used in disputes
12201222
allocations[_allocationID].tokens = 0; // This avoid collect(), close() and claim() to be called
1223+
allocations[_allocationID].createdAtEpoch = 0;
1224+
allocations[_allocationID].closedAtEpoch = 0;
1225+
allocations[_allocationID].collectedFees = 0;
1226+
allocations[_allocationID].effectiveAllocation = 0;
1227+
allocations[_allocationID].accRewardsPerAllocatedToken = 0;
12211228

12221229
// -- Interactions --
12231230

test/staking/allocation.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ describe('Staking:Allocation', () => {
701701
// After state
702702
const afterBalance = await grt.balanceOf(indexer.address)
703703
const afterStake = await staking.stakes(indexer.address)
704+
const afterAlloc = await staking.allocations(allocationID)
704705
const afterRebatePool = await staking.rebates(beforeAlloc.closedAtEpoch)
705706

706707
// Funds distributed to indexer
@@ -715,6 +716,13 @@ describe('Staking:Allocation', () => {
715716
} else {
716717
expect(afterStake.tokensStaked).eq(beforeStake.tokensStaked)
717718
}
719+
// Allocation updated (purged)
720+
expect(afterAlloc.tokens).eq(toGRT('0'))
721+
expect(afterAlloc.createdAtEpoch).eq(toGRT('0'))
722+
expect(afterAlloc.closedAtEpoch).eq(toGRT('0'))
723+
expect(afterAlloc.collectedFees).eq(toGRT('0'))
724+
expect(afterAlloc.effectiveAllocation).eq(toGRT('0'))
725+
expect(afterAlloc.accRewardsPerAllocatedToken).eq(toGRT('0'))
718726
// Rebate updated
719727
expect(afterRebatePool.unclaimedAllocationsCount).eq(
720728
beforeRebatePool.unclaimedAllocationsCount - 1,

0 commit comments

Comments
 (0)