@across-protocol/sdk 4.0.0-beta.27 → 4.0.0-beta.3

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 +4 -5
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +162 -318
  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 -3
  8. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -33
  9. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  10. package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
  11. package/dist/cjs/clients/SpokePoolClient.js +4 -13
  12. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  13. package/dist/cjs/constants.d.ts +1 -1
  14. package/dist/cjs/constants.js +2 -2
  15. package/dist/cjs/constants.js.map +1 -1
  16. package/dist/cjs/providers/index.d.ts +0 -1
  17. package/dist/cjs/providers/index.js +0 -2
  18. package/dist/cjs/providers/index.js.map +1 -1
  19. package/dist/cjs/utils/AddressUtils.d.ts +0 -1
  20. package/dist/cjs/utils/AddressUtils.js +1 -14
  21. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  22. package/dist/cjs/utils/CachingUtils.js +1 -1
  23. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  24. package/dist/cjs/utils/DepositUtils.d.ts +1 -2
  25. package/dist/cjs/utils/DepositUtils.js +4 -13
  26. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  27. package/dist/cjs/utils/NetworkUtils.d.ts +0 -1
  28. package/dist/cjs/utils/NetworkUtils.js +1 -6
  29. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  30. package/dist/cjs/utils/SpokeUtils.js +3 -3
  31. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  32. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  33. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +186 -382
  34. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  35. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
  36. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
  37. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  38. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
  39. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -42
  40. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  41. package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
  42. package/dist/esm/clients/SpokePoolClient.js +4 -20
  43. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  44. package/dist/esm/constants.d.ts +1 -1
  45. package/dist/esm/constants.js +2 -2
  46. package/dist/esm/constants.js.map +1 -1
  47. package/dist/esm/providers/index.d.ts +0 -1
  48. package/dist/esm/providers/index.js +0 -2
  49. package/dist/esm/providers/index.js.map +1 -1
  50. package/dist/esm/utils/AddressUtils.d.ts +0 -1
  51. package/dist/esm/utils/AddressUtils.js +0 -16
  52. package/dist/esm/utils/AddressUtils.js.map +1 -1
  53. package/dist/esm/utils/CachingUtils.js +1 -1
  54. package/dist/esm/utils/CachingUtils.js.map +1 -1
  55. package/dist/esm/utils/DepositUtils.d.ts +1 -2
  56. package/dist/esm/utils/DepositUtils.js +5 -14
  57. package/dist/esm/utils/DepositUtils.js.map +1 -1
  58. package/dist/esm/utils/NetworkUtils.d.ts +0 -6
  59. package/dist/esm/utils/NetworkUtils.js +0 -10
  60. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  61. package/dist/esm/utils/SpokeUtils.js +4 -4
  62. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  63. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
  64. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  65. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
  66. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  67. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
  68. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  69. package/dist/types/clients/SpokePoolClient.d.ts +0 -8
  70. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  71. package/dist/types/constants.d.ts +1 -1
  72. package/dist/types/constants.d.ts.map +1 -1
  73. package/dist/types/providers/index.d.ts +0 -1
  74. package/dist/types/providers/index.d.ts.map +1 -1
  75. package/dist/types/utils/AddressUtils.d.ts +0 -1
  76. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  77. package/dist/types/utils/DepositUtils.d.ts +1 -2
  78. package/dist/types/utils/DepositUtils.d.ts.map +1 -1
  79. package/dist/types/utils/NetworkUtils.d.ts +0 -6
  80. package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
  81. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/clients/BundleDataClient/BundleDataClient.ts +179 -382
  84. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
  85. package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
  86. package/src/clients/SpokePoolClient.ts +6 -19
  87. package/src/constants.ts +3 -3
  88. package/src/providers/index.ts +0 -1
  89. package/src/utils/AddressUtils.ts +0 -16
  90. package/src/utils/CachingUtils.ts +1 -1
  91. package/src/utils/DepositUtils.ts +5 -14
  92. package/src/utils/NetworkUtils.ts +0 -11
  93. package/src/utils/SpokeUtils.ts +6 -6
  94. package/dist/cjs/providers/mockProvider.d.ts +0 -19
  95. package/dist/cjs/providers/mockProvider.js +0 -70
  96. package/dist/cjs/providers/mockProvider.js.map +0 -1
  97. package/dist/esm/providers/mockProvider.d.ts +0 -23
  98. package/dist/esm/providers/mockProvider.js +0 -73
  99. package/dist/esm/providers/mockProvider.js.map +0 -1
  100. package/dist/types/providers/mockProvider.d.ts +0 -24
  101. package/dist/types/providers/mockProvider.d.ts.map +0 -1
  102. package/src/providers/mockProvider.ts +0 -77
@@ -6,13 +6,9 @@ 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;
13
- if ((0, utils_1.chainIsEvm)(deposit.originChainId) && !(0, utils_1.isValidEvmAddress)(deposit.depositor)) {
14
- return;
15
- }
16
12
  var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
17
13
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
18
14
  (0, utils_1.assign)(dict, [originChainId, inputToken], []);
@@ -27,11 +23,8 @@ function updateBundleDepositsV3(dict, deposit) {
27
23
  }
28
24
  dict[originChainId][inputToken].push(deposit);
29
25
  }
30
- function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
26
+ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
31
27
  var _a, _b;
32
- if ((0, utils_1.chainIsEvm)(repaymentChainId) && !(0, utils_1.isValidEvmAddress)(repaymentAddress)) {
33
- return;
34
- }
35
28
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
36
29
  (0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
37
30
  fills: [],
@@ -40,22 +33,22 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
40
33
  refunds: {},
41
34
  });
42
35
  }
43
- var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
36
+ var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
44
37
  (0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
45
38
  var refundObj = dict[repaymentChainId][repaymentToken];
46
- var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
39
+ var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
47
40
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
48
- if (!(0, utils_1.isSlowFill)(bundleFill)) {
49
- var refundAmount = bundleFill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
41
+ if (!(0, utils_1.isSlowFill)(fill)) {
42
+ var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
50
43
  refundObj.totalRefundAmount = refundObj.totalRefundAmount
51
44
  ? refundObj.totalRefundAmount.add(refundAmount)
52
45
  : refundAmount;
53
46
  (_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
54
- if (refundObj.refunds[bundleFill.relayer]) {
55
- refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
47
+ if (refundObj.refunds[fill.relayer]) {
48
+ refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
56
49
  }
57
50
  else {
58
- refundObj.refunds[bundleFill.relayer] = refundAmount;
51
+ refundObj.refunds[fill.relayer] = refundAmount;
59
52
  }
60
53
  }
61
54
  }
@@ -153,7 +146,7 @@ var BundleDataClient = (function () {
153
146
  at: "BundleDataClient#loadPersistedDataFromArweave",
154
147
  message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
155
148
  blockRanges: JSON.stringify(blockRangesForChains),
156
- bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
149
+ bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
157
150
  });
158
151
  return [2, bundleData];
159
152
  }
@@ -195,107 +188,64 @@ var BundleDataClient = (function () {
195
188
  return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
196
189
  case 1:
197
190
  arweaveData = _a.sent();
198
- if (!(arweaveData === undefined)) return [3, 3];
199
- return [4, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
200
- case 2:
201
- combinedRefunds = _a.sent();
202
- return [3, 4];
203
- case 3:
204
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
205
- combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
206
- Object.keys(combinedRefunds).forEach(function (chainId) {
207
- if (_this.spokePoolClients[Number(chainId)] === undefined) {
208
- delete combinedRefunds[Number(chainId)];
209
- }
210
- });
211
- _a.label = 4;
212
- case 4: return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
191
+ if (arweaveData === undefined) {
192
+ combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
193
+ }
194
+ else {
195
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
196
+ combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
197
+ Object.keys(combinedRefunds).forEach(function (chainId) {
198
+ if (_this.spokePoolClients[Number(chainId)] === undefined) {
199
+ delete combinedRefunds[Number(chainId)];
200
+ }
201
+ });
202
+ }
203
+ return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
213
204
  }
214
205
  });
215
206
  });
216
207
  };
217
208
  BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
218
- return tslib_1.__awaiter(this, void 0, void 0, function () {
219
- var refundsForChain, _loop_1, this_1, _i, chainIds_1, chainId;
220
- var _this = this;
221
- return tslib_1.__generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0:
224
- refundsForChain = {};
225
- _loop_1 = function (chainId) {
226
- var chainIndex, fillsToCount;
227
- return tslib_1.__generator(this, function (_b) {
228
- switch (_b.label) {
229
- case 0:
230
- if (this_1.spokePoolClients[chainId] === undefined) {
231
- return [2, "continue"];
232
- }
233
- chainIndex = chainIds.indexOf(chainId);
234
- return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
235
- var matchingDeposit, hasMatchingDeposit, validRepayment;
236
- return tslib_1.__generator(this, function (_a) {
237
- switch (_a.label) {
238
- case 0:
239
- if (fill.blockNumber < blockRanges[chainIndex][0] ||
240
- fill.blockNumber > blockRanges[chainIndex][1] ||
241
- (0, utils_1.isZeroValueFillOrSlowFillRequest)(fill)) {
242
- return [2, false];
243
- }
244
- if (this.spokePoolClients[fill.originChainId] === undefined) {
245
- return [2, false];
246
- }
247
- matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
248
- hasMatchingDeposit = matchingDeposit !== undefined &&
249
- this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
250
- if (!hasMatchingDeposit) return [3, 2];
251
- return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
252
- .getChainIdIndicesForBlock(blockRanges[0][1])
253
- .filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
254
- case 1:
255
- validRepayment = _a.sent();
256
- if (!(0, utils_1.isDefined)(validRepayment)) {
257
- return [2, false];
258
- }
259
- _a.label = 2;
260
- case 2: return [2, hasMatchingDeposit];
261
- }
262
- });
263
- }); })];
264
- case 1:
265
- fillsToCount = _b.sent();
266
- fillsToCount.forEach(function (fill) {
267
- var _a, _b, _c;
268
- var _d;
269
- var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
270
- (0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
271
- var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
272
- var relayer = fill.relayer, refundAmount = fill.inputAmount;
273
- (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
274
- (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
275
- var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
276
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
277
- });
278
- return [2];
279
- }
280
- });
281
- };
282
- this_1 = this;
283
- _i = 0, chainIds_1 = chainIds;
284
- _a.label = 1;
285
- case 1:
286
- if (!(_i < chainIds_1.length)) return [3, 4];
287
- chainId = chainIds_1[_i];
288
- return [5, _loop_1(chainId)];
289
- case 2:
290
- _a.sent();
291
- _a.label = 3;
292
- case 3:
293
- _i++;
294
- return [3, 1];
295
- case 4: return [2, refundsForChain];
209
+ var _this = this;
210
+ var refundsForChain = {};
211
+ var _loop_1 = function (chainId) {
212
+ if (this_1.spokePoolClients[chainId] === undefined) {
213
+ return "continue";
214
+ }
215
+ var chainIndex = chainIds.indexOf(chainId);
216
+ this_1.spokePoolClients[chainId]
217
+ .getFills()
218
+ .filter(function (fill) {
219
+ if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
220
+ return false;
221
+ }
222
+ if (_this.spokePoolClients[fill.originChainId] === undefined) {
223
+ return false;
296
224
  }
225
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
226
+ var hasMatchingDeposit = matchingDeposit !== undefined &&
227
+ _this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
228
+ return hasMatchingDeposit;
229
+ })
230
+ .forEach(function (fill) {
231
+ var _a, _b, _c;
232
+ var _d;
233
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
234
+ (0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
235
+ var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
236
+ var relayer = fill.relayer, refundAmount = fill.inputAmount;
237
+ (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
238
+ (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
239
+ var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
240
+ refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
297
241
  });
298
- });
242
+ };
243
+ var this_1 = this;
244
+ for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
245
+ var chainId = chainIds_1[_i];
246
+ _loop_1(chainId);
247
+ }
248
+ return refundsForChain;
299
249
  };
300
250
  BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
301
251
  if (this.spokePoolClients[chainId] === undefined) {
@@ -367,39 +317,32 @@ var BundleDataClient = (function () {
367
317
  return [initialBlockRange[1] + 1, blockRange[1]];
368
318
  });
369
319
  }
370
- var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
371
- return tslib_1.__generator(this, function (_e) {
372
- switch (_e.label) {
320
+ var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
321
+ return tslib_1.__generator(this, function (_a) {
322
+ switch (_a.label) {
373
323
  case 0:
374
324
  hubPoolClient = this.clients.hubPoolClient;
375
325
  nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
376
326
  chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
377
327
  combinedRefunds = [];
378
328
  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));
379
- if (!hubPoolClient.hasPendingProposal()) return [3, 5];
329
+ if (!hubPoolClient.hasPendingProposal()) return [3, 2];
380
330
  pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
381
331
  return [4, this.loadArweaveData(pendingBundleBlockRanges)];
382
332
  case 1:
383
- arweaveData = _e.sent();
384
- if (!(arweaveData === undefined)) return [3, 3];
385
- _b = (_a = combinedRefunds).push;
386
- return [4, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
387
- case 2:
388
- _b.apply(_a, [_e.sent()]);
389
- return [3, 4];
390
- case 3:
391
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
392
- combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
393
- _e.label = 4;
394
- case 4:
333
+ arweaveData = _a.sent();
334
+ if (arweaveData === undefined) {
335
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
336
+ }
337
+ else {
338
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
339
+ combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
340
+ }
395
341
  widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
396
- _e.label = 5;
397
- case 5:
342
+ _a.label = 2;
343
+ case 2:
398
344
  start = performance.now();
399
- _d = (_c = combinedRefunds).push;
400
- return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
401
- case 6:
402
- _d.apply(_c, [_e.sent()]);
345
+ combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
403
346
  this.logger.debug({
404
347
  at: "BundleDataClient#getNextBundleRefunds",
405
348
  message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -530,7 +473,7 @@ var BundleDataClient = (function () {
530
473
  };
531
474
  BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
532
475
  return tslib_1.__awaiter(this, void 0, void 0, function () {
533
- 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;
476
+ 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;
534
477
  var _this = this;
535
478
  return tslib_1.__generator(this, function (_c) {
536
479
  switch (_c.label) {
@@ -550,7 +493,6 @@ var BundleDataClient = (function () {
550
493
  bundleDepositsV3 = {};
551
494
  bundleFillsV3 = {};
552
495
  bundleInvalidFillsV3 = [];
553
- bundleUnrepayableFillsV3 = [];
554
496
  bundleSlowFillsV3 = {};
555
497
  expiredDepositsToRefundV3 = {};
556
498
  unexecutableSlowFills = {};
@@ -599,13 +541,6 @@ var BundleDataClient = (function () {
599
541
  v3RelayHashes = {};
600
542
  bundleDepositHashes = [];
601
543
  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";
609
544
  depositCounter = 0;
610
545
  _loop_2 = function (originChainId) {
611
546
  var originClient = spokePoolClients[originChainId];
@@ -623,27 +558,20 @@ var BundleDataClient = (function () {
623
558
  var relayDataHash = _this.getRelayHashFromEvent(deposit);
624
559
  if (!v3RelayHashes[relayDataHash]) {
625
560
  v3RelayHashes[relayDataHash] = {
626
- deposits: [deposit],
561
+ deposit: deposit,
627
562
  fill: undefined,
628
563
  slowFillRequest: undefined,
629
564
  };
630
565
  }
631
- else {
632
- v3RelayHashes[relayDataHash].deposits.push(deposit);
633
- }
634
566
  if (deposit.inputAmount.eq(0)) {
635
567
  return;
636
568
  }
637
- var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
638
- var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
639
- (0, utils_1.assert)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
640
- decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
641
569
  if (deposit.blockNumber >= originChainBlockRange[0]) {
642
- bundleDepositHashes.push(newBundleDepositHash);
570
+ bundleDepositHashes.push(relayDataHash);
643
571
  updateBundleDepositsV3(bundleDepositsV3, deposit);
644
572
  }
645
573
  else if (deposit.blockNumber < originChainBlockRange[0]) {
646
- olderDepositHashes.push(newBundleDepositHash);
574
+ olderDepositHashes.push(relayDataHash);
647
575
  }
648
576
  });
649
577
  }
@@ -668,7 +596,7 @@ var BundleDataClient = (function () {
668
596
  case 0:
669
597
  originClient = spokePoolClients[originChainId];
670
598
  _loop_4 = function (destinationChainId) {
671
- var destinationClient, destinationChainBlockRange, originChainBlockRange, fastFillsReplacingSlowFills;
599
+ var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
672
600
  return tslib_1.__generator(this, function (_g) {
673
601
  switch (_g.label) {
674
602
  case 0:
@@ -677,90 +605,58 @@ var BundleDataClient = (function () {
677
605
  }
678
606
  destinationClient = spokePoolClients[destinationChainId];
679
607
  destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
680
- originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
681
608
  fastFillsReplacingSlowFills = [];
682
609
  return [4, (0, utils_1.forEachAsync)(destinationClient
683
610
  .getFillsForOriginChain(originChainId)
684
611
  .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 () {
685
- var relayDataHash, fillToRefund_1, duplicateDeposits, historicalDeposit, matchedDeposit, fillToRefund;
612
+ var relayDataHash, historicalDeposit, matchedDeposit;
686
613
  return tslib_1.__generator(this, function (_a) {
687
614
  switch (_a.label) {
688
615
  case 0:
689
- fillCounter++;
690
616
  relayDataHash = this.getRelayHashFromEvent(fill);
691
- if (!v3RelayHashes[relayDataHash]) return [3, 5];
692
- if (!!v3RelayHashes[relayDataHash].fill) return [3, 3];
693
- (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary.");
694
- v3RelayHashes[relayDataHash].fill = fill;
695
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
696
- return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
697
- case 1:
698
- fillToRefund_1 = _a.sent();
699
- if (!(0, utils_1.isDefined)(fillToRefund_1)) {
700
- bundleUnrepayableFillsV3.push(fill);
701
- }
702
- else {
703
- v3RelayHashes[relayDataHash].fill = fillToRefund_1;
704
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp }));
705
- duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
706
- duplicateDeposits.forEach(function (duplicateDeposit) {
707
- if ((0, utils_1.isSlowFill)(fill)) {
708
- updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
709
- }
710
- else {
711
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
617
+ fillCounter++;
618
+ if (v3RelayHashes[relayDataHash]) {
619
+ if (!v3RelayHashes[relayDataHash].fill) {
620
+ (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
621
+ v3RelayHashes[relayDataHash].fill = fill;
622
+ if (fill.blockNumber >= destinationChainBlockRange[0]) {
623
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
624
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
625
+ _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
626
+ fastFillsReplacingSlowFills.push(relayDataHash);
627
+ }
712
628
  }
713
- });
714
- }
715
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
716
- _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
717
- fastFillsReplacingSlowFills.push(relayDataHash);
629
+ }
630
+ return [2];
718
631
  }
719
- _a.label = 2;
720
- case 2: return [3, 4];
721
- case 3: throw new Error("Duplicate fill detected");
722
- case 4: return [2];
723
- case 5:
724
632
  v3RelayHashes[relayDataHash] = {
725
- deposits: undefined,
633
+ deposit: undefined,
726
634
  fill: fill,
727
635
  slowFillRequest: undefined,
728
636
  };
729
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 9];
637
+ if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
730
638
  if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
731
639
  bundleInvalidFillsV3.push(fill);
732
640
  return [2];
733
641
  }
734
642
  return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
735
- case 6:
643
+ case 1:
736
644
  historicalDeposit = _a.sent();
737
- if (!!historicalDeposit.found) return [3, 7];
738
- bundleInvalidFillsV3.push(fill);
739
- return [3, 9];
740
- case 7:
741
- matchedDeposit = historicalDeposit.deposit;
742
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
645
+ if (!historicalDeposit.found) {
743
646
  bundleInvalidFillsV3.push(fill);
744
- return [2];
745
- }
746
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
747
- return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
748
- case 8:
749
- fillToRefund = _a.sent();
750
- if (!(0, utils_1.isDefined)(fillToRefund)) {
751
- bundleUnrepayableFillsV3.push(fill);
752
647
  }
753
648
  else {
649
+ matchedDeposit = historicalDeposit.deposit;
754
650
  (0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
755
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
756
- v3RelayHashes[relayDataHash].fill = fillToRefund;
757
- }
758
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
759
- _canCreateSlowFillLeaf(matchedDeposit)) {
760
- fastFillsReplacingSlowFills.push(relayDataHash);
651
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
652
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
653
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
654
+ _canCreateSlowFillLeaf(matchedDeposit)) {
655
+ fastFillsReplacingSlowFills.push(relayDataHash);
656
+ }
761
657
  }
762
- _a.label = 9;
763
- case 9: return [2];
658
+ _a.label = 2;
659
+ case 2: return [2];
764
660
  }
765
661
  });
766
662
  }); })];
@@ -782,26 +678,23 @@ var BundleDataClient = (function () {
782
678
  if (v3RelayHashes[relayDataHash].fill) {
783
679
  return [2];
784
680
  }
785
- (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary.");
786
- matchedDeposit = v3RelayHashes[relayDataHash].deposits[0];
681
+ (0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
682
+ matchedDeposit = v3RelayHashes[relayDataHash].deposit;
787
683
  if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
788
684
  _canCreateSlowFillLeaf(matchedDeposit) &&
789
685
  !_depositIsExpired(matchedDeposit)) {
790
686
  validatedBundleSlowFills.push(matchedDeposit);
791
687
  }
792
688
  }
793
- else {
794
- throw new Error("Duplicate slow fill request detected.");
795
- }
796
689
  return [2];
797
690
  }
798
691
  v3RelayHashes[relayDataHash] = {
799
- deposits: undefined,
692
+ deposit: undefined,
800
693
  fill: undefined,
801
694
  slowFillRequest: slowFillRequest,
802
695
  };
803
- if (!(exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline) &&
804
- slowFillRequest.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
696
+ if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
697
+ exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3, 2];
805
698
  return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
806
699
  case 1:
807
700
  historicalDeposit = _a.sent();
@@ -809,11 +702,8 @@ var BundleDataClient = (function () {
809
702
  return [2];
810
703
  }
811
704
  matchedDeposit = historicalDeposit.deposit;
812
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
813
- return [2];
814
- }
815
705
  (0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
816
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
706
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
817
707
  if (!_canCreateSlowFillLeaf(matchedDeposit) ||
818
708
  _depositIsExpired(matchedDeposit)) {
819
709
  return [2];
@@ -826,30 +716,26 @@ var BundleDataClient = (function () {
826
716
  }); })];
827
717
  case 2:
828
718
  _g.sent();
829
- return [4, (0, utils_1.mapAsync)(bundleDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
830
- var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, fillStatus, prefill, verifiedFill;
831
- return tslib_1.__generator(this, function (_c) {
832
- switch (_c.label) {
719
+ originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
720
+ return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
721
+ var deposit = v3RelayHashes[depositHash].deposit;
722
+ return (deposit &&
723
+ deposit.originChainId === originChainId &&
724
+ deposit.destinationChainId === destinationChainId &&
725
+ deposit.blockNumber >= originBlockRange[0] &&
726
+ deposit.blockNumber <= originBlockRange[1] &&
727
+ !(0, utils_1.isZeroValueDeposit)(deposit));
728
+ }), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
729
+ var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
730
+ return tslib_1.__generator(this, function (_b) {
731
+ switch (_b.label) {
833
732
  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];
733
+ _a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
840
734
  if (!deposit)
841
735
  throw new Error("Deposit should exist in relay hash dictionary.");
842
- if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
843
- return [2];
844
- }
845
736
  if (fill) {
846
- if (canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0]) {
847
- if (!(0, utils_1.isSlowFill)(fill)) {
848
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
849
- }
850
- else {
851
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
852
- }
737
+ if (fill.blockNumber < destinationChainBlockRange[0] && !(0, utils_1.isSlowFill)(fill)) {
738
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
853
739
  }
854
740
  return [2];
855
741
  }
@@ -857,8 +743,7 @@ var BundleDataClient = (function () {
857
743
  if (_depositIsExpired(deposit)) {
858
744
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
859
745
  }
860
- else if (canRefundPrefills &&
861
- slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
746
+ else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
862
747
  _canCreateSlowFillLeaf(deposit)) {
863
748
  validatedBundleSlowFills.push(deposit);
864
749
  }
@@ -866,55 +751,42 @@ var BundleDataClient = (function () {
866
751
  }
867
752
  return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
868
753
  case 1:
869
- fillStatus = _c.sent();
870
- if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 5];
871
- return [4, this.findMatchingFillEvent(deposit, destinationClient)];
754
+ fillStatus = _b.sent();
755
+ if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
756
+ return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
872
757
  case 2:
873
- prefill = _c.sent();
874
- (0, utils_1.assert)((0, utils_1.isDefined)(prefill), "findFillEvent# Cannot find prefill: ".concat(relayDataHash));
875
- (0, utils_1.assert)(this.getRelayHashFromEvent(prefill) === relayDataHash, "Relay hashes should match.");
876
- if (!canRefundPrefills) return [3, 4];
877
- return [4, (0, utils_2.verifyFillRepayment)(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
878
- case 3:
879
- verifiedFill = _c.sent();
880
- if (!(0, utils_1.isDefined)(verifiedFill)) {
881
- bundleUnrepayableFillsV3.push(prefill);
882
- }
883
- else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
884
- validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
885
- }
886
- else {
887
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
758
+ prefill = (_b.sent());
759
+ if (!(0, utils_1.isSlowFill)(prefill)) {
760
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
888
761
  }
889
- _c.label = 4;
890
- case 4: return [3, 6];
891
- case 5:
762
+ return [3, 4];
763
+ case 3:
892
764
  if (_depositIsExpired(deposit)) {
893
765
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
894
766
  }
895
767
  else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
896
- if (canRefundPrefills && _canCreateSlowFillLeaf(deposit)) {
768
+ if (_canCreateSlowFillLeaf(deposit)) {
897
769
  validatedBundleSlowFills.push(deposit);
898
770
  }
899
771
  }
900
- _c.label = 6;
901
- case 6: return [2];
772
+ _b.label = 4;
773
+ case 4: return [2];
902
774
  }
903
775
  });
904
776
  }); })];
905
777
  case 3:
906
778
  _g.sent();
907
779
  fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
908
- var _a = v3RelayHashes[relayDataHash], deposits = _a.deposits, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
780
+ var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
909
781
  (0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
910
- if (!deposits || deposits.length < 1) {
782
+ if (!deposit) {
911
783
  throw new Error("Deposit should exist in relay hash dictionary.");
912
784
  }
913
- (0, utils_1.assert)(_canCreateSlowFillLeaf(deposits[0]), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
785
+ (0, utils_1.assert)(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
914
786
  var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
915
787
  if (!slowFillRequest ||
916
788
  slowFillRequest.blockNumber < destinationBlockRange[0]) {
917
- validatedBundleUnexecutableSlowFills.push(deposits[0]);
789
+ validatedBundleUnexecutableSlowFills.push(deposit);
918
790
  }
919
791
  });
920
792
  return [2];
@@ -955,17 +827,13 @@ var BundleDataClient = (function () {
955
827
  message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
956
828
  });
957
829
  start = performance.now();
958
- return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
959
- var _a, relayDataHash, index, _b, deposits, slowFillRequest, fill, deposit, destinationChainId, destinationBlockRange, fillStatus;
960
- return tslib_1.__generator(this, function (_c) {
961
- switch (_c.label) {
830
+ return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
831
+ var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
832
+ return tslib_1.__generator(this, function (_b) {
833
+ switch (_b.label) {
962
834
  case 0:
963
- _a = decodeBundleDepositHash(depositHash), relayDataHash = _a.relayDataHash, index = _a.index;
964
- _b = v3RelayHashes[relayDataHash], deposits = _b.deposits, slowFillRequest = _b.slowFillRequest, fill = _b.fill;
965
- if (!deposits || deposits.length < 1) {
966
- throw new Error("Deposit should exist in relay hash dictionary.");
967
- }
968
- deposit = deposits[index];
835
+ _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
836
+ (0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
969
837
  destinationChainId = deposit.destinationChainId;
970
838
  destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
971
839
  if (!(!fill &&
@@ -975,7 +843,7 @@ var BundleDataClient = (function () {
975
843
  spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
976
844
  return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
977
845
  case 1:
978
- fillStatus = _c.sent();
846
+ fillStatus = _b.sent();
979
847
  if (fillStatus !== interfaces_1.FillStatus.Filled) {
980
848
  updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
981
849
  }
@@ -985,7 +853,7 @@ var BundleDataClient = (function () {
985
853
  if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
986
854
  validatedBundleUnexecutableSlowFills.push(deposit);
987
855
  }
988
- _c.label = 2;
856
+ _b.label = 2;
989
857
  case 2: return [2];
990
858
  }
991
859
  });
@@ -996,7 +864,7 @@ var BundleDataClient = (function () {
996
864
  promises = [
997
865
  validatedBundleV3Fills.length > 0
998
866
  ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
999
- var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposits[0];
867
+ var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1000
868
  (0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
1001
869
  var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
1002
870
  return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
@@ -1023,18 +891,14 @@ var BundleDataClient = (function () {
1023
891
  v3FillLpFees.forEach(function (_a, idx) {
1024
892
  var realizedLpFeePct = _a.realizedLpFeePct;
1025
893
  var fill = validatedBundleV3Fills[idx];
1026
- var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposits[0];
894
+ var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1027
895
  (0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
1028
896
  var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
1029
- updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
897
+ updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
1030
898
  });
1031
899
  v3SlowFillLpFees.forEach(function (_a, idx) {
1032
900
  var lpFeePct = _a.realizedLpFeePct;
1033
901
  var deposit = validatedBundleSlowFills[idx];
1034
- var relayDataHash = _this.getRelayHashFromEvent(deposit);
1035
- if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
1036
- return;
1037
- }
1038
902
  updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
1039
903
  });
1040
904
  v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
@@ -1042,7 +906,7 @@ var BundleDataClient = (function () {
1042
906
  var deposit = validatedBundleUnexecutableSlowFills[idx];
1043
907
  updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
1044
908
  });
1045
- v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
909
+ v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
1046
910
  if (bundleInvalidFillsV3.length > 0) {
1047
911
  this.logger.debug({
1048
912
  at: "BundleDataClient#loadData",
@@ -1051,14 +915,6 @@ var BundleDataClient = (function () {
1051
915
  bundleInvalidFillsV3: bundleInvalidFillsV3,
1052
916
  });
1053
917
  }
1054
- if (bundleUnrepayableFillsV3.length > 0) {
1055
- this.logger.debug({
1056
- at: "BundleDataClient#loadData",
1057
- message: "Finished loading V3 spoke pool data and found some unrepayable V3 fills in range",
1058
- blockRangesForChains: blockRangesForChains,
1059
- bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
1060
- });
1061
- }
1062
918
  this.logger.debug({
1063
919
  at: "BundleDataClient#loadDataFromScratch",
1064
920
  message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -1077,17 +933,7 @@ var BundleDataClient = (function () {
1077
933
  });
1078
934
  };
1079
935
  BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
1080
- 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);
1081
- };
1082
- BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
1083
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1084
- return tslib_1.__generator(this, function (_a) {
1085
- switch (_a.label) {
1086
- case 0: return [4, (0, utils_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
1087
- case 1: return [2, _a.sent()];
1088
- }
1089
- });
1090
- });
936
+ 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);
1091
937
  };
1092
938
  BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
1093
939
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -1098,7 +944,7 @@ var BundleDataClient = (function () {
1098
944
  case 0:
1099
945
  _b = (_a = Object).fromEntries;
1100
946
  return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1101
- var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, _endTime, _b, endBlockDelta, endTime;
947
+ var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
1102
948
  return tslib_1.__generator(this, function (_c) {
1103
949
  switch (_c.label) {
1104
950
  case 0:
@@ -1112,7 +958,7 @@ var BundleDataClient = (function () {
1112
958
  return [2];
1113
959
  }
1114
960
  startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
1115
- endBlockForChain = Math.min(_endBlockForChain + 1, spokePoolClient.latestBlockSearched);
961
+ endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
1116
962
  return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
1117
963
  case 1:
1118
964
  _b = [
@@ -1122,10 +968,8 @@ var BundleDataClient = (function () {
1122
968
  case 2:
1123
969
  _a = _b.concat([
1124
970
  _c.sent()
1125
- ]), startTime = _a[0], _endTime = _a[1];
1126
- endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
1127
- endTime = Math.max(0, _endTime - endBlockDelta);
1128
- (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, "."));
971
+ ]), startTime = _a[0], endTime = _a[1];
972
+ (0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
1129
973
  (0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
1130
974
  return [2, [chainId, [startTime, endTime]]];
1131
975
  }