@across-protocol/sdk 3.4.14 → 3.4.16

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 (67) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +179 -111
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
  5. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +33 -1
  6. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  7. package/dist/cjs/providers/index.d.ts +1 -0
  8. package/dist/cjs/providers/index.js +2 -0
  9. package/dist/cjs/providers/index.js.map +1 -1
  10. package/dist/cjs/providers/mockProvider.d.ts +19 -0
  11. package/dist/cjs/providers/mockProvider.js +70 -0
  12. package/dist/cjs/providers/mockProvider.js.map +1 -0
  13. package/dist/cjs/utils/AddressUtils.d.ts +1 -0
  14. package/dist/cjs/utils/AddressUtils.js +14 -1
  15. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  16. package/dist/cjs/utils/DepositUtils.d.ts +2 -1
  17. package/dist/cjs/utils/DepositUtils.js +9 -0
  18. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  19. package/dist/cjs/utils/NetworkUtils.d.ts +1 -0
  20. package/dist/cjs/utils/NetworkUtils.js +6 -1
  21. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  22. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
  23. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +213 -137
  24. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  25. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
  26. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +42 -1
  27. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  28. package/dist/esm/providers/index.d.ts +1 -0
  29. package/dist/esm/providers/index.js +2 -0
  30. package/dist/esm/providers/index.js.map +1 -1
  31. package/dist/esm/providers/mockProvider.d.ts +23 -0
  32. package/dist/esm/providers/mockProvider.js +73 -0
  33. package/dist/esm/providers/mockProvider.js.map +1 -0
  34. package/dist/esm/utils/AddressUtils.d.ts +1 -0
  35. package/dist/esm/utils/AddressUtils.js +16 -0
  36. package/dist/esm/utils/AddressUtils.js.map +1 -1
  37. package/dist/esm/utils/DepositUtils.d.ts +2 -1
  38. package/dist/esm/utils/DepositUtils.js +9 -0
  39. package/dist/esm/utils/DepositUtils.js.map +1 -1
  40. package/dist/esm/utils/NetworkUtils.d.ts +6 -0
  41. package/dist/esm/utils/NetworkUtils.js +10 -0
  42. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  43. package/dist/esm/utils/SpokeUtils.js +1 -1
  44. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  45. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
  46. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  47. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
  48. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  49. package/dist/types/providers/index.d.ts +1 -0
  50. package/dist/types/providers/index.d.ts.map +1 -1
  51. package/dist/types/providers/mockProvider.d.ts +24 -0
  52. package/dist/types/providers/mockProvider.d.ts.map +1 -0
  53. package/dist/types/utils/AddressUtils.d.ts +1 -0
  54. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  55. package/dist/types/utils/DepositUtils.d.ts +2 -1
  56. package/dist/types/utils/DepositUtils.d.ts.map +1 -1
  57. package/dist/types/utils/NetworkUtils.d.ts +6 -0
  58. package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
  59. package/package.json +1 -1
  60. package/src/clients/BundleDataClient/BundleDataClient.ts +109 -57
  61. package/src/clients/BundleDataClient/utils/FillUtils.ts +47 -2
  62. package/src/providers/index.ts +1 -0
  63. package/src/providers/mockProvider.ts +77 -0
  64. package/src/utils/AddressUtils.ts +16 -0
  65. package/src/utils/DepositUtils.ts +9 -0
  66. package/src/utils/NetworkUtils.ts +11 -0
  67. package/src/utils/SpokeUtils.ts +1 -1
@@ -1,13 +1,17 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  import _ from "lodash";
3
3
  import { FillType, FillStatus, } from "../../interfaces";
4
- import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, } from "../../utils";
5
- import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, } from "./utils";
4
+ import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, filterAsync, bnUint32Max, isZeroValueDeposit, chainIsEvm, isValidEvmAddress, } from "../../utils";
5
+ import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, verifyFillRepayment, } from "./utils";
6
6
  // max(uint256) - 1
7
7
  export var INFINITE_FILL_DEADLINE = bnUint32Max;
8
8
  // V3 dictionary helper functions
9
9
  function updateExpiredDepositsV3(dict, deposit) {
10
10
  var _a;
11
+ // A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
12
+ if (chainIsEvm(deposit.originChainId) && !isValidEvmAddress(deposit.depositor)) {
13
+ return;
14
+ }
11
15
  var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
12
16
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
13
17
  assign(dict, [originChainId, inputToken], []);
@@ -22,8 +26,12 @@ function updateBundleDepositsV3(dict, deposit) {
22
26
  }
23
27
  dict[originChainId][inputToken].push(deposit);
24
28
  }
25
- function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
29
+ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
26
30
  var _a, _b;
31
+ // It is impossible to refund a deposit if the repayment chain is EVM and the relayer is a non-evm address.
32
+ if (chainIsEvm(repaymentChainId) && !isValidEvmAddress(repaymentAddress)) {
33
+ return;
34
+ }
27
35
  if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
28
36
  assign(dict, [repaymentChainId, repaymentToken], {
29
37
  fills: [],
@@ -32,26 +40,26 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
32
40
  refunds: {},
33
41
  });
34
42
  }
35
- var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct });
43
+ var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
36
44
  // Add all fills, slow and fast, to dictionary.
37
45
  assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
38
46
  // All fills update the bundle LP fees.
39
47
  var refundObj = dict[repaymentChainId][repaymentToken];
40
- var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
48
+ var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
41
49
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
42
50
  // Only fast fills get refunded.
43
- if (!isSlowFill(fill)) {
44
- var refundAmount = fill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
51
+ if (!isSlowFill(bundleFill)) {
52
+ var refundAmount = bundleFill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
45
53
  refundObj.totalRefundAmount = refundObj.totalRefundAmount
46
54
  ? refundObj.totalRefundAmount.add(refundAmount)
47
55
  : refundAmount;
48
56
  // Instantiate dictionary if it doesn't exist.
49
57
  (_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
50
- if (refundObj.refunds[fill.relayer]) {
51
- refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
58
+ if (refundObj.refunds[bundleFill.relayer]) {
59
+ refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
52
60
  }
53
61
  else {
54
- refundObj.refunds[fill.relayer] = refundAmount;
62
+ refundObj.refunds[bundleFill.relayer] = refundAmount;
55
63
  }
56
64
  }
57
65
  }
@@ -209,77 +217,122 @@ var BundleDataClient = /** @class */ (function () {
209
217
  return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
210
218
  case 1:
211
219
  arweaveData = _a.sent();
212
- if (arweaveData === undefined) {
213
- combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
214
- }
215
- else {
216
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
217
- combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
218
- // If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
219
- // chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
220
- // a reasonable assumption. This empty refund chain also matches what the alternative
221
- // `getApproximateRefundsForBlockRange` would return.
222
- Object.keys(combinedRefunds).forEach(function (chainId) {
223
- if (_this.spokePoolClients[Number(chainId)] === undefined) {
224
- delete combinedRefunds[Number(chainId)];
225
- }
226
- });
227
- }
228
- // The latest proposed bundle's refund leaves might have already been partially or entirely executed.
229
- // We have to deduct the executed amounts from the total refund amounts.
230
- return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
220
+ if (!(arweaveData === undefined)) return [3 /*break*/, 3];
221
+ return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
222
+ case 2:
223
+ combinedRefunds = _a.sent();
224
+ return [3 /*break*/, 4];
225
+ case 3:
226
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
227
+ combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
228
+ // If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
229
+ // chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
230
+ // a reasonable assumption. This empty refund chain also matches what the alternative
231
+ // `getApproximateRefundsForBlockRange` would return.
232
+ Object.keys(combinedRefunds).forEach(function (chainId) {
233
+ if (_this.spokePoolClients[Number(chainId)] === undefined) {
234
+ delete combinedRefunds[Number(chainId)];
235
+ }
236
+ });
237
+ _a.label = 4;
238
+ case 4:
239
+ // The latest proposed bundle's refund leaves might have already been partially or entirely executed.
240
+ // We have to deduct the executed amounts from the total refund amounts.
241
+ return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
231
242
  }
232
243
  });
233
244
  });
234
245
  };
235
246
  // @dev This helper function should probably be moved to the InventoryClient
236
247
  BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
237
- var _this = this;
238
- var refundsForChain = {};
239
- var _loop_1 = function (chainId) {
240
- if (this_1.spokePoolClients[chainId] === undefined) {
241
- return "continue";
242
- }
243
- var chainIndex = chainIds.indexOf(chainId);
244
- this_1.spokePoolClients[chainId]
245
- .getFills()
246
- .filter(function (fill) {
247
- if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
248
- return false;
249
- }
250
- // If origin spoke pool client isn't defined, we can't validate it.
251
- if (_this.spokePoolClients[fill.originChainId] === undefined) {
252
- return false;
248
+ return __awaiter(this, void 0, void 0, function () {
249
+ var refundsForChain, _loop_1, this_1, _i, chainIds_1, chainId;
250
+ var _this = this;
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0:
254
+ refundsForChain = {};
255
+ _loop_1 = function (chainId) {
256
+ var chainIndex, fillsToCount;
257
+ return __generator(this, function (_b) {
258
+ switch (_b.label) {
259
+ case 0:
260
+ if (this_1.spokePoolClients[chainId] === undefined) {
261
+ return [2 /*return*/, "continue"];
262
+ }
263
+ chainIndex = chainIds.indexOf(chainId);
264
+ return [4 /*yield*/, filterAsync(this_1.spokePoolClients[chainId].getFills(), function (fill) { return __awaiter(_this, void 0, void 0, function () {
265
+ var matchingDeposit, hasMatchingDeposit, validRepayment;
266
+ return __generator(this, function (_a) {
267
+ switch (_a.label) {
268
+ case 0:
269
+ if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
270
+ return [2 /*return*/, false];
271
+ }
272
+ // If origin spoke pool client isn't defined, we can't validate it.
273
+ if (this.spokePoolClients[fill.originChainId] === undefined) {
274
+ return [2 /*return*/, false];
275
+ }
276
+ matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
277
+ hasMatchingDeposit = matchingDeposit !== undefined &&
278
+ this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
279
+ if (!hasMatchingDeposit) return [3 /*break*/, 2];
280
+ return [4 /*yield*/, verifyFillRepayment(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit,
281
+ // @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
282
+ // disabled block ranges.
283
+ this.clients.configStoreClient
284
+ .getChainIdIndicesForBlock(blockRanges[0][1])
285
+ .filter(function (_chainId, i) { return !isChainDisabled(blockRanges[i]); }))];
286
+ case 1:
287
+ validRepayment = _a.sent();
288
+ if (!isDefined(validRepayment)) {
289
+ return [2 /*return*/, false];
290
+ }
291
+ _a.label = 2;
292
+ case 2: return [2 /*return*/, hasMatchingDeposit];
293
+ }
294
+ });
295
+ }); })];
296
+ case 1:
297
+ fillsToCount = _b.sent();
298
+ fillsToCount.forEach(function (fill) {
299
+ var _a, _b, _c;
300
+ var _d;
301
+ var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
302
+ assert(isDefined(matchingDeposit), "Deposit not found for fill.");
303
+ var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
304
+ ), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
305
+ // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
306
+ // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
307
+ // in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
308
+ // worst from the relayer's perspective.
309
+ var relayer = fill.relayer, refundAmount = fill.inputAmount;
310
+ (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
311
+ (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
312
+ var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
313
+ refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
314
+ });
315
+ return [2 /*return*/];
316
+ }
317
+ });
318
+ };
319
+ this_1 = this;
320
+ _i = 0, chainIds_1 = chainIds;
321
+ _a.label = 1;
322
+ case 1:
323
+ if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
324
+ chainId = chainIds_1[_i];
325
+ return [5 /*yield**/, _loop_1(chainId)];
326
+ case 2:
327
+ _a.sent();
328
+ _a.label = 3;
329
+ case 3:
330
+ _i++;
331
+ return [3 /*break*/, 1];
332
+ case 4: return [2 /*return*/, refundsForChain];
253
333
  }
254
- var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
255
- var hasMatchingDeposit = matchingDeposit !== undefined &&
256
- _this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
257
- return hasMatchingDeposit;
258
- })
259
- .forEach(function (fill) {
260
- var _a, _b, _c;
261
- var _d;
262
- var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
263
- assert(isDefined(matchingDeposit), "Deposit not found for fill.");
264
- var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
265
- ), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
266
- // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
267
- // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
268
- // in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
269
- // worst from the relayer's perspective.
270
- var relayer = fill.relayer, refundAmount = fill.inputAmount;
271
- (_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
272
- (_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
273
- var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
274
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
275
334
  });
276
- };
277
- var this_1 = this;
278
- for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
279
- var chainId = chainIds_1[_i];
280
- _loop_1(chainId);
281
- }
282
- return refundsForChain;
335
+ });
283
336
  };
284
337
  BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
285
338
  if (this.spokePoolClients[chainId] === undefined) {
@@ -371,33 +424,40 @@ var BundleDataClient = /** @class */ (function () {
371
424
  return [initialBlockRange[1] + 1, blockRange[1]];
372
425
  });
373
426
  }
374
- var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
375
- return __generator(this, function (_a) {
376
- switch (_a.label) {
427
+ var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
428
+ return __generator(this, function (_e) {
429
+ switch (_e.label) {
377
430
  case 0:
378
431
  hubPoolClient = this.clients.hubPoolClient;
379
432
  nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
380
433
  chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
381
434
  combinedRefunds = [];
382
435
  widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
383
- if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
436
+ if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 5];
384
437
  pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
385
438
  return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
386
439
  case 1:
387
- arweaveData = _a.sent();
388
- if (arweaveData === undefined) {
389
- combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
390
- }
391
- else {
392
- bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
393
- combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
394
- }
440
+ arweaveData = _e.sent();
441
+ if (!(arweaveData === undefined)) return [3 /*break*/, 3];
442
+ _b = (_a = combinedRefunds).push;
443
+ return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
444
+ case 2:
445
+ _b.apply(_a, [_e.sent()]);
446
+ return [3 /*break*/, 4];
447
+ case 3:
448
+ bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
449
+ combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
450
+ _e.label = 4;
451
+ case 4:
395
452
  // Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
396
453
  widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
397
- _a.label = 2;
398
- case 2:
454
+ _e.label = 5;
455
+ case 5:
399
456
  start = performance.now();
400
- combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
457
+ _d = (_c = combinedRefunds).push;
458
+ return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
459
+ case 6:
460
+ _d.apply(_c, [_e.sent()]);
401
461
  this.logger.debug({
402
462
  at: "BundleDataClient#getNextBundleRefunds",
403
463
  message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
@@ -632,6 +692,8 @@ var BundleDataClient = /** @class */ (function () {
632
692
  }
633
693
  // If deposit block is within origin chain bundle block range, then save as bundle deposit.
634
694
  // If deposit is in bundle and it has expired, additionally save it as an expired deposit.
695
+ // Note: if the `depositor` field in the expired deposit is an invalid address, e.g. a bytes32 address on an EVM
696
+ // chain, then the deposit refund is invalid and ignored.
635
697
  // If deposit is not in the bundle block range, then save it as an older deposit that
636
698
  // may have expired.
637
699
  if (deposit.blockNumber >= originChainBlockRange[0] && deposit.blockNumber <= originChainBlockRange[1]) {
@@ -690,73 +752,87 @@ var BundleDataClient = /** @class */ (function () {
690
752
  // We can remove fills for deposits with input amount equal to zero because these will result in 0 refunded
691
753
  // tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
692
754
  // request for the deposit, we'd want to see the fill took place.
693
- .filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueDeposit(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
694
- var relayDataHash, historicalDeposit, matchedDeposit;
755
+ .filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueDeposit(fill); }), function (_fill) { return __awaiter(_this, void 0, void 0, function () {
756
+ var relayDataHash, fill, historicalDeposit, matchedDeposit, fill;
695
757
  return __generator(this, function (_a) {
696
758
  switch (_a.label) {
697
759
  case 0:
698
- relayDataHash = this.getRelayHashFromEvent(fill);
699
760
  fillCounter++;
700
- if (v3RelayHashes[relayDataHash]) {
701
- if (!v3RelayHashes[relayDataHash].fill) {
702
- assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
703
- // At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
704
- // so this fill is validated.
705
- v3RelayHashes[relayDataHash].fill = fill;
706
- if (fill.blockNumber >= destinationChainBlockRange[0]) {
707
- validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
708
- // If fill replaced a slow fill request, then mark it as one that might have created an
709
- // unexecutable slow fill. We can't know for sure until we check the slow fill request
710
- // events.
711
- // slow fill requests for deposits from or to lite chains are considered invalid
712
- if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
713
- !v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
714
- !v3RelayHashes[relayDataHash].deposit.toLiteChain) {
715
- fastFillsReplacingSlowFills.push(relayDataHash);
716
- }
717
- }
718
- }
761
+ relayDataHash = this.getRelayHashFromEvent(_fill);
762
+ if (!v3RelayHashes[relayDataHash]) return [3 /*break*/, 3];
763
+ if (!!v3RelayHashes[relayDataHash].fill) return [3 /*break*/, 2];
764
+ assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
765
+ return [4 /*yield*/, verifyFillRepayment(_fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposit, allChainIds)];
766
+ case 1:
767
+ fill = _a.sent();
768
+ if (!isDefined(fill)) {
769
+ bundleInvalidFillsV3.push(_fill);
719
770
  return [2 /*return*/];
720
771
  }
772
+ // At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
773
+ // so this fill is validated.
774
+ v3RelayHashes[relayDataHash].fill = fill;
775
+ if (fill.blockNumber >= destinationChainBlockRange[0]) {
776
+ validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
777
+ // If fill replaced a slow fill request, then mark it as one that might have created an
778
+ // unexecutable slow fill. We can't know for sure until we check the slow fill request
779
+ // events.
780
+ // slow fill requests for deposits from or to lite chains are considered invalid
781
+ if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
782
+ !v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
783
+ !v3RelayHashes[relayDataHash].deposit.toLiteChain) {
784
+ fastFillsReplacingSlowFills.push(relayDataHash);
785
+ }
786
+ }
787
+ _a.label = 2;
788
+ case 2: return [2 /*return*/];
789
+ case 3:
721
790
  // At this point, there is no relay hash dictionary entry for this fill, so we need to
722
- // instantiate the entry.
791
+ // instantiate the entry. We won't modify the fill.relayer until we match it with a deposit.
723
792
  v3RelayHashes[relayDataHash] = {
724
793
  deposit: undefined,
725
- fill: fill,
794
+ fill: _fill,
726
795
  slowFillRequest: undefined,
727
796
  };
728
- if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
797
+ if (!(_fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 7];
729
798
  // Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
730
799
  // to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
731
800
  // skip the historical query.
732
- if (!INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
733
- bundleInvalidFillsV3.push(fill);
801
+ if (!INFINITE_FILL_DEADLINE.eq(_fill.fillDeadline)) {
802
+ bundleInvalidFillsV3.push(_fill);
734
803
  return [2 /*return*/];
735
804
  }
736
- return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
737
- case 1:
805
+ return [4 /*yield*/, queryHistoricalDepositForFill(originClient, _fill)];
806
+ case 4:
738
807
  historicalDeposit = _a.sent();
739
- if (!historicalDeposit.found) {
740
- bundleInvalidFillsV3.push(fill);
808
+ if (!!historicalDeposit.found) return [3 /*break*/, 5];
809
+ bundleInvalidFillsV3.push(_fill);
810
+ return [3 /*break*/, 7];
811
+ case 5:
812
+ matchedDeposit = historicalDeposit.deposit;
813
+ return [4 /*yield*/, verifyFillRepayment(_fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
814
+ case 6:
815
+ fill = _a.sent();
816
+ if (!isDefined(fill)) {
817
+ bundleInvalidFillsV3.push(_fill);
818
+ return [2 /*return*/];
741
819
  }
742
- else {
743
- matchedDeposit = historicalDeposit.deposit;
744
- // @dev Since queryHistoricalDepositForFill validates the fill by checking individual
745
- // object property values against the deposit's, we
746
- // sanity check it here by comparing the full relay hashes. If there's an error here then the
747
- // historical deposit query is not working as expected.
748
- assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
749
- validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
750
- v3RelayHashes[relayDataHash].deposit = matchedDeposit;
751
- // slow fill requests for deposits from or to lite chains are considered invalid
752
- if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
753
- !matchedDeposit.fromLiteChain &&
754
- !matchedDeposit.toLiteChain) {
755
- fastFillsReplacingSlowFills.push(relayDataHash);
756
- }
820
+ v3RelayHashes[relayDataHash].fill = fill;
821
+ // @dev Since queryHistoricalDepositForFill validates the fill by checking individual
822
+ // object property values against the deposit's, we
823
+ // sanity check it here by comparing the full relay hashes. If there's an error here then the
824
+ // historical deposit query is not working as expected.
825
+ assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
826
+ validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
827
+ v3RelayHashes[relayDataHash].deposit = matchedDeposit;
828
+ // slow fill requests for deposits from or to lite chains are considered invalid
829
+ if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
830
+ !matchedDeposit.fromLiteChain &&
831
+ !matchedDeposit.toLiteChain) {
832
+ fastFillsReplacingSlowFills.push(relayDataHash);
757
833
  }
758
- _a.label = 2;
759
- case 2: return [2 /*return*/];
834
+ _a.label = 7;
835
+ case 7: return [2 /*return*/];
760
836
  }
761
837
  });
762
838
  }); })];
@@ -1025,7 +1101,7 @@ var BundleDataClient = /** @class */ (function () {
1025
1101
  var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
1026
1102
  assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
1027
1103
  var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
1028
- updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
1104
+ updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
1029
1105
  });
1030
1106
  v3SlowFillLpFees.forEach(function (_a, idx) {
1031
1107
  var lpFeePct = _a.realizedLpFeePct;