@across-protocol/sdk 3.4.15 → 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.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +174 -123
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +33 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +1 -0
- package/dist/cjs/providers/index.js +2 -0
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/providers/mockProvider.d.ts +19 -0
- package/dist/cjs/providers/mockProvider.js +70 -0
- package/dist/cjs/providers/mockProvider.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +204 -151
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +42 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/providers/index.d.ts +1 -0
- package/dist/esm/providers/index.js +2 -0
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/providers/mockProvider.d.ts +23 -0
- package/dist/esm/providers/mockProvider.js +73 -0
- package/dist/esm/providers/mockProvider.js.map +1 -0
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +3 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/providers/mockProvider.d.ts +24 -0
- package/dist/types/providers/mockProvider.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +98 -70
- package/src/clients/BundleDataClient/utils/FillUtils.ts +47 -2
- package/src/providers/index.ts +1 -0
- package/src/providers/mockProvider.ts +77 -0
|
@@ -1,8 +1,8 @@
|
|
|
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, chainIsEvm, isValidEvmAddress, } 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
|
|
@@ -26,10 +26,10 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
26
26
|
}
|
|
27
27
|
dict[originChainId][inputToken].push(deposit);
|
|
28
28
|
}
|
|
29
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
29
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
|
|
30
30
|
var _a, _b;
|
|
31
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(
|
|
32
|
+
if (chainIsEvm(repaymentChainId) && !isValidEvmAddress(repaymentAddress)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
@@ -40,26 +40,26 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
40
40
|
refunds: {},
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct });
|
|
43
|
+
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
|
|
44
44
|
// Add all fills, slow and fast, to dictionary.
|
|
45
45
|
assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
46
46
|
// All fills update the bundle LP fees.
|
|
47
47
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
48
|
-
var realizedLpFee =
|
|
48
|
+
var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
|
|
49
49
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
50
50
|
// Only fast fills get refunded.
|
|
51
|
-
if (!isSlowFill(
|
|
52
|
-
var refundAmount =
|
|
51
|
+
if (!isSlowFill(bundleFill)) {
|
|
52
|
+
var refundAmount = bundleFill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
|
|
53
53
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
54
54
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
55
55
|
: refundAmount;
|
|
56
56
|
// Instantiate dictionary if it doesn't exist.
|
|
57
57
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
58
|
-
if (refundObj.refunds[
|
|
59
|
-
refundObj.refunds[
|
|
58
|
+
if (refundObj.refunds[bundleFill.relayer]) {
|
|
59
|
+
refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
refundObj.refunds[
|
|
62
|
+
refundObj.refunds[bundleFill.relayer] = refundAmount;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -217,77 +217,122 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
217
217
|
return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
218
218
|
case 1:
|
|
219
219
|
arweaveData = _a.sent();
|
|
220
|
-
if (arweaveData === undefined)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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)];
|
|
239
242
|
}
|
|
240
243
|
});
|
|
241
244
|
});
|
|
242
245
|
};
|
|
243
246
|
// @dev This helper function should probably be moved to the InventoryClient
|
|
244
247
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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];
|
|
261
333
|
}
|
|
262
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
263
|
-
var hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
264
|
-
_this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
|
|
265
|
-
return hasMatchingDeposit;
|
|
266
|
-
})
|
|
267
|
-
.forEach(function (fill) {
|
|
268
|
-
var _a, _b, _c;
|
|
269
|
-
var _d;
|
|
270
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
271
|
-
assert(isDefined(matchingDeposit), "Deposit not found for fill.");
|
|
272
|
-
var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
|
|
273
|
-
), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
274
|
-
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
|
|
275
|
-
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
|
|
276
|
-
// in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
|
|
277
|
-
// worst from the relayer's perspective.
|
|
278
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
279
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
280
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
281
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
|
|
282
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
283
334
|
});
|
|
284
|
-
};
|
|
285
|
-
var this_1 = this;
|
|
286
|
-
for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
|
|
287
|
-
var chainId = chainIds_1[_i];
|
|
288
|
-
_loop_1(chainId);
|
|
289
|
-
}
|
|
290
|
-
return refundsForChain;
|
|
335
|
+
});
|
|
291
336
|
};
|
|
292
337
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
293
338
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -379,33 +424,40 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
379
424
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
380
425
|
});
|
|
381
426
|
}
|
|
382
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
383
|
-
return __generator(this, function (
|
|
384
|
-
switch (
|
|
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) {
|
|
385
430
|
case 0:
|
|
386
431
|
hubPoolClient = this.clients.hubPoolClient;
|
|
387
432
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
388
433
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
389
434
|
combinedRefunds = [];
|
|
390
435
|
widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
391
|
-
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/,
|
|
436
|
+
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 5];
|
|
392
437
|
pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
393
438
|
return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
394
439
|
case 1:
|
|
395
|
-
arweaveData =
|
|
396
|
-
if (arweaveData === undefined)
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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:
|
|
403
452
|
// Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
|
|
404
453
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
405
|
-
|
|
406
|
-
case
|
|
454
|
+
_e.label = 5;
|
|
455
|
+
case 5:
|
|
407
456
|
start = performance.now();
|
|
408
|
-
combinedRefunds.push
|
|
457
|
+
_d = (_c = combinedRefunds).push;
|
|
458
|
+
return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
459
|
+
case 6:
|
|
460
|
+
_d.apply(_c, [_e.sent()]);
|
|
409
461
|
this.logger.debug({
|
|
410
462
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
411
463
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -700,86 +752,87 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
700
752
|
// We can remove fills for deposits with input amount equal to zero because these will result in 0 refunded
|
|
701
753
|
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
|
|
702
754
|
// request for the deposit, we'd want to see the fill took place.
|
|
703
|
-
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueDeposit(fill); }), function (
|
|
704
|
-
var relayDataHash,
|
|
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;
|
|
705
757
|
return __generator(this, function (_a) {
|
|
706
758
|
switch (_a.label) {
|
|
707
759
|
case 0:
|
|
708
|
-
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
709
760
|
fillCounter++;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
720
|
-
// events.
|
|
721
|
-
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
722
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
723
|
-
!v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
|
|
724
|
-
!v3RelayHashes[relayDataHash].deposit.toLiteChain) {
|
|
725
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
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);
|
|
729
770
|
return [2 /*return*/];
|
|
730
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:
|
|
731
790
|
// At this point, there is no relay hash dictionary entry for this fill, so we need to
|
|
732
|
-
// instantiate the entry.
|
|
791
|
+
// instantiate the entry. We won't modify the fill.relayer until we match it with a deposit.
|
|
733
792
|
v3RelayHashes[relayDataHash] = {
|
|
734
793
|
deposit: undefined,
|
|
735
|
-
fill:
|
|
794
|
+
fill: _fill,
|
|
736
795
|
slowFillRequest: undefined,
|
|
737
796
|
};
|
|
738
|
-
if (!(
|
|
797
|
+
if (!(_fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 7];
|
|
739
798
|
// Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
|
|
740
799
|
// to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
|
|
741
800
|
// skip the historical query.
|
|
742
|
-
if (!INFINITE_FILL_DEADLINE.eq(
|
|
743
|
-
bundleInvalidFillsV3.push(
|
|
801
|
+
if (!INFINITE_FILL_DEADLINE.eq(_fill.fillDeadline)) {
|
|
802
|
+
bundleInvalidFillsV3.push(_fill);
|
|
744
803
|
return [2 /*return*/];
|
|
745
804
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
case 1:
|
|
749
|
-
fillTransaction = _a.sent();
|
|
750
|
-
originRelayer = fillTransaction.from;
|
|
751
|
-
// Repayment chain is still an EVM chain, but the msg.sender is a bytes32 address, so the fill is invalid.
|
|
752
|
-
if (!isValidEvmAddress(originRelayer)) {
|
|
753
|
-
bundleInvalidFillsV3.push(fill);
|
|
754
|
-
return [2 /*return*/];
|
|
755
|
-
}
|
|
756
|
-
// Otherwise, assume the relayer to be repaid is the msg.sender.
|
|
757
|
-
fill.relayer = originRelayer;
|
|
758
|
-
_a.label = 2;
|
|
759
|
-
case 2: return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
|
|
760
|
-
case 3:
|
|
805
|
+
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, _fill)];
|
|
806
|
+
case 4:
|
|
761
807
|
historicalDeposit = _a.sent();
|
|
762
|
-
if (
|
|
763
|
-
|
|
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*/];
|
|
764
819
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
779
|
-
}
|
|
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);
|
|
780
833
|
}
|
|
781
|
-
_a.label =
|
|
782
|
-
case
|
|
834
|
+
_a.label = 7;
|
|
835
|
+
case 7: return [2 /*return*/];
|
|
783
836
|
}
|
|
784
837
|
});
|
|
785
838
|
}); })];
|
|
@@ -1048,7 +1101,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1048
1101
|
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1049
1102
|
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1050
1103
|
var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1051
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1104
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
|
|
1052
1105
|
});
|
|
1053
1106
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1054
1107
|
var lpFeePct = _a.realizedLpFeePct;
|