1
1
const ethers = require ( 'ethers' ) ;
2
+ const { toBytes32 } = require ( '../../../index' ) ;
2
3
const { assert } = require ( '../../contracts/common' ) ;
4
+ const { exchangeSomething, ignoreFeePeriodDuration } = require ( '../utils/exchanging' ) ;
3
5
const { ensureBalance } = require ( '../utils/balances' ) ;
4
- const { ignoreMinimumStakeTime } = require ( '../utils/stakeTime' ) ;
6
+ const { ignoreMinimumStakeTime } = require ( '../utils/staking' ) ;
7
+ const { skipIfL2 } = require ( '../utils/l2' ) ;
5
8
6
- function itCanMintAndBurn ( { ctx } ) {
7
- describe ( 'staking' , ( ) => {
9
+ function itCanStake ( { ctx } ) {
10
+ describe ( 'staking and claiming ' , ( ) => {
8
11
const SNXAmount = ethers . utils . parseEther ( '100' ) ;
9
- const sUSDamount = ethers . utils . parseEther ( '1' ) ;
12
+ const amountToIssueAndBurnsUSD = ethers . utils . parseEther ( '1' ) ;
10
13
11
14
let user ;
12
- let Synthetix , SynthsUSD ;
13
- let balancesUSD ;
15
+ let Synthetix , SynthsUSD , FeePool ;
16
+ let balancesUSD , debtsUSD ;
14
17
15
18
before ( 'target contracts and users' , ( ) => {
16
- ( { Synthetix, SynthsUSD } = ctx . contracts ) ;
19
+ ( { Synthetix, SynthsUSD, FeePool } = ctx . contracts ) ;
17
20
18
21
user = ctx . users . someUser ;
19
22
} ) ;
@@ -30,41 +33,90 @@ function itCanMintAndBurn({ ctx }) {
30
33
before ( 'issue sUSD' , async ( ) => {
31
34
Synthetix = Synthetix . connect ( user ) ;
32
35
33
- const tx = await Synthetix . issueSynths ( sUSDamount ) ;
36
+ const tx = await Synthetix . issueSynths ( amountToIssueAndBurnsUSD ) ;
34
37
await tx . wait ( ) ;
35
38
} ) ;
36
39
37
40
it ( 'issues the expected amount of sUSD' , async ( ) => {
38
- assert . bnEqual ( await SynthsUSD . balanceOf ( user . address ) , balancesUSD . add ( sUSDamount ) ) ;
41
+ assert . bnEqual (
42
+ await SynthsUSD . balanceOf ( user . address ) ,
43
+ balancesUSD . add ( amountToIssueAndBurnsUSD )
44
+ ) ;
45
+ } ) ;
46
+
47
+ describe ( 'claiming' , ( ) => {
48
+ // TODO: Disabled until Optimism supports 5s time granularity.
49
+ // We can set fee period duration to 5s, but we dont want this test
50
+ // to wait 3m, which is the current time granularity.
51
+ skipIfL2 ( {
52
+ ctx,
53
+ reason :
54
+ 'ops L2 time granularity needs to be less than 3m, so we cant close the fee period' ,
55
+ } ) ;
56
+
57
+ before ( 'exchange something' , async ( ) => {
58
+ await exchangeSomething ( { ctx } ) ;
59
+ } ) ;
60
+
61
+ describe ( 'when the fee period closes' , ( ) => {
62
+ ignoreFeePeriodDuration ( { ctx } ) ;
63
+
64
+ before ( 'close the current fee period' , async ( ) => {
65
+ FeePool = FeePool . connect ( ctx . users . owner ) ;
66
+
67
+ const tx = await FeePool . closeCurrentFeePeriod ( ) ;
68
+ await tx . wait ( ) ;
69
+ } ) ;
70
+
71
+ describe ( 'when the user claims rewards' , ( ) => {
72
+ before ( 'record balances' , async ( ) => {
73
+ balancesUSD = await SynthsUSD . balanceOf ( user . address ) ;
74
+ } ) ;
75
+
76
+ before ( 'claim' , async ( ) => {
77
+ FeePool = FeePool . connect ( user ) ;
78
+
79
+ const tx = await FeePool . claimFees ( ) ;
80
+ await tx . wait ( ) ;
81
+ } ) ;
82
+
83
+ it ( 'shows a slight increase in the users sUSD balance' , async ( ) => {
84
+ assert . bnGt ( await SynthsUSD . balanceOf ( user . address ) , balancesUSD ) ;
85
+ } ) ;
86
+ } ) ;
87
+ } ) ;
39
88
} ) ;
40
89
} ) ;
41
90
42
91
describe ( 'when the user burns sUSD' , ( ) => {
43
92
ignoreMinimumStakeTime ( { ctx } ) ;
44
93
45
- before ( 'record values ' , async ( ) => {
46
- balancesUSD = await SynthsUSD . balanceOf ( user . address ) ;
94
+ before ( 'record debt ' , async ( ) => {
95
+ debtsUSD = await Synthetix . debtBalanceOf ( user . address , toBytes32 ( 'sUSD' ) ) ;
47
96
} ) ;
48
97
49
98
before ( 'burn sUSD' , async ( ) => {
50
99
Synthetix = Synthetix . connect ( user ) ;
51
100
52
- const tx = await Synthetix . burnSynths ( sUSDamount ) ;
101
+ const tx = await Synthetix . burnSynths ( amountToIssueAndBurnsUSD ) ;
53
102
await tx . wait ( ) ;
54
103
} ) ;
55
104
56
- it ( 'burnt the expected amount of sUSD' , async ( ) => {
57
- const newBalancesUSD = await SynthsUSD . balanceOf ( user . address ) ;
58
- const expected = balancesUSD . sub ( sUSDamount ) ;
59
- const delta = newBalancesUSD . sub ( expected ) ;
60
- const variance = ethers . utils . parseUnits ( '2' , 'gwei' ) ;
105
+ it ( 'reduced the expected amount of debt' , async ( ) => {
106
+ const newDebtsUSD = await Synthetix . debtBalanceOf ( user . address , toBytes32 ( 'sUSD' ) ) ;
107
+ const debtReduction = debtsUSD . sub ( newDebtsUSD ) ;
61
108
62
- assert . bnLt ( delta , variance ) ;
109
+ const tolerance = ethers . utils . parseUnits ( '40' , 'gwei' ) ;
110
+ assert . bnClose (
111
+ debtReduction . toString ( ) ,
112
+ amountToIssueAndBurnsUSD . toString ( ) ,
113
+ tolerance . toString ( )
114
+ ) ;
63
115
} ) ;
64
116
} ) ;
65
117
} ) ;
66
118
}
67
119
68
120
module . exports = {
69
- itCanMintAndBurn ,
121
+ itCanStake ,
70
122
} ;
0 commit comments