@@ -4,6 +4,7 @@ import { BigNumber, constants, ContractTransaction, utils } from 'ethers'
4
4
import { L2FixtureContracts , NetworkFixture } from '../lib/fixtures'
5
5
6
6
import { BigNumber as BN } from 'bignumber.js'
7
+ import { FakeContract , smock } from '@defi-wonderland/smock'
7
8
8
9
import {
9
10
advanceBlocks ,
@@ -30,11 +31,13 @@ const dripIssuanceRate = toBN('1000000023206889619')
30
31
describe ( 'L2Reservoir' , ( ) => {
31
32
let governor : Account
32
33
let testAccount1 : Account
34
+ let testAccount2 : Account
33
35
let mockRouter : Account
34
36
let mockL1GRT : Account
35
37
let mockL1Gateway : Account
36
38
let mockL1Reservoir : Account
37
39
let fixture : NetworkFixture
40
+ let arbTxMock : FakeContract
38
41
39
42
let grt : L2GraphToken
40
43
let l2Reservoir : L2Reservoir
@@ -122,7 +125,7 @@ describe('L2Reservoir', () => {
122
125
}
123
126
124
127
before ( async function ( ) {
125
- ; [ governor , testAccount1 , mockRouter , mockL1GRT , mockL1Gateway , mockL1Reservoir ] =
128
+ ; [ governor , testAccount1 , mockRouter , mockL1GRT , mockL1Gateway , mockL1Reservoir , testAccount2 ] =
126
129
await getAccounts ( )
127
130
128
131
fixture = new NetworkFixture ( )
@@ -136,6 +139,11 @@ describe('L2Reservoir', () => {
136
139
mockL1Gateway . address ,
137
140
mockL1Reservoir . address ,
138
141
)
142
+
143
+ arbTxMock = await smock . fake ( 'IArbTxWithRedeemer' , {
144
+ address : '0x000000000000000000000000000000000000006E' ,
145
+ } )
146
+ arbTxMock . getCurrentRedeemer . returns ( mockL1Reservoir . address )
139
147
} )
140
148
141
149
beforeEach ( async function ( ) {
@@ -157,7 +165,42 @@ describe('L2Reservoir', () => {
157
165
await expect ( await l2Reservoir . nextDripNonce ( ) ) . to . eq ( toBN ( '10' ) )
158
166
} )
159
167
} )
168
+
169
+ describe ( 'setL1ReservoirAddress' , async function ( ) {
170
+ it ( 'rejects unauthorized calls' , async function ( ) {
171
+ const tx = l2Reservoir
172
+ . connect ( testAccount1 . signer )
173
+ . setL1ReservoirAddress ( testAccount1 . address )
174
+ await expect ( tx ) . revertedWith ( 'Caller must be Controller governor' )
175
+ } )
176
+ it ( 'sets the L1Reservoir address' , async function ( ) {
177
+ const tx = l2Reservoir . connect ( governor . signer ) . setL1ReservoirAddress ( testAccount1 . address )
178
+ await expect ( tx ) . emit ( l2Reservoir , 'L1ReservoirAddressUpdated' ) . withArgs ( testAccount1 . address )
179
+ await expect ( await l2Reservoir . l1ReservoirAddress ( ) ) . to . eq ( testAccount1 . address )
180
+ } )
181
+ } )
182
+
183
+ describe ( 'setL2KeeperRewardFraction' , async function ( ) {
184
+ it ( 'rejects unauthorized calls' , async function ( ) {
185
+ const tx = l2Reservoir . connect ( testAccount1 . signer ) . setL2KeeperRewardFraction ( toBN ( 1 ) )
186
+ await expect ( tx ) . revertedWith ( 'Caller must be Controller governor' )
187
+ } )
188
+ it ( 'rejects invalid values (> 1)' , async function ( ) {
189
+ const tx = l2Reservoir . connect ( governor . signer ) . setL2KeeperRewardFraction ( toGRT ( '1.000001' ) )
190
+ await expect ( tx ) . revertedWith ( 'INVALID_VALUE' )
191
+ } )
192
+ it ( 'sets the L1Reservoir address' , async function ( ) {
193
+ const tx = l2Reservoir . connect ( governor . signer ) . setL2KeeperRewardFraction ( toGRT ( '0.999' ) )
194
+ await expect ( tx ) . emit ( l2Reservoir , 'L2KeeperRewardFractionUpdated' ) . withArgs ( toGRT ( '0.999' ) )
195
+ await expect ( await l2Reservoir . l2KeeperRewardFraction ( ) ) . to . eq ( toGRT ( '0.999' ) )
196
+ } )
197
+ } )
198
+
160
199
describe ( 'receiveDrip' , async function ( ) {
200
+ beforeEach ( async function ( ) {
201
+ await l2Reservoir . connect ( governor . signer ) . setL2KeeperRewardFraction ( toGRT ( '0.2' ) )
202
+ await l2Reservoir . connect ( governor . signer ) . setL1ReservoirAddress ( mockL1Reservoir . address )
203
+ } )
161
204
it ( 'rejects the call when not called by the gateway' , async function ( ) {
162
205
const tx = l2Reservoir
163
206
. connect ( governor . signer )
@@ -232,6 +275,32 @@ describe('L2Reservoir', () => {
232
275
. withArgs ( l2Reservoir . address , testAccount1 . address , reward )
233
276
await expect ( await grt . balanceOf ( testAccount1 . address ) ) . to . eq ( reward )
234
277
} )
278
+ it ( 'delivers part of the keeper reward to the L2 redeemer' , async function ( ) {
279
+ arbTxMock . getCurrentRedeemer . returns ( testAccount2 . address )
280
+ await l2Reservoir . connect ( governor . signer ) . setL2KeeperRewardFraction ( toGRT ( '0.25' ) )
281
+ normalizedSupply = dripNormalizedSupply
282
+ const reward = toGRT ( '16' )
283
+ const receiveDripTx = await l2Reservoir . populateTransaction . receiveDrip (
284
+ dripNormalizedSupply ,
285
+ dripIssuanceRate ,
286
+ toBN ( '0' ) ,
287
+ reward ,
288
+ testAccount1 . address ,
289
+ )
290
+ const tx = await validGatewayFinalizeTransfer ( receiveDripTx . data , reward )
291
+ dripBlock = await latestBlock ( )
292
+ await expect ( await l2Reservoir . normalizedTokenSupplyCache ( ) ) . to . eq ( dripNormalizedSupply )
293
+ await expect ( await l2Reservoir . issuanceRate ( ) ) . to . eq ( dripIssuanceRate )
294
+ await expect ( tx ) . emit ( l2Reservoir , 'DripReceived' ) . withArgs ( dripNormalizedSupply )
295
+ await expect ( tx )
296
+ . emit ( grt , 'Transfer' )
297
+ . withArgs ( l2Reservoir . address , testAccount1 . address , toGRT ( '12' ) )
298
+ await expect ( tx )
299
+ . emit ( grt , 'Transfer' )
300
+ . withArgs ( l2Reservoir . address , testAccount2 . address , toGRT ( '4' ) )
301
+ await expect ( await grt . balanceOf ( testAccount1 . address ) ) . to . eq ( toGRT ( '12' ) )
302
+ await expect ( await grt . balanceOf ( testAccount2 . address ) ) . to . eq ( toGRT ( '4' ) )
303
+ } )
235
304
it ( 'updates the normalized supply cache and issuance rate' , async function ( ) {
236
305
normalizedSupply = dripNormalizedSupply
237
306
let receiveDripTx = await l2Reservoir . populateTransaction . receiveDrip (
0 commit comments