1
- import { BundleDataClient , HubPoolClient , MultiCallerClient , SpokePoolClient } from "../src/clients" ;
2
- import {
3
- EvmAddress ,
4
- buildRelayerRefundTree ,
5
- MAX_UINT_VAL ,
6
- RelayerRefundLeaf ,
7
- toBN ,
8
- toBNWei ,
9
- toAddressType ,
10
- } from "../src/utils" ;
1
+ import { HubPoolClient , MultiCallerClient , SpokePoolClient } from "../src/clients" ;
2
+ import { EvmAddress , buildRelayerRefundTree , MAX_UINT_VAL , RelayerRefundLeaf , toBNWei } from "../src/utils" ;
11
3
import {
12
4
MAX_L1_TOKENS_PER_POOL_REBALANCE_LEAF ,
13
5
MAX_REFUNDS_PER_RELAYER_REFUND_LEAF ,
14
6
amountToDeposit ,
15
7
destinationChainId ,
16
- repaymentChainId ,
17
8
} from "./constants" ;
18
9
import { setupDataworker } from "./fixtures/Dataworker.Fixture" ;
19
10
import { Contract , SignerWithAddress , depositV3 , ethers , expect , fillV3Relay } from "./utils" ;
@@ -148,11 +139,9 @@ describe("Dataworker: Execute relayer refunds", async function () {
148
139
} ) ;
149
140
describe ( "Computing refunds for bundles" , function ( ) {
150
141
let relayer : SignerWithAddress ;
151
- let bundleDataClient : BundleDataClient ;
152
142
153
143
beforeEach ( async function ( ) {
154
144
relayer = depositor ;
155
- bundleDataClient = dataworkerInstance . clients . bundleDataClient ;
156
145
await updateAllClients ( ) ;
157
146
158
147
const deposit1 = await depositV3 (
@@ -172,169 +161,5 @@ describe("Dataworker: Execute relayer refunds", async function () {
172
161
173
162
await updateAllClients ( ) ;
174
163
} ) ;
175
- it ( "No validated bundle refunds" , async function ( ) {
176
- // Propose a bundle:
177
- await dataworkerInstance . proposeRootBundle ( spokePoolClients ) ;
178
- await multiCallerClient . executeTxnQueues ( ) ;
179
- await updateAllClients ( ) ;
180
-
181
- // No bundle is validated so no refunds.
182
- const refunds = await bundleDataClient . getPendingRefundsFromValidBundles ( ) ;
183
- expect (
184
- bundleDataClient . getTotalRefund (
185
- refunds ,
186
- EvmAddress . from ( relayer . address ) ,
187
- destinationChainId ,
188
- toAddressType ( erc20_2 . address , destinationChainId )
189
- )
190
- ) . to . equal ( toBN ( 0 ) ) ;
191
- } ) ;
192
- it ( "Get refunds from validated bundles" , async function ( ) {
193
- await updateAllClients ( ) ;
194
- // Propose a bundle:
195
- await dataworkerInstance . proposeRootBundle ( spokePoolClients ) ;
196
- await multiCallerClient . executeTxnQueues ( ) ;
197
-
198
- // Advance time and execute leaves:
199
- await hubPool . setCurrentTime ( Number ( await hubPool . getCurrentTime ( ) ) + Number ( await hubPool . liveness ( ) ) + 1 ) ;
200
- await updateAllClients ( ) ;
201
- await dataworkerInstance . executePoolRebalanceLeaves ( spokePoolClients , await getNewBalanceAllocator ( ) ) ;
202
- await multiCallerClient . executeTxnQueues ( ) ;
203
-
204
- // Before relayer refund leaves are not executed, should have pending refunds:
205
- await updateAllClients ( ) ;
206
- const validatedRootBundles = hubPoolClient . getValidatedRootBundles ( ) ;
207
- expect ( validatedRootBundles . length ) . to . equal ( 1 ) ;
208
- const refunds = await bundleDataClient . getPendingRefundsFromValidBundles ( ) ;
209
- const totalRefund1 = bundleDataClient . getTotalRefund (
210
- refunds ,
211
- toAddressType ( relayer . address , destinationChainId ) ,
212
- destinationChainId ,
213
- toAddressType ( erc20_2 . address , destinationChainId )
214
- ) ;
215
- expect ( totalRefund1 ) . to . gt ( 0 ) ;
216
-
217
- // Test edge cases of `getTotalRefund` that should return BN(0)
218
- expect (
219
- bundleDataClient . getTotalRefund (
220
- refunds ,
221
- toAddressType ( relayer . address , repaymentChainId ) ,
222
- repaymentChainId ,
223
- toAddressType ( erc20_2 . address , repaymentChainId )
224
- )
225
- ) . to . equal ( toBN ( 0 ) ) ;
226
- expect (
227
- bundleDataClient . getTotalRefund (
228
- refunds ,
229
- toAddressType ( relayer . address , destinationChainId ) ,
230
- destinationChainId ,
231
- toAddressType ( erc20_1 . address , destinationChainId )
232
- )
233
- ) . to . equal ( toBN ( 0 ) ) ;
234
-
235
- // Manually relay the roots to spoke pools since adapter is a dummy and won't actually relay messages.
236
- const rootBundle = validatedRootBundles [ 0 ] ;
237
- await spokePool_1 . relayRootBundle ( rootBundle . relayerRefundRoot , rootBundle . slowRelayRoot ) ;
238
- await spokePool_2 . relayRootBundle ( rootBundle . relayerRefundRoot , rootBundle . slowRelayRoot ) ;
239
- await updateAllClients ( ) ;
240
-
241
- // Execute relayer refund leaves. Send funds to spoke pools to execute the leaves.
242
- await erc20_2 . mint ( spokePool_2 . address , amountToDeposit ) ;
243
- await dataworkerInstance . executeRelayerRefundLeaves ( spokePoolClients , await getNewBalanceAllocator ( ) ) ;
244
- await multiCallerClient . executeTxnQueues ( ) ;
245
-
246
- // Should now have zero pending refunds
247
- await updateAllClients ( ) ;
248
- // If we call `getPendingRefundsFromLatestBundle` multiple times, there should be no error. If there is an error,
249
- // then it means that `getPendingRefundsFromLatestBundle` is mutating the return value of `.loadData` which is
250
- // stored in the bundle data client's cache. `getPendingRefundsFromLatestBundle` should instead be using a
251
- // deep cloned copy of `.loadData`'s output.
252
- await bundleDataClient . getPendingRefundsFromValidBundles ( ) ;
253
- const postExecutionRefunds = await bundleDataClient . getPendingRefundsFromValidBundles ( ) ;
254
- expect (
255
- bundleDataClient . getTotalRefund (
256
- postExecutionRefunds ,
257
- toAddressType ( relayer . address , destinationChainId ) ,
258
- destinationChainId ,
259
- toAddressType ( erc20_2 . address , destinationChainId )
260
- )
261
- ) . to . equal ( toBN ( 0 ) ) ;
262
-
263
- // Submit fill2 and propose another bundle:
264
- const newDepositAmount = amountToDeposit . mul ( 2 ) ;
265
- const deposit2 = await depositV3 (
266
- spokePool_1 ,
267
- destinationChainId ,
268
- depositor ,
269
- erc20_1 . address ,
270
- newDepositAmount ,
271
- erc20_2 . address ,
272
- amountToDeposit
273
- ) ;
274
- await updateAllClients ( ) ;
275
-
276
- // Submit a valid fill.
277
- await fillV3Relay ( spokePool_2 , deposit2 , relayer , destinationChainId ) ;
278
- await updateAllClients ( ) ;
279
-
280
- // Validate another bundle:
281
- await dataworkerInstance . proposeRootBundle ( spokePoolClients ) ;
282
- await multiCallerClient . executeTxnQueues ( ) ;
283
- await hubPool . setCurrentTime ( Number ( await hubPool . getCurrentTime ( ) ) + Number ( await hubPool . liveness ( ) ) + 1 ) ;
284
- await updateAllClients ( ) ;
285
- await dataworkerInstance . executePoolRebalanceLeaves ( spokePoolClients , await getNewBalanceAllocator ( ) ) ;
286
- await multiCallerClient . executeTxnQueues ( ) ;
287
- await updateAllClients ( ) ;
288
-
289
- expect ( hubPoolClient . getValidatedRootBundles ( ) . length ) . to . equal ( 2 ) ;
290
-
291
- // Should include refunds for most recently validated bundle but not count first one
292
- // since they were already refunded.
293
- const refunds2 = await bundleDataClient . getPendingRefundsFromValidBundles ( ) ;
294
- expect (
295
- bundleDataClient . getTotalRefund (
296
- refunds2 ,
297
- toAddressType ( relayer . address , destinationChainId ) ,
298
- destinationChainId ,
299
- toAddressType ( erc20_2 . address , destinationChainId )
300
- )
301
- ) . to . gt ( 0 ) ;
302
- } ) ;
303
- it ( "Refunds in next bundle" , async function ( ) {
304
- // Before proposal should show refunds:
305
- expect (
306
- bundleDataClient . getRefundsFor (
307
- ( await bundleDataClient . getNextBundleRefunds ( ) ) [ 0 ] ,
308
- toAddressType ( relayer . address , destinationChainId ) ,
309
- destinationChainId ,
310
- toAddressType ( erc20_2 . address , destinationChainId )
311
- )
312
- ) . to . gt ( 0 ) ;
313
-
314
- // Propose a bundle:
315
- await dataworkerInstance . proposeRootBundle ( spokePoolClients ) ;
316
- await multiCallerClient . executeTxnQueues ( ) ;
317
- await updateAllClients ( ) ;
318
-
319
- // After proposal but before execution should show upcoming refund:
320
- expect (
321
- bundleDataClient . getRefundsFor (
322
- ( await bundleDataClient . getNextBundleRefunds ( ) ) [ 0 ] ,
323
- toAddressType ( relayer . address , destinationChainId ) ,
324
- destinationChainId ,
325
- toAddressType ( erc20_2 . address , destinationChainId )
326
- )
327
- ) . to . gt ( 0 ) ;
328
-
329
- // Advance time and execute root bundle:
330
- await hubPool . setCurrentTime ( Number ( await hubPool . getCurrentTime ( ) ) + Number ( await hubPool . liveness ( ) ) + 1 ) ;
331
- await updateAllClients ( ) ;
332
- await dataworkerInstance . executePoolRebalanceLeaves ( spokePoolClients , await getNewBalanceAllocator ( ) ) ;
333
- await multiCallerClient . executeTxnQueues ( ) ;
334
-
335
- // Should reset to no refunds in "next bundle", though these will show up in pending bundle.
336
- await updateAllClients ( ) ;
337
- expect ( await bundleDataClient . getNextBundleRefunds ( ) ) . to . deep . equal ( [ { } ] ) ;
338
- } ) ;
339
164
} ) ;
340
165
} ) ;
0 commit comments