@across-protocol/sdk 4.3.58 → 4.3.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +45 -332
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +6 -4
  5. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  6. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +5 -0
  7. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  8. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  9. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -3
  10. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  11. package/dist/cjs/clients/HubPoolClient.d.ts +3 -9
  12. package/dist/cjs/clients/HubPoolClient.js +44 -68
  13. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  14. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +4 -3
  15. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  16. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +2 -2
  17. package/dist/cjs/clients/mocks/MockHubPoolClient.js +1 -1
  18. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  19. package/dist/cjs/providers/retryProvider.js +6 -4
  20. package/dist/cjs/providers/retryProvider.js.map +1 -1
  21. package/dist/cjs/providers/utils.js +1 -1
  22. package/dist/cjs/providers/utils.js.map +1 -1
  23. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
  24. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +47 -373
  25. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  26. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +6 -4
  27. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  28. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +6 -1
  29. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  30. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  31. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -2
  32. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  33. package/dist/esm/clients/HubPoolClient.d.ts +3 -9
  34. package/dist/esm/clients/HubPoolClient.js +48 -74
  35. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  36. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +4 -3
  37. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  38. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +2 -2
  39. package/dist/esm/clients/mocks/MockHubPoolClient.js +1 -1
  40. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  41. package/dist/esm/providers/retryProvider.js +6 -4
  42. package/dist/esm/providers/retryProvider.js.map +1 -1
  43. package/dist/esm/providers/utils.js +2 -2
  44. package/dist/esm/providers/utils.js.map +1 -1
  45. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
  46. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  47. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  48. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  49. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
  50. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  51. package/dist/types/clients/HubPoolClient.d.ts +3 -9
  52. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  53. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  54. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +2 -2
  55. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  56. package/dist/types/providers/retryProvider.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/src/clients/BundleDataClient/BundleDataClient.ts +12 -358
  59. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +13 -20
  60. package/src/clients/BundleDataClient/utils/FillUtils.ts +7 -1
  61. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +8 -2
  62. package/src/clients/HubPoolClient.ts +49 -80
  63. package/src/clients/SpokePoolClient/SpokePoolClient.ts +15 -11
  64. package/src/clients/mocks/MockHubPoolClient.ts +3 -3
  65. package/src/providers/retryProvider.ts +6 -4
  66. package/src/providers/utils.ts +2 -2
@@ -4,8 +4,8 @@ import _ from "lodash";
4
4
  import { FillType, FillStatus, } from "../../interfaces";
5
5
  import { findFillEvent as findEvmFillEvent } from "../../arch/evm";
6
6
  import { findFillEvent as findSvmFillEvent } from "../../arch/svm";
7
- import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, getRelayEventKey, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, isZeroValueFillOrSlowFillRequest, duplicateEvent, invalidOutputToken, getNetworkName, toBytes32, convertRelayDataParamsToBytes32, convertFillParamsToBytes32, } from "../../utils";
8
- import { BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, verifyFillRepayment, } from "./utils";
7
+ import { bnZero, queryHistoricalDepositForFill, assign, fixedPointAdjustment, isDefined, forEachAsync, getBlockRangeForChain, getRelayEventKey, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, isZeroValueFillOrSlowFillRequest, duplicateEvent, invalidOutputToken, toBytes32, convertRelayDataParamsToBytes32, convertFillParamsToBytes32, } from "../../utils";
8
+ import { BundleDataSS, getRefundInformationFromFill, isChainDisabledAtBlock, prettyPrintV3SpokePoolEvents, verifyFillRepayment, } from "./utils";
9
9
  import { isEVMSpokePoolClient, isSVMSpokePoolClient } from "../SpokePoolClient";
10
10
  import { SpokePoolManager } from "../SpokePoolClient/SpokePoolClientManager";
11
11
  // max(uint256) - 1
@@ -240,332 +240,6 @@ var BundleDataClient = /** @class */ (function () {
240
240
  });
241
241
  });
242
242
  };
243
- // @dev This function should probably be moved to the InventoryClient since it bypasses loadData completely now.
244
- BundleDataClient.prototype.getPendingRefundsFromValidBundles = function () {
245
- return __awaiter(this, void 0, void 0, function () {
246
- var refunds, bundle, _a, _b;
247
- return __generator(this, function (_c) {
248
- switch (_c.label) {
249
- case 0:
250
- refunds = [];
251
- if (!this.clients.hubPoolClient.isUpdated) {
252
- throw new Error("BundleDataClient::getPendingRefundsFromValidBundles HubPoolClient not updated.");
253
- }
254
- bundle = this.clients.hubPoolClient.getLatestFullyExecutedRootBundle(this.clients.hubPoolClient.latestHeightSearched);
255
- if (!(bundle !== undefined)) return [3 /*break*/, 2];
256
- _b = (_a = refunds).push;
257
- return [4 /*yield*/, this.getPendingRefundsFromBundle(bundle)];
258
- case 1:
259
- _b.apply(_a, [_c.sent()]);
260
- _c.label = 2;
261
- case 2: // No more valid bundles in history!
262
- return [2 /*return*/, refunds];
263
- }
264
- });
265
- });
266
- };
267
- // @dev This function should probably be moved to the InventoryClient since it bypasses loadData completely now.
268
- // Return refunds from input bundle.
269
- BundleDataClient.prototype.getPendingRefundsFromBundle = function (bundle) {
270
- return __awaiter(this, void 0, void 0, function () {
271
- var nextBundleMainnetStartBlock, chainIds, bundleEvaluationBlockRanges, combinedRefunds, arweaveData, bundleFillsV3, expiredDepositsToRefundV3;
272
- var _this = this;
273
- return __generator(this, function (_a) {
274
- switch (_a.label) {
275
- case 0:
276
- nextBundleMainnetStartBlock = this.clients.hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, this.clients.hubPoolClient.latestHeightSearched, this.clients.hubPoolClient.chainId);
277
- chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
278
- bundleEvaluationBlockRanges = getImpliedBundleBlockRanges(this.clients.hubPoolClient, this.clients.configStoreClient, bundle);
279
- return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
280
- case 1:
281
- arweaveData = _a.sent();
282
- if (!!isDefined(arweaveData)) return [3 /*break*/, 3];
283
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
284
- case 2:
285
- combinedRefunds = _a.sent();
286
- return [3 /*break*/, 4];
287
- case 3:
288
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
289
- combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
290
- // If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
291
- // chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
292
- // a reasonable assumption. This empty refund chain also matches what the alternative
293
- // `getApproximateRefundsForBlockRange` would return.
294
- Object.keys(combinedRefunds).forEach(function (chainId) {
295
- if (!_this.spokePoolClientManager.getClient(Number(chainId))) {
296
- delete combinedRefunds[Number(chainId)];
297
- }
298
- });
299
- _a.label = 4;
300
- case 4:
301
- // The latest proposed bundle's refund leaves might have already been partially or entirely executed.
302
- // We have to deduct the executed amounts from the total refund amounts.
303
- return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
304
- }
305
- });
306
- });
307
- };
308
- // @dev This helper function should probably be moved to the InventoryClient
309
- BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
310
- return __awaiter(this, void 0, void 0, function () {
311
- var refundsForChain, bundleEndBlockForMainnet, _loop_1, this_1, _i, chainIds_1, chainId;
312
- var _this = this;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- refundsForChain = {};
317
- bundleEndBlockForMainnet = blockRanges[0][1];
318
- _loop_1 = function (chainId) {
319
- var spokePoolClient, chainIndex, fillsToCount;
320
- return __generator(this, function (_b) {
321
- switch (_b.label) {
322
- case 0:
323
- spokePoolClient = this_1.spokePoolClientManager.getClient(chainId);
324
- if (!isDefined(spokePoolClient)) {
325
- return [2 /*return*/, "continue"];
326
- }
327
- chainIndex = chainIds.indexOf(chainId);
328
- fillsToCount = spokePoolClient.getFills().filter(function (fill) {
329
- if (fill.blockNumber < blockRanges[chainIndex][0] ||
330
- fill.blockNumber > blockRanges[chainIndex][1] ||
331
- isZeroValueFillOrSlowFillRequest(fill) ||
332
- invalidOutputToken(fill)) {
333
- return false;
334
- }
335
- var originSpokePoolClient = _this.spokePoolClientManager.getClient(fill.originChainId);
336
- // If origin spoke pool client isn't defined, we can't validate it.
337
- if (!isDefined(originSpokePoolClient)) {
338
- return false;
339
- }
340
- var matchingDeposit = originSpokePoolClient.getDeposit(fill.depositId);
341
- var hasMatchingDeposit = matchingDeposit !== undefined && getRelayEventKey(fill) === getRelayEventKey(matchingDeposit);
342
- return hasMatchingDeposit;
343
- });
344
- return [4 /*yield*/, forEachAsync(fillsToCount, function (_fill) { return __awaiter(_this, void 0, void 0, function () {
345
- var originChain, originSpokePoolClient, matchingDeposit, spokeClient, provider, fill, _a, chainToSendRefundTo, repaymentToken, relayer, refundAmount, existingRefundAmount;
346
- var _b, _c, _d;
347
- var _e, _f;
348
- return __generator(this, function (_g) {
349
- switch (_g.label) {
350
- case 0:
351
- originChain = getNetworkName(_fill.originChainId);
352
- originSpokePoolClient = this.spokePoolClientManager.getClient(_fill.originChainId);
353
- assert(isDefined(originSpokePoolClient), "No SpokePoolClient for chain ".concat(originChain));
354
- matchingDeposit = originSpokePoolClient.getDeposit(_fill.depositId);
355
- assert(isDefined(matchingDeposit), "No ".concat(originChain, " deposit found for ").concat(getNetworkName(_fill.destinationChainId), " fill ").concat(_fill.depositId));
356
- spokeClient = this.spokePoolClientManager.getClient(_fill.destinationChainId);
357
- assert(isDefined(spokeClient), "SpokePoolClient for ".concat(getNetworkName(_fill.destinationChainId), " not found for fill."));
358
- if (isEVMSpokePoolClient(spokeClient)) {
359
- provider = spokeClient.spokePool.provider;
360
- }
361
- else if (isSVMSpokePoolClient(spokeClient)) {
362
- provider = spokeClient.svmEventsClient.getRpc();
363
- }
364
- return [4 /*yield*/, verifyFillRepayment(_fill, provider, matchingDeposit, this.clients.hubPoolClient, bundleEndBlockForMainnet)];
365
- case 1:
366
- fill = _g.sent();
367
- if (!isDefined(fill)) {
368
- return [2 /*return*/];
369
- }
370
- _a = getRefundInformationFromFill(__assign(__assign({}, fill), { fromLiteChain: matchingDeposit.fromLiteChain }), this.clients.hubPoolClient, bundleEndBlockForMainnet), chainToSendRefundTo = _a.chainToSendRefundTo, repaymentToken = _a.repaymentToken;
371
- relayer = fill.relayer, refundAmount = fill.inputAmount;
372
- (_b = refundsForChain[chainToSendRefundTo]) !== null && _b !== void 0 ? _b : (refundsForChain[chainToSendRefundTo] = {});
373
- (_c = (_e = refundsForChain[chainToSendRefundTo])[_f = repaymentToken.toBytes32()]) !== null && _c !== void 0 ? _c : (_e[_f] = {});
374
- existingRefundAmount = (_d = refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()]) !== null && _d !== void 0 ? _d : bnZero;
375
- refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] =
376
- existingRefundAmount.add(refundAmount);
377
- return [2 /*return*/];
378
- }
379
- });
380
- }); })];
381
- case 1:
382
- _b.sent();
383
- return [2 /*return*/];
384
- }
385
- });
386
- };
387
- this_1 = this;
388
- _i = 0, chainIds_1 = chainIds;
389
- _a.label = 1;
390
- case 1:
391
- if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
392
- chainId = chainIds_1[_i];
393
- return [5 /*yield**/, _loop_1(chainId)];
394
- case 2:
395
- _a.sent();
396
- _a.label = 3;
397
- case 3:
398
- _i++;
399
- return [3 /*break*/, 1];
400
- case 4: return [2 /*return*/, refundsForChain];
401
- }
402
- });
403
- });
404
- };
405
- BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
406
- var spokePoolClient = this.spokePoolClientManager.getClient(chainId);
407
- if (!isDefined(spokePoolClient)) {
408
- return toBN(0);
409
- }
410
- return spokePoolClient
411
- .getDeposits()
412
- .filter(function (deposit) { return deposit.blockNumber > latestBlockToSearch && deposit.inputToken.eq(l2Token); })
413
- .reduce(function (acc, deposit) {
414
- return acc.add(deposit.inputAmount);
415
- }, toBN(0));
416
- };
417
- // @dev This function should probably be moved to the InventoryClient since it bypasses loadData completely now.
418
- // Return refunds from the next valid bundle. This will contain any refunds that have been sent but are not included
419
- // in a valid bundle with all of its leaves executed. This contains refunds from:
420
- // - Bundles that passed liveness but have not had all of their pool rebalance leaves executed.
421
- // - Bundles that are pending liveness
422
- // - Fills sent after the pending, but not validated, bundle
423
- BundleDataClient.prototype.getNextBundleRefunds = function () {
424
- return __awaiter(this, void 0, void 0, function () {
425
- // Return block ranges for blocks after _pendingBlockRanges and up to widestBlockRanges.
426
- // If a chain is disabled or doesn't have a spoke pool client, return a range of 0
427
- function getBlockRangeDelta(_pendingBlockRanges) {
428
- return widestBundleBlockRanges.map(function (blockRange, index) {
429
- var _a;
430
- // If pending block range doesn't have an entry for the widest range, which is possible when a new chain
431
- // is added to the CHAIN_ID_INDICES list, then simply set the initial block range to the widest block range.
432
- // This will produce a block range delta of 0 where the returned range for this chain is [widest[1], widest[1]].
433
- var initialBlockRange = (_a = _pendingBlockRanges[index]) !== null && _a !== void 0 ? _a : blockRange;
434
- // If chain is disabled, return disabled range
435
- if (initialBlockRange[0] === initialBlockRange[1]) {
436
- return initialBlockRange;
437
- }
438
- // If pending bundle end block exceeds widest end block or if widest end block is undefined
439
- // (which is possible if the spoke pool client for the chain is not defined), return an empty range since there are no
440
- // "new" events to consider for this chain.
441
- if (!isDefined(blockRange[1]) || initialBlockRange[1] >= blockRange[1]) {
442
- return [initialBlockRange[1], initialBlockRange[1]];
443
- }
444
- // If initialBlockRange][0] > widestBlockRange[0], then we'll ignore any blocks
445
- // between initialBlockRange[0] and widestBlockRange[0] (inclusive) for simplicity reasons. In practice
446
- // this should not happen.
447
- return [initialBlockRange[1] + 1, blockRange[1]];
448
- });
449
- }
450
- var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
451
- return __generator(this, function (_e) {
452
- switch (_e.label) {
453
- case 0:
454
- hubPoolClient = this.clients.hubPoolClient;
455
- nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestHeightSearched, hubPoolClient.chainId);
456
- chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
457
- combinedRefunds = [];
458
- return [4 /*yield*/, getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClientManager.getSpokePoolClients(), getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestHeightSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestHeightSearched))];
459
- case 1:
460
- widestBundleBlockRanges = _e.sent();
461
- if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 6];
462
- pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
463
- return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
464
- case 2:
465
- arweaveData = _e.sent();
466
- if (!!isDefined(arweaveData)) return [3 /*break*/, 4];
467
- _b = (_a = combinedRefunds).push;
468
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
469
- case 3:
470
- _b.apply(_a, [_e.sent()]);
471
- return [3 /*break*/, 5];
472
- case 4:
473
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
474
- combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
475
- _e.label = 5;
476
- case 5:
477
- // Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
478
- widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
479
- _e.label = 6;
480
- case 6:
481
- start = performance.now();
482
- _d = (_c = combinedRefunds).push;
483
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
484
- case 7:
485
- _d.apply(_c, [_e.sent()]);
486
- this.logger.debug({
487
- at: "BundleDataClient#getNextBundleRefunds",
488
- message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
489
- blockRanges: JSON.stringify(widestBundleBlockRanges),
490
- });
491
- return [2 /*return*/, combinedRefunds];
492
- }
493
- });
494
- });
495
- };
496
- // @dev This helper function should probably be moved to the InventoryClient
497
- BundleDataClient.prototype.getExecutedRefunds = function (spokePoolClient, relayerRefundRoot) {
498
- var _a, _b;
499
- if (!isDefined(spokePoolClient)) {
500
- return {};
501
- }
502
- // @dev Search from right to left since there can be multiple root bundles with the same relayer refund root.
503
- // The caller should take caution if they're trying to use this function to find matching refunds for older
504
- // root bundles as opposed to more recent ones.
505
- var bundle = _.findLast(spokePoolClient.getRootBundleRelays(), function (bundle) { return bundle.relayerRefundRoot === relayerRefundRoot; });
506
- if (bundle === undefined) {
507
- return {};
508
- }
509
- var executedRefundLeaves = spokePoolClient
510
- .getRelayerRefundExecutions()
511
- .filter(function (leaf) { return leaf.rootBundleId === bundle.rootBundleId; });
512
- var executedRefunds = {};
513
- for (var _i = 0, executedRefundLeaves_1 = executedRefundLeaves; _i < executedRefundLeaves_1.length; _i++) {
514
- var refundLeaf = executedRefundLeaves_1[_i];
515
- var tokenAddress = refundLeaf.l2TokenAddress.toBytes32();
516
- var executedTokenRefunds = ((_a = executedRefunds[tokenAddress]) !== null && _a !== void 0 ? _a : (executedRefunds[tokenAddress] = {}));
517
- for (var i = 0; i < refundLeaf.refundAddresses.length; i++) {
518
- var relayer = refundLeaf.refundAddresses[i].toBytes32();
519
- var refundAmount = refundLeaf.refundAmounts[i];
520
- (_b = executedTokenRefunds[relayer]) !== null && _b !== void 0 ? _b : (executedTokenRefunds[relayer] = bnZero);
521
- executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
522
- }
523
- }
524
- return executedRefunds;
525
- };
526
- // @dev This helper function should probably be moved to the InventoryClient
527
- BundleDataClient.prototype.deductExecutedRefunds = function (allRefunds, bundleContainingRefunds) {
528
- for (var _i = 0, _a = Object.keys(allRefunds); _i < _a.length; _i++) {
529
- var chainIdStr = _a[_i];
530
- var chainId = Number(chainIdStr);
531
- var spokePoolClient = this.spokePoolClientManager.getClient(chainId);
532
- if (!isDefined(spokePoolClient)) {
533
- continue;
534
- }
535
- var executedRefunds = this.getExecutedRefunds(spokePoolClient, bundleContainingRefunds.relayerRefundRoot);
536
- for (var _b = 0, _c = Object.keys(allRefunds[chainId]); _b < _c.length; _b++) {
537
- var tokenAddress = _c[_b];
538
- var refunds = allRefunds[chainId][tokenAddress];
539
- if (executedRefunds[tokenAddress] === undefined || refunds === undefined) {
540
- continue;
541
- }
542
- for (var _d = 0, _e = Object.keys(refunds); _d < _e.length; _d++) {
543
- var relayer = _e[_d];
544
- var executedAmount = executedRefunds[tokenAddress][relayer];
545
- if (executedAmount === undefined) {
546
- continue;
547
- }
548
- // Since there should only be a single executed relayer refund leaf for each relayer-token-chain combination,
549
- // we can deduct this refund and mark it as executed if the executed amount is > 0.
550
- refunds[relayer] = bnZero;
551
- }
552
- }
553
- }
554
- return allRefunds;
555
- };
556
- BundleDataClient.prototype.getRefundsFor = function (bundleRefunds, relayer, chainId, token) {
557
- if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
558
- return BigNumber.from(0);
559
- }
560
- var allRefunds = bundleRefunds[chainId][token.toBytes32()];
561
- return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
562
- };
563
- BundleDataClient.prototype.getTotalRefund = function (refunds, relayer, chainId, refundToken) {
564
- var _this = this;
565
- return refunds.reduce(function (totalRefund, refunds) {
566
- return totalRefund.add(_this.getRefundsFor(refunds, relayer, chainId, refundToken));
567
- }, bnZero);
568
- };
569
243
  BundleDataClient.prototype.loadArweaveData = function (blockRangesForChains) {
570
244
  return __awaiter(this, void 0, void 0, function () {
571
245
  var arweaveKey, arweaveData, _a, _b;
@@ -622,10 +296,10 @@ var BundleDataClient = /** @class */ (function () {
622
296
  };
623
297
  BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
624
298
  return __awaiter(this, void 0, void 0, function () {
625
- var start, key, chainIds, bundleEndBlockForMainnet, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleUnrepayableFillsV3, bundleInvalidSlowFillRequests, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, decodeBundleDepositHash, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable, invalidFillsWithPartialMatchedDeposits_1, preFillsForNextBundle_1, unknownReasonInvalidFills_1;
299
+ var start, key, _a, bundleStartBlockForMainnet, bundleEndBlockForMainnet, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleUnrepayableFillsV3, bundleInvalidSlowFillRequests, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, decodeBundleDepositHash, _loop_1, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_2, _b, allChainIds_2, originChainId, promises, _c, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable, invalidFillsWithPartialMatchedDeposits_1, preFillsForNextBundle_1, unknownReasonInvalidFills_1;
626
300
  var _this = this;
627
- return __generator(this, function (_c) {
628
- switch (_c.label) {
301
+ return __generator(this, function (_d) {
302
+ switch (_d.label) {
629
303
  case 0:
630
304
  start = performance.now();
631
305
  key = JSON.stringify(blockRangesForChains);
@@ -635,8 +309,8 @@ var BundleDataClient = /** @class */ (function () {
635
309
  else if (!this.clients.hubPoolClient.isUpdated) {
636
310
  throw new Error("HubPoolClient not updated");
637
311
  }
638
- chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(blockRangesForChains[0][0]);
639
- bundleEndBlockForMainnet = blockRangesForChains[0][1];
312
+ _a = blockRangesForChains[0], bundleStartBlockForMainnet = _a[0], bundleEndBlockForMainnet = _a[1];
313
+ chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(bundleStartBlockForMainnet);
640
314
  if (blockRangesForChains.length > chainIds.length) {
641
315
  throw new Error("Unexpected block range list length of ".concat(blockRangesForChains.length, ", should be <= ").concat(chainIds.length));
642
316
  }
@@ -648,10 +322,6 @@ var BundleDataClient = /** @class */ (function () {
648
322
  bundleSlowFillsV3 = {};
649
323
  expiredDepositsToRefundV3 = {};
650
324
  unexecutableSlowFills = {};
651
- _isChainDisabled = function (chainId) {
652
- var blockRangeForChain = getBlockRangeForChain(blockRangesForChains, chainId, chainIds);
653
- return isChainDisabled(blockRangeForChain);
654
- };
655
325
  _canCreateSlowFillLeaf = function (deposit) {
656
326
  return (
657
327
  // Cannot slow fill when input and output tokens are not equivalent.
@@ -674,7 +344,10 @@ var BundleDataClient = /** @class */ (function () {
674
344
  };
675
345
  allChainIds = blockRangesForChains
676
346
  .map(function (_blockRange, index) { return chainIds[index]; })
677
- .filter(function (chainId) { return !_isChainDisabled(chainId) && spokePoolClients[chainId] !== undefined; });
347
+ .filter(function (chainId) {
348
+ return !isChainDisabledAtBlock(chainId, bundleStartBlockForMainnet, _this.clients.configStoreClient) &&
349
+ spokePoolClients[chainId] !== undefined;
350
+ });
678
351
  allChainIds.forEach(function (chainId) {
679
352
  var spokePoolClient = spokePoolClients[chainId];
680
353
  if (!spokePoolClient.isUpdated) {
@@ -686,7 +359,7 @@ var BundleDataClient = /** @class */ (function () {
686
359
  if (!!_cachedBundleTimestamps) return [3 /*break*/, 2];
687
360
  return [4 /*yield*/, this.getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients)];
688
361
  case 1:
689
- bundleBlockTimestamps = _c.sent();
362
+ bundleBlockTimestamps = _d.sent();
690
363
  this.setBundleTimestampsInCache(key, bundleBlockTimestamps);
691
364
  this.logger.debug({
692
365
  at: "BundleDataClient#loadData",
@@ -697,7 +370,7 @@ var BundleDataClient = /** @class */ (function () {
697
370
  return [3 /*break*/, 3];
698
371
  case 2:
699
372
  bundleBlockTimestamps = _cachedBundleTimestamps;
700
- _c.label = 3;
373
+ _d.label = 3;
701
374
  case 3:
702
375
  v3RelayHashes = {};
703
376
  bundleDepositHashes = [];
@@ -706,11 +379,11 @@ var BundleDataClient = /** @class */ (function () {
706
379
  var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
707
380
  return { relayDataHash: relayDataHash, index: Number(i) };
708
381
  };
709
- _loop_2 = function (originChainId) {
382
+ _loop_1 = function (originChainId) {
710
383
  var originClient = spokePoolClients[originChainId];
711
384
  var originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
712
- for (var _d = 0, allChainIds_3 = allChainIds; _d < allChainIds_3.length; _d++) {
713
- var destinationChainId = allChainIds_3[_d];
385
+ for (var _e = 0, allChainIds_3 = allChainIds; _e < allChainIds_3.length; _e++) {
386
+ var destinationChainId = allChainIds_3[_e];
714
387
  originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
715
388
  var _a, _b;
716
389
  if (deposit.blockNumber > originChainBlockRange[1] || isZeroValueDeposit(deposit)) {
@@ -761,7 +434,7 @@ var BundleDataClient = /** @class */ (function () {
761
434
  // for convenient matching with fills.
762
435
  for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
763
436
  originChainId = allChainIds_1[_i];
764
- _loop_2(originChainId);
437
+ _loop_1(originChainId);
765
438
  }
766
439
  this.logger.debug({
767
440
  at: "BundleDataClient#loadData",
@@ -772,16 +445,16 @@ var BundleDataClient = /** @class */ (function () {
772
445
  validatedBundleSlowFills = [];
773
446
  validatedBundleUnexecutableSlowFills = [];
774
447
  fillCounter = 0;
775
- _loop_3 = function (originChainId) {
776
- var originClient, _loop_4, _e, allChainIds_4, destinationChainId;
777
- return __generator(this, function (_f) {
778
- switch (_f.label) {
448
+ _loop_2 = function (originChainId) {
449
+ var originClient, _loop_3, _f, allChainIds_4, destinationChainId;
450
+ return __generator(this, function (_g) {
451
+ switch (_g.label) {
779
452
  case 0:
780
453
  originClient = spokePoolClients[originChainId];
781
- _loop_4 = function (destinationChainId) {
454
+ _loop_3 = function (destinationChainId) {
782
455
  var destinationClient, destinationChainBlockRange, originChainBlockRange, fastFillsReplacingSlowFills;
783
- return __generator(this, function (_g) {
784
- switch (_g.label) {
456
+ return __generator(this, function (_h) {
457
+ switch (_h.label) {
785
458
  case 0:
786
459
  destinationClient = spokePoolClients[destinationChainId];
787
460
  destinationChainBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
@@ -921,7 +594,7 @@ var BundleDataClient = /** @class */ (function () {
921
594
  });
922
595
  }); })];
923
596
  case 1:
924
- _g.sent();
597
+ _h.sent();
925
598
  // Process slow fill requests and produce slow fill leaves while maintaining the following the invariants:
926
599
  // - Slow fill leaves cannot be produced for deposits that have expired in this bundle.
927
600
  // - Slow fill leaves cannot be produced for deposits that have been filled.
@@ -1017,7 +690,7 @@ var BundleDataClient = /** @class */ (function () {
1017
690
  // - Duplicate slow fill requests for the same relay data hash are impossible to send.
1018
691
  // - Slow fill requests can only be sent before the deposit's fillDeadline.
1019
692
  // - Slow fill requests for a deposit that has been filled.
1020
- _g.sent();
693
+ _h.sent();
1021
694
  // Process deposits and maintain the following invariants:
1022
695
  // - Deposits matching fills that are not type SlowFill from previous bundle block ranges should produce
1023
696
  // refunds for those fills.
@@ -1161,7 +834,7 @@ var BundleDataClient = /** @class */ (function () {
1161
834
  // - We've created slow fill leaves for all slow fill requests in this bundle matching an unfilled deposit.
1162
835
  // - Deposits for the same relay data hash can be sent an arbitrary amount of times.
1163
836
  // - Deposits can be sent an arbitrary amount of time after a fill has been sent for the matching relay data.
1164
- _g.sent();
837
+ _h.sent();
1165
838
  // For all fills that came after a slow fill request, we can now check if the slow fill request
1166
839
  // was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
1167
840
  // leaf that is now unexecutable.
@@ -1194,33 +867,33 @@ var BundleDataClient = /** @class */ (function () {
1194
867
  }
1195
868
  });
1196
869
  };
1197
- _e = 0, allChainIds_4 = allChainIds;
1198
- _f.label = 1;
870
+ _f = 0, allChainIds_4 = allChainIds;
871
+ _g.label = 1;
1199
872
  case 1:
1200
- if (!(_e < allChainIds_4.length)) return [3 /*break*/, 4];
1201
- destinationChainId = allChainIds_4[_e];
1202
- return [5 /*yield**/, _loop_4(destinationChainId)];
873
+ if (!(_f < allChainIds_4.length)) return [3 /*break*/, 4];
874
+ destinationChainId = allChainIds_4[_f];
875
+ return [5 /*yield**/, _loop_3(destinationChainId)];
1203
876
  case 2:
1204
- _f.sent();
1205
- _f.label = 3;
877
+ _g.sent();
878
+ _g.label = 3;
1206
879
  case 3:
1207
- _e++;
880
+ _f++;
1208
881
  return [3 /*break*/, 1];
1209
882
  case 4: return [2 /*return*/];
1210
883
  }
1211
884
  });
1212
885
  };
1213
- _a = 0, allChainIds_2 = allChainIds;
1214
- _c.label = 4;
886
+ _b = 0, allChainIds_2 = allChainIds;
887
+ _d.label = 4;
1215
888
  case 4:
1216
- if (!(_a < allChainIds_2.length)) return [3 /*break*/, 7];
1217
- originChainId = allChainIds_2[_a];
1218
- return [5 /*yield**/, _loop_3(originChainId)];
889
+ if (!(_b < allChainIds_2.length)) return [3 /*break*/, 7];
890
+ originChainId = allChainIds_2[_b];
891
+ return [5 /*yield**/, _loop_2(originChainId)];
1219
892
  case 5:
1220
- _c.sent();
1221
- _c.label = 6;
893
+ _d.sent();
894
+ _d.label = 6;
1222
895
  case 6:
1223
- _a++;
896
+ _b++;
1224
897
  return [3 /*break*/, 4];
1225
898
  case 7:
1226
899
  this.logger.debug({
@@ -1287,7 +960,7 @@ var BundleDataClient = /** @class */ (function () {
1287
960
  // For all deposits older than this bundle, we need to check if they expired in this bundle and if they did,
1288
961
  // whether there was a slow fill created for it in a previous bundle that is now unexecutable and replaced
1289
962
  // by a new expired deposit refund.
1290
- _c.sent();
963
+ _d.sent();
1291
964
  // Batch compute V3 lp fees.
1292
965
  start = performance.now();
1293
966
  promises = [
@@ -1314,7 +987,7 @@ var BundleDataClient = /** @class */ (function () {
1314
987
  ];
1315
988
  return [4 /*yield*/, Promise.all(promises)];
1316
989
  case 9:
1317
- _b = _c.sent(), v3FillLpFees = _b[0], v3SlowFillLpFees = _b[1], v3UnexecutableSlowFillLpFees = _b[2];
990
+ _c = _d.sent(), v3FillLpFees = _c[0], v3SlowFillLpFees = _c[1], v3UnexecutableSlowFillLpFees = _c[2];
1318
991
  this.logger.debug({
1319
992
  at: "BundleDataClient#loadData",
1320
993
  message: "Computed batch async LP fees in ".concat(performance.now() - start, "ms."),
@@ -1450,7 +1123,8 @@ var BundleDataClient = /** @class */ (function () {
1450
1123
  switch (_c.label) {
1451
1124
  case 0:
1452
1125
  blockRangeForChain = blockRangesForChains[index];
1453
- if (!isDefined(blockRangeForChain) || isChainDisabled(blockRangeForChain)) {
1126
+ if (!isDefined(blockRangeForChain) ||
1127
+ isChainDisabledAtBlock(chainId, blockRangesForChains[0][0], this.clients.configStoreClient)) {
1454
1128
  return [2 /*return*/];
1455
1129
  }
1456
1130
  _startBlockForChain = blockRangeForChain[0], _endBlockForChain = blockRangeForChain[1];