1
+ import { BigNumber } from 'ethers'
2
+ import { parseEther } from 'ethers/lib/utils'
1
3
import Table from 'cli-table'
2
4
import PQueue from 'p-queue'
3
5
import { task } from 'hardhat/config'
@@ -6,32 +8,53 @@ import '@nomiclabs/hardhat-ethers'
6
8
7
9
import '../gre'
8
10
9
- task ( 'query:rebates' , 'List rebate pools' ) . setAction ( async ( _ , hre : HardhatRuntimeEnvironment ) => {
10
- const { contracts } = hre
11
- const { formatEther } = hre . ethers . utils
11
+ task ( 'query:rebates' , 'List rebate pools' )
12
+ . addParam ( 'count' , 'Number of pools to query' )
13
+ . setAction ( async ( { count } , hre : HardhatRuntimeEnvironment ) => {
14
+ const { contracts } = hre
15
+ const { formatEther } = hre . ethers . utils
12
16
13
- const table = new Table ( {
14
- head : [ 'Epoch' , 'Total Fees' , 'Claimed Amount' , 'Unclaimed Allocs' ] ,
15
- colWidths : [ 10 , 40 , 40 , 20 ] ,
16
- } )
17
+ const table = new Table ( {
18
+ head : [ 'Epoch' , 'Fees' , 'Claimed' , 'Allos' , 'Done (%)' ] ,
19
+ colWidths : [ 10 , 40 , 40 , 10 , 10 ] ,
20
+ } )
21
+
22
+ // Get epoch data
23
+ const currentEpoch = await contracts . EpochManager . currentEpoch ( )
17
24
18
- // Get epoch data
19
- const currentEpoch = await contracts . EpochManager . currentEpoch ( )
25
+ // Summaries
26
+ let totalAllos = 0
27
+ let totalUnclaimed = BigNumber . from ( 0 )
20
28
21
- // Get rebates
22
- const queue = new PQueue ( { concurrency : 4 } )
23
- for ( let i = 0 ; i < 5 ; i ++ ) {
24
- const epoch = currentEpoch . sub ( i )
25
- const rebatePool = await contracts . Staking . rebates ( epoch )
26
- table . push ( [
27
- epoch ,
28
- formatEther ( rebatePool . fees ) ,
29
- formatEther ( rebatePool . claimedRewards ) ,
30
- rebatePool . unclaimedAllocationsCount ,
31
- ] )
32
- }
33
- await queue . onIdle ( )
29
+ // Get rebates
30
+ const items = [ ]
31
+ const queue = new PQueue ( { concurrency : 10 } )
32
+ for ( let i = 0 ; i < count ; i ++ ) {
33
+ queue . add ( async ( ) => {
34
+ // Calculations
35
+ const epoch = currentEpoch . sub ( i ) . toNumber ( )
36
+ const rebatePool = await contracts . Staking . rebates ( epoch )
37
+ const shareClaimed = rebatePool . fees . gt ( 0 )
38
+ ? formatEther ( rebatePool . claimedRewards . mul ( parseEther ( '1' ) ) . div ( rebatePool . fees ) )
39
+ : '1'
40
+ // Add to table
41
+ items . push ( [
42
+ epoch ,
43
+ formatEther ( rebatePool . fees ) ,
44
+ formatEther ( rebatePool . claimedRewards ) ,
45
+ rebatePool . unclaimedAllocationsCount ,
46
+ Math . round ( parseFloat ( shareClaimed ) * 100 ) ,
47
+ ] )
48
+ // Add to summaries
49
+ totalAllos += rebatePool . unclaimedAllocationsCount
50
+ totalUnclaimed = totalUnclaimed . add ( rebatePool . fees . sub ( rebatePool . claimedRewards ) )
51
+ } )
52
+ }
53
+ await queue . onIdle ( )
34
54
35
- // Display
36
- console . log ( table . toString ( ) )
37
- } )
55
+ // Display
56
+ table . push ( ...items . sort ( ( a , b ) => b [ 0 ] - a [ 0 ] ) )
57
+ console . log ( table . toString ( ) )
58
+ console . log ( `> Unclaimed Allos: ${ totalAllos } ` )
59
+ console . log ( `> Unclaimed Fees: ${ formatEther ( totalUnclaimed ) } ` )
60
+ } )
0 commit comments