@@ -31,9 +31,6 @@ contract Staking is Governed {
31
31
// 100% in parts per million
32
32
uint256 private constant MAX_PPM = 1000000 ;
33
33
34
- // 1 basis point (0.01%) is 100 parts per million (PPM)
35
- uint256 private constant BASIS_PT = 100 ;
36
-
37
34
// -- State --
38
35
39
36
// Percentage of fees going to curators
@@ -157,17 +154,14 @@ contract Staking is Governed {
157
154
* @param _governor Owner address of this contract
158
155
* @param _token Address of the Graph Protocol token
159
156
* @param _epochManager Address of the EpochManager contract
160
- * @param _curation Address of the Curation contract
161
157
*/
162
158
constructor (
163
159
address _governor ,
164
160
address _token ,
165
- address _epochManager ,
166
- address _curation
161
+ address _epochManager
167
162
) public Governed (_governor) {
168
163
token = GraphToken (_token);
169
164
epochManager = EpochManager (_epochManager);
170
- curation = Curation (_curation);
171
165
}
172
166
173
167
/**
@@ -250,7 +244,7 @@ contract Staking is Governed {
250
244
* @param _indexer Address of the indexer
251
245
* @return Amount of tokens staked by the indexer
252
246
*/
253
- function getIndexerStakeTokens (address _indexer ) public view returns (uint256 ) {
247
+ function getIndexerStakedTokens (address _indexer ) public view returns (uint256 ) {
254
248
return stakes[_indexer].tokensIndexer;
255
249
}
256
250
@@ -268,6 +262,21 @@ contract Staking is Governed {
268
262
return stakes[_indexer].allocations[_subgraphID];
269
263
}
270
264
265
+ /**
266
+ * @dev Get an outstanding unclaimed settlement
267
+ * @param _epoch Epoch when the settlement ocurred
268
+ * @param _indexer Address of the indexer
269
+ * @param _subgraphID ID of the subgraph settled
270
+ * @return Settlement data
271
+ */
272
+ function getSettlement (
273
+ uint256 _epoch ,
274
+ address _indexer ,
275
+ bytes32 _subgraphID
276
+ ) public view returns (Rebates.Settlement memory ) {
277
+ return rebates[_epoch].settlements[_indexer][_subgraphID];
278
+ }
279
+
271
280
/**
272
281
* @dev Slash the indexer stake
273
282
* @param _indexer Address of indexer to slash
@@ -283,9 +292,10 @@ contract Staking is Governed {
283
292
) external onlySlasher {
284
293
Stakes.Indexer storage indexerStake = stakes[_indexer];
285
294
295
+ require (_tokens > 0 , "Slashing: cannot slash zero tokens " );
296
+ require (_tokens >= _reward, "Slashing: reward cannot be higher than slashed amount " );
286
297
require (indexerStake.hasTokens (), "Slashing: indexer has no stakes " );
287
298
require (_beneficiary != address (0 ), "Slashing: beneficiary must not be an empty address " );
288
- require (_tokens >= _reward, "Slashing: reward cannot be higher than slashed amount " );
289
299
require (
290
300
_tokens <= indexerStake.tokensSlashable (),
291
301
"Slashing: cannot slash more than staked amount "
@@ -328,11 +338,14 @@ contract Staking is Governed {
328
338
function stake (uint256 _tokens ) external {
329
339
address indexer = msg .sender ;
330
340
341
+ require (_tokens > 0 , "Staking: cannot stake zero tokens " );
342
+
331
343
// Transfer tokens to stake from indexer to this contract
332
344
require (
333
345
token.transferFrom (indexer, address (this ), _tokens),
334
346
"Staking: Cannot transfer tokens to stake "
335
347
);
348
+
336
349
// Stake the transferred tokens
337
350
_stake (indexer, _tokens);
338
351
}
@@ -460,24 +473,27 @@ contract Staking is Governed {
460
473
epochsSinceSettlement >= channelDisputeEpochs,
461
474
"Rebate: need to wait channel dispute period "
462
475
);
476
+
463
477
require (settlement.allocation > 0 , "Rebate: settlement does not exist " );
464
478
465
479
// Process rebate
466
480
uint256 tokensToClaim = pool.redeem (indexer, _subgraphID);
467
- require (tokensToClaim > 0 , "Rebate: no tokens available to claim " );
468
481
469
- // All settlements processed then prune rebate pool
482
+ // When all settlements processed then prune rebate pool
470
483
if (pool.settlementsCount == 0 ) {
471
484
delete rebates[_epoch];
472
485
}
473
486
474
- // Assign claimed tokens
475
- if (_restake) {
476
- // Restake to place fees into the indexer stake
477
- _stake (indexer, tokensToClaim);
478
- } else {
479
- // Transfer funds back to the indexer
480
- require (token.transfer (indexer, tokensToClaim), "Rebate: cannot transfer tokens " );
487
+ // When there are tokens to claim from the rebate pool, transfer or restake
488
+ if (tokensToClaim > 0 ) {
489
+ // Assign claimed tokens
490
+ if (_restake) {
491
+ // Restake to place fees into the indexer stake
492
+ _stake (indexer, tokensToClaim);
493
+ } else {
494
+ // Transfer funds back to the indexer
495
+ require (token.transfer (indexer, tokensToClaim), "Rebate: cannot transfer tokens " );
496
+ }
481
497
}
482
498
483
499
emit RebateClaimed (
@@ -517,7 +533,11 @@ contract Staking is Governed {
517
533
bytes32 subgraphID = channels[_channelID].subgraphID;
518
534
Stakes.Allocation storage alloc = stakes[indexer].allocations[subgraphID];
519
535
520
- require (alloc.hasChannel (), "Channel: Must be active for settlement " );
536
+ require (_channelID != address (0 ), "Channel: ChannelID cannot be empty address " );
537
+ require (
538
+ alloc.channelID == _channelID,
539
+ "Channel: The allocation has no channel, or the channel was already settled "
540
+ );
521
541
522
542
// Time conditions
523
543
(uint256 epochs , uint256 currentEpoch ) = epochManager.epochsSince (alloc.createdAtEpoch);
@@ -558,8 +578,8 @@ contract Staking is Governed {
558
578
_tokens,
559
579
_channelID,
560
580
_from,
561
- rebateFees,
562
581
curationFees,
582
+ rebateFees,
563
583
effectiveAllocation
564
584
);
565
585
}
0 commit comments