@@ -2,7 +2,6 @@ import { expect } from 'chai'
2
2
import { constants , BigNumber } from 'ethers'
3
3
import { BigNumber as BN } from 'bignumber.js'
4
4
5
- import { deployContract } from '../lib/deployment'
6
5
import { NetworkFixture } from '../lib/fixtures'
7
6
8
7
import { Curation } from '../../build/types/Curation'
@@ -23,6 +22,7 @@ import {
23
22
Account ,
24
23
advanceToNextEpoch ,
25
24
provider ,
25
+ advanceBlock ,
26
26
} from '../lib/testHelpers'
27
27
28
28
const MAX_PPM = 1000000
@@ -39,6 +39,7 @@ describe('Rewards', () => {
39
39
let indexer1 : Account
40
40
let indexer2 : Account
41
41
let oracle : Account
42
+ let assetHolder : Account
42
43
43
44
let fixture : NetworkFixture
44
45
@@ -131,7 +132,8 @@ describe('Rewards', () => {
131
132
}
132
133
133
134
before ( async function ( ) {
134
- ; [ delegator , governor , curator1 , curator2 , indexer1 , indexer2 , oracle ] = await getAccounts ( )
135
+ ; [ delegator , governor , curator1 , curator2 , indexer1 , indexer2 , oracle , assetHolder ] =
136
+ await getAccounts ( )
135
137
136
138
fixture = new NetworkFixture ( )
137
139
; ( { grt, curation, epochManager, staking, rewardsManager } = await fixture . load (
@@ -142,7 +144,7 @@ describe('Rewards', () => {
142
144
await rewardsManager . connect ( governor . signer ) . setIssuancePerBlock ( ISSUANCE_PER_BLOCK )
143
145
144
146
// Distribute test funds
145
- for ( const wallet of [ indexer1 , indexer2 , curator1 , curator2 ] ) {
147
+ for ( const wallet of [ indexer1 , indexer2 , curator1 , curator2 , assetHolder ] ) {
146
148
await grt . connect ( governor . signer ) . mint ( wallet . address , toGRT ( '1000000' ) )
147
149
await grt . connect ( wallet . signer ) . approve ( staking . address , toGRT ( '1000000' ) )
148
150
await grt . connect ( wallet . signer ) . approve ( curation . address , toGRT ( '1000000' ) )
@@ -955,4 +957,69 @@ describe('Rewards', () => {
955
957
expect ( event1 . amount ) . eq ( event2 . amount )
956
958
} )
957
959
} )
960
+
961
+ describe ( 'rewards progression when collecting query fees' , function ( ) {
962
+ it ( 'collect query fees with two subgraphs and one allocation' , async function ( ) {
963
+ async function getRewardsAccrual ( subgraphs ) {
964
+ const [ sg1 , sg2 ] = await Promise . all (
965
+ subgraphs . map ( ( sg ) => rewardsManager . getAccRewardsForSubgraph ( sg ) ) ,
966
+ )
967
+ return {
968
+ sg1,
969
+ sg2,
970
+ all : sg1 . add ( sg2 ) ,
971
+ }
972
+ }
973
+
974
+ // set curation percentage
975
+ await staking . setCurationPercentage ( 100000 )
976
+
977
+ // allow the asset holder
978
+ const tokensToCollect = toGRT ( '10000' )
979
+ await staking . connect ( governor . signer ) . setAssetHolder ( assetHolder . address , true )
980
+
981
+ // signal in two subgraphs in the same block
982
+ const subgraphs = [ subgraphDeploymentID1 , subgraphDeploymentID2 ]
983
+ for ( const sub of subgraphs ) {
984
+ await curation . connect ( curator1 . signer ) . mint ( sub , toGRT ( '1500' ) , 0 )
985
+ }
986
+
987
+ // snapshot block before any accrual (we substract 1 because accrual starts after the first mint happens)
988
+ const b1 = await epochManager . blockNum ( ) . then ( ( x ) => x . toNumber ( ) - 1 )
989
+
990
+ // allocate
991
+ const tokensToAllocate = toGRT ( '12500' )
992
+ await staking
993
+ . connect ( indexer1 . signer )
994
+ . multicall ( [
995
+ await staking . populateTransaction . stake ( tokensToAllocate ) . then ( ( tx ) => tx . data ) ,
996
+ await staking . populateTransaction
997
+ . allocateFrom (
998
+ indexer1 . address ,
999
+ subgraphDeploymentID1 ,
1000
+ tokensToAllocate ,
1001
+ allocationID1 ,
1002
+ metadata ,
1003
+ await channelKey1 . generateProof ( indexer1 . address ) ,
1004
+ )
1005
+ . then ( ( tx ) => tx . data ) ,
1006
+ ] )
1007
+
1008
+ // move time fwd
1009
+ await advanceBlock ( )
1010
+
1011
+ // collect funds into staking for that sub
1012
+ await staking . connect ( assetHolder . signer ) . collect ( tokensToCollect , allocationID1 )
1013
+
1014
+ // check rewards diff
1015
+ await rewardsManager . getRewards ( allocationID1 ) . then ( formatGRT )
1016
+
1017
+ await advanceBlock ( )
1018
+ const accrual = await getRewardsAccrual ( subgraphs )
1019
+ const b2 = await epochManager . blockNum ( ) . then ( ( x ) => x . toNumber ( ) )
1020
+
1021
+ // round comparison because there is a small precision error due to dividing and accrual per signal
1022
+ expect ( toRound ( accrual . all ) ) . eq ( toRound ( ISSUANCE_PER_BLOCK . mul ( b2 - b1 ) ) )
1023
+ } )
1024
+ } )
958
1025
} )
0 commit comments