@across-protocol/sdk 4.0.0-beta.34 → 4.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +189 -352
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -47
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
- package/dist/cjs/clients/SpokePoolClient.js +1 -10
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +0 -1
- package/dist/cjs/providers/index.js +0 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +0 -1
- package/dist/cjs/utils/AddressUtils.js +1 -6
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.js +1 -1
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +0 -21
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +0 -1
- package/dist/cjs/utils/SpokeUtils.js +8 -15
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +0 -1
- package/dist/cjs/utils/common.js +1 -2
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +274 -455
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -54
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
- package/dist/esm/clients/SpokePoolClient.js +1 -17
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/providers/index.d.ts +0 -1
- package/dist/esm/providers/index.js +0 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +0 -1
- package/dist/esm/utils/AddressUtils.js +0 -9
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.js +2 -2
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +1 -29
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +0 -1
- package/dist/esm/utils/SpokeUtils.js +7 -13
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/common.d.ts +0 -1
- package/dist/esm/utils/common.js +0 -1
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/types/clients/SpokePoolClient.d.ts +0 -8
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +0 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +0 -1
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +0 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +243 -427
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -66
- package/src/clients/SpokePoolClient.ts +3 -16
- package/src/clients/mocks/MockSpokePoolClient.ts +1 -14
- package/src/constants.ts +3 -3
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -10
- package/src/utils/DepositUtils.ts +2 -2
- package/src/utils/EventUtils.ts +1 -29
- package/src/utils/SpokeUtils.ts +8 -21
- package/src/utils/common.ts +0 -2
- package/dist/cjs/providers/mockProvider.d.ts +0 -19
- package/dist/cjs/providers/mockProvider.js +0 -70
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/esm/providers/mockProvider.d.ts +0 -23
- package/dist/esm/providers/mockProvider.js +0 -73
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts +0 -24
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/src/providers/mockProvider.ts +0 -77
|
@@ -1,9 +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,
|
|
5
|
-
import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled,
|
|
6
|
-
import { PRE_FILL_MIN_CONFIG_STORE_VERSION } from "../../constants";
|
|
4
|
+
import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, findFillEvent, isZeroValueFillOrSlowFillRequest, chainIsEvm, isValidEvmAddress, } from "../../utils";
|
|
5
|
+
import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, } from "./utils";
|
|
7
6
|
// max(uint256) - 1
|
|
8
7
|
export var INFINITE_FILL_DEADLINE = bnUint32Max;
|
|
9
8
|
// V3 dictionary helper functions
|
|
@@ -27,10 +26,12 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
27
26
|
}
|
|
28
27
|
dict[originChainId][inputToken].push(deposit);
|
|
29
28
|
}
|
|
30
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken
|
|
29
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
31
30
|
var _a, _b;
|
|
32
|
-
//
|
|
33
|
-
|
|
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(fill.repaymentChainId) && !isValidEvmAddress(fill.relayer)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
34
35
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
35
36
|
assign(dict, [repaymentChainId, repaymentToken], {
|
|
36
37
|
fills: [],
|
|
@@ -39,26 +40,26 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
39
40
|
refunds: {},
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct
|
|
43
|
+
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct });
|
|
43
44
|
// Add all fills, slow and fast, to dictionary.
|
|
44
45
|
assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
45
46
|
// All fills update the bundle LP fees.
|
|
46
47
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
47
|
-
var realizedLpFee =
|
|
48
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
|
|
48
49
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
49
50
|
// Only fast fills get refunded.
|
|
50
|
-
if (!isSlowFill(
|
|
51
|
-
var refundAmount =
|
|
51
|
+
if (!isSlowFill(fill)) {
|
|
52
|
+
var refundAmount = fill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
|
|
52
53
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
53
54
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
54
55
|
: refundAmount;
|
|
55
56
|
// Instantiate dictionary if it doesn't exist.
|
|
56
57
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
57
|
-
if (refundObj.refunds[
|
|
58
|
-
refundObj.refunds[
|
|
58
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
59
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
59
60
|
}
|
|
60
61
|
else {
|
|
61
|
-
refundObj.refunds[
|
|
62
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -72,9 +73,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
|
|
|
72
73
|
}
|
|
73
74
|
function updateBundleSlowFills(dict, deposit) {
|
|
74
75
|
var _a;
|
|
75
|
-
if (chainIsEvm(deposit.destinationChainId) && !isValidEvmAddress(deposit.recipient)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
76
|
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
79
77
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
80
78
|
assign(dict, [destinationChainId, outputToken], []);
|
|
@@ -172,7 +170,8 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
172
170
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
173
171
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
174
172
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
175
|
-
bundleData: prettyPrintV3SpokePoolEvents(bundleData.bundleDepositsV3, bundleData.bundleFillsV3,
|
|
173
|
+
bundleData: prettyPrintV3SpokePoolEvents(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], // Invalid fills are not persisted to Arweave.
|
|
174
|
+
bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
|
|
176
175
|
});
|
|
177
176
|
return [2 /*return*/, bundleData];
|
|
178
177
|
}
|
|
@@ -218,124 +217,77 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
218
217
|
return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
219
218
|
case 1:
|
|
220
219
|
arweaveData = _a.sent();
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// The latest proposed bundle's refund leaves might have already been partially or entirely executed.
|
|
241
|
-
// We have to deduct the executed amounts from the total refund amounts.
|
|
242
|
-
return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
220
|
+
if (arweaveData === undefined) {
|
|
221
|
+
combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
225
|
+
combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
|
|
226
|
+
// If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
|
|
227
|
+
// chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
|
|
228
|
+
// a reasonable assumption. This empty refund chain also matches what the alternative
|
|
229
|
+
// `getApproximateRefundsForBlockRange` would return.
|
|
230
|
+
Object.keys(combinedRefunds).forEach(function (chainId) {
|
|
231
|
+
if (_this.spokePoolClients[Number(chainId)] === undefined) {
|
|
232
|
+
delete combinedRefunds[Number(chainId)];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// The latest proposed bundle's refund leaves might have already been partially or entirely executed.
|
|
237
|
+
// We have to deduct the executed amounts from the total refund amounts.
|
|
238
|
+
return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
243
239
|
}
|
|
244
240
|
});
|
|
245
241
|
});
|
|
246
242
|
};
|
|
247
243
|
// @dev This helper function should probably be moved to the InventoryClient
|
|
248
244
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return [4 /*yield*/, filterAsync(this_1.spokePoolClients[chainId].getFills(), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
266
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
267
|
-
return __generator(this, function (_a) {
|
|
268
|
-
switch (_a.label) {
|
|
269
|
-
case 0:
|
|
270
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
271
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
272
|
-
isZeroValueFillOrSlowFillRequest(fill)) {
|
|
273
|
-
return [2 /*return*/, false];
|
|
274
|
-
}
|
|
275
|
-
// If origin spoke pool client isn't defined, we can't validate it.
|
|
276
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
277
|
-
return [2 /*return*/, false];
|
|
278
|
-
}
|
|
279
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
280
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
281
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
282
|
-
if (!hasMatchingDeposit) return [3 /*break*/, 2];
|
|
283
|
-
return [4 /*yield*/, verifyFillRepayment(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit,
|
|
284
|
-
// @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
|
|
285
|
-
// disabled block ranges.
|
|
286
|
-
this.clients.configStoreClient
|
|
287
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
288
|
-
.filter(function (_chainId, i) { return !isChainDisabled(blockRanges[i]); }))];
|
|
289
|
-
case 1:
|
|
290
|
-
validRepayment = _a.sent();
|
|
291
|
-
if (!isDefined(validRepayment)) {
|
|
292
|
-
return [2 /*return*/, false];
|
|
293
|
-
}
|
|
294
|
-
_a.label = 2;
|
|
295
|
-
case 2: return [2 /*return*/, hasMatchingDeposit];
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}); })];
|
|
299
|
-
case 1:
|
|
300
|
-
fillsToCount = _b.sent();
|
|
301
|
-
fillsToCount.forEach(function (fill) {
|
|
302
|
-
var _a, _b, _c;
|
|
303
|
-
var _d;
|
|
304
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
305
|
-
assert(isDefined(matchingDeposit), "Deposit not found for fill.");
|
|
306
|
-
var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
|
|
307
|
-
), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
308
|
-
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
|
|
309
|
-
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
|
|
310
|
-
// in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
|
|
311
|
-
// worst from the relayer's perspective.
|
|
312
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
313
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
314
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
315
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
|
|
316
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
317
|
-
});
|
|
318
|
-
return [2 /*return*/];
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
};
|
|
322
|
-
this_1 = this;
|
|
323
|
-
_i = 0, chainIds_1 = chainIds;
|
|
324
|
-
_a.label = 1;
|
|
325
|
-
case 1:
|
|
326
|
-
if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
|
|
327
|
-
chainId = chainIds_1[_i];
|
|
328
|
-
return [5 /*yield**/, _loop_1(chainId)];
|
|
329
|
-
case 2:
|
|
330
|
-
_a.sent();
|
|
331
|
-
_a.label = 3;
|
|
332
|
-
case 3:
|
|
333
|
-
_i++;
|
|
334
|
-
return [3 /*break*/, 1];
|
|
335
|
-
case 4: return [2 /*return*/, refundsForChain];
|
|
245
|
+
var _this = this;
|
|
246
|
+
var refundsForChain = {};
|
|
247
|
+
var _loop_1 = function (chainId) {
|
|
248
|
+
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
249
|
+
return "continue";
|
|
250
|
+
}
|
|
251
|
+
var chainIndex = chainIds.indexOf(chainId);
|
|
252
|
+
this_1.spokePoolClients[chainId]
|
|
253
|
+
.getFills()
|
|
254
|
+
.filter(function (fill) {
|
|
255
|
+
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
// If origin spoke pool client isn't defined, we can't validate it.
|
|
259
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
260
|
+
return false;
|
|
336
261
|
}
|
|
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);
|
|
337
283
|
});
|
|
338
|
-
}
|
|
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;
|
|
339
291
|
};
|
|
340
292
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
341
293
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -380,10 +332,12 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
380
332
|
case 1:
|
|
381
333
|
_a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
|
|
382
334
|
hubPoolClient = this.clients.hubPoolClient;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
335
|
+
return [4 /*yield*/, _buildPoolRebalanceRoot(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
|
|
336
|
+
hubPoolClient: hubPoolClient,
|
|
337
|
+
configStoreClient: hubPoolClient.configStoreClient,
|
|
338
|
+
})];
|
|
339
|
+
case 2:
|
|
340
|
+
root = _b.sent();
|
|
387
341
|
return [2 /*return*/, {
|
|
388
342
|
root: root,
|
|
389
343
|
blockRanges: blockRanges,
|
|
@@ -425,40 +379,33 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
425
379
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
426
380
|
});
|
|
427
381
|
}
|
|
428
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
429
|
-
return __generator(this, function (
|
|
430
|
-
switch (
|
|
382
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
383
|
+
return __generator(this, function (_a) {
|
|
384
|
+
switch (_a.label) {
|
|
431
385
|
case 0:
|
|
432
386
|
hubPoolClient = this.clients.hubPoolClient;
|
|
433
387
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
434
388
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
435
389
|
combinedRefunds = [];
|
|
436
390
|
widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
437
|
-
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/,
|
|
391
|
+
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
|
|
438
392
|
pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
439
393
|
return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
440
394
|
case 1:
|
|
441
|
-
arweaveData =
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
450
|
-
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
451
|
-
_e.label = 4;
|
|
452
|
-
case 4:
|
|
395
|
+
arweaveData = _a.sent();
|
|
396
|
+
if (arweaveData === undefined) {
|
|
397
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
401
|
+
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
402
|
+
}
|
|
453
403
|
// Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
|
|
454
404
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
455
|
-
|
|
456
|
-
case
|
|
405
|
+
_a.label = 2;
|
|
406
|
+
case 2:
|
|
457
407
|
start = performance.now();
|
|
458
|
-
|
|
459
|
-
return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
460
|
-
case 6:
|
|
461
|
-
_d.apply(_c, [_e.sent()]);
|
|
408
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
462
409
|
this.logger.debug({
|
|
463
410
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
464
411
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -601,7 +548,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
601
548
|
};
|
|
602
549
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
603
550
|
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3,
|
|
551
|
+
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;
|
|
605
552
|
var _this = this;
|
|
606
553
|
return __generator(this, function (_c) {
|
|
607
554
|
switch (_c.label) {
|
|
@@ -621,8 +568,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
621
568
|
bundleDepositsV3 = {};
|
|
622
569
|
bundleFillsV3 = {};
|
|
623
570
|
bundleInvalidFillsV3 = [];
|
|
624
|
-
bundleUnrepayableFillsV3 = [];
|
|
625
|
-
bundleInvalidSlowFillRequests = [];
|
|
626
571
|
bundleSlowFillsV3 = {};
|
|
627
572
|
expiredDepositsToRefundV3 = {};
|
|
628
573
|
unexecutableSlowFills = {};
|
|
@@ -680,13 +625,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
680
625
|
v3RelayHashes = {};
|
|
681
626
|
bundleDepositHashes = [];
|
|
682
627
|
olderDepositHashes = [];
|
|
683
|
-
|
|
684
|
-
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
685
|
-
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
686
|
-
};
|
|
687
|
-
startBlockForMainnet = getBlockRangeForChain(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
|
|
688
|
-
versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
|
|
689
|
-
canRefundPrefills = versionAtProposalBlock >= PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
|
|
628
|
+
depositCounter = 0;
|
|
690
629
|
_loop_2 = function (originChainId) {
|
|
691
630
|
var originClient = spokePoolClients[originChainId];
|
|
692
631
|
var originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
@@ -696,45 +635,48 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
696
635
|
continue;
|
|
697
636
|
}
|
|
698
637
|
originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
|
|
638
|
+
// Only evaluate deposits that are in this bundle or in previous bundles. This means we cannot issue fill
|
|
639
|
+
// refunds or slow fills here for deposits that are in future bundles (i.e. "pre-fills"). Instead, we'll
|
|
640
|
+
// evaluate these pre-fills once the deposit is inside the "current" bundle block range.
|
|
699
641
|
if (deposit.blockNumber > originChainBlockRange[1] || isZeroValueDeposit(deposit)) {
|
|
700
642
|
return;
|
|
701
643
|
}
|
|
644
|
+
depositCounter++;
|
|
702
645
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
646
|
+
// Duplicate deposits are treated like normal deposits.
|
|
703
647
|
if (!v3RelayHashes[relayDataHash]) {
|
|
704
648
|
v3RelayHashes[relayDataHash] = {
|
|
705
|
-
|
|
649
|
+
deposit: deposit,
|
|
706
650
|
fill: undefined,
|
|
707
651
|
slowFillRequest: undefined,
|
|
708
652
|
};
|
|
709
653
|
}
|
|
710
|
-
|
|
711
|
-
|
|
654
|
+
// Once we've saved the deposit hash into v3RelayHashes, then we can exit early here if the inputAmount
|
|
655
|
+
// is 0 because there can be no expired amount to refund and no unexecutable slow fill amount to return
|
|
656
|
+
// if this deposit did expire. Input amount can only be zero at this point if the message is non-empty,
|
|
657
|
+
// but the message doesn't matter for expired deposits and unexecutable slow fills.
|
|
658
|
+
if (deposit.inputAmount.eq(0)) {
|
|
659
|
+
return;
|
|
712
660
|
}
|
|
713
|
-
//
|
|
714
|
-
// we
|
|
715
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
716
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
717
|
-
assert(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
718
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
661
|
+
// Evaluate all expired deposits after fetching fill statuses,
|
|
662
|
+
// since we can't know for certain whether an expired deposit was filled a long time ago.
|
|
719
663
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
720
|
-
bundleDepositHashes.push(
|
|
664
|
+
bundleDepositHashes.push(relayDataHash);
|
|
721
665
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
722
666
|
}
|
|
723
667
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
724
|
-
olderDepositHashes.push(
|
|
668
|
+
olderDepositHashes.push(relayDataHash);
|
|
725
669
|
}
|
|
726
670
|
});
|
|
727
671
|
}
|
|
728
672
|
};
|
|
729
|
-
// Prerequisite step: Load all deposit events from the current or older bundles into the v3RelayHashes dictionary
|
|
730
|
-
// for convenient matching with fills.
|
|
731
673
|
for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
|
|
732
674
|
originChainId = allChainIds_1[_i];
|
|
733
675
|
_loop_2(originChainId);
|
|
734
676
|
}
|
|
735
677
|
this.logger.debug({
|
|
736
678
|
at: "BundleDataClient#loadData",
|
|
737
|
-
message: "Processed ".concat(
|
|
679
|
+
message: "Processed ".concat(depositCounter, " deposits in ").concat(performance.now() - start, "ms."),
|
|
738
680
|
});
|
|
739
681
|
start = performance.now();
|
|
740
682
|
validatedBundleV3Fills = [];
|
|
@@ -748,7 +690,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
748
690
|
case 0:
|
|
749
691
|
originClient = spokePoolClients[originChainId];
|
|
750
692
|
_loop_4 = function (destinationChainId) {
|
|
751
|
-
var destinationClient, destinationChainBlockRange,
|
|
693
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
752
694
|
return __generator(this, function (_g) {
|
|
753
695
|
switch (_g.label) {
|
|
754
696
|
case 0:
|
|
@@ -757,7 +699,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
757
699
|
}
|
|
758
700
|
destinationClient = spokePoolClients[destinationChainId];
|
|
759
701
|
destinationChainBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
760
|
-
originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
761
702
|
fastFillsReplacingSlowFills = [];
|
|
762
703
|
return [4 /*yield*/, forEachAsync(destinationClient
|
|
763
704
|
.getFillsForOriginChain(originChainId)
|
|
@@ -765,58 +706,40 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
765
706
|
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
|
|
766
707
|
// request for the deposit, we'd want to see the fill took place.
|
|
767
708
|
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
768
|
-
var relayDataHash,
|
|
709
|
+
var relayDataHash, fillTransaction, originRelayer, historicalDeposit, matchedDeposit;
|
|
769
710
|
return __generator(this, function (_a) {
|
|
770
711
|
switch (_a.label) {
|
|
771
712
|
case 0:
|
|
772
|
-
fillCounter++;
|
|
773
713
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
792
|
-
if (isSlowFill(fill)) {
|
|
793
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
|
|
714
|
+
fillCounter++;
|
|
715
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
716
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
717
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
718
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
719
|
+
// so this fill is validated.
|
|
720
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
721
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
722
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
723
|
+
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
724
|
+
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
725
|
+
// events.
|
|
726
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
727
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
728
|
+
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
|
|
729
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
730
|
+
}
|
|
797
731
|
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
801
|
-
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
802
|
-
// events.
|
|
803
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
804
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
805
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
732
|
+
}
|
|
733
|
+
return [2 /*return*/];
|
|
806
734
|
}
|
|
807
|
-
_a.label = 2;
|
|
808
|
-
case 2: return [3 /*break*/, 4];
|
|
809
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
810
|
-
case 4: return [2 /*return*/];
|
|
811
|
-
case 5:
|
|
812
735
|
// At this point, there is no relay hash dictionary entry for this fill, so we need to
|
|
813
|
-
// instantiate the entry.
|
|
736
|
+
// instantiate the entry.
|
|
814
737
|
v3RelayHashes[relayDataHash] = {
|
|
815
|
-
|
|
738
|
+
deposit: undefined,
|
|
816
739
|
fill: fill,
|
|
817
740
|
slowFillRequest: undefined,
|
|
818
741
|
};
|
|
819
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/,
|
|
742
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 4];
|
|
820
743
|
// Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
|
|
821
744
|
// to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
|
|
822
745
|
// skip the historical query.
|
|
@@ -824,58 +747,49 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
824
747
|
bundleInvalidFillsV3.push(fill);
|
|
825
748
|
return [2 /*return*/];
|
|
826
749
|
}
|
|
827
|
-
return [
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
835
|
-
// If deposit is in a following bundle, then this fill will have to be refunded once that deposit
|
|
836
|
-
// is in the current bundle.
|
|
837
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
750
|
+
if (!(chainIsEvm(fill.repaymentChainId) && !isValidEvmAddress(fill.relayer))) return [3 /*break*/, 2];
|
|
751
|
+
return [4 /*yield*/, originClient.spokePool.provider.getTransaction(fill.transactionHash)];
|
|
752
|
+
case 1:
|
|
753
|
+
fillTransaction = _a.sent();
|
|
754
|
+
originRelayer = fillTransaction.from;
|
|
755
|
+
// Repayment chain is still an EVM chain, but the msg.sender is a bytes32 address, so the fill is invalid.
|
|
756
|
+
if (!isValidEvmAddress(originRelayer)) {
|
|
838
757
|
bundleInvalidFillsV3.push(fill);
|
|
839
758
|
return [2 /*return*/];
|
|
840
759
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
760
|
+
// Otherwise, assume the relayer to be repaid is the msg.sender.
|
|
761
|
+
fill.relayer = originRelayer;
|
|
762
|
+
_a.label = 2;
|
|
763
|
+
case 2: return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
|
|
764
|
+
case 3:
|
|
765
|
+
historicalDeposit = _a.sent();
|
|
766
|
+
if (!historicalDeposit.found) {
|
|
767
|
+
bundleInvalidFillsV3.push(fill);
|
|
849
768
|
}
|
|
850
769
|
else {
|
|
770
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
851
771
|
// @dev Since queryHistoricalDepositForFill validates the fill by checking individual
|
|
852
772
|
// object property values against the deposit's, we
|
|
853
773
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
854
774
|
// historical deposit query is not working as expected.
|
|
855
775
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
856
|
-
validatedBundleV3Fills.push(__assign(__assign({},
|
|
857
|
-
v3RelayHashes[relayDataHash].
|
|
858
|
-
//
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
776
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
777
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
778
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
779
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
780
|
+
_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
781
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
782
|
+
}
|
|
864
783
|
}
|
|
865
|
-
_a.label =
|
|
866
|
-
case
|
|
784
|
+
_a.label = 4;
|
|
785
|
+
case 4: return [2 /*return*/];
|
|
867
786
|
}
|
|
868
787
|
});
|
|
869
788
|
}); })];
|
|
870
789
|
case 1:
|
|
871
790
|
_g.sent();
|
|
872
|
-
// Process slow fill requests
|
|
873
|
-
//
|
|
874
|
-
// - Slow fill leaves cannot be produced for deposits that have been filled.
|
|
875
|
-
// Assumptions about fills:
|
|
876
|
-
// - Duplicate slow fill requests for the same relay data hash are impossible to send.
|
|
877
|
-
// - Slow fill requests can only be sent before the deposit's fillDeadline.
|
|
878
|
-
// - Slow fill requests for a deposit that has been filled.
|
|
791
|
+
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
792
|
+
// for deposits that would expire in this bundle.
|
|
879
793
|
return [4 /*yield*/, forEachAsync(destinationClient
|
|
880
794
|
.getSlowFillRequestsForOriginChain(originChainId)
|
|
881
795
|
.filter(function (request) {
|
|
@@ -888,58 +802,55 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
888
802
|
relayDataHash = this.getRelayHashFromEvent(slowFillRequest);
|
|
889
803
|
if (v3RelayHashes[relayDataHash]) {
|
|
890
804
|
if (!v3RelayHashes[relayDataHash].slowFillRequest) {
|
|
805
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is either a matching
|
|
806
|
+
// fill or deposit.
|
|
891
807
|
v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
|
|
892
808
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
893
|
-
//
|
|
894
|
-
//
|
|
895
|
-
// for a fill older than this slow fill request.
|
|
809
|
+
// If there is a fill matching the relay hash, then this slow fill request can't be used
|
|
810
|
+
// to create a slow fill for a filled deposit.
|
|
896
811
|
return [2 /*return*/];
|
|
897
812
|
}
|
|
898
|
-
assert(isDefined(v3RelayHashes[relayDataHash].
|
|
899
|
-
matchedDeposit = v3RelayHashes[relayDataHash].
|
|
813
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
814
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
815
|
+
// If there is no fill matching the relay hash, then this might be a valid slow fill request
|
|
816
|
+
// that we should produce a slow fill leaf for. Check if the slow fill request is in the
|
|
817
|
+
// destination chain block range.
|
|
900
818
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
901
819
|
_canCreateSlowFillLeaf(matchedDeposit) &&
|
|
820
|
+
// Deposit must not have expired in this bundle.
|
|
902
821
|
!_depositIsExpired(matchedDeposit)) {
|
|
822
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
823
|
+
// so this slow fill request relay data is correct.
|
|
903
824
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
904
825
|
}
|
|
905
826
|
}
|
|
906
|
-
else {
|
|
907
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
908
|
-
}
|
|
909
827
|
return [2 /*return*/];
|
|
910
828
|
}
|
|
911
829
|
// Instantiate dictionary if there is neither a deposit nor fill matching it.
|
|
912
830
|
v3RelayHashes[relayDataHash] = {
|
|
913
|
-
|
|
831
|
+
deposit: undefined,
|
|
914
832
|
fill: undefined,
|
|
915
833
|
slowFillRequest: slowFillRequest,
|
|
916
834
|
};
|
|
917
|
-
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0]
|
|
918
|
-
|
|
919
|
-
bundleInvalidSlowFillRequests.push(slowFillRequest);
|
|
920
|
-
return [2 /*return*/];
|
|
921
|
-
}
|
|
835
|
+
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
836
|
+
INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3 /*break*/, 2];
|
|
922
837
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, slowFillRequest)];
|
|
923
838
|
case 1:
|
|
924
839
|
historicalDeposit = _a.sent();
|
|
925
840
|
if (!historicalDeposit.found) {
|
|
926
|
-
|
|
841
|
+
// TODO: Invalid slow fill request. Maybe worth logging.
|
|
927
842
|
return [2 /*return*/];
|
|
928
843
|
}
|
|
929
844
|
matchedDeposit = historicalDeposit.deposit;
|
|
930
|
-
// If deposit is in a following bundle, then this slow fill request will have to be created
|
|
931
|
-
// once that deposit is in the current bundle.
|
|
932
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
933
|
-
bundleInvalidSlowFillRequests.push(slowFillRequest);
|
|
934
|
-
return [2 /*return*/];
|
|
935
|
-
}
|
|
936
845
|
// @dev Since queryHistoricalDepositForFill validates the slow fill request by checking individual
|
|
937
846
|
// object property values against the deposit's, we
|
|
938
847
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
939
848
|
// historical deposit query is not working as expected.
|
|
940
849
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
941
|
-
v3RelayHashes[relayDataHash].
|
|
942
|
-
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
850
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
851
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
852
|
+
// Deposit must not have expired in this bundle.
|
|
853
|
+
_depositIsExpired(matchedDeposit)) {
|
|
943
854
|
return [2 /*return*/];
|
|
944
855
|
}
|
|
945
856
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
@@ -949,167 +860,116 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
949
860
|
});
|
|
950
861
|
}); })];
|
|
951
862
|
case 2:
|
|
952
|
-
// Process slow fill requests
|
|
953
|
-
//
|
|
954
|
-
// - Slow fill leaves cannot be produced for deposits that have been filled.
|
|
955
|
-
// Assumptions about fills:
|
|
956
|
-
// - Duplicate slow fill requests for the same relay data hash are impossible to send.
|
|
957
|
-
// - Slow fill requests can only be sent before the deposit's fillDeadline.
|
|
958
|
-
// - Slow fill requests for a deposit that has been filled.
|
|
863
|
+
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
864
|
+
// for deposits that would expire in this bundle.
|
|
959
865
|
_g.sent();
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
//
|
|
963
|
-
// -
|
|
964
|
-
//
|
|
965
|
-
// -
|
|
966
|
-
//
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// - If the deposit has a matching fill or slow fill request in the bundle then we have already stored
|
|
975
|
-
// it in the relay hashes dictionary.
|
|
976
|
-
// - We've created refunds for all fills in this bundle matching a deposit.
|
|
977
|
-
// - We've created slow fill leaves for all slow fill requests in this bundle matching an unfilled deposit.
|
|
978
|
-
// - Deposits for the same relay data hash can be sent an arbitrary amount of times.
|
|
979
|
-
// - Deposits can be sent an arbitrary amount of time after a fill has been sent for the matching relay data.
|
|
980
|
-
return [4 /*yield*/, mapAsync(bundleDepositHashes, function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
981
|
-
var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, fillToRefund, fillStatus, prefill, verifiedFill;
|
|
982
|
-
var _this = this;
|
|
983
|
-
return __generator(this, function (_c) {
|
|
984
|
-
switch (_c.label) {
|
|
866
|
+
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
867
|
+
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
868
|
+
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
869
|
+
// this "pre-fill" if the fill took place in a previous bundle.
|
|
870
|
+
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
871
|
+
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
872
|
+
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
873
|
+
return [4 /*yield*/, mapAsync(bundleDepositHashes.filter(function (depositHash) {
|
|
874
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
875
|
+
return (deposit && deposit.originChainId === originChainId && deposit.destinationChainId === destinationChainId);
|
|
876
|
+
}), function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
877
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
878
|
+
return __generator(this, function (_b) {
|
|
879
|
+
switch (_b.label) {
|
|
985
880
|
case 0:
|
|
986
|
-
_a =
|
|
987
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
988
|
-
if (!deposits || deposits.length === 0) {
|
|
989
|
-
throw new Error("Deposits should exist in relay hash dictionary.");
|
|
990
|
-
}
|
|
991
|
-
deposit = deposits[index];
|
|
881
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
992
882
|
if (!deposit)
|
|
993
883
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
994
|
-
|
|
884
|
+
// We are willing to refund a pre-fill multiple times for each duplicate deposit.
|
|
885
|
+
// This is because a duplicate deposit for a pre-fill cannot get
|
|
886
|
+
// refunded to the depositor anymore because its fill status on-chain has changed to Filled. Therefore
|
|
887
|
+
// any duplicate deposits result in a net loss of funds for the depositor and effectively pay out
|
|
888
|
+
// the pre-filler.
|
|
889
|
+
// If fill exists in memory, then the only case in which we need to create a refund is if the
|
|
890
|
+
// the fill occurred in a previous bundle. There are no expiry refunds for filled deposits.
|
|
891
|
+
if (fill) {
|
|
892
|
+
if (fill.blockNumber < destinationChainBlockRange[0] && !isSlowFill(fill)) {
|
|
893
|
+
// If fill is in the current bundle then we can assume there is already a refund for it, so only
|
|
894
|
+
// include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
|
|
895
|
+
// we won't consider it, following the previous treatment of fills after the bundle block range.
|
|
896
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
897
|
+
}
|
|
995
898
|
return [2 /*return*/];
|
|
996
899
|
}
|
|
997
|
-
if (!fill) return [3 /*break*/, 3];
|
|
998
|
-
if (!(canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0])) return [3 /*break*/, 2];
|
|
999
|
-
return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
|
|
1000
|
-
case 1:
|
|
1001
|
-
fillToRefund = _c.sent();
|
|
1002
|
-
if (!isDefined(fillToRefund)) {
|
|
1003
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
1004
|
-
}
|
|
1005
|
-
else if (!isSlowFill(fill)) {
|
|
1006
|
-
v3RelayHashes[relayDataHash].fill = fillToRefund;
|
|
1007
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1008
|
-
}
|
|
1009
|
-
else {
|
|
1010
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1011
|
-
}
|
|
1012
|
-
_c.label = 2;
|
|
1013
|
-
case 2: return [2 /*return*/];
|
|
1014
|
-
case 3:
|
|
1015
900
|
// If a slow fill request exists in memory, then we know the deposit has not been filled because fills
|
|
1016
|
-
// must follow slow fill requests and we would have seen the fill already if it existed
|
|
1017
|
-
//
|
|
1018
|
-
//
|
|
1019
|
-
// in
|
|
901
|
+
// must follow slow fill requests and we would have seen the fill already if it existed. Therefore,
|
|
902
|
+
// we can conclude that either the deposit has expired and we need to create a deposit expiry refund, or
|
|
903
|
+
// we need to create a slow fill leaf for the deposit. The latter should only happen if the slow fill request
|
|
904
|
+
// took place in a prior bundle otherwise we would have already created a slow fill leaf for it.
|
|
1020
905
|
if (slowFillRequest) {
|
|
1021
906
|
if (_depositIsExpired(deposit)) {
|
|
1022
907
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1023
908
|
}
|
|
1024
|
-
else if (
|
|
1025
|
-
|
|
1026
|
-
_canCreateSlowFillLeaf(deposit) &&
|
|
1027
|
-
validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
|
|
909
|
+
else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
910
|
+
_canCreateSlowFillLeaf(deposit)) {
|
|
1028
911
|
validatedBundleSlowFills.push(deposit);
|
|
1029
912
|
}
|
|
1030
913
|
return [2 /*return*/];
|
|
1031
914
|
}
|
|
1032
915
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
1033
|
-
case
|
|
1034
|
-
fillStatus =
|
|
1035
|
-
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/,
|
|
1036
|
-
return [4 /*yield*/,
|
|
1037
|
-
case
|
|
1038
|
-
prefill =
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (!canRefundPrefills) return [3 /*break*/, 7];
|
|
1042
|
-
return [4 /*yield*/, verifyFillRepayment(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
1043
|
-
case 6:
|
|
1044
|
-
verifiedFill = _c.sent();
|
|
1045
|
-
if (!isDefined(verifiedFill)) {
|
|
1046
|
-
bundleUnrepayableFillsV3.push(prefill);
|
|
1047
|
-
}
|
|
1048
|
-
else if (!isSlowFill(verifiedFill)) {
|
|
1049
|
-
validatedBundleV3Fills.push(__assign(__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
916
|
+
case 1:
|
|
917
|
+
fillStatus = _b.sent();
|
|
918
|
+
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/, 3];
|
|
919
|
+
return [4 /*yield*/, findFillEvent(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
920
|
+
case 2:
|
|
921
|
+
prefill = (_b.sent());
|
|
922
|
+
if (!isSlowFill(prefill)) {
|
|
923
|
+
validatedBundleV3Fills.push(__assign(__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1053
924
|
}
|
|
1054
|
-
|
|
1055
|
-
case
|
|
1056
|
-
case 8:
|
|
925
|
+
return [3 /*break*/, 4];
|
|
926
|
+
case 3:
|
|
1057
927
|
if (_depositIsExpired(deposit)) {
|
|
1058
928
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1059
929
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
930
|
+
// If slow fill requested, then issue a slow fill leaf for the deposit.
|
|
931
|
+
else if (fillStatus === FillStatus.RequestedSlowFill) {
|
|
932
|
+
// Input and Output tokens must be equivalent on the deposit for this to be slow filled.
|
|
933
|
+
// Slow fill requests for deposits from or to lite chains are considered invalid
|
|
934
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
935
|
+
// If deposit newly expired, then we can't create a slow fill leaf for it but we can
|
|
936
|
+
// create a deposit refund for it.
|
|
1064
937
|
validatedBundleSlowFills.push(deposit);
|
|
1065
938
|
}
|
|
1066
939
|
}
|
|
1067
|
-
|
|
1068
|
-
case
|
|
940
|
+
_b.label = 4;
|
|
941
|
+
case 4: return [2 /*return*/];
|
|
1069
942
|
}
|
|
1070
943
|
});
|
|
1071
944
|
}); })];
|
|
1072
945
|
case 3:
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
//
|
|
1076
|
-
// -
|
|
1077
|
-
//
|
|
1078
|
-
// -
|
|
1079
|
-
//
|
|
1080
|
-
// - An expired deposit cannot be refunded if the deposit was filled.
|
|
1081
|
-
// - If a deposit from a prior bundle expired in this bundle, had a slow fill request created for it
|
|
1082
|
-
// in a prior bundle, and has not been filled yet, then an unexecutable slow fill leaf has been created
|
|
1083
|
-
// and needs to be refunded to the HubPool.
|
|
1084
|
-
// - Deposits matching slow fill requests from previous bundle block ranges should produce slow fills
|
|
1085
|
-
// if the deposit has not been filled.
|
|
1086
|
-
// Assumptions:
|
|
1087
|
-
// - If the deposit has a matching fill or slow fill request in the bundle then we have already stored
|
|
1088
|
-
// it in the relay hashes dictionary.
|
|
1089
|
-
// - We've created refunds for all fills in this bundle matching a deposit.
|
|
1090
|
-
// - We've created slow fill leaves for all slow fill requests in this bundle matching an unfilled deposit.
|
|
1091
|
-
// - Deposits for the same relay data hash can be sent an arbitrary amount of times.
|
|
1092
|
-
// - Deposits can be sent an arbitrary amount of time after a fill has been sent for the matching relay data.
|
|
946
|
+
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
947
|
+
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
948
|
+
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
949
|
+
// this "pre-fill" if the fill took place in a previous bundle.
|
|
950
|
+
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
951
|
+
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
952
|
+
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
1093
953
|
_g.sent();
|
|
1094
954
|
// For all fills that came after a slow fill request, we can now check if the slow fill request
|
|
1095
955
|
// was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
|
|
1096
956
|
// leaf that is now unexecutable.
|
|
1097
957
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
1098
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
958
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1099
959
|
assert((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
1100
960
|
// Needed for TSC - are implicitely checking that deposit exists by making it to this point.
|
|
1101
|
-
if (!
|
|
961
|
+
if (!deposit) {
|
|
1102
962
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1103
963
|
}
|
|
1104
964
|
// We should never push fast fills involving lite chains here because slow fill requests for them are invalid:
|
|
1105
|
-
assert(_canCreateSlowFillLeaf(
|
|
965
|
+
assert(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
|
|
1106
966
|
var destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1107
967
|
if (
|
|
1108
968
|
// If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
|
|
1109
969
|
// created that would be considered excess.
|
|
1110
970
|
!slowFillRequest ||
|
|
1111
971
|
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1112
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
972
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1113
973
|
}
|
|
1114
974
|
});
|
|
1115
975
|
return [2 /*return*/];
|
|
@@ -1153,17 +1013,13 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1153
1013
|
// For all deposits older than this bundle, we need to check if they expired in this bundle and if they did,
|
|
1154
1014
|
// whether there was a slow fill created for it in a previous bundle that is now unexecutable and replaced
|
|
1155
1015
|
// by a new expired deposit refund.
|
|
1156
|
-
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (
|
|
1157
|
-
var _a,
|
|
1158
|
-
return __generator(this, function (
|
|
1159
|
-
switch (
|
|
1016
|
+
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (relayDataHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
1017
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
1018
|
+
return __generator(this, function (_b) {
|
|
1019
|
+
switch (_b.label) {
|
|
1160
1020
|
case 0:
|
|
1161
|
-
_a =
|
|
1162
|
-
|
|
1163
|
-
if (!deposits || deposits.length < 1) {
|
|
1164
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1165
|
-
}
|
|
1166
|
-
deposit = deposits[index];
|
|
1021
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1022
|
+
assert(isDefined(deposit), "Deposit should exist in relay hash dictionary.");
|
|
1167
1023
|
destinationChainId = deposit.destinationChainId;
|
|
1168
1024
|
destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1169
1025
|
if (!
|
|
@@ -1177,7 +1033,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1177
1033
|
return [3 /*break*/, 2];
|
|
1178
1034
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
1179
1035
|
case 1:
|
|
1180
|
-
fillStatus =
|
|
1036
|
+
fillStatus = _b.sent();
|
|
1181
1037
|
// If there is no matching fill and the deposit expired in this bundle and the fill status on-chain is not
|
|
1182
1038
|
// Filled, then we can to refund it as an expired deposit.
|
|
1183
1039
|
if (fillStatus !== FillStatus.Filled) {
|
|
@@ -1199,7 +1055,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1199
1055
|
if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1200
1056
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1201
1057
|
}
|
|
1202
|
-
|
|
1058
|
+
_b.label = 2;
|
|
1203
1059
|
case 2: return [2 /*return*/];
|
|
1204
1060
|
}
|
|
1205
1061
|
});
|
|
@@ -1214,7 +1070,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1214
1070
|
promises = [
|
|
1215
1071
|
validatedBundleV3Fills.length > 0
|
|
1216
1072
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
1217
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1073
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1218
1074
|
assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1219
1075
|
var paymentChainId = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1220
1076
|
return __assign(__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1241,23 +1097,14 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1241
1097
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1242
1098
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1243
1099
|
var fill = validatedBundleV3Fills[idx];
|
|
1244
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1100
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1245
1101
|
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1246
1102
|
var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1247
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
1103
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1248
1104
|
});
|
|
1249
1105
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1250
1106
|
var lpFeePct = _a.realizedLpFeePct;
|
|
1251
1107
|
var deposit = validatedBundleSlowFills[idx];
|
|
1252
|
-
// We should not create slow fill leaves for duplicate deposit hashes and we should only create a slow
|
|
1253
|
-
// fill leaf for the first deposit (the quote timestamp of the deposit determines the LP fee, so its
|
|
1254
|
-
// important we pick out the correct deposit). Deposits are pushed into validatedBundleSlowFills in ascending
|
|
1255
|
-
// order so the following slice will only match the first deposit.
|
|
1256
|
-
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
1257
|
-
if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
|
|
1258
|
-
return;
|
|
1259
|
-
}
|
|
1260
|
-
assert(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
|
|
1261
1108
|
updateBundleSlowFills(bundleSlowFillsV3, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1262
1109
|
});
|
|
1263
1110
|
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
@@ -1265,31 +1112,15 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1265
1112
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
1266
1113
|
updateBundleExcessSlowFills(unexecutableSlowFills, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1267
1114
|
});
|
|
1268
|
-
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1115
|
+
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1269
1116
|
if (bundleInvalidFillsV3.length > 0) {
|
|
1270
1117
|
this.logger.debug({
|
|
1271
1118
|
at: "BundleDataClient#loadData",
|
|
1272
|
-
message: "Finished loading V3 spoke pool data and found some invalid fills in range",
|
|
1119
|
+
message: "Finished loading V3 spoke pool data and found some invalid V3 fills in range",
|
|
1273
1120
|
blockRangesForChains: blockRangesForChains,
|
|
1274
1121
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
1275
1122
|
});
|
|
1276
1123
|
}
|
|
1277
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
1278
|
-
this.logger.debug({
|
|
1279
|
-
at: "BundleDataClient#loadData",
|
|
1280
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable fills in range",
|
|
1281
|
-
blockRangesForChains: blockRangesForChains,
|
|
1282
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
if (bundleInvalidSlowFillRequests.length > 0) {
|
|
1286
|
-
this.logger.debug({
|
|
1287
|
-
at: "BundleDataClient#loadData",
|
|
1288
|
-
message: "Finished loading V3 spoke pool data and found some invalid slow fill requests in range",
|
|
1289
|
-
blockRangesForChains: blockRangesForChains,
|
|
1290
|
-
bundleInvalidSlowFillRequests: bundleInvalidSlowFillRequests,
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
1124
|
this.logger.debug({
|
|
1294
1125
|
at: "BundleDataClient#loadDataFromScratch",
|
|
1295
1126
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -1314,16 +1145,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1314
1145
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1315
1146
|
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);
|
|
1316
1147
|
};
|
|
1317
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1318
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1319
|
-
return __generator(this, function (_a) {
|
|
1320
|
-
switch (_a.label) {
|
|
1321
|
-
case 0: return [4 /*yield*/, findFillEvent(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1322
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
});
|
|
1326
|
-
};
|
|
1327
1148
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1328
1149
|
return __awaiter(this, void 0, void 0, function () {
|
|
1329
1150
|
var _a, _b;
|
|
@@ -1333,7 +1154,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1333
1154
|
case 0:
|
|
1334
1155
|
_b = (_a = Object).fromEntries;
|
|
1335
1156
|
return [4 /*yield*/, mapAsync(chainIds, function (chainId, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1336
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
1157
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1337
1158
|
return __generator(this, function (_c) {
|
|
1338
1159
|
switch (_c.label) {
|
|
1339
1160
|
case 0:
|
|
@@ -1348,7 +1169,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1348
1169
|
return [2 /*return*/];
|
|
1349
1170
|
}
|
|
1350
1171
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1351
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
1172
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1352
1173
|
return [4 /*yield*/, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1353
1174
|
case 1:
|
|
1354
1175
|
_b = [
|
|
@@ -1358,11 +1179,9 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1358
1179
|
case 2:
|
|
1359
1180
|
_a = _b.concat([
|
|
1360
1181
|
_c.sent()
|
|
1361
|
-
]), startTime = _a[0],
|
|
1362
|
-
endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
|
|
1363
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1182
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
1364
1183
|
// Sanity checks:
|
|
1365
|
-
assert(endTime >= startTime, "End time
|
|
1184
|
+
assert(endTime >= startTime, "End time should be greater than start time.");
|
|
1366
1185
|
assert(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1367
1186
|
return [2 /*return*/, [chainId, [startTime, endTime]]];
|
|
1368
1187
|
}
|