@@ -573,19 +573,29 @@ describe('Rewards', () => {
573
573
}
574
574
575
575
it ( 'should distribute rewards on closed allocation and stake' , async function ( ) {
576
+
577
+ // Align with the epoch boundary
578
+ await advanceToNextEpoch ( epochManager )
576
579
// Setup
577
580
await setupIndexerAllocation ( )
578
581
579
582
// Jump
580
- await advanceBlocks ( await epochManager . epochLength ( ) )
583
+ await advanceToNextEpoch ( epochManager )
581
584
582
585
// Before state
583
586
const beforeTokenSupply = await grt . totalSupply ( )
584
587
const beforeIndexer1Stake = await staking . getIndexerStakedTokens ( indexer1 . address )
585
588
const beforeIndexer1Balance = await grt . balanceOf ( indexer1 . address )
586
589
const beforeStakingBalance = await grt . balanceOf ( staking . address )
587
590
588
- const expectedIndexingRewards = toGRT ( '1471954234' )
591
+ // All the rewards in this subgraph go to this allocation.
592
+ // Rewards per token will be (totalSupply * issuanceRate^nBlocks - totalSupply) / allocatedTokens
593
+ // The first snapshot is after allocating, that is 2 blocks after the signal is minted:
594
+ // startRewardsPerToken = (10004000000 * 1.01227 ^ 2 - 10004000000) / 12500 = 122945.16
595
+ // The final snapshot is when we close the allocation, that happens 9 blocks later:
596
+ // endRewardsPerToken = (10004000000 * 1.01227 ^ 9 - 10004000000) / 12500 = 92861.24
597
+ // Then our expected rewards are (endRewardsPerToken - startRewardsPerToken) * 12500.
598
+ const expectedIndexingRewards = toGRT ( '913715958' )
589
599
590
600
// Close allocation. At this point rewards should be collected for that indexer
591
601
const tx = await staking
@@ -623,19 +633,28 @@ describe('Rewards', () => {
623
633
const destinationAddress = randomHexBytes ( 20 )
624
634
await staking . connect ( indexer1 . signer ) . setRewardsDestination ( destinationAddress )
625
635
636
+ // Align with the epoch boundary
637
+ await advanceToNextEpoch ( epochManager )
626
638
// Setup
627
639
await setupIndexerAllocation ( )
628
640
629
641
// Jump
630
- await advanceBlocks ( await epochManager . epochLength ( ) )
642
+ await advanceToNextEpoch ( epochManager )
631
643
632
644
// Before state
633
645
const beforeTokenSupply = await grt . totalSupply ( )
634
646
const beforeIndexer1Stake = await staking . getIndexerStakedTokens ( indexer1 . address )
635
647
const beforeDestinationBalance = await grt . balanceOf ( destinationAddress )
636
648
const beforeStakingBalance = await grt . balanceOf ( staking . address )
637
649
638
- const expectedIndexingRewards = toGRT ( '1471954234' )
650
+ // All the rewards in this subgraph go to this allocation.
651
+ // Rewards per token will be (totalSupply * issuanceRate^nBlocks - totalSupply) / allocatedTokens
652
+ // The first snapshot is after allocating, that is 2 blocks after the signal is minted:
653
+ // startRewardsPerToken = (10004000000 * 1.01227 ^ 2 - 10004000000) / 12500 = 122945.16
654
+ // The final snapshot is when we close the allocation, that happens 9 blocks later:
655
+ // endRewardsPerToken = (10004000000 * 1.01227 ^ 9 - 10004000000) / 12500 = 92861.24
656
+ // Then our expected rewards are (endRewardsPerToken - startRewardsPerToken) * 12500.
657
+ const expectedIndexingRewards = toGRT ( '913715958' )
639
658
640
659
// Close allocation. At this point rewards should be collected for that indexer
641
660
const tx = await staking
@@ -678,10 +697,13 @@ describe('Rewards', () => {
678
697
}
679
698
const tokensToDelegate = toGRT ( '2000' )
680
699
700
+ // Align with the epoch boundary
701
+ await advanceToNextEpoch ( epochManager )
702
+ // Setup the allocation and delegators
681
703
await setupIndexerAllocationWithDelegation ( tokensToDelegate , delegationParams )
682
704
683
705
// Jump
684
- await advanceBlocks ( await epochManager . epochLength ( ) )
706
+ await advanceToNextEpoch ( epochManager )
685
707
686
708
// Before state
687
709
const beforeTokenSupply = await grt . totalSupply ( )
@@ -698,8 +720,15 @@ describe('Rewards', () => {
698
720
699
721
// Check that rewards are put into indexer stake (only indexer cut)
700
722
// Check that rewards are put into delegators pool accordingly
701
- // NOTE: calculated manually on a spreadsheet
702
- const expectedIndexingRewards = toGRT ( '1454109066' )
723
+
724
+ // All the rewards in this subgraph go to this allocation.
725
+ // Rewards per token will be (totalSupply * issuanceRate^nBlocks - totalSupply) / allocatedTokens
726
+ // The first snapshot is after allocating, that is 2 blocks after the signal is minted:
727
+ // startRewardsPerToken = (10004000000 * 1.01227 ^ 2 - 10004000000) / 14500 = 8466.995
728
+ // The final snapshot is when we close the allocation, that happens 4 blocks later:
729
+ // endRewardsPerToken = (10004000000 * 1.01227 ^ 4 - 10004000000) / 14500 = 34496.55
730
+ // Then our expected rewards are (endRewardsPerToken - startRewardsPerToken) * 14500.
731
+ const expectedIndexingRewards = toGRT ( '377428566.77' )
703
732
// Calculate delegators cut
704
733
const indexerRewards = delegationParams . indexingRewardCut
705
734
. mul ( expectedIndexingRewards )
@@ -725,7 +754,7 @@ describe('Rewards', () => {
725
754
await setupIndexerAllocation ( )
726
755
727
756
// Jump
728
- await advanceBlocks ( await epochManager . epochLength ( ) )
757
+ await advanceToNextEpoch ( epochManager )
729
758
730
759
// Close allocation. At this point rewards should be collected for that indexer
731
760
const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID , randomHexBytes ( ) )
@@ -769,7 +798,7 @@ describe('Rewards', () => {
769
798
)
770
799
771
800
// Jump
772
- await advanceBlocks ( await epochManager . epochLength ( ) )
801
+ await advanceToNextEpoch ( epochManager )
773
802
774
803
// Remove all signal from the subgraph
775
804
const curatorShares = await curation . getCuratorSignal ( curator1 . address , subgraphDeploymentID1 )
0 commit comments