Skip to content

Commit 5e31905

Browse files
committed
refactor: rename NO_ALLOCATION to NO_ALLOCATED_TOKENS
The condition guards against zero tokens allocated to a subgraph, not the absence of allocation objects. A subgraph can have open allocations resized to zero tokens, making the old name misleading. Rename across contracts, tests, and docs for clarity.
1 parent affc8b4 commit 5e31905

9 files changed

Lines changed: 38 additions & 38 deletions

File tree

docs/RewardAccountingSafety.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ _allocations.snapshotRewards(..., onSubgraphAllocationUpdate()); // ③ Updates
8282

8383
**Why this order matters**:
8484

85-
- Step ① with zero allocations → triggers NO_ALLOCATION reclaim for gap period
85+
- Step ① with zero allocations → triggers NO_ALLOCATED_TOKENS reclaim for gap period
8686
- Step ② creates allocation → now allocatedTokens > 0
8787
- Step ③ same block → newRewards ≈ 0, just confirms snapshot
8888

@@ -112,7 +112,7 @@ Every reward path that cannot reach an allocation has a reclaim handler:
112112
| No global signal | `updateAccRewardsPerSignal()` with signalledTokens = 0 | `NO_SIGNAL` |
113113
| Subgraph denied | `onSubgraphSignalUpdate()` or `onSubgraphAllocationUpdate()` | `SUBGRAPH_DENIED` |
114114
| Below minimum signal | `onSubgraphSignalUpdate()` or `onSubgraphAllocationUpdate()` | `BELOW_MINIMUM_SIGNAL` |
115-
| No allocations | `onSubgraphSignalUpdate()` or `onSubgraphAllocationUpdate()` | `NO_ALLOCATION` |
115+
| No allocations | `onSubgraphSignalUpdate()` or `onSubgraphAllocationUpdate()` | `NO_ALLOCATED_TOKENS` |
116116
| Indexer ineligible | `takeRewards()` | `INDEXER_INELIGIBLE` |
117117
| Stale/zero POI | `_presentPoi()` | `STALE_POI` / `ZERO_POI` |
118118
| Allocation close | `_closeAllocation()` | `CLOSE_ALLOCATION` |
@@ -124,7 +124,7 @@ Every reward path that cannot reach an allocation has a reclaim handler:
124124
| Failure Mode | How Prevented |
125125
| ---------------------------- | ------------------------------------------------------------------------------------ |
126126
| Double-mint same rewards | Snapshot updated after every claim; same-block calls return ~0 |
127-
| Rewards stuck in accumulator | NO_ALLOCATION reclaim before allocation creation |
127+
| Rewards stuck in accumulator | NO_ALLOCATED_TOKENS reclaim before allocation creation |
128128
| Gap period loss | `_getAllocationData` calls `onSubgraphAllocationUpdate` before allocation exists |
129129
| Denial-period accumulation | `accRewardsForSubgraph` tracks; `accRewardsPerAllocatedToken` frozen; diff reclaimed |
130130
| Signal change mid-period | `onSubgraphSignalUpdate` hook called before signal changes |

docs/RewardConditions.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ Quick reference for all reward conditions and how they are handled across Reward
44

55
## Summary Table
66

7-
| Condition | Identifier | Handled By | Action | Rewards Outcome |
8-
| ---------------------- | ----------------------------------- | ----------------- | ------------------------- | ------------------------------------- |
9-
| `NONE` | `bytes32(0)` || Normal path | Claimed by indexer |
10-
| `NO_SIGNAL` | `keccak256("NO_SIGNAL")` | RewardsManager | Reclaim | To reclaim address |
7+
| Condition | Identifier | Handled By | Action | Rewards Outcome |
8+
| ---------------------- | ----------------------------------- | ----------------- | ------------------------- | -------------------------------------- |
9+
| `NONE` | `bytes32(0)` || Normal path | Claimed by indexer |
10+
| `NO_SIGNAL` | `keccak256("NO_SIGNAL")` | RewardsManager | Reclaim | To reclaim address |
1111
| `SUBGRAPH_DENIED` | `keccak256("SUBGRAPH_DENIED")` | Both | Reclaim (RM) / Defer (AM) | New: reclaimed; Uncollected: preserved |
12-
| `BELOW_MINIMUM_SIGNAL` | `keccak256("BELOW_MINIMUM_SIGNAL")` | RewardsManager | Reclaim | To reclaim address |
13-
| `NO_ALLOCATION` | `keccak256("NO_ALLOCATION")` | RewardsManager | Reclaim | To reclaim address |
14-
| `INDEXER_INELIGIBLE` | `keccak256("INDEXER_INELIGIBLE")` | RewardsManager | Reclaim | To reclaim address |
15-
| `STALE_POI` | `keccak256("STALE_POI")` | AllocationManager | Reclaim | To reclaim address |
16-
| `ZERO_POI` | `keccak256("ZERO_POI")` | AllocationManager | Reclaim | To reclaim address |
17-
| `ALLOCATION_TOO_YOUNG` | `keccak256("ALLOCATION_TOO_YOUNG")` | AllocationManager | Defer | Preserved for later |
18-
| `CLOSE_ALLOCATION` | `keccak256("CLOSE_ALLOCATION")` | AllocationManager | Reclaim | To reclaim address |
12+
| `BELOW_MINIMUM_SIGNAL` | `keccak256("BELOW_MINIMUM_SIGNAL")` | RewardsManager | Reclaim | To reclaim address |
13+
| `NO_ALLOCATED_TOKENS` | `keccak256("NO_ALLOCATED_TOKENS")` | RewardsManager | Reclaim | To reclaim address |
14+
| `INDEXER_INELIGIBLE` | `keccak256("INDEXER_INELIGIBLE")` | RewardsManager | Reclaim | To reclaim address |
15+
| `STALE_POI` | `keccak256("STALE_POI")` | AllocationManager | Reclaim | To reclaim address |
16+
| `ZERO_POI` | `keccak256("ZERO_POI")` | AllocationManager | Reclaim | To reclaim address |
17+
| `ALLOCATION_TOO_YOUNG` | `keccak256("ALLOCATION_TOO_YOUNG")` | AllocationManager | Defer | Preserved for later |
18+
| `CLOSE_ALLOCATION` | `keccak256("CLOSE_ALLOCATION")` | AllocationManager | Reclaim | To reclaim address |
1919

2020
## Reward Distribution Levels
2121

@@ -36,7 +36,7 @@ Rewards flow through three levels, with reclaim possible at each:
3636
│ ───────────────────────────────────────────────────────────────── │
3737
│ onSubgraphSignalUpdate() / onSubgraphAllocationUpdate() │
3838
│ │
39-
│ Reclaim: SUBGRAPH_DENIED, BELOW_MINIMUM_SIGNAL, NO_ALLOCATION
39+
│ Reclaim: SUBGRAPH_DENIED, BELOW_MINIMUM_SIGNAL, NO_ALLOCATED_TOKENS
4040
│ │
4141
│ Behavior: │
4242
│ - accRewardsForSubgraph only increases when claimable │
@@ -104,7 +104,7 @@ Rewards flow through three levels, with reclaim possible at each:
104104
- **Effect**: `accRewardsPerAllocatedToken` stops increasing
105105
- **Handling**: Rewards reclaimed to configured address
106106

107-
#### NO_ALLOCATION
107+
#### NO_ALLOCATED_TOKENS
108108

109109
- **Trigger**: Subgraph has signal but zero allocated tokens
110110
- **Effect**: Rewards cannot be distributed to allocations

packages/contracts-test/tests/unit/rewards/rewards-calculations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ describe('Rewards - Calculations', () => {
402402

403403
// Prepare expected results
404404
// Option B model: accRewardsForSubgraph only tracks distributable rewards
405-
// 2 blocks before allocation = reclaimed (NO_ALLOCATION), 5 blocks after = distributable
405+
// 2 blocks before allocation = reclaimed (NO_ALLOCATED_TOKENS), 5 blocks after = distributable
406406
const expectedSubgraphRewards = toGRT('1000') // 5 blocks × 200 GRT/block
407407
const expectedRewardsAT = toGRT('0.08') // 1000 GRT / 12500 allocated tokens
408408

packages/contracts-test/tests/unit/rewards/rewards-reclaim.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function expectApproxEq(actual: BigNumber, expected: BigNumber, message: string)
3030
`${message}: difference ${diff.toString()} exceeds tolerance ${REWARDS_TOLERANCE}`,
3131
).to.be.true
3232
}
33-
const NO_ALLOCATION = utils.id('NO_ALLOCATION')
33+
const NO_ALLOCATED_TOKENS = utils.id('NO_ALLOCATED_TOKENS')
3434
const BELOW_MINIMUM_SIGNAL = utils.id('BELOW_MINIMUM_SIGNAL')
3535

3636
describe('Rewards - Reclaim Addresses', () => {
@@ -879,10 +879,10 @@ describe('Rewards - Reclaim Addresses', () => {
879879
})
880880
})
881881

882-
describe('reclaim NO_ALLOCATION - signal but no allocations', function () {
883-
it('should reclaim when signal exists but no allocations and NO_ALLOCATION address set', async function () {
884-
// Set reclaim address for NO_ALLOCATION
885-
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATION, reclaimWallet.address)
882+
describe('reclaim NO_ALLOCATED_TOKENS - signal but no allocations', function () {
883+
it('should reclaim when signal exists but no allocations and NO_ALLOCATED_TOKENS address set', async function () {
884+
// Set reclaim address for NO_ALLOCATED_TOKENS
885+
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATED_TOKENS, reclaimWallet.address)
886886

887887
// Create signal but NO allocation
888888
const signalled1 = toGRT('1500')

packages/contracts-test/tests/unit/rewards/rewards-signal-allocation-update.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,23 +449,23 @@ describe('Rewards: Signal and Allocation Update Accounting', () => {
449449
})
450450

451451
describe('onSubgraphSignalUpdate with no allocations', function () {
452-
it('should reclaim as NO_ALLOCATION when signal exists but no allocations', async function () {
452+
it('should reclaim as NO_ALLOCATED_TOKENS when signal exists but no allocations', async function () {
453453
// Setup: only signal, no allocation
454454
await grt.connect(governor).mint(curator.address, tokensToSignal)
455455
await grt.connect(curator).approve(curation.address, tokensToSignal)
456456
await curation.connect(curator).mint(subgraphDeploymentID, tokensToSignal, 0)
457457

458-
// Configure reclaim address for NO_ALLOCATION
459-
const NO_ALLOCATION = hre.ethers.utils.id('NO_ALLOCATION')
460-
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATION, governor.address)
458+
// Configure reclaim address for NO_ALLOCATED_TOKENS
459+
const NO_ALLOCATED_TOKENS = hre.ethers.utils.id('NO_ALLOCATED_TOKENS')
460+
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATED_TOKENS, governor.address)
461461

462462
// Record initial state
463463
const initialState = await rewardsManager.subgraphs(subgraphDeploymentID)
464464

465465
// Advance blocks - rewards should accumulate
466466
await helpers.mine(100)
467467

468-
// Call onSubgraphSignalUpdate - should reclaim as NO_ALLOCATION
468+
// Call onSubgraphSignalUpdate - should reclaim as NO_ALLOCATED_TOKENS
469469
const tx = await rewardsManager.connect(governor).onSubgraphSignalUpdate(subgraphDeploymentID)
470470
const receipt = await tx.wait()
471471
const afterSignalUpdate = await rewardsManager.subgraphs(subgraphDeploymentID)
@@ -476,10 +476,10 @@ describe('Rewards: Signal and Allocation Update Accounting', () => {
476476
'accRewardsForSubgraph should not change when no allocations (rewards reclaimed)',
477477
)
478478

479-
// Verify reclaim event was emitted with NO_ALLOCATION reason
479+
// Verify reclaim event was emitted with NO_ALLOCATED_TOKENS reason
480480
const reclaimEvent = receipt.events?.find((e) => e.event === 'RewardsReclaimed')
481481
expect(reclaimEvent).to.not.be.undefined
482-
expect(reclaimEvent!.args![0]).to.equal(NO_ALLOCATION, 'Should reclaim with NO_ALLOCATION reason')
482+
expect(reclaimEvent!.args![0]).to.equal(NO_ALLOCATED_TOKENS, 'Should reclaim with NO_ALLOCATED_TOKENS reason')
483483
expect(reclaimEvent!.args![1]).to.be.gt(0, 'Should have reclaimed rewards')
484484
})
485485

@@ -496,8 +496,8 @@ describe('Rewards: Signal and Allocation Update Accounting', () => {
496496
await helpers.mine(100)
497497

498498
// Configure reclaim and call signal update
499-
const NO_ALLOCATION = hre.ethers.utils.id('NO_ALLOCATION')
500-
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATION, governor.address)
499+
const NO_ALLOCATED_TOKENS = hre.ethers.utils.id('NO_ALLOCATED_TOKENS')
500+
await rewardsManager.connect(governor).setReclaimAddress(NO_ALLOCATED_TOKENS, governor.address)
501501
await rewardsManager.connect(governor).onSubgraphSignalUpdate(subgraphDeploymentID)
502502

503503
// View should remain stable (rewards reclaimed)

packages/contracts-test/tests/unit/rewards/rewards-subgraph-service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe('Rewards - SubgraphService', () => {
380380
// Mine blocks
381381
await helpers.mine(5)
382382

383-
// Get rewards - Option B: with no allocations, rewards are reclaimed (NO_ALLOCATION)
383+
// Get rewards - Option B: with no allocations, rewards are reclaimed (NO_ALLOCATED_TOKENS)
384384
// so both accRewardsPerAllocatedToken and accRewardsForSubgraph remain 0
385385
const [accRewardsPerAllocatedToken, accRewardsForSubgraph] =
386386
await rewardsManager.getAccRewardsPerAllocatedToken(subgraphDeploymentID1)

packages/contracts-test/tests/unit/rewards/rewards.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe('Rewards', () => {
348348
await curation.connect(curator1).mint(subgraphDeploymentID1, signalled1, 0)
349349
await curation.connect(curator2).mint(subgraphDeploymentID2, signalled2, 0)
350350

351-
// Create allocations for both subgraphs so rewards are accumulated (not reclaimed as NO_ALLOCATION)
351+
// Create allocations for both subgraphs so rewards are accumulated (not reclaimed as NO_ALLOCATED_TOKENS)
352352
await grt.connect(governor).mint(indexer1.address, tokensToStake)
353353
await grt.connect(indexer1).approve(staking.address, tokensToStake)
354354
await staking.connect(indexer1).stake(tokensToStake)
@@ -426,7 +426,7 @@ describe('Rewards', () => {
426426
const signalled1 = toGRT('1500')
427427
await curation.connect(curator1).mint(subgraphDeploymentID1, signalled1, 0)
428428

429-
// Create an allocation so rewards are accumulated (not reclaimed as NO_ALLOCATION)
429+
// Create an allocation so rewards are accumulated (not reclaimed as NO_ALLOCATED_TOKENS)
430430
const tokensToStake = toGRT('100000')
431431
const tokensToAllocate = toGRT('10000')
432432
await grt.connect(governor).mint(indexer1.address, tokensToStake)

packages/contracts/contracts/rewards/RewardsManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ contract RewardsManager is
416416

417417
/**
418418
* @notice Get subgraph rewards state including effective reclaim condition
419-
* @dev Determines claimability with priority: SUBGRAPH_DENIED > BELOW_MINIMUM_SIGNAL > NO_ALLOCATION > NONE
419+
* @dev Determines claimability with priority: SUBGRAPH_DENIED > BELOW_MINIMUM_SIGNAL > NO_ALLOCATED_TOKENS > NONE
420420
* When multiple conditions apply, prefers conditions with configured reclaim addresses.
421421
* @param _subgraphDeploymentID Subgraph deployment
422422
* @return newRewards Rewards accumulated since last snapshot
@@ -440,7 +440,7 @@ contract RewardsManager is
440440
if (
441441
subgraphAllocatedTokens == 0 &&
442442
(condition == RewardsCondition.NONE || reclaimAddresses[condition] == address(0))
443-
) condition = RewardsCondition.NO_ALLOCATION;
443+
) condition = RewardsCondition.NO_ALLOCATED_TOKENS;
444444
}
445445

446446
/**

packages/interfaces/contracts/contracts/rewards/RewardsCondition.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ library RewardsCondition {
4949
/// @notice Subgraph signal below minimumSubgraphSignal threshold
5050
bytes32 public constant BELOW_MINIMUM_SIGNAL = keccak256("BELOW_MINIMUM_SIGNAL");
5151

52-
/// @notice No allocations exist for subgraph
53-
bytes32 public constant NO_ALLOCATION = keccak256("NO_ALLOCATION");
52+
/// @notice No tokens allocated to subgraph
53+
bytes32 public constant NO_ALLOCATED_TOKENS = keccak256("NO_ALLOCATED_TOKENS");
5454
}

0 commit comments

Comments
 (0)