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