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

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