@@ -1105,9 +1105,6 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1105
1105
) private {
1106
1106
require (_isAuth (_indexer), "!auth " );
1107
1107
1108
- // Only allocations with a non-zero token amount are allowed
1109
- require (_tokens > 0 , "!tokens " );
1110
-
1111
1108
// Check allocation
1112
1109
require (_allocationID != address (0 ), "!alloc " );
1113
1110
require (_getAllocationState (_allocationID) == AllocationState.Null, "!null " );
@@ -1119,7 +1116,9 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1119
1116
require (ECDSA.recover (digest, _proof) == _allocationID, "!proof " );
1120
1117
1121
1118
// Needs to have free capacity not used for other purposes to allocate
1122
- require (getIndexerCapacity (_indexer) >= _tokens, "!capacity " );
1119
+ if (_tokens > 0 ) {
1120
+ require (getIndexerCapacity (_indexer) >= _tokens, "!capacity " );
1121
+ }
1123
1122
1124
1123
// Creates an allocation
1125
1124
// Allocation identifiers are not reused
@@ -1136,14 +1135,16 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1136
1135
);
1137
1136
allocations[_allocationID] = alloc;
1138
1137
1139
- // Mark allocated tokens as used
1140
- stakes[_indexer].allocate (alloc.tokens);
1138
+ if (_tokens > 0 ) {
1139
+ // Mark allocated tokens as used
1140
+ stakes[_indexer].allocate (alloc.tokens);
1141
1141
1142
- // Track total allocations per subgraph
1143
- // Used for rewards calculations
1144
- subgraphAllocations[alloc.subgraphDeploymentID] = subgraphAllocations[
1145
- alloc.subgraphDeploymentID
1146
- ].add (alloc.tokens);
1142
+ // Track total allocations per subgraph
1143
+ // Used for rewards calculations
1144
+ subgraphAllocations[alloc.subgraphDeploymentID] = subgraphAllocations[
1145
+ alloc.subgraphDeploymentID
1146
+ ].add (alloc.tokens);
1147
+ }
1147
1148
1148
1149
emit AllocationCreated (
1149
1150
_indexer,
@@ -1206,14 +1207,16 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1206
1207
_updateRewards (alloc.subgraphDeploymentID);
1207
1208
}
1208
1209
1209
- // Free allocated tokens from use
1210
- stakes[alloc.indexer].unallocate (alloc.tokens);
1210
+ if (alloc.tokens > 0 ) {
1211
+ // Free allocated tokens from use
1212
+ stakes[alloc.indexer].unallocate (alloc.tokens);
1211
1213
1212
- // Track total allocations per subgraph
1213
- // Used for rewards calculations
1214
- subgraphAllocations[alloc.subgraphDeploymentID] = subgraphAllocations[
1215
- alloc.subgraphDeploymentID
1216
- ].sub (alloc.tokens);
1214
+ // Track total allocations per subgraph
1215
+ // Used for rewards calculations
1216
+ subgraphAllocations[alloc.subgraphDeploymentID] = subgraphAllocations[
1217
+ alloc.subgraphDeploymentID
1218
+ ].sub (alloc.tokens);
1219
+ }
1217
1220
1218
1221
emit AllocationClosed (
1219
1222
alloc.indexer,
@@ -1255,8 +1258,8 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1255
1258
// Purge allocation data except for:
1256
1259
// - indexer: used in disputes and to avoid reusing an allocationID
1257
1260
// - subgraphDeploymentID: used in disputes
1258
- allocations[_allocationID].tokens = 0 ; // This avoid collect(), close() and claim() to be called
1259
- allocations[_allocationID].createdAtEpoch = 0 ;
1261
+ allocations[_allocationID].tokens = 0 ;
1262
+ allocations[_allocationID].createdAtEpoch = 0 ; // This avoid collect(), close() and claim() to be called
1260
1263
allocations[_allocationID].closedAtEpoch = 0 ;
1261
1264
allocations[_allocationID].collectedFees = 0 ;
1262
1265
allocations[_allocationID].effectiveAllocation = 0 ;
@@ -1526,7 +1529,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1526
1529
if (alloc.indexer == address (0 )) {
1527
1530
return AllocationState.Null;
1528
1531
}
1529
- if (alloc.tokens == 0 ) {
1532
+ if (alloc.createdAtEpoch == 0 ) {
1530
1533
return AllocationState.Claimed;
1531
1534
}
1532
1535
0 commit comments