@across-protocol/sdk 4.0.0-beta.34 → 4.0.0-beta.5

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 (114) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +189 -352
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
  5. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +2 -1
  6. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  7. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
  8. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -47
  9. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  10. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
  11. package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
  12. package/dist/cjs/clients/SpokePoolClient.js +1 -10
  13. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  14. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +1 -2
  15. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +1 -11
  16. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  17. package/dist/cjs/constants.d.ts +1 -1
  18. package/dist/cjs/constants.js +2 -2
  19. package/dist/cjs/constants.js.map +1 -1
  20. package/dist/cjs/providers/index.d.ts +0 -1
  21. package/dist/cjs/providers/index.js +0 -2
  22. package/dist/cjs/providers/index.js.map +1 -1
  23. package/dist/cjs/utils/AddressUtils.d.ts +0 -1
  24. package/dist/cjs/utils/AddressUtils.js +1 -6
  25. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  26. package/dist/cjs/utils/DepositUtils.js +1 -1
  27. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  28. package/dist/cjs/utils/EventUtils.js +0 -21
  29. package/dist/cjs/utils/EventUtils.js.map +1 -1
  30. package/dist/cjs/utils/SpokeUtils.d.ts +0 -1
  31. package/dist/cjs/utils/SpokeUtils.js +8 -15
  32. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  33. package/dist/cjs/utils/common.d.ts +0 -1
  34. package/dist/cjs/utils/common.js +1 -2
  35. package/dist/cjs/utils/common.js.map +1 -1
  36. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  37. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +274 -455
  38. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  39. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
  40. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
  41. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  42. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
  43. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -54
  44. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  45. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
  46. package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
  47. package/dist/esm/clients/SpokePoolClient.js +1 -17
  48. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  49. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +1 -2
  50. package/dist/esm/clients/mocks/MockSpokePoolClient.js +1 -11
  51. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  52. package/dist/esm/constants.d.ts +1 -1
  53. package/dist/esm/constants.js +2 -2
  54. package/dist/esm/constants.js.map +1 -1
  55. package/dist/esm/providers/index.d.ts +0 -1
  56. package/dist/esm/providers/index.js +0 -2
  57. package/dist/esm/providers/index.js.map +1 -1
  58. package/dist/esm/utils/AddressUtils.d.ts +0 -1
  59. package/dist/esm/utils/AddressUtils.js +0 -9
  60. package/dist/esm/utils/AddressUtils.js.map +1 -1
  61. package/dist/esm/utils/DepositUtils.js +2 -2
  62. package/dist/esm/utils/DepositUtils.js.map +1 -1
  63. package/dist/esm/utils/EventUtils.js +1 -29
  64. package/dist/esm/utils/EventUtils.js.map +1 -1
  65. package/dist/esm/utils/SpokeUtils.d.ts +0 -1
  66. package/dist/esm/utils/SpokeUtils.js +7 -13
  67. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  68. package/dist/esm/utils/common.d.ts +0 -1
  69. package/dist/esm/utils/common.js +0 -1
  70. package/dist/esm/utils/common.js.map +1 -1
  71. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  72. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  73. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
  74. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  75. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
  76. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  77. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
  78. package/dist/types/clients/SpokePoolClient.d.ts +0 -8
  79. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  80. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +1 -2
  81. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  82. package/dist/types/constants.d.ts +1 -1
  83. package/dist/types/constants.d.ts.map +1 -1
  84. package/dist/types/providers/index.d.ts +0 -1
  85. package/dist/types/providers/index.d.ts.map +1 -1
  86. package/dist/types/utils/AddressUtils.d.ts +0 -1
  87. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  88. package/dist/types/utils/EventUtils.d.ts.map +1 -1
  89. package/dist/types/utils/SpokeUtils.d.ts +0 -1
  90. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  91. package/dist/types/utils/common.d.ts +0 -1
  92. package/dist/types/utils/common.d.ts.map +1 -1
  93. package/package.json +1 -1
  94. package/src/clients/BundleDataClient/BundleDataClient.ts +243 -427
  95. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
  96. package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -66
  97. package/src/clients/SpokePoolClient.ts +3 -16
  98. package/src/clients/mocks/MockSpokePoolClient.ts +1 -14
  99. package/src/constants.ts +3 -3
  100. package/src/providers/index.ts +0 -1
  101. package/src/utils/AddressUtils.ts +0 -10
  102. package/src/utils/DepositUtils.ts +2 -2
  103. package/src/utils/EventUtils.ts +1 -29
  104. package/src/utils/SpokeUtils.ts +8 -21
  105. package/src/utils/common.ts +0 -2
  106. package/dist/cjs/providers/mockProvider.d.ts +0 -19
  107. package/dist/cjs/providers/mockProvider.js +0 -70
  108. package/dist/cjs/providers/mockProvider.js.map +0 -1
  109. package/dist/esm/providers/mockProvider.d.ts +0 -23
  110. package/dist/esm/providers/mockProvider.js +0 -73
  111. package/dist/esm/providers/mockProvider.js.map +0 -1
  112. package/dist/types/providers/mockProvider.d.ts +0 -24
  113. package/dist/types/providers/mockProvider.d.ts.map +0 -1
  114. package/src/providers/mockProvider.ts +0 -77
@@ -6,7 +6,6 @@ var lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  var interfaces_1 = require("../../interfaces");
7
7
  var utils_1 = require("../../utils");
8
8
  var utils_2 = require("./utils");
9
- var constants_1 = require("../../constants");
10
9
  exports.INFINITE_FILL_DEADLINE = utils_1.bnUint32Max;
11
10
  function updateExpiredDepositsV3(dict, deposit) {
12
11
  var _a;
@@ -27,9 +26,11 @@ function updateBundleDepositsV3(dict, deposit) {
27
26
  }
28
27
  dict[originChainId][inputToken].push(deposit);
29
28
  }
30
- function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
29
+ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
31
30
  var _a, _b;
32
- (0, utils_1.assert)((0, utils_1.chainIsEvm)(repaymentChainId) && (0, utils_2.isEvmRepaymentValid)(fill, repaymentChainId), "validatedBundleV3Fills dictionary should only contain fills with valid repayment information");
31
+ if ((0, utils_1.chainIsEvm)(fill.repaymentChainId) && !(0, utils_1.isValidEvmAddress)(fill.relayer)) {
32
+ return;
33
+ }
33
34
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
34
35
  (0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
35
36
  fills: [],
@@ -38,22 +39,22 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
38
39
  refunds: {},
39
40
  });
40
41
  }
41
- var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
42
+ var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
42
43
  (0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
43
44
  var refundObj = dict[repaymentChainId][repaymentToken];
44
- var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
45
+ var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
45
46
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
46
- if (!(0, utils_1.isSlowFill)(bundleFill)) {
47
- var refundAmount = bundleFill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
47
+ if (!(0, utils_1.isSlowFill)(fill)) {
48
+ var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
48
49
  refundObj.totalRefundAmount = refundObj.totalRefundAmount
49
50
  ? refundObj.totalRefundAmount.add(refundAmount)
50
51
  : refundAmount;
51
52
  (_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
52
- if (refundObj.refunds[bundleFill.relayer]) {
53
- refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
53
+ if (refundObj.refunds[fill.relayer]) {
54
+ refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
54
55
  }
55
56
  else {
56
- refundObj.refunds[bundleFill.relayer] = refundAmount;
57
+ refundObj.refunds[fill.relayer] = refundAmount;
57
58
  }
58
59
  }
59
60
  }
@@ -67,9 +68,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
67
68
  }
68
69
  function updateBundleSlowFills(dict, deposit) {
69
70
  var _a;
70
- if ((0, utils_1.chainIsEvm)(deposit.destinationChainId) && !(0, utils_1.isValidEvmAddress)(deposit.recipient)) {
71
- return;
72
- }
73
71
  var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
74
72
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
75
73
  (0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
@@ -154,7 +152,7 @@ var BundleDataClient = (function () {
154
152
  at: "BundleDataClient#loadPersistedDataFromArweave",
155
153
  message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
156
154
  blockRanges: JSON.stringify(blockRangesForChains),
157
- bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
155
+ bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
158
156
  });
159
157
  return [2, bundleData];
160
158
  }
@@ -196,107 +194,64 @@ var BundleDataClient = (function () {
196
194
  return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
197
195
  case 1:
198
196
  arweaveData = _a.sent();
199
- if (!(arweaveData === undefined)) return [3, 3];
200
- return [4, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
201
- case 2:
202
- combinedRefunds = _a.sent();
203
- return [3, 4];
204
- case 3:
205
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
206
- combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
207
- Object.keys(combinedRefunds).forEach(function (chainId) {
208
- if (_this.spokePoolClients[Number(chainId)] === undefined) {
209
- delete combinedRefunds[Number(chainId)];
210
- }
211
- });
212
- _a.label = 4;
213
- case 4: return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
197
+ if (arweaveData === undefined) {
198
+ combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
199
+ }
200
+ else {
201
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
202
+ combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
203
+ Object.keys(combinedRefunds).forEach(function (chainId) {
204
+ if (_this.spokePoolClients[Number(chainId)] === undefined) {
205
+ delete combinedRefunds[Number(chainId)];
206
+ }
207
+ });
208
+ }
209
+ return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
214
210
  }
215
211
  });
216
212
  });
217
213
  };
218
214
  BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
219
- return tslib_1.__awaiter(this, void 0, void 0, function () {
220
- var refundsForChain, _loop_1, this_1, _i, chainIds_1, chainId;
221
- var _this = this;
222
- return tslib_1.__generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0:
225
- refundsForChain = {};
226
- _loop_1 = function (chainId) {
227
- var chainIndex, fillsToCount;
228
- return tslib_1.__generator(this, function (_b) {
229
- switch (_b.label) {
230
- case 0:
231
- if (this_1.spokePoolClients[chainId] === undefined) {
232
- return [2, "continue"];
233
- }
234
- chainIndex = chainIds.indexOf(chainId);
235
- return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
236
- var matchingDeposit, hasMatchingDeposit, validRepayment;
237
- return tslib_1.__generator(this, function (_a) {
238
- switch (_a.label) {
239
- case 0:
240
- if (fill.blockNumber < blockRanges[chainIndex][0] ||
241
- fill.blockNumber > blockRanges[chainIndex][1] ||
242
- (0, utils_1.isZeroValueFillOrSlowFillRequest)(fill)) {
243
- return [2, false];
244
- }
245
- if (this.spokePoolClients[fill.originChainId] === undefined) {
246
- return [2, false];
247
- }
248
- matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
249
- hasMatchingDeposit = matchingDeposit !== undefined &&
250
- this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
251
- if (!hasMatchingDeposit) return [3, 2];
252
- return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
253
- .getChainIdIndicesForBlock(blockRanges[0][1])
254
- .filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
255
- case 1:
256
- validRepayment = _a.sent();
257
- if (!(0, utils_1.isDefined)(validRepayment)) {
258
- return [2, false];
259
- }
260
- _a.label = 2;
261
- case 2: return [2, hasMatchingDeposit];
262
- }
263
- });
264
- }); })];
265
- case 1:
266
- fillsToCount = _b.sent();
267
- fillsToCount.forEach(function (fill) {
268
- var _a, _b, _c;
269
- var _d;
270
- var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
271
- (0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
272
- var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
273
- var relayer = fill.relayer, refundAmount = fill.inputAmount;
274
- (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
275
- (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
276
- var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
277
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
278
- });
279
- return [2];
280
- }
281
- });
282
- };
283
- this_1 = this;
284
- _i = 0, chainIds_1 = chainIds;
285
- _a.label = 1;
286
- case 1:
287
- if (!(_i < chainIds_1.length)) return [3, 4];
288
- chainId = chainIds_1[_i];
289
- return [5, _loop_1(chainId)];
290
- case 2:
291
- _a.sent();
292
- _a.label = 3;
293
- case 3:
294
- _i++;
295
- return [3, 1];
296
- case 4: return [2, refundsForChain];
215
+ var _this = this;
216
+ var refundsForChain = {};
217
+ var _loop_1 = function (chainId) {
218
+ if (this_1.spokePoolClients[chainId] === undefined) {
219
+ return "continue";
220
+ }
221
+ var chainIndex = chainIds.indexOf(chainId);
222
+ this_1.spokePoolClients[chainId]
223
+ .getFills()
224
+ .filter(function (fill) {
225
+ if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
226
+ return false;
227
+ }
228
+ if (_this.spokePoolClients[fill.originChainId] === undefined) {
229
+ return false;
297
230
  }
231
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
232
+ var hasMatchingDeposit = matchingDeposit !== undefined &&
233
+ _this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
234
+ return hasMatchingDeposit;
235
+ })
236
+ .forEach(function (fill) {
237
+ var _a, _b, _c;
238
+ var _d;
239
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
240
+ (0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
241
+ var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
242
+ var relayer = fill.relayer, refundAmount = fill.inputAmount;
243
+ (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
244
+ (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
245
+ var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
246
+ refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
298
247
  });
299
- });
248
+ };
249
+ var this_1 = this;
250
+ for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
251
+ var chainId = chainIds_1[_i];
252
+ _loop_1(chainId);
253
+ }
254
+ return refundsForChain;
300
255
  };
301
256
  BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
302
257
  if (this.spokePoolClients[chainId] === undefined) {
@@ -339,10 +294,12 @@ var BundleDataClient = (function () {
339
294
  case 1:
340
295
  _a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
341
296
  hubPoolClient = this.clients.hubPoolClient;
342
- root = (0, utils_2._buildPoolRebalanceRoot)(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
343
- hubPoolClient: hubPoolClient,
344
- configStoreClient: hubPoolClient.configStoreClient,
345
- });
297
+ return [4, (0, utils_2._buildPoolRebalanceRoot)(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
298
+ hubPoolClient: hubPoolClient,
299
+ configStoreClient: hubPoolClient.configStoreClient,
300
+ })];
301
+ case 2:
302
+ root = _b.sent();
346
303
  return [2, {
347
304
  root: root,
348
305
  blockRanges: blockRanges,
@@ -366,39 +323,32 @@ var BundleDataClient = (function () {
366
323
  return [initialBlockRange[1] + 1, blockRange[1]];
367
324
  });
368
325
  }
369
- var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
370
- return tslib_1.__generator(this, function (_e) {
371
- switch (_e.label) {
326
+ var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
327
+ return tslib_1.__generator(this, function (_a) {
328
+ switch (_a.label) {
372
329
  case 0:
373
330
  hubPoolClient = this.clients.hubPoolClient;
374
331
  nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
375
332
  chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
376
333
  combinedRefunds = [];
377
334
  widestBundleBlockRanges = (0, utils_2.getWidestPossibleExpectedBlockRange)(chainIds, this.spokePoolClients, (0, utils_2.getEndBlockBuffers)(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
378
- if (!hubPoolClient.hasPendingProposal()) return [3, 5];
335
+ if (!hubPoolClient.hasPendingProposal()) return [3, 2];
379
336
  pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
380
337
  return [4, this.loadArweaveData(pendingBundleBlockRanges)];
381
338
  case 1:
382
- arweaveData = _e.sent();
383
- if (!(arweaveData === undefined)) return [3, 3];
384
- _b = (_a = combinedRefunds).push;
385
- return [4, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
386
- case 2:
387
- _b.apply(_a, [_e.sent()]);
388
- return [3, 4];
389
- case 3:
390
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
391
- combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
392
- _e.label = 4;
393
- case 4:
339
+ arweaveData = _a.sent();
340
+ if (arweaveData === undefined) {
341
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
342
+ }
343
+ else {
344
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
345
+ combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
346
+ }
394
347
  widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
395
- _e.label = 5;
396
- case 5:
348
+ _a.label = 2;
349
+ case 2:
397
350
  start = performance.now();
398
- _d = (_c = combinedRefunds).push;
399
- return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
400
- case 6:
401
- _d.apply(_c, [_e.sent()]);
351
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
402
352
  this.logger.debug({
403
353
  at: "BundleDataClient#getNextBundleRefunds",
404
354
  message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -529,7 +479,7 @@ var BundleDataClient = (function () {
529
479
  };
530
480
  BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
531
481
  return tslib_1.__awaiter(this, void 0, void 0, function () {
532
- var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleUnrepayableFillsV3, bundleInvalidSlowFillRequests, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, decodeBundleDepositHash, startBlockForMainnet, versionAtProposalBlock, canRefundPrefills, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
482
+ var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _depositIsExpired, _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;
533
483
  var _this = this;
534
484
  return tslib_1.__generator(this, function (_c) {
535
485
  switch (_c.label) {
@@ -549,8 +499,6 @@ var BundleDataClient = (function () {
549
499
  bundleDepositsV3 = {};
550
500
  bundleFillsV3 = {};
551
501
  bundleInvalidFillsV3 = [];
552
- bundleUnrepayableFillsV3 = [];
553
- bundleInvalidSlowFillRequests = [];
554
502
  bundleSlowFillsV3 = {};
555
503
  expiredDepositsToRefundV3 = {};
556
504
  unexecutableSlowFills = {};
@@ -599,13 +547,7 @@ var BundleDataClient = (function () {
599
547
  v3RelayHashes = {};
600
548
  bundleDepositHashes = [];
601
549
  olderDepositHashes = [];
602
- decodeBundleDepositHash = function (depositHash) {
603
- var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
604
- return { relayDataHash: relayDataHash, index: Number(i) };
605
- };
606
- startBlockForMainnet = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
607
- versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
608
- canRefundPrefills = versionAtProposalBlock >= constants_1.PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
550
+ depositCounter = 0;
609
551
  _loop_2 = function (originChainId) {
610
552
  var originClient = spokePoolClients[originChainId];
611
553
  var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
@@ -618,27 +560,24 @@ var BundleDataClient = (function () {
618
560
  if (deposit.blockNumber > originChainBlockRange[1] || (0, utils_1.isZeroValueDeposit)(deposit)) {
619
561
  return;
620
562
  }
563
+ depositCounter++;
621
564
  var relayDataHash = _this.getRelayHashFromEvent(deposit);
622
565
  if (!v3RelayHashes[relayDataHash]) {
623
566
  v3RelayHashes[relayDataHash] = {
624
- deposits: [deposit],
567
+ deposit: deposit,
625
568
  fill: undefined,
626
569
  slowFillRequest: undefined,
627
570
  };
628
571
  }
629
- else {
630
- v3RelayHashes[relayDataHash].deposits.push(deposit);
572
+ if (deposit.inputAmount.eq(0)) {
573
+ return;
631
574
  }
632
- var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
633
- var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
634
- (0, utils_1.assert)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
635
- decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
636
575
  if (deposit.blockNumber >= originChainBlockRange[0]) {
637
- bundleDepositHashes.push(newBundleDepositHash);
576
+ bundleDepositHashes.push(relayDataHash);
638
577
  updateBundleDepositsV3(bundleDepositsV3, deposit);
639
578
  }
640
579
  else if (deposit.blockNumber < originChainBlockRange[0]) {
641
- olderDepositHashes.push(newBundleDepositHash);
580
+ olderDepositHashes.push(relayDataHash);
642
581
  }
643
582
  });
644
583
  }
@@ -649,7 +588,7 @@ var BundleDataClient = (function () {
649
588
  }
650
589
  this.logger.debug({
651
590
  at: "BundleDataClient#loadData",
652
- message: "Processed ".concat(bundleDepositHashes.length + olderDepositHashes.length, " deposits in ").concat(performance.now() - start, "ms."),
591
+ message: "Processed ".concat(depositCounter, " deposits in ").concat(performance.now() - start, "ms."),
653
592
  });
654
593
  start = performance.now();
655
594
  validatedBundleV3Fills = [];
@@ -663,7 +602,7 @@ var BundleDataClient = (function () {
663
602
  case 0:
664
603
  originClient = spokePoolClients[originChainId];
665
604
  _loop_4 = function (destinationChainId) {
666
- var destinationClient, destinationChainBlockRange, originChainBlockRange, fastFillsReplacingSlowFills;
605
+ var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
667
606
  return tslib_1.__generator(this, function (_g) {
668
607
  switch (_g.label) {
669
608
  case 0:
@@ -672,90 +611,69 @@ var BundleDataClient = (function () {
672
611
  }
673
612
  destinationClient = spokePoolClients[destinationChainId];
674
613
  destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
675
- originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
676
614
  fastFillsReplacingSlowFills = [];
677
615
  return [4, (0, utils_1.forEachAsync)(destinationClient
678
616
  .getFillsForOriginChain(originChainId)
679
617
  .filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill); }), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
680
- var relayDataHash, fillToRefund_1, duplicateDeposits, historicalDeposit, matchedDeposit, fillToRefund;
618
+ var relayDataHash, fillTransaction, originRelayer, historicalDeposit, matchedDeposit;
681
619
  return tslib_1.__generator(this, function (_a) {
682
620
  switch (_a.label) {
683
621
  case 0:
684
- fillCounter++;
685
622
  relayDataHash = this.getRelayHashFromEvent(fill);
686
- if (!v3RelayHashes[relayDataHash]) return [3, 5];
687
- if (!!v3RelayHashes[relayDataHash].fill) return [3, 3];
688
- (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary.");
689
- v3RelayHashes[relayDataHash].fill = fill;
690
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
691
- return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
692
- case 1:
693
- fillToRefund_1 = _a.sent();
694
- if (!(0, utils_1.isDefined)(fillToRefund_1)) {
695
- bundleUnrepayableFillsV3.push(fill);
696
- }
697
- else {
698
- v3RelayHashes[relayDataHash].fill = fillToRefund_1;
699
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp }));
700
- duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
701
- duplicateDeposits.forEach(function (duplicateDeposit) {
702
- if ((0, utils_1.isSlowFill)(fill)) {
703
- updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
704
- }
705
- else {
706
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
623
+ fillCounter++;
624
+ if (v3RelayHashes[relayDataHash]) {
625
+ if (!v3RelayHashes[relayDataHash].fill) {
626
+ (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
627
+ v3RelayHashes[relayDataHash].fill = fill;
628
+ if (fill.blockNumber >= destinationChainBlockRange[0]) {
629
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
630
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
631
+ _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
632
+ fastFillsReplacingSlowFills.push(relayDataHash);
633
+ }
707
634
  }
708
- });
709
- }
710
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
711
- _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
712
- fastFillsReplacingSlowFills.push(relayDataHash);
635
+ }
636
+ return [2];
713
637
  }
714
- _a.label = 2;
715
- case 2: return [3, 4];
716
- case 3: throw new Error("Duplicate fill detected");
717
- case 4: return [2];
718
- case 5:
719
638
  v3RelayHashes[relayDataHash] = {
720
- deposits: undefined,
639
+ deposit: undefined,
721
640
  fill: fill,
722
641
  slowFillRequest: undefined,
723
642
  };
724
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 9];
643
+ if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 4];
725
644
  if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
726
645
  bundleInvalidFillsV3.push(fill);
727
646
  return [2];
728
647
  }
729
- return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
730
- case 6:
731
- historicalDeposit = _a.sent();
732
- if (!!historicalDeposit.found) return [3, 7];
733
- bundleInvalidFillsV3.push(fill);
734
- return [3, 9];
735
- case 7:
736
- matchedDeposit = historicalDeposit.deposit;
737
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
648
+ if (!((0, utils_1.chainIsEvm)(fill.repaymentChainId) && !(0, utils_1.isValidEvmAddress)(fill.relayer))) return [3, 2];
649
+ return [4, originClient.spokePool.provider.getTransaction(fill.transactionHash)];
650
+ case 1:
651
+ fillTransaction = _a.sent();
652
+ originRelayer = fillTransaction.from;
653
+ if (!(0, utils_1.isValidEvmAddress)(originRelayer)) {
738
654
  bundleInvalidFillsV3.push(fill);
739
655
  return [2];
740
656
  }
741
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
742
- return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
743
- case 8:
744
- fillToRefund = _a.sent();
745
- if (!(0, utils_1.isDefined)(fillToRefund)) {
746
- bundleUnrepayableFillsV3.push(fill);
657
+ fill.relayer = originRelayer;
658
+ _a.label = 2;
659
+ case 2: return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
660
+ case 3:
661
+ historicalDeposit = _a.sent();
662
+ if (!historicalDeposit.found) {
663
+ bundleInvalidFillsV3.push(fill);
747
664
  }
748
665
  else {
666
+ matchedDeposit = historicalDeposit.deposit;
749
667
  (0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
750
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
751
- v3RelayHashes[relayDataHash].fill = fillToRefund;
752
- }
753
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
754
- _canCreateSlowFillLeaf(matchedDeposit)) {
755
- fastFillsReplacingSlowFills.push(relayDataHash);
668
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
669
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
670
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
671
+ _canCreateSlowFillLeaf(matchedDeposit)) {
672
+ fastFillsReplacingSlowFills.push(relayDataHash);
673
+ }
756
674
  }
757
- _a.label = 9;
758
- case 9: return [2];
675
+ _a.label = 4;
676
+ case 4: return [2];
759
677
  }
760
678
  });
761
679
  }); })];
@@ -777,44 +695,34 @@ var BundleDataClient = (function () {
777
695
  if (v3RelayHashes[relayDataHash].fill) {
778
696
  return [2];
779
697
  }
780
- (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary.");
781
- matchedDeposit = v3RelayHashes[relayDataHash].deposits[0];
698
+ (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
699
+ matchedDeposit = v3RelayHashes[relayDataHash].deposit;
782
700
  if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
783
701
  _canCreateSlowFillLeaf(matchedDeposit) &&
784
702
  !_depositIsExpired(matchedDeposit)) {
785
703
  validatedBundleSlowFills.push(matchedDeposit);
786
704
  }
787
705
  }
788
- else {
789
- throw new Error("Duplicate slow fill request detected.");
790
- }
791
706
  return [2];
792
707
  }
793
708
  v3RelayHashes[relayDataHash] = {
794
- deposits: undefined,
709
+ deposit: undefined,
795
710
  fill: undefined,
796
711
  slowFillRequest: slowFillRequest,
797
712
  };
798
- if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
799
- if (!exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline)) {
800
- bundleInvalidSlowFillRequests.push(slowFillRequest);
801
- return [2];
802
- }
713
+ if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
714
+ exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3, 2];
803
715
  return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
804
716
  case 1:
805
717
  historicalDeposit = _a.sent();
806
718
  if (!historicalDeposit.found) {
807
- bundleInvalidSlowFillRequests.push(slowFillRequest);
808
719
  return [2];
809
720
  }
810
721
  matchedDeposit = historicalDeposit.deposit;
811
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
812
- bundleInvalidSlowFillRequests.push(slowFillRequest);
813
- return [2];
814
- }
815
722
  (0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
816
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
817
- if (!_canCreateSlowFillLeaf(matchedDeposit) || _depositIsExpired(matchedDeposit)) {
723
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
724
+ if (!_canCreateSlowFillLeaf(matchedDeposit) ||
725
+ _depositIsExpired(matchedDeposit)) {
818
726
  return [2];
819
727
  }
820
728
  validatedBundleSlowFills.push(matchedDeposit);
@@ -825,105 +733,71 @@ var BundleDataClient = (function () {
825
733
  }); })];
826
734
  case 2:
827
735
  _g.sent();
828
- return [4, (0, utils_1.mapAsync)(bundleDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
829
- var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, fillToRefund, fillStatus, prefill, verifiedFill;
830
- var _this = this;
831
- return tslib_1.__generator(this, function (_c) {
832
- switch (_c.label) {
736
+ return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
737
+ var deposit = v3RelayHashes[depositHash].deposit;
738
+ return (deposit && deposit.originChainId === originChainId && deposit.destinationChainId === destinationChainId);
739
+ }), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
740
+ var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
741
+ return tslib_1.__generator(this, function (_b) {
742
+ switch (_b.label) {
833
743
  case 0:
834
- _a = decodeBundleDepositHash(depositHash), relayDataHash = _a.relayDataHash, index = _a.index;
835
- _b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
836
- if (!deposits || deposits.length === 0) {
837
- throw new Error("Deposits should exist in relay hash dictionary.");
838
- }
839
- deposit = deposits[index];
744
+ _a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
840
745
  if (!deposit)
841
746
  throw new Error("Deposit should exist in relay hash dictionary.");
842
- if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
747
+ if (fill) {
748
+ if (fill.blockNumber < destinationChainBlockRange[0] && !(0, utils_1.isSlowFill)(fill)) {
749
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
750
+ }
843
751
  return [2];
844
752
  }
845
- if (!fill) return [3, 3];
846
- if (!(canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0])) return [3, 2];
847
- return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
848
- case 1:
849
- fillToRefund = _c.sent();
850
- if (!(0, utils_1.isDefined)(fillToRefund)) {
851
- bundleUnrepayableFillsV3.push(fill);
852
- }
853
- else if (!(0, utils_1.isSlowFill)(fill)) {
854
- v3RelayHashes[relayDataHash].fill = fillToRefund;
855
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: deposit.quoteTimestamp }));
856
- }
857
- else {
858
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
859
- }
860
- _c.label = 2;
861
- case 2: return [2];
862
- case 3:
863
753
  if (slowFillRequest) {
864
754
  if (_depositIsExpired(deposit)) {
865
755
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
866
756
  }
867
- else if (canRefundPrefills &&
868
- slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
869
- _canCreateSlowFillLeaf(deposit) &&
870
- validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
757
+ else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
758
+ _canCreateSlowFillLeaf(deposit)) {
871
759
  validatedBundleSlowFills.push(deposit);
872
760
  }
873
761
  return [2];
874
762
  }
875
763
  return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
876
- case 4:
877
- fillStatus = _c.sent();
878
- if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 8];
879
- return [4, this.findMatchingFillEvent(deposit, destinationClient)];
880
- case 5:
881
- prefill = _c.sent();
882
- (0, utils_1.assert)((0, utils_1.isDefined)(prefill), "findFillEvent# Cannot find prefill: ".concat(relayDataHash));
883
- (0, utils_1.assert)(this.getRelayHashFromEvent(prefill) === relayDataHash, "Relay hashes should match.");
884
- if (!canRefundPrefills) return [3, 7];
885
- return [4, (0, utils_2.verifyFillRepayment)(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
886
- case 6:
887
- verifiedFill = _c.sent();
888
- if (!(0, utils_1.isDefined)(verifiedFill)) {
889
- bundleUnrepayableFillsV3.push(prefill);
890
- }
891
- else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
892
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
893
- }
894
- else {
895
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
764
+ case 1:
765
+ fillStatus = _b.sent();
766
+ if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
767
+ return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
768
+ case 2:
769
+ prefill = (_b.sent());
770
+ if (!(0, utils_1.isSlowFill)(prefill)) {
771
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
896
772
  }
897
- _c.label = 7;
898
- case 7: return [3, 9];
899
- case 8:
773
+ return [3, 4];
774
+ case 3:
900
775
  if (_depositIsExpired(deposit)) {
901
776
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
902
777
  }
903
- else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill &&
904
- validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
905
- if (canRefundPrefills && _canCreateSlowFillLeaf(deposit)) {
778
+ else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
779
+ if (_canCreateSlowFillLeaf(deposit)) {
906
780
  validatedBundleSlowFills.push(deposit);
907
781
  }
908
782
  }
909
- _c.label = 9;
910
- case 9: return [2];
783
+ _b.label = 4;
784
+ case 4: return [2];
911
785
  }
912
786
  });
913
787
  }); })];
914
788
  case 3:
915
789
  _g.sent();
916
790
  fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
917
- var _a = v3RelayHashes[relayDataHash], deposits = _a.deposits, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
791
+ var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
918
792
  (0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
919
- if (!deposits || deposits.length < 1) {
793
+ if (!deposit) {
920
794
  throw new Error("Deposit should exist in relay hash dictionary.");
921
795
  }
922
- (0, utils_1.assert)(_canCreateSlowFillLeaf(deposits[0]), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
796
+ (0, utils_1.assert)(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
923
797
  var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
924
798
  if (!slowFillRequest ||
925
799
  slowFillRequest.blockNumber < destinationBlockRange[0]) {
926
- validatedBundleUnexecutableSlowFills.push(deposits[0]);
800
+ validatedBundleUnexecutableSlowFills.push(deposit);
927
801
  }
928
802
  });
929
803
  return [2];
@@ -964,17 +838,13 @@ var BundleDataClient = (function () {
964
838
  message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
965
839
  });
966
840
  start = performance.now();
967
- return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
968
- var _a, relayDataHash, index, _b, deposits, slowFillRequest, fill, deposit, destinationChainId, destinationBlockRange, fillStatus;
969
- return tslib_1.__generator(this, function (_c) {
970
- switch (_c.label) {
841
+ return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
842
+ var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
843
+ return tslib_1.__generator(this, function (_b) {
844
+ switch (_b.label) {
971
845
  case 0:
972
- _a = decodeBundleDepositHash(depositHash), relayDataHash = _a.relayDataHash, index = _a.index;
973
- _b = v3RelayHashes[relayDataHash], deposits = _b.deposits, slowFillRequest = _b.slowFillRequest, fill = _b.fill;
974
- if (!deposits || deposits.length < 1) {
975
- throw new Error("Deposit should exist in relay hash dictionary.");
976
- }
977
- deposit = deposits[index];
846
+ _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
847
+ (0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
978
848
  destinationChainId = deposit.destinationChainId;
979
849
  destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
980
850
  if (!(!fill &&
@@ -984,7 +854,7 @@ var BundleDataClient = (function () {
984
854
  spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
985
855
  return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
986
856
  case 1:
987
- fillStatus = _c.sent();
857
+ fillStatus = _b.sent();
988
858
  if (fillStatus !== interfaces_1.FillStatus.Filled) {
989
859
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
990
860
  }
@@ -994,7 +864,7 @@ var BundleDataClient = (function () {
994
864
  if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
995
865
  validatedBundleUnexecutableSlowFills.push(deposit);
996
866
  }
997
- _c.label = 2;
867
+ _b.label = 2;
998
868
  case 2: return [2];
999
869
  }
1000
870
  });
@@ -1005,7 +875,7 @@ var BundleDataClient = (function () {
1005
875
  promises = [
1006
876
  validatedBundleV3Fills.length > 0
1007
877
  ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
1008
- var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposits[0];
878
+ var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1009
879
  (0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
1010
880
  var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
1011
881
  return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
@@ -1032,19 +902,14 @@ var BundleDataClient = (function () {
1032
902
  v3FillLpFees.forEach(function (_a, idx) {
1033
903
  var realizedLpFeePct = _a.realizedLpFeePct;
1034
904
  var fill = validatedBundleV3Fills[idx];
1035
- var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposits[0];
905
+ var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1036
906
  (0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
1037
907
  var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
1038
- updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
908
+ updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
1039
909
  });
1040
910
  v3SlowFillLpFees.forEach(function (_a, idx) {
1041
911
  var lpFeePct = _a.realizedLpFeePct;
1042
912
  var deposit = validatedBundleSlowFills[idx];
1043
- var relayDataHash = _this.getRelayHashFromEvent(deposit);
1044
- if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
1045
- return;
1046
- }
1047
- (0, utils_1.assert)(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
1048
913
  updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
1049
914
  });
1050
915
  v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
@@ -1052,31 +917,15 @@ var BundleDataClient = (function () {
1052
917
  var deposit = validatedBundleUnexecutableSlowFills[idx];
1053
918
  updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
1054
919
  });
1055
- v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
920
+ v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
1056
921
  if (bundleInvalidFillsV3.length > 0) {
1057
922
  this.logger.debug({
1058
923
  at: "BundleDataClient#loadData",
1059
- message: "Finished loading V3 spoke pool data and found some invalid fills in range",
924
+ message: "Finished loading V3 spoke pool data and found some invalid V3 fills in range",
1060
925
  blockRangesForChains: blockRangesForChains,
1061
926
  bundleInvalidFillsV3: bundleInvalidFillsV3,
1062
927
  });
1063
928
  }
1064
- if (bundleUnrepayableFillsV3.length > 0) {
1065
- this.logger.debug({
1066
- at: "BundleDataClient#loadData",
1067
- message: "Finished loading V3 spoke pool data and found some unrepayable fills in range",
1068
- blockRangesForChains: blockRangesForChains,
1069
- bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
1070
- });
1071
- }
1072
- if (bundleInvalidSlowFillRequests.length > 0) {
1073
- this.logger.debug({
1074
- at: "BundleDataClient#loadData",
1075
- message: "Finished loading V3 spoke pool data and found some invalid slow fill requests in range",
1076
- blockRangesForChains: blockRangesForChains,
1077
- bundleInvalidSlowFillRequests: bundleInvalidSlowFillRequests,
1078
- });
1079
- }
1080
929
  this.logger.debug({
1081
930
  at: "BundleDataClient#loadDataFromScratch",
1082
931
  message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -1097,16 +946,6 @@ var BundleDataClient = (function () {
1097
946
  BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
1098
947
  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);
1099
948
  };
1100
- BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
1101
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1102
- return tslib_1.__generator(this, function (_a) {
1103
- switch (_a.label) {
1104
- case 0: return [4, (0, utils_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
1105
- case 1: return [2, _a.sent()];
1106
- }
1107
- });
1108
- });
1109
- };
1110
949
  BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
1111
950
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1112
951
  var _a, _b;
@@ -1116,7 +955,7 @@ var BundleDataClient = (function () {
1116
955
  case 0:
1117
956
  _b = (_a = Object).fromEntries;
1118
957
  return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1119
- var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, _endTime, _b, endBlockDelta, endTime;
958
+ var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
1120
959
  return tslib_1.__generator(this, function (_c) {
1121
960
  switch (_c.label) {
1122
961
  case 0:
@@ -1130,7 +969,7 @@ var BundleDataClient = (function () {
1130
969
  return [2];
1131
970
  }
1132
971
  startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
1133
- endBlockForChain = Math.min(_endBlockForChain + 1, spokePoolClient.latestBlockSearched);
972
+ endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
1134
973
  return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
1135
974
  case 1:
1136
975
  _b = [
@@ -1140,10 +979,8 @@ var BundleDataClient = (function () {
1140
979
  case 2:
1141
980
  _a = _b.concat([
1142
981
  _c.sent()
1143
- ]), startTime = _a[0], _endTime = _a[1];
1144
- endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
1145
- endTime = Math.max(0, _endTime - endBlockDelta);
1146
- (0, utils_1.assert)(endTime >= startTime, "End time for block ".concat(endBlockForChain, " should be greater than start time for block ").concat(startBlockForChain, ": ").concat(endTime, " >= ").concat(startTime, "."));
982
+ ]), startTime = _a[0], endTime = _a[1];
983
+ (0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
1147
984
  (0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
1148
985
  return [2, [chainId, [startTime, endTime]]];
1149
986
  }