@across-protocol/sdk 4.0.0-beta.18 → 4.0.0-beta.2

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 (93) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +146 -241
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
  5. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -33
  6. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  7. package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
  8. package/dist/cjs/clients/SpokePoolClient.js +4 -13
  9. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  10. package/dist/cjs/constants.d.ts +0 -1
  11. package/dist/cjs/constants.js +1 -2
  12. package/dist/cjs/constants.js.map +1 -1
  13. package/dist/cjs/providers/index.d.ts +0 -1
  14. package/dist/cjs/providers/index.js +0 -2
  15. package/dist/cjs/providers/index.js.map +1 -1
  16. package/dist/cjs/utils/AddressUtils.d.ts +0 -1
  17. package/dist/cjs/utils/AddressUtils.js +1 -14
  18. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  19. package/dist/cjs/utils/CachingUtils.js +1 -1
  20. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  21. package/dist/cjs/utils/DepositUtils.d.ts +1 -2
  22. package/dist/cjs/utils/DepositUtils.js +3 -12
  23. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  24. package/dist/cjs/utils/NetworkUtils.d.ts +0 -1
  25. package/dist/cjs/utils/NetworkUtils.js +1 -6
  26. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  27. package/dist/cjs/utils/SpokeUtils.js +3 -3
  28. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  29. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  30. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +181 -305
  31. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  32. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
  33. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -42
  34. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  35. package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
  36. package/dist/esm/clients/SpokePoolClient.js +4 -20
  37. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  38. package/dist/esm/constants.d.ts +0 -1
  39. package/dist/esm/constants.js +1 -2
  40. package/dist/esm/constants.js.map +1 -1
  41. package/dist/esm/providers/index.d.ts +0 -1
  42. package/dist/esm/providers/index.js +0 -2
  43. package/dist/esm/providers/index.js.map +1 -1
  44. package/dist/esm/utils/AddressUtils.d.ts +0 -1
  45. package/dist/esm/utils/AddressUtils.js +0 -16
  46. package/dist/esm/utils/AddressUtils.js.map +1 -1
  47. package/dist/esm/utils/CachingUtils.js +1 -1
  48. package/dist/esm/utils/CachingUtils.js.map +1 -1
  49. package/dist/esm/utils/DepositUtils.d.ts +1 -2
  50. package/dist/esm/utils/DepositUtils.js +3 -12
  51. package/dist/esm/utils/DepositUtils.js.map +1 -1
  52. package/dist/esm/utils/NetworkUtils.d.ts +0 -6
  53. package/dist/esm/utils/NetworkUtils.js +0 -10
  54. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  55. package/dist/esm/utils/SpokeUtils.js +4 -4
  56. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  57. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  58. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  59. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
  60. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  61. package/dist/types/clients/SpokePoolClient.d.ts +0 -8
  62. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  63. package/dist/types/constants.d.ts +0 -1
  64. package/dist/types/constants.d.ts.map +1 -1
  65. package/dist/types/providers/index.d.ts +0 -1
  66. package/dist/types/providers/index.d.ts.map +1 -1
  67. package/dist/types/utils/AddressUtils.d.ts +0 -1
  68. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  69. package/dist/types/utils/DepositUtils.d.ts +1 -2
  70. package/dist/types/utils/DepositUtils.d.ts.map +1 -1
  71. package/dist/types/utils/NetworkUtils.d.ts +0 -6
  72. package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
  73. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  74. package/package.json +1 -1
  75. package/src/clients/BundleDataClient/BundleDataClient.ts +132 -251
  76. package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
  77. package/src/clients/SpokePoolClient.ts +6 -19
  78. package/src/constants.ts +1 -3
  79. package/src/providers/index.ts +0 -1
  80. package/src/utils/AddressUtils.ts +0 -16
  81. package/src/utils/CachingUtils.ts +1 -1
  82. package/src/utils/DepositUtils.ts +3 -12
  83. package/src/utils/NetworkUtils.ts +0 -11
  84. package/src/utils/SpokeUtils.ts +5 -6
  85. package/dist/cjs/providers/mockProvider.d.ts +0 -19
  86. package/dist/cjs/providers/mockProvider.js +0 -70
  87. package/dist/cjs/providers/mockProvider.js.map +0 -1
  88. package/dist/esm/providers/mockProvider.d.ts +0 -23
  89. package/dist/esm/providers/mockProvider.js +0 -73
  90. package/dist/esm/providers/mockProvider.js.map +0 -1
  91. package/dist/types/providers/mockProvider.d.ts +0 -24
  92. package/dist/types/providers/mockProvider.d.ts.map +0 -1
  93. package/src/providers/mockProvider.ts +0 -77
@@ -1,18 +1,13 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  import _ from "lodash";
3
3
  import { FillType, FillStatus, } from "../../interfaces";
4
- import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, filterAsync, bnUint32Max, isZeroValueDeposit, findFillEvent, isZeroValueFillOrSlowFillRequest, chainIsEvm, isValidEvmAddress, } from "../../utils";
5
- import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, verifyFillRepayment, } from "./utils";
6
- import { PRE_FILL_MIN_CONFIG_STORE_VERSION } from "../../constants";
4
+ import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, findFillEvent, isZeroValueFillOrSlowFillRequest, } from "../../utils";
5
+ import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, } from "./utils";
7
6
  // max(uint256) - 1
8
7
  export var INFINITE_FILL_DEADLINE = bnUint32Max;
9
8
  // V3 dictionary helper functions
10
9
  function updateExpiredDepositsV3(dict, deposit) {
11
10
  var _a;
12
- // A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
13
- if (chainIsEvm(deposit.originChainId) && !isValidEvmAddress(deposit.depositor)) {
14
- return;
15
- }
16
11
  var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
17
12
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
18
13
  assign(dict, [originChainId, inputToken], []);
@@ -27,12 +22,8 @@ function updateBundleDepositsV3(dict, deposit) {
27
22
  }
28
23
  dict[originChainId][inputToken].push(deposit);
29
24
  }
30
- function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
25
+ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
31
26
  var _a, _b;
32
- // It is impossible to refund a deposit if the repayment chain is EVM and the relayer is a non-evm address.
33
- if (chainIsEvm(repaymentChainId) && !isValidEvmAddress(repaymentAddress)) {
34
- return;
35
- }
36
27
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
37
28
  assign(dict, [repaymentChainId, repaymentToken], {
38
29
  fills: [],
@@ -41,26 +32,26 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
41
32
  refunds: {},
42
33
  });
43
34
  }
44
- var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
35
+ var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct });
45
36
  // Add all fills, slow and fast, to dictionary.
46
37
  assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
47
38
  // All fills update the bundle LP fees.
48
39
  var refundObj = dict[repaymentChainId][repaymentToken];
49
- var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
40
+ var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
50
41
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
51
42
  // Only fast fills get refunded.
52
- if (!isSlowFill(bundleFill)) {
53
- var refundAmount = bundleFill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
43
+ if (!isSlowFill(fill)) {
44
+ var refundAmount = fill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
54
45
  refundObj.totalRefundAmount = refundObj.totalRefundAmount
55
46
  ? refundObj.totalRefundAmount.add(refundAmount)
56
47
  : refundAmount;
57
48
  // Instantiate dictionary if it doesn't exist.
58
49
  (_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
59
- if (refundObj.refunds[bundleFill.relayer]) {
60
- refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
50
+ if (refundObj.refunds[fill.relayer]) {
51
+ refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
61
52
  }
62
53
  else {
63
- refundObj.refunds[bundleFill.relayer] = refundAmount;
54
+ refundObj.refunds[fill.relayer] = refundAmount;
64
55
  }
65
56
  }
66
57
  }
@@ -218,124 +209,77 @@ var BundleDataClient = /** @class */ (function () {
218
209
  return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
219
210
  case 1:
220
211
  arweaveData = _a.sent();
221
- if (!(arweaveData === undefined)) return [3 /*break*/, 3];
222
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
223
- case 2:
224
- combinedRefunds = _a.sent();
225
- return [3 /*break*/, 4];
226
- case 3:
227
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
228
- combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
229
- // If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
230
- // chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
231
- // a reasonable assumption. This empty refund chain also matches what the alternative
232
- // `getApproximateRefundsForBlockRange` would return.
233
- Object.keys(combinedRefunds).forEach(function (chainId) {
234
- if (_this.spokePoolClients[Number(chainId)] === undefined) {
235
- delete combinedRefunds[Number(chainId)];
236
- }
237
- });
238
- _a.label = 4;
239
- case 4:
240
- // The latest proposed bundle's refund leaves might have already been partially or entirely executed.
241
- // We have to deduct the executed amounts from the total refund amounts.
242
- return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
212
+ if (arweaveData === undefined) {
213
+ combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
214
+ }
215
+ else {
216
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
217
+ combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
218
+ // If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
219
+ // chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
220
+ // a reasonable assumption. This empty refund chain also matches what the alternative
221
+ // `getApproximateRefundsForBlockRange` would return.
222
+ Object.keys(combinedRefunds).forEach(function (chainId) {
223
+ if (_this.spokePoolClients[Number(chainId)] === undefined) {
224
+ delete combinedRefunds[Number(chainId)];
225
+ }
226
+ });
227
+ }
228
+ // The latest proposed bundle's refund leaves might have already been partially or entirely executed.
229
+ // We have to deduct the executed amounts from the total refund amounts.
230
+ return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
243
231
  }
244
232
  });
245
233
  });
246
234
  };
247
235
  // @dev This helper function should probably be moved to the InventoryClient
248
236
  BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
249
- return __awaiter(this, void 0, void 0, function () {
250
- var refundsForChain, _loop_1, this_1, _i, chainIds_1, chainId;
251
- var _this = this;
252
- return __generator(this, function (_a) {
253
- switch (_a.label) {
254
- case 0:
255
- refundsForChain = {};
256
- _loop_1 = function (chainId) {
257
- var chainIndex, fillsToCount;
258
- return __generator(this, function (_b) {
259
- switch (_b.label) {
260
- case 0:
261
- if (this_1.spokePoolClients[chainId] === undefined) {
262
- return [2 /*return*/, "continue"];
263
- }
264
- chainIndex = chainIds.indexOf(chainId);
265
- return [4 /*yield*/, filterAsync(this_1.spokePoolClients[chainId].getFills(), function (fill) { return __awaiter(_this, void 0, void 0, function () {
266
- var matchingDeposit, hasMatchingDeposit, validRepayment;
267
- return __generator(this, function (_a) {
268
- switch (_a.label) {
269
- case 0:
270
- if (fill.blockNumber < blockRanges[chainIndex][0] ||
271
- fill.blockNumber > blockRanges[chainIndex][1] ||
272
- isZeroValueFillOrSlowFillRequest(fill)) {
273
- return [2 /*return*/, false];
274
- }
275
- // If origin spoke pool client isn't defined, we can't validate it.
276
- if (this.spokePoolClients[fill.originChainId] === undefined) {
277
- return [2 /*return*/, false];
278
- }
279
- matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
280
- hasMatchingDeposit = matchingDeposit !== undefined &&
281
- this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
282
- if (!hasMatchingDeposit) return [3 /*break*/, 2];
283
- return [4 /*yield*/, verifyFillRepayment(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit,
284
- // @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
285
- // disabled block ranges.
286
- this.clients.configStoreClient
287
- .getChainIdIndicesForBlock(blockRanges[0][1])
288
- .filter(function (_chainId, i) { return !isChainDisabled(blockRanges[i]); }))];
289
- case 1:
290
- validRepayment = _a.sent();
291
- if (!isDefined(validRepayment)) {
292
- return [2 /*return*/, false];
293
- }
294
- _a.label = 2;
295
- case 2: return [2 /*return*/, hasMatchingDeposit];
296
- }
297
- });
298
- }); })];
299
- case 1:
300
- fillsToCount = _b.sent();
301
- fillsToCount.forEach(function (fill) {
302
- var _a, _b, _c;
303
- var _d;
304
- var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
305
- assert(isDefined(matchingDeposit), "Deposit not found for fill.");
306
- var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
307
- ), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
308
- // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
309
- // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
310
- // in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
311
- // worst from the relayer's perspective.
312
- var relayer = fill.relayer, refundAmount = fill.inputAmount;
313
- (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
314
- (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
315
- var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
316
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
317
- });
318
- return [2 /*return*/];
319
- }
320
- });
321
- };
322
- this_1 = this;
323
- _i = 0, chainIds_1 = chainIds;
324
- _a.label = 1;
325
- case 1:
326
- if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
327
- chainId = chainIds_1[_i];
328
- return [5 /*yield**/, _loop_1(chainId)];
329
- case 2:
330
- _a.sent();
331
- _a.label = 3;
332
- case 3:
333
- _i++;
334
- return [3 /*break*/, 1];
335
- case 4: return [2 /*return*/, refundsForChain];
237
+ var _this = this;
238
+ var refundsForChain = {};
239
+ var _loop_1 = function (chainId) {
240
+ if (this_1.spokePoolClients[chainId] === undefined) {
241
+ return "continue";
242
+ }
243
+ var chainIndex = chainIds.indexOf(chainId);
244
+ this_1.spokePoolClients[chainId]
245
+ .getFills()
246
+ .filter(function (fill) {
247
+ if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
248
+ return false;
249
+ }
250
+ // If origin spoke pool client isn't defined, we can't validate it.
251
+ if (_this.spokePoolClients[fill.originChainId] === undefined) {
252
+ return false;
336
253
  }
254
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
255
+ var hasMatchingDeposit = matchingDeposit !== undefined &&
256
+ _this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
257
+ return hasMatchingDeposit;
258
+ })
259
+ .forEach(function (fill) {
260
+ var _a, _b, _c;
261
+ var _d;
262
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
263
+ assert(isDefined(matchingDeposit), "Deposit not found for fill.");
264
+ var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
265
+ ), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
266
+ // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
267
+ // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
268
+ // in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
269
+ // worst from the relayer's perspective.
270
+ var relayer = fill.relayer, refundAmount = fill.inputAmount;
271
+ (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
272
+ (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
273
+ var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
274
+ refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
337
275
  });
338
- });
276
+ };
277
+ var this_1 = this;
278
+ for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
279
+ var chainId = chainIds_1[_i];
280
+ _loop_1(chainId);
281
+ }
282
+ return refundsForChain;
339
283
  };
340
284
  BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
341
285
  if (this.spokePoolClients[chainId] === undefined) {
@@ -427,40 +371,33 @@ var BundleDataClient = /** @class */ (function () {
427
371
  return [initialBlockRange[1] + 1, blockRange[1]];
428
372
  });
429
373
  }
430
- var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
431
- return __generator(this, function (_e) {
432
- switch (_e.label) {
374
+ var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
375
+ return __generator(this, function (_a) {
376
+ switch (_a.label) {
433
377
  case 0:
434
378
  hubPoolClient = this.clients.hubPoolClient;
435
379
  nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
436
380
  chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
437
381
  combinedRefunds = [];
438
382
  widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
439
- if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 5];
383
+ if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
440
384
  pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
441
385
  return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
442
386
  case 1:
443
- arweaveData = _e.sent();
444
- if (!(arweaveData === undefined)) return [3 /*break*/, 3];
445
- _b = (_a = combinedRefunds).push;
446
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
447
- case 2:
448
- _b.apply(_a, [_e.sent()]);
449
- return [3 /*break*/, 4];
450
- case 3:
451
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
452
- combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
453
- _e.label = 4;
454
- case 4:
387
+ arweaveData = _a.sent();
388
+ if (arweaveData === undefined) {
389
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
390
+ }
391
+ else {
392
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
393
+ combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
394
+ }
455
395
  // Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
456
396
  widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
457
- _e.label = 5;
458
- case 5:
397
+ _a.label = 2;
398
+ case 2:
459
399
  start = performance.now();
460
- _d = (_c = combinedRefunds).push;
461
- return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
462
- case 6:
463
- _d.apply(_c, [_e.sent()]);
400
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
464
401
  this.logger.debug({
465
402
  at: "BundleDataClient#getNextBundleRefunds",
466
403
  message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -603,7 +540,7 @@ var BundleDataClient = /** @class */ (function () {
603
540
  };
604
541
  BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
605
542
  return __awaiter(this, void 0, void 0, function () {
606
- var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, startBlockForMainnet, versionAtProposalBlock, canRefundPrefills, depositCounter, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
543
+ var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, depositCounter, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
607
544
  var _this = this;
608
545
  return __generator(this, function (_c) {
609
546
  switch (_c.label) {
@@ -638,9 +575,6 @@ var BundleDataClient = /** @class */ (function () {
638
575
  !deposit.fromLiteChain &&
639
576
  !deposit.toLiteChain);
640
577
  };
641
- _depositIsExpired = function (deposit) {
642
- return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
643
- };
644
578
  _getFillStatusForDeposit = function (deposit, queryBlock) {
645
579
  return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit,
646
580
  // We can assume that in production
@@ -680,9 +614,6 @@ var BundleDataClient = /** @class */ (function () {
680
614
  v3RelayHashes = {};
681
615
  bundleDepositHashes = [];
682
616
  olderDepositHashes = [];
683
- startBlockForMainnet = getBlockRangeForChain(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
684
- versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
685
- canRefundPrefills = versionAtProposalBlock >= PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
686
617
  depositCounter = 0;
687
618
  _loop_2 = function (originChainId) {
688
619
  var originClient = spokePoolClients[originChainId];
@@ -696,12 +627,11 @@ var BundleDataClient = /** @class */ (function () {
696
627
  // Only evaluate deposits that are in this bundle or in previous bundles. This means we cannot issue fill
697
628
  // refunds or slow fills here for deposits that are in future bundles (i.e. "pre-fills"). Instead, we'll
698
629
  // evaluate these pre-fills once the deposit is inside the "current" bundle block range.
699
- if (deposit.blockNumber > originChainBlockRange[1] || isZeroValueDeposit(deposit)) {
630
+ if (isZeroValueDeposit(deposit) || deposit.blockNumber > originChainBlockRange[1]) {
700
631
  return;
701
632
  }
702
633
  depositCounter++;
703
634
  var relayDataHash = _this.getRelayHashFromEvent(deposit);
704
- // Duplicate deposits are treated like normal deposits.
705
635
  if (!v3RelayHashes[relayDataHash]) {
706
636
  v3RelayHashes[relayDataHash] = {
707
637
  deposit: deposit,
@@ -716,8 +646,6 @@ var BundleDataClient = /** @class */ (function () {
716
646
  if (deposit.inputAmount.eq(0)) {
717
647
  return;
718
648
  }
719
- // Evaluate all expired deposits after fetching fill statuses,
720
- // since we can't know for certain whether an expired deposit was filled a long time ago.
721
649
  if (deposit.blockNumber >= originChainBlockRange[0]) {
722
650
  bundleDepositHashes.push(relayDataHash);
723
651
  updateBundleDepositsV3(bundleDepositsV3, deposit);
@@ -748,7 +676,7 @@ var BundleDataClient = /** @class */ (function () {
748
676
  case 0:
749
677
  originClient = spokePoolClients[originChainId];
750
678
  _loop_4 = function (destinationChainId) {
751
- var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
679
+ var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
752
680
  return __generator(this, function (_g) {
753
681
  switch (_g.label) {
754
682
  case 0:
@@ -764,56 +692,41 @@ var BundleDataClient = /** @class */ (function () {
764
692
  // tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
765
693
  // request for the deposit, we'd want to see the fill took place.
766
694
  .filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
767
- var relayDataHash, fillToRefund, duplicateDeposits, historicalDeposit, matchedDeposit, fillToRefund;
695
+ var relayDataHash, historicalDeposit, matchedDeposit;
768
696
  return __generator(this, function (_a) {
769
697
  switch (_a.label) {
770
698
  case 0:
771
- fillCounter++;
772
699
  relayDataHash = this.getRelayHashFromEvent(fill);
773
- if (!v3RelayHashes[relayDataHash]) return [3 /*break*/, 5];
774
- if (!!v3RelayHashes[relayDataHash].fill) return [3 /*break*/, 3];
775
- assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
776
- // At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
777
- // so this fill can no longer be filled on-chain.
778
- v3RelayHashes[relayDataHash].fill = fill;
779
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
780
- return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposit, allChainIds)];
781
- case 1:
782
- fillToRefund = _a.sent();
783
- if (!isDefined(fillToRefund)) {
784
- bundleInvalidFillsV3.push(fill);
785
- // We don't return here yet because we still need to mark unexecutable slow fill leaves
786
- // or duplicate deposits. However, we won't issue a fast fill refund.
787
- }
788
- else {
789
- v3RelayHashes[relayDataHash].fill = fillToRefund;
790
- validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
791
- }
792
- // If fill replaced a slow fill request, then mark it as one that might have created an
793
- // unexecutable slow fill. We can't know for sure until we check the slow fill request
794
- // events.
795
- // slow fill requests for deposits from or to lite chains are considered invalid
796
- if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
797
- _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
798
- fastFillsReplacingSlowFills.push(relayDataHash);
700
+ fillCounter++;
701
+ if (v3RelayHashes[relayDataHash]) {
702
+ if (!v3RelayHashes[relayDataHash].fill) {
703
+ assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
704
+ // At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
705
+ // so this fill is validated.
706
+ v3RelayHashes[relayDataHash].fill = fill;
707
+ if (fill.blockNumber >= destinationChainBlockRange[0]) {
708
+ validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
709
+ // If fill replaced a slow fill request, then mark it as one that might have created an
710
+ // unexecutable slow fill. We can't know for sure until we check the slow fill request
711
+ // events.
712
+ // slow fill requests for deposits from or to lite chains are considered invalid
713
+ if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
714
+ !v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
715
+ !v3RelayHashes[relayDataHash].deposit.toLiteChain) {
716
+ fastFillsReplacingSlowFills.push(relayDataHash);
717
+ }
718
+ }
719
+ }
720
+ return [2 /*return*/];
799
721
  }
800
- duplicateDeposits = originClient.getDuplicateDeposits(v3RelayHashes[relayDataHash].deposit);
801
- duplicateDeposits.forEach(function (duplicateDeposit) {
802
- updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
803
- });
804
- _a.label = 2;
805
- case 2: return [3 /*break*/, 4];
806
- case 3: throw new Error("Duplicate fill detected.");
807
- case 4: return [2 /*return*/];
808
- case 5:
809
722
  // At this point, there is no relay hash dictionary entry for this fill, so we need to
810
- // instantiate the entry. We won't modify the fill.relayer until we match it with a deposit.
723
+ // instantiate the entry.
811
724
  v3RelayHashes[relayDataHash] = {
812
725
  deposit: undefined,
813
726
  fill: fill,
814
727
  slowFillRequest: undefined,
815
728
  };
816
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 9];
729
+ if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
817
730
  // Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
818
731
  // to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
819
732
  // skip the historical query.
@@ -822,38 +735,29 @@ var BundleDataClient = /** @class */ (function () {
822
735
  return [2 /*return*/];
823
736
  }
824
737
  return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
825
- case 6:
738
+ case 1:
826
739
  historicalDeposit = _a.sent();
827
- if (!!historicalDeposit.found) return [3 /*break*/, 7];
828
- bundleInvalidFillsV3.push(fill);
829
- return [3 /*break*/, 9];
830
- case 7:
831
- matchedDeposit = historicalDeposit.deposit;
832
- v3RelayHashes[relayDataHash].deposit = matchedDeposit;
833
- return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
834
- case 8:
835
- fillToRefund = _a.sent();
836
- if (!isDefined(fillToRefund)) {
740
+ if (!historicalDeposit.found) {
837
741
  bundleInvalidFillsV3.push(fill);
838
- // Don't return yet as we still need to mark down any unexecutable slow fill leaves
839
- // in case this fast fill replaced a slow fill request.
840
742
  }
841
743
  else {
744
+ matchedDeposit = historicalDeposit.deposit;
842
745
  // @dev Since queryHistoricalDepositForFill validates the fill by checking individual
843
746
  // object property values against the deposit's, we
844
747
  // sanity check it here by comparing the full relay hashes. If there's an error here then the
845
748
  // historical deposit query is not working as expected.
846
749
  assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
847
750
  validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
848
- v3RelayHashes[relayDataHash].fill = fillToRefund;
849
- }
850
- // slow fill requests for deposits from or to lite chains are considered invalid
851
- if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
852
- _canCreateSlowFillLeaf(matchedDeposit)) {
853
- fastFillsReplacingSlowFills.push(relayDataHash);
751
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
752
+ // slow fill requests for deposits from or to lite chains are considered invalid
753
+ if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
754
+ !matchedDeposit.fromLiteChain &&
755
+ !matchedDeposit.toLiteChain) {
756
+ fastFillsReplacingSlowFills.push(relayDataHash);
757
+ }
854
758
  }
855
- _a.label = 9;
856
- case 9: return [2 /*return*/];
759
+ _a.label = 2;
760
+ case 2: return [2 /*return*/];
857
761
  }
858
762
  });
859
763
  }); })];
@@ -878,28 +782,25 @@ var BundleDataClient = /** @class */ (function () {
878
782
  v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
879
783
  if (v3RelayHashes[relayDataHash].fill) {
880
784
  // If there is a fill matching the relay hash, then this slow fill request can't be used
881
- // to create a slow fill for a filled deposit. This takes advantage of the fact that
882
- // slow fill requests must precede fills, so if there is a matching fill for this request's
883
- // relay data, then this slow fill will be unexecutable.
785
+ // to create a slow fill for a filled deposit.
884
786
  return [2 /*return*/];
885
787
  }
886
788
  assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
887
789
  matchedDeposit = v3RelayHashes[relayDataHash].deposit;
790
+ if (!_canCreateSlowFillLeaf(matchedDeposit)) {
791
+ return [2 /*return*/];
792
+ }
888
793
  // If there is no fill matching the relay hash, then this might be a valid slow fill request
889
794
  // that we should produce a slow fill leaf for. Check if the slow fill request is in the
890
795
  // destination chain block range.
891
796
  if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
892
- _canCreateSlowFillLeaf(matchedDeposit) &&
893
797
  // Deposit must not have expired in this bundle.
894
- !_depositIsExpired(matchedDeposit)) {
798
+ slowFillRequest.fillDeadline >= bundleBlockTimestamps[destinationChainId][1]) {
895
799
  // At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
896
800
  // so this slow fill request relay data is correct.
897
801
  validatedBundleSlowFills.push(matchedDeposit);
898
802
  }
899
803
  }
900
- else {
901
- throw new Error("Duplicate slow fill request detected.");
902
- }
903
804
  return [2 /*return*/];
904
805
  }
905
806
  // Instantiate dictionary if there is neither a deposit nor fill matching it.
@@ -926,7 +827,7 @@ var BundleDataClient = /** @class */ (function () {
926
827
  v3RelayHashes[relayDataHash].deposit = matchedDeposit;
927
828
  if (!_canCreateSlowFillLeaf(matchedDeposit) ||
928
829
  // Deposit must not have expired in this bundle.
929
- _depositIsExpired(matchedDeposit)) {
830
+ slowFillRequest.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
930
831
  return [2 /*return*/];
931
832
  }
932
833
  validatedBundleSlowFills.push(matchedDeposit);
@@ -939,20 +840,17 @@ var BundleDataClient = /** @class */ (function () {
939
840
  // Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
940
841
  // for deposits that would expire in this bundle.
941
842
  _g.sent();
942
- // Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
943
- // Therefore, let's go through each deposit in this bundle again and check a few things in order:
944
- // - Has the deposit been filled ? If so, then we need to issue a relayer refund for
945
- // this "pre-fill" if the fill took place in a previous bundle.
946
- // - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
947
- // - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
948
- // for this "pre-slow-fill-request" if this request took place in a previous bundle.
949
- // @todo Only start refunding pre-fills and slow fill requests after a config store version is activated. We
950
- // should remove this check once we've advanced far beyond the version bump block.
843
+ originBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
951
844
  return [4 /*yield*/, mapAsync(bundleDepositHashes.filter(function (depositHash) {
952
845
  var deposit = v3RelayHashes[depositHash].deposit;
953
- return (deposit && deposit.originChainId === originChainId && deposit.destinationChainId === destinationChainId);
846
+ return (deposit &&
847
+ deposit.originChainId === originChainId &&
848
+ deposit.destinationChainId === destinationChainId &&
849
+ deposit.blockNumber >= originBlockRange[0] &&
850
+ deposit.blockNumber <= originBlockRange[1] &&
851
+ !isZeroValueDeposit(deposit));
954
852
  }), function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
955
- var _a, deposit, fill, slowFillRequest, fillStatus, prefill, verifiedFill;
853
+ var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
956
854
  return __generator(this, function (_b) {
957
855
  switch (_b.label) {
958
856
  case 0:
@@ -967,15 +865,11 @@ var BundleDataClient = /** @class */ (function () {
967
865
  // If fill exists in memory, then the only case in which we need to create a refund is if the
968
866
  // the fill occurred in a previous bundle. There are no expiry refunds for filled deposits.
969
867
  if (fill) {
970
- if (canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0] && !isSlowFill(fill)) {
868
+ if (!isSlowFill(fill) && fill.blockNumber < destinationChainBlockRange[0]) {
971
869
  // If fill is in the current bundle then we can assume there is already a refund for it, so only
972
870
  // include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
973
871
  // we won't consider it, following the previous treatment of fills after the bundle block range.
974
872
  validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
975
- // We don't refund duplicate deposits for pre-fill refunds because we are refunding the pre-fill instead
976
- // using the duplicate deposited funds. We make an assumption that duplicate deposits for pre-fills
977
- // are highly unlikely because deposits for pre-fills are designed to be sent by the pre-filler,
978
- // so the depositor's approval should protect them from the pre-filler sending multiple deposits.
979
873
  }
980
874
  return [2 /*return*/];
981
875
  }
@@ -985,12 +879,11 @@ var BundleDataClient = /** @class */ (function () {
985
879
  // we need to create a slow fill leaf for the deposit. The latter should only happen if the slow fill request
986
880
  // took place in a prior bundle otherwise we would have already created a slow fill leaf for it.
987
881
  if (slowFillRequest) {
988
- if (_depositIsExpired(deposit)) {
882
+ if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
989
883
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
990
884
  }
991
- else if (canRefundPrefills &&
992
- slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
993
- _canCreateSlowFillLeaf(deposit)) {
885
+ else if (_canCreateSlowFillLeaf(deposit) &&
886
+ slowFillRequest.blockNumber < destinationChainBlockRange[0]) {
994
887
  validatedBundleSlowFills.push(deposit);
995
888
  }
996
889
  return [2 /*return*/];
@@ -998,48 +891,34 @@ var BundleDataClient = /** @class */ (function () {
998
891
  return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
999
892
  case 1:
1000
893
  fillStatus = _b.sent();
1001
- if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/, 4];
1002
- return [4 /*yield*/, this.findMatchingFillEvent(deposit, destinationClient)];
894
+ if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/, 3];
895
+ return [4 /*yield*/, findFillEvent(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
1003
896
  case 2:
1004
- prefill = _b.sent();
1005
- assert(isDefined(prefill), "findFillEvent# Cannot find prefill: ".concat(depositHash));
1006
- assert(this.getRelayHashFromEvent(prefill) === depositHash, "Relay hashes should match.");
1007
- return [4 /*yield*/, verifyFillRepayment(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
1008
- case 3:
1009
- verifiedFill = _b.sent();
1010
- if (canRefundPrefills && isDefined(verifiedFill) && !isSlowFill(verifiedFill)) {
1011
- validatedBundleV3Fills.push(__assign(__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
897
+ prefill = (_b.sent());
898
+ if (!isSlowFill(prefill)) {
899
+ validatedBundleV3Fills.push(__assign(__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
1012
900
  }
1013
- return [3 /*break*/, 5];
1014
- case 4:
1015
- if (_depositIsExpired(deposit)) {
901
+ return [3 /*break*/, 4];
902
+ case 3:
903
+ if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
1016
904
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
1017
905
  }
1018
906
  // If slow fill requested, then issue a slow fill leaf for the deposit.
1019
907
  else if (fillStatus === FillStatus.RequestedSlowFill) {
1020
908
  // Input and Output tokens must be equivalent on the deposit for this to be slow filled.
1021
909
  // Slow fill requests for deposits from or to lite chains are considered invalid
1022
- if (canRefundPrefills && _canCreateSlowFillLeaf(deposit)) {
910
+ if (_canCreateSlowFillLeaf(deposit)) {
1023
911
  // If deposit newly expired, then we can't create a slow fill leaf for it but we can
1024
912
  // create a deposit refund for it.
1025
913
  validatedBundleSlowFills.push(deposit);
1026
914
  }
1027
915
  }
1028
- _b.label = 5;
1029
- case 5: return [2 /*return*/];
916
+ _b.label = 4;
917
+ case 4: return [2 /*return*/];
1030
918
  }
1031
919
  });
1032
920
  }); })];
1033
921
  case 3:
1034
- // Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
1035
- // Therefore, let's go through each deposit in this bundle again and check a few things in order:
1036
- // - Has the deposit been filled ? If so, then we need to issue a relayer refund for
1037
- // this "pre-fill" if the fill took place in a previous bundle.
1038
- // - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
1039
- // - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
1040
- // for this "pre-slow-fill-request" if this request took place in a previous bundle.
1041
- // @todo Only start refunding pre-fills and slow fill requests after a config store version is activated. We
1042
- // should remove this check once we've advanced far beyond the version bump block.
1043
922
  _g.sent();
1044
923
  // For all fills that came after a slow fill request, we can now check if the slow fill request
1045
924
  // was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
@@ -1052,13 +931,16 @@ var BundleDataClient = /** @class */ (function () {
1052
931
  throw new Error("Deposit should exist in relay hash dictionary.");
1053
932
  }
1054
933
  // We should never push fast fills involving lite chains here because slow fill requests for them are invalid:
1055
- assert(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
934
+ assert(!deposit.fromLiteChain && !deposit.toLiteChain, "fastFillsReplacingSlowFills should not contain lite chain deposits");
1056
935
  var destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
1057
936
  if (
1058
- // If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
1059
- // created that would be considered excess.
1060
- !slowFillRequest ||
1061
- slowFillRequest.blockNumber < destinationBlockRange[0]) {
937
+ // If the slow fill request that was replaced by this fill was in an older bundle, then we don't
938
+ // need to check if the slow fill request was valid since we can assume all bundles in the past
939
+ // were validated. However, we might as well double check.
940
+ _this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
941
+ // If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
942
+ // created that would be considered excess.
943
+ (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
1062
944
  validatedBundleUnexecutableSlowFills.push(deposit);
1063
945
  }
1064
946
  });
@@ -1116,7 +998,7 @@ var BundleDataClient = /** @class */ (function () {
1116
998
  // If there is a valid fill that we saw matching this deposit, then it does not need a refund.
1117
999
  (!fill &&
1118
1000
  isDefined(deposit) && // Needed for TSC - we check this above.
1119
- _depositIsExpired(deposit) &&
1001
+ deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1] &&
1120
1002
  deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
1121
1003
  spokePoolClients[destinationChainId] !== undefined))
1122
1004
  // If there is a valid fill that we saw matching this deposit, then it does not need a refund.
@@ -1132,7 +1014,8 @@ var BundleDataClient = /** @class */ (function () {
1132
1014
  // If fill status is RequestedSlowFill, then we might need to mark down an unexecutable
1133
1015
  // slow fill that we're going to replace with an expired deposit refund.
1134
1016
  // If deposit cannot be slow filled, then exit early.
1135
- if (fillStatus !== FillStatus.RequestedSlowFill || !_canCreateSlowFillLeaf(deposit)) {
1017
+ // slow fill requests for deposits from or to lite chains are considered invalid
1018
+ if (fillStatus !== FillStatus.RequestedSlowFill || deposit.fromLiteChain || deposit.toLiteChain) {
1136
1019
  return [2 /*return*/];
1137
1020
  }
1138
1021
  // Now, check if there was a slow fill created for this deposit in a previous bundle which would now be
@@ -1140,9 +1023,14 @@ var BundleDataClient = /** @class */ (function () {
1140
1023
  // slow fill request or the matching slow fill request took place in a previous bundle.
1141
1024
  // If there is a slow fill request in this bundle, then the expired deposit refund will supercede
1142
1025
  // the slow fill request. If there is no slow fill request seen or its older than this bundle, then we can
1143
- // assume a slow fill leaf was created for it because of the previous _canCreateSlowFillLeaf check.
1144
- // The slow fill request was also sent before the fill deadline expired since we checked that above.
1145
- if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
1026
+ // assume a slow fill leaf was created for it because its tokens are equivalent. The slow fill request was
1027
+ // also sent before the fill deadline expired since we checked that above.
1028
+ if (
1029
+ // Since this deposit was requested for a slow fill in an older bundle at this point, we don't
1030
+ // technically need to check if the slow fill request was valid since we can assume all bundles in the past
1031
+ // were validated. However, we might as well double check.
1032
+ this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
1033
+ (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
1146
1034
  validatedBundleUnexecutableSlowFills.push(deposit);
1147
1035
  }
1148
1036
  _b.label = 2;
@@ -1190,7 +1078,7 @@ var BundleDataClient = /** @class */ (function () {
1190
1078
  var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1191
1079
  assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
1192
1080
  var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
1193
- updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
1081
+ updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
1194
1082
  });
1195
1083
  v3SlowFillLpFees.forEach(function (_a, idx) {
1196
1084
  var lpFeePct = _a.realizedLpFeePct;
@@ -1233,17 +1121,7 @@ var BundleDataClient = /** @class */ (function () {
1233
1121
  // spoke pool contract. However, this internal function is used to uniquely identify a bridging event
1234
1122
  // for speed since its easier to build a string from the event data than to hash it.
1235
1123
  BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
1236
- return "".concat(event.depositor, "-").concat(event.recipient, "-").concat(event.exclusiveRelayer, "-").concat(event.inputToken, "-").concat(event.outputToken, "-").concat(event.inputAmount, "-").concat(event.outputAmount, "-").concat(event.originChainId, "-").concat(event.depositId.toString(), "-").concat(event.fillDeadline, "-").concat(event.exclusivityDeadline, "-").concat(event.message, "-").concat(event.destinationChainId);
1237
- };
1238
- BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
1239
- return __awaiter(this, void 0, void 0, function () {
1240
- return __generator(this, function (_a) {
1241
- switch (_a.label) {
1242
- case 0: return [4 /*yield*/, findFillEvent(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
1243
- case 1: return [2 /*return*/, _a.sent()];
1244
- }
1245
- });
1246
- });
1124
+ return "".concat(event.depositor, "-").concat(event.recipient, "-").concat(event.exclusiveRelayer, "-").concat(event.inputToken, "-").concat(event.outputToken, "-").concat(event.inputAmount, "-").concat(event.outputAmount, "-").concat(event.originChainId, "-").concat(event.depositId, "-").concat(event.fillDeadline, "-").concat(event.exclusivityDeadline, "-").concat(event.message, "-").concat(event.destinationChainId);
1247
1125
  };
1248
1126
  BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
1249
1127
  return __awaiter(this, void 0, void 0, function () {
@@ -1254,7 +1132,7 @@ var BundleDataClient = /** @class */ (function () {
1254
1132
  case 0:
1255
1133
  _b = (_a = Object).fromEntries;
1256
1134
  return [4 /*yield*/, mapAsync(chainIds, function (chainId, index) { return __awaiter(_this, void 0, void 0, function () {
1257
- var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, _endTime, _b, endBlockDelta, endTime;
1135
+ var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
1258
1136
  return __generator(this, function (_c) {
1259
1137
  switch (_c.label) {
1260
1138
  case 0:
@@ -1269,7 +1147,7 @@ var BundleDataClient = /** @class */ (function () {
1269
1147
  return [2 /*return*/];
1270
1148
  }
1271
1149
  startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
1272
- endBlockForChain = Math.min(_endBlockForChain + 1, spokePoolClient.latestBlockSearched);
1150
+ endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
1273
1151
  return [4 /*yield*/, spokePoolClient.getTimestampForBlock(startBlockForChain)];
1274
1152
  case 1:
1275
1153
  _b = [
@@ -1279,11 +1157,9 @@ var BundleDataClient = /** @class */ (function () {
1279
1157
  case 2:
1280
1158
  _a = _b.concat([
1281
1159
  _c.sent()
1282
- ]), startTime = _a[0], _endTime = _a[1];
1283
- endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
1284
- endTime = Math.max(0, _endTime - endBlockDelta);
1160
+ ]), startTime = _a[0], endTime = _a[1];
1285
1161
  // Sanity checks:
1286
- assert(endTime >= startTime, "End time for block ".concat(endBlockForChain, " should be greater than start time for block ").concat(startBlockForChain, ": ").concat(endTime, " >= ").concat(startTime, "."));
1162
+ assert(endTime >= startTime, "End time should be greater than start time.");
1287
1163
  assert(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
1288
1164
  return [2 /*return*/, [chainId, [startTime, endTime]]];
1289
1165
  }