@@ -50,12 +50,15 @@ describe('Rewards', () => {
50
50
let rewardsManagerMock : RewardsManagerMock
51
51
52
52
// Derive some channel keys for each indexer used to sign attestations
53
- const channelKey = deriveChannelKey ( )
53
+ const channelKey1 = deriveChannelKey ( )
54
+ const channelKey2 = deriveChannelKey ( )
54
55
55
56
const subgraphDeploymentID1 = randomHexBytes ( )
56
57
const subgraphDeploymentID2 = randomHexBytes ( )
57
58
58
- const allocationID = channelKey . address
59
+ const allocationID1 = channelKey1 . address
60
+ const allocationID2 = channelKey2 . address
61
+
59
62
const metadata = HashZero
60
63
61
64
const ISSUANCE_RATE_PERIODS = 4 // blocks required to issue 5% rewards
@@ -97,6 +100,10 @@ describe('Rewards', () => {
97
100
98
101
async accrued ( ) {
99
102
const nBlocks = await this . elapsedBlocks ( )
103
+ return this . accruedByElapsed ( nBlocks )
104
+ }
105
+
106
+ async accruedByElapsed ( nBlocks : BigNumber | number ) {
100
107
const n = getRewardsPerSignal (
101
108
new BN ( this . totalSupply . toString ( ) ) ,
102
109
new BN ( ISSUANCE_RATE_PER_BLOCK . toString ( ) ) . div ( 1e18 ) ,
@@ -395,9 +402,9 @@ describe('Rewards', () => {
395
402
indexer1 . address ,
396
403
subgraphDeploymentID1 ,
397
404
tokensToAllocate ,
398
- allocationID ,
405
+ allocationID1 ,
399
406
metadata ,
400
- await channelKey . generateProof ( indexer1 . address ) ,
407
+ await channelKey1 . generateProof ( indexer1 . address ) ,
401
408
)
402
409
403
410
// Jump
@@ -433,9 +440,9 @@ describe('Rewards', () => {
433
440
indexer1 . address ,
434
441
subgraphDeploymentID1 ,
435
442
tokensToAllocate ,
436
- allocationID ,
443
+ allocationID1 ,
437
444
metadata ,
438
- await channelKey . generateProof ( indexer1 . address ) ,
445
+ await channelKey1 . generateProof ( indexer1 . address ) ,
439
446
)
440
447
441
448
// Jump
@@ -477,16 +484,16 @@ describe('Rewards', () => {
477
484
indexer1 . address ,
478
485
subgraphDeploymentID1 ,
479
486
tokensToAllocate ,
480
- allocationID ,
487
+ allocationID1 ,
481
488
metadata ,
482
- await channelKey . generateProof ( indexer1 . address ) ,
489
+ await channelKey1 . generateProof ( indexer1 . address ) ,
483
490
)
484
491
485
492
// Jump
486
493
await advanceBlocks ( ISSUANCE_RATE_PERIODS )
487
494
488
495
// Rewards
489
- const contractRewards = await rewardsManager . getRewards ( allocationID )
496
+ const contractRewards = await rewardsManager . getRewards ( allocationID1 )
490
497
491
498
// We trust using this function in the test because we tested it
492
499
// standalone in a previous test
@@ -523,9 +530,9 @@ describe('Rewards', () => {
523
530
indexer1 . address ,
524
531
subgraphDeploymentID1 ,
525
532
tokensToAllocate ,
526
- allocationID ,
533
+ allocationID1 ,
527
534
metadata ,
528
- await channelKey . generateProof ( indexer1 . address ) ,
535
+ await channelKey1 . generateProof ( indexer1 . address ) ,
529
536
)
530
537
}
531
538
@@ -566,9 +573,9 @@ describe('Rewards', () => {
566
573
indexer1 . address ,
567
574
subgraphDeploymentID1 ,
568
575
tokensToAllocate ,
569
- allocationID ,
576
+ allocationID1 ,
570
577
metadata ,
571
- await channelKey . generateProof ( indexer1 . address ) ,
578
+ await channelKey1 . generateProof ( indexer1 . address ) ,
572
579
)
573
580
}
574
581
@@ -599,11 +606,11 @@ describe('Rewards', () => {
599
606
// Close allocation. At this point rewards should be collected for that indexer
600
607
const tx = await staking
601
608
. connect ( indexer1 . signer )
602
- . closeAllocation ( allocationID , randomHexBytes ( ) )
609
+ . closeAllocation ( allocationID1 , randomHexBytes ( ) )
603
610
const receipt = await tx . wait ( )
604
611
const event = rewardsManager . interface . parseLog ( receipt . logs [ 1 ] ) . args
605
612
expect ( event . indexer ) . eq ( indexer1 . address )
606
- expect ( event . allocationID ) . eq ( allocationID )
613
+ expect ( event . allocationID1 ) . eq ( allocationID1 )
607
614
expect ( event . epoch ) . eq ( await epochManager . currentEpoch ( ) )
608
615
expect ( toRound ( event . amount ) ) . eq ( toRound ( expectedIndexingRewards ) )
609
616
@@ -658,11 +665,11 @@ describe('Rewards', () => {
658
665
// Close allocation. At this point rewards should be collected for that indexer
659
666
const tx = await staking
660
667
. connect ( indexer1 . signer )
661
- . closeAllocation ( allocationID , randomHexBytes ( ) )
668
+ . closeAllocation ( allocationID1 , randomHexBytes ( ) )
662
669
const receipt = await tx . wait ( )
663
670
const event = rewardsManager . interface . parseLog ( receipt . logs [ 1 ] ) . args
664
671
expect ( event . indexer ) . eq ( indexer1 . address )
665
- expect ( event . allocationID ) . eq ( allocationID )
672
+ expect ( event . allocationID1 ) . eq ( allocationID1 )
666
673
expect ( event . epoch ) . eq ( await epochManager . currentEpoch ( ) )
667
674
expect ( toRound ( event . amount ) ) . eq ( toRound ( expectedIndexingRewards ) )
668
675
@@ -710,7 +717,7 @@ describe('Rewards', () => {
710
717
const beforeIndexer1Stake = await staking . getIndexerStakedTokens ( indexer1 . address )
711
718
712
719
// Close allocation. At this point rewards should be collected for that indexer
713
- await staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID , randomHexBytes ( ) )
720
+ await staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
714
721
715
722
// After state
716
723
const afterTokenSupply = await grt . totalSupply ( )
@@ -756,10 +763,10 @@ describe('Rewards', () => {
756
763
await advanceToNextEpoch ( epochManager )
757
764
758
765
// Close allocation. At this point rewards should be collected for that indexer
759
- const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID , randomHexBytes ( ) )
766
+ const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
760
767
await expect ( tx )
761
768
. emit ( rewardsManager , 'RewardsDenied' )
762
- . withArgs ( indexer1 . address , allocationID , await epochManager . currentEpoch ( ) )
769
+ . withArgs ( indexer1 . address , allocationID1 , await epochManager . currentEpoch ( ) )
763
770
} )
764
771
} )
765
772
} )
@@ -791,9 +798,9 @@ describe('Rewards', () => {
791
798
indexer1 . address ,
792
799
subgraphDeploymentID1 ,
793
800
tokensToAllocate ,
794
- allocationID ,
801
+ allocationID1 ,
795
802
metadata ,
796
- await channelKey . generateProof ( indexer1 . address ) ,
803
+ await channelKey1 . generateProof ( indexer1 . address ) ,
797
804
)
798
805
799
806
// Jump
@@ -804,7 +811,58 @@ describe('Rewards', () => {
804
811
await curation . connect ( curator1 . signer ) . burn ( subgraphDeploymentID1 , curatorShares , 0 )
805
812
806
813
// Close allocation. At this point rewards should be collected for that indexer
807
- await staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID , randomHexBytes ( ) )
814
+ await staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
815
+ } )
816
+ } )
817
+
818
+ describe ( 'multiple allocations' , function ( ) {
819
+ it ( 'two simultanous-similar allocations should get same amount of rewards' , async function ( ) {
820
+ await advanceToNextEpoch ( epochManager )
821
+
822
+ // Setup
823
+ await epochManager . setEpochLength ( 10 )
824
+
825
+ // Update total signalled
826
+ const signalled1 = toGRT ( '1500' )
827
+ await curation . connect ( curator1 . signer ) . mint ( subgraphDeploymentID1 , signalled1 , 0 )
828
+
829
+ // Stake
830
+ const tokensToStake = toGRT ( '12500' )
831
+ await staking . connect ( indexer1 . signer ) . stake ( tokensToStake )
832
+
833
+ // Allocate simultaneously
834
+ const tokensToAlloc = toGRT ( '5000' )
835
+ const tx1 = await staking . populateTransaction . allocateFrom (
836
+ indexer1 . address ,
837
+ subgraphDeploymentID1 ,
838
+ tokensToAlloc ,
839
+ allocationID1 ,
840
+ metadata ,
841
+ await channelKey1 . generateProof ( indexer1 . address ) ,
842
+ )
843
+ const tx2 = await staking . populateTransaction . allocateFrom (
844
+ indexer1 . address ,
845
+ subgraphDeploymentID1 ,
846
+ tokensToAlloc ,
847
+ allocationID2 ,
848
+ metadata ,
849
+ await channelKey2 . generateProof ( indexer1 . address ) ,
850
+ )
851
+ await staking . connect ( indexer1 . signer ) . multicall ( [ tx1 . data , tx2 . data ] )
852
+
853
+ // Jump
854
+ await advanceToNextEpoch ( epochManager )
855
+
856
+ // Close allocations simultaneously
857
+ const tx3 = await staking . populateTransaction . closeAllocation ( allocationID1 , randomHexBytes ( ) )
858
+ const tx4 = await staking . populateTransaction . closeAllocation ( allocationID2 , randomHexBytes ( ) )
859
+ const tx5 = await staking . connect ( indexer1 . signer ) . multicall ( [ tx3 . data , tx4 . data ] )
860
+
861
+ // Both allocations should receive the same amount of rewards
862
+ const receipt = await tx5 . wait ( )
863
+ const event1 = rewardsManager . interface . parseLog ( receipt . logs [ 1 ] ) . args
864
+ const event2 = rewardsManager . interface . parseLog ( receipt . logs [ 5 ] ) . args
865
+ expect ( event1 . amount ) . eq ( event2 . amount )
808
866
} )
809
867
} )
810
868
} )
0 commit comments