@across-protocol/sdk 4.0.0-beta.19 → 4.0.0-beta.2
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 +176 -308
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.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 +0 -1
- package/dist/cjs/constants.js +1 -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 +3 -12
- 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 +214 -370
- package/dist/esm/clients/BundleDataClient/BundleDataClient.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 +0 -1
- package/dist/esm/constants.js +1 -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 +3 -12
- 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/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 +0 -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 +215 -375
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
- package/src/clients/SpokePoolClient.ts +6 -19
- package/src/constants.ts +1 -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 +3 -12
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +5 -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
|
}
|
|
@@ -218,124 +209,77 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
218
209
|
return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
219
210
|
case 1:
|
|
220
211
|
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)];
|
|
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)];
|
|
243
231
|
}
|
|
244
232
|
});
|
|
245
233
|
});
|
|
246
234
|
};
|
|
247
235
|
// @dev This helper function should probably be moved to the InventoryClient
|
|
248
236
|
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];
|
|
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;
|
|
336
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);
|
|
337
275
|
});
|
|
338
|
-
}
|
|
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;
|
|
339
283
|
};
|
|
340
284
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
341
285
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -427,40 +371,33 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
427
371
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
428
372
|
});
|
|
429
373
|
}
|
|
430
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
431
|
-
return __generator(this, function (
|
|
432
|
-
switch (
|
|
374
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
375
|
+
return __generator(this, function (_a) {
|
|
376
|
+
switch (_a.label) {
|
|
433
377
|
case 0:
|
|
434
378
|
hubPoolClient = this.clients.hubPoolClient;
|
|
435
379
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
436
380
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
437
381
|
combinedRefunds = [];
|
|
438
382
|
widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
439
|
-
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/,
|
|
383
|
+
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
|
|
440
384
|
pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
441
385
|
return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
442
386
|
case 1:
|
|
443
|
-
arweaveData =
|
|
444
|
-
if (
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
452
|
-
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
453
|
-
_e.label = 4;
|
|
454
|
-
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
|
+
}
|
|
455
395
|
// Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
|
|
456
396
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
457
|
-
|
|
458
|
-
case
|
|
397
|
+
_a.label = 2;
|
|
398
|
+
case 2:
|
|
459
399
|
start = performance.now();
|
|
460
|
-
|
|
461
|
-
return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
462
|
-
case 6:
|
|
463
|
-
_d.apply(_c, [_e.sent()]);
|
|
400
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
464
401
|
this.logger.debug({
|
|
465
402
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
466
403
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -603,7 +540,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
603
540
|
};
|
|
604
541
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
605
542
|
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf,
|
|
543
|
+
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _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;
|
|
607
544
|
var _this = this;
|
|
608
545
|
return __generator(this, function (_c) {
|
|
609
546
|
switch (_c.label) {
|
|
@@ -638,9 +575,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
638
575
|
!deposit.fromLiteChain &&
|
|
639
576
|
!deposit.toLiteChain);
|
|
640
577
|
};
|
|
641
|
-
_depositIsExpired = function (deposit) {
|
|
642
|
-
return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
|
|
643
|
-
};
|
|
644
578
|
_getFillStatusForDeposit = function (deposit, queryBlock) {
|
|
645
579
|
return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit,
|
|
646
580
|
// We can assume that in production
|
|
@@ -680,13 +614,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
680
614
|
v3RelayHashes = {};
|
|
681
615
|
bundleDepositHashes = [];
|
|
682
616
|
olderDepositHashes = [];
|
|
683
|
-
decodeBundleDepositHash = function (depositHash) {
|
|
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";
|
|
690
617
|
depositCounter = 0;
|
|
691
618
|
_loop_2 = function (originChainId) {
|
|
692
619
|
var originClient = spokePoolClients[originChainId];
|
|
@@ -700,21 +627,18 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
700
627
|
// Only evaluate deposits that are in this bundle or in previous bundles. This means we cannot issue fill
|
|
701
628
|
// refunds or slow fills here for deposits that are in future bundles (i.e. "pre-fills"). Instead, we'll
|
|
702
629
|
// evaluate these pre-fills once the deposit is inside the "current" bundle block range.
|
|
703
|
-
if (deposit.blockNumber > originChainBlockRange[1]
|
|
630
|
+
if (isZeroValueDeposit(deposit) || deposit.blockNumber > originChainBlockRange[1]) {
|
|
704
631
|
return;
|
|
705
632
|
}
|
|
706
633
|
depositCounter++;
|
|
707
634
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
708
635
|
if (!v3RelayHashes[relayDataHash]) {
|
|
709
636
|
v3RelayHashes[relayDataHash] = {
|
|
710
|
-
|
|
637
|
+
deposit: deposit,
|
|
711
638
|
fill: undefined,
|
|
712
639
|
slowFillRequest: undefined,
|
|
713
640
|
};
|
|
714
641
|
}
|
|
715
|
-
else {
|
|
716
|
-
v3RelayHashes[relayDataHash].deposits.push(deposit);
|
|
717
|
-
}
|
|
718
642
|
// Once we've saved the deposit hash into v3RelayHashes, then we can exit early here if the inputAmount
|
|
719
643
|
// is 0 because there can be no expired amount to refund and no unexecutable slow fill amount to return
|
|
720
644
|
// if this deposit did expire. Input amount can only be zero at this point if the message is non-empty,
|
|
@@ -722,18 +646,12 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
722
646
|
if (deposit.inputAmount.eq(0)) {
|
|
723
647
|
return;
|
|
724
648
|
}
|
|
725
|
-
// Evaluate all expired deposits after fetching fill statuses,
|
|
726
|
-
// since we can't know for certain whether an expired deposit was filled a long time ago.
|
|
727
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
728
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
729
|
-
assert(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
730
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
731
649
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
732
|
-
bundleDepositHashes.push(
|
|
650
|
+
bundleDepositHashes.push(relayDataHash);
|
|
733
651
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
734
652
|
}
|
|
735
653
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
736
|
-
olderDepositHashes.push(
|
|
654
|
+
olderDepositHashes.push(relayDataHash);
|
|
737
655
|
}
|
|
738
656
|
});
|
|
739
657
|
}
|
|
@@ -758,7 +676,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
758
676
|
case 0:
|
|
759
677
|
originClient = spokePoolClients[originChainId];
|
|
760
678
|
_loop_4 = function (destinationChainId) {
|
|
761
|
-
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
679
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
|
|
762
680
|
return __generator(this, function (_g) {
|
|
763
681
|
switch (_g.label) {
|
|
764
682
|
case 0:
|
|
@@ -774,56 +692,41 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
774
692
|
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
|
|
775
693
|
// request for the deposit, we'd want to see the fill took place.
|
|
776
694
|
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
777
|
-
var relayDataHash,
|
|
695
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
778
696
|
return __generator(this, function (_a) {
|
|
779
697
|
switch (_a.label) {
|
|
780
698
|
case 0:
|
|
781
|
-
fillCounter++;
|
|
782
699
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
783
|
-
|
|
784
|
-
if (
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
// events.
|
|
805
|
-
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
806
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
807
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
808
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
700
|
+
fillCounter++;
|
|
701
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
702
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
703
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
704
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
705
|
+
// so this fill is validated.
|
|
706
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
707
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
708
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
709
|
+
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
710
|
+
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
711
|
+
// events.
|
|
712
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
713
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
714
|
+
!v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
|
|
715
|
+
!v3RelayHashes[relayDataHash].deposit.toLiteChain) {
|
|
716
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return [2 /*return*/];
|
|
809
721
|
}
|
|
810
|
-
duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
|
|
811
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
812
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
813
|
-
});
|
|
814
|
-
_a.label = 2;
|
|
815
|
-
case 2: return [3 /*break*/, 4];
|
|
816
|
-
case 3: throw new Error("Duplicate fill detected.");
|
|
817
|
-
case 4: return [2 /*return*/];
|
|
818
|
-
case 5:
|
|
819
722
|
// At this point, there is no relay hash dictionary entry for this fill, so we need to
|
|
820
|
-
// instantiate the entry.
|
|
723
|
+
// instantiate the entry.
|
|
821
724
|
v3RelayHashes[relayDataHash] = {
|
|
822
|
-
|
|
725
|
+
deposit: undefined,
|
|
823
726
|
fill: fill,
|
|
824
727
|
slowFillRequest: undefined,
|
|
825
728
|
};
|
|
826
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/,
|
|
729
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
|
|
827
730
|
// Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
|
|
828
731
|
// to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
|
|
829
732
|
// skip the historical query.
|
|
@@ -832,38 +735,29 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
832
735
|
return [2 /*return*/];
|
|
833
736
|
}
|
|
834
737
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
|
|
835
|
-
case
|
|
738
|
+
case 1:
|
|
836
739
|
historicalDeposit = _a.sent();
|
|
837
|
-
if (
|
|
838
|
-
bundleInvalidFillsV3.push(fill);
|
|
839
|
-
return [3 /*break*/, 9];
|
|
840
|
-
case 7:
|
|
841
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
842
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
843
|
-
return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
844
|
-
case 8:
|
|
845
|
-
fillToRefund = _a.sent();
|
|
846
|
-
if (!isDefined(fillToRefund)) {
|
|
740
|
+
if (!historicalDeposit.found) {
|
|
847
741
|
bundleInvalidFillsV3.push(fill);
|
|
848
|
-
// Don't return yet as we still need to mark down any unexecutable slow fill leaves
|
|
849
|
-
// in case this fast fill replaced a slow fill request.
|
|
850
742
|
}
|
|
851
743
|
else {
|
|
744
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
852
745
|
// @dev Since queryHistoricalDepositForFill validates the fill by checking individual
|
|
853
746
|
// object property values against the deposit's, we
|
|
854
747
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
855
748
|
// historical deposit query is not working as expected.
|
|
856
749
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
857
|
-
validatedBundleV3Fills.push(__assign(__assign({},
|
|
858
|
-
v3RelayHashes[relayDataHash].
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
750
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
751
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
752
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
753
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
754
|
+
!matchedDeposit.fromLiteChain &&
|
|
755
|
+
!matchedDeposit.toLiteChain) {
|
|
756
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
757
|
+
}
|
|
864
758
|
}
|
|
865
|
-
_a.label =
|
|
866
|
-
case
|
|
759
|
+
_a.label = 2;
|
|
760
|
+
case 2: return [2 /*return*/];
|
|
867
761
|
}
|
|
868
762
|
});
|
|
869
763
|
}); })];
|
|
@@ -888,33 +782,30 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
888
782
|
v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
|
|
889
783
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
890
784
|
// If there is a fill matching the relay hash, then this slow fill request can't be used
|
|
891
|
-
// to create a slow fill for a filled deposit.
|
|
892
|
-
|
|
893
|
-
|
|
785
|
+
// to create a slow fill for a filled deposit.
|
|
786
|
+
return [2 /*return*/];
|
|
787
|
+
}
|
|
788
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
789
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
790
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
894
791
|
return [2 /*return*/];
|
|
895
792
|
}
|
|
896
|
-
assert(isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary.");
|
|
897
|
-
matchedDeposit = v3RelayHashes[relayDataHash].deposits[0];
|
|
898
793
|
// If there is no fill matching the relay hash, then this might be a valid slow fill request
|
|
899
794
|
// that we should produce a slow fill leaf for. Check if the slow fill request is in the
|
|
900
795
|
// destination chain block range.
|
|
901
796
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
902
|
-
_canCreateSlowFillLeaf(matchedDeposit) &&
|
|
903
797
|
// Deposit must not have expired in this bundle.
|
|
904
|
-
|
|
798
|
+
slowFillRequest.fillDeadline >= bundleBlockTimestamps[destinationChainId][1]) {
|
|
905
799
|
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
906
800
|
// so this slow fill request relay data is correct.
|
|
907
801
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
908
802
|
}
|
|
909
803
|
}
|
|
910
|
-
else {
|
|
911
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
912
|
-
}
|
|
913
804
|
return [2 /*return*/];
|
|
914
805
|
}
|
|
915
806
|
// Instantiate dictionary if there is neither a deposit nor fill matching it.
|
|
916
807
|
v3RelayHashes[relayDataHash] = {
|
|
917
|
-
|
|
808
|
+
deposit: undefined,
|
|
918
809
|
fill: undefined,
|
|
919
810
|
slowFillRequest: slowFillRequest,
|
|
920
811
|
};
|
|
@@ -933,10 +824,10 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
933
824
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
934
825
|
// historical deposit query is not working as expected.
|
|
935
826
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
936
|
-
v3RelayHashes[relayDataHash].
|
|
827
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
937
828
|
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
938
829
|
// Deposit must not have expired in this bundle.
|
|
939
|
-
|
|
830
|
+
slowFillRequest.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
940
831
|
return [2 /*return*/];
|
|
941
832
|
}
|
|
942
833
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
@@ -949,35 +840,23 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
949
840
|
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
950
841
|
// for deposits that would expire in this bundle.
|
|
951
842
|
_g.sent();
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
var _a,
|
|
963
|
-
return __generator(this, function (
|
|
964
|
-
switch (
|
|
843
|
+
originBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
844
|
+
return [4 /*yield*/, mapAsync(bundleDepositHashes.filter(function (depositHash) {
|
|
845
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
846
|
+
return (deposit &&
|
|
847
|
+
deposit.originChainId === originChainId &&
|
|
848
|
+
deposit.destinationChainId === destinationChainId &&
|
|
849
|
+
deposit.blockNumber >= originBlockRange[0] &&
|
|
850
|
+
deposit.blockNumber <= originBlockRange[1] &&
|
|
851
|
+
!isZeroValueDeposit(deposit));
|
|
852
|
+
}), function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
853
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
854
|
+
return __generator(this, function (_b) {
|
|
855
|
+
switch (_b.label) {
|
|
965
856
|
case 0:
|
|
966
|
-
_a =
|
|
967
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
968
|
-
deposit = deposits[index];
|
|
857
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
969
858
|
if (!deposit)
|
|
970
859
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
971
|
-
if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
|
|
972
|
-
return [2 /*return*/];
|
|
973
|
-
}
|
|
974
|
-
isDuplicateDepositInBundle = bundleDepositHashes
|
|
975
|
-
.slice(0, currentBundleDepositHashIndex)
|
|
976
|
-
.some(function (_depositHash) {
|
|
977
|
-
var _relayDataHash = decodeBundleDepositHash(_depositHash).relayDataHash;
|
|
978
|
-
return _relayDataHash === relayDataHash;
|
|
979
|
-
});
|
|
980
|
-
duplicateDepositsInBundle = deposits.slice(index + 1);
|
|
981
860
|
// We are willing to refund a pre-fill multiple times for each duplicate deposit.
|
|
982
861
|
// This is because a duplicate deposit for a pre-fill cannot get
|
|
983
862
|
// refunded to the depositor anymore because its fill status on-chain has changed to Filled. Therefore
|
|
@@ -986,18 +865,11 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
986
865
|
// If fill exists in memory, then the only case in which we need to create a refund is if the
|
|
987
866
|
// the fill occurred in a previous bundle. There are no expiry refunds for filled deposits.
|
|
988
867
|
if (fill) {
|
|
989
|
-
if (!
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
// If fill is in the current bundle then we can assume there is already a refund for it, so only
|
|
995
|
-
// include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
|
|
996
|
-
// we won't consider it, following the previous treatment of fills after the bundle block range.
|
|
997
|
-
if (!isSlowFill(fill)) {
|
|
998
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
868
|
+
if (!isSlowFill(fill) && fill.blockNumber < destinationChainBlockRange[0]) {
|
|
869
|
+
// If fill is in the current bundle then we can assume there is already a refund for it, so only
|
|
870
|
+
// include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
|
|
871
|
+
// we won't consider it, following the previous treatment of fills after the bundle block range.
|
|
872
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1001
873
|
}
|
|
1002
874
|
return [2 /*return*/];
|
|
1003
875
|
}
|
|
@@ -1007,87 +879,69 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1007
879
|
// we need to create a slow fill leaf for the deposit. The latter should only happen if the slow fill request
|
|
1008
880
|
// took place in a prior bundle otherwise we would have already created a slow fill leaf for it.
|
|
1009
881
|
if (slowFillRequest) {
|
|
1010
|
-
if (
|
|
882
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
1011
883
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1012
884
|
}
|
|
1013
|
-
else if (
|
|
1014
|
-
|
|
1015
|
-
slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
1016
|
-
_canCreateSlowFillLeaf(deposit)) {
|
|
885
|
+
else if (_canCreateSlowFillLeaf(deposit) &&
|
|
886
|
+
slowFillRequest.blockNumber < destinationChainBlockRange[0]) {
|
|
1017
887
|
validatedBundleSlowFills.push(deposit);
|
|
1018
888
|
}
|
|
1019
889
|
return [2 /*return*/];
|
|
1020
890
|
}
|
|
1021
891
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
1022
892
|
case 1:
|
|
1023
|
-
fillStatus =
|
|
1024
|
-
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/,
|
|
1025
|
-
return [4 /*yield*/,
|
|
893
|
+
fillStatus = _b.sent();
|
|
894
|
+
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/, 3];
|
|
895
|
+
return [4 /*yield*/, findFillEvent(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
1026
896
|
case 2:
|
|
1027
|
-
prefill =
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
if (!!isDuplicateDepositInBundle) return [3 /*break*/, 4];
|
|
1031
|
-
duplicateDepositsInBundle.forEach(function (duplicateDeposit) {
|
|
1032
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
1033
|
-
});
|
|
1034
|
-
return [4 /*yield*/, verifyFillRepayment(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
1035
|
-
case 3:
|
|
1036
|
-
verifiedFill = _c.sent();
|
|
1037
|
-
if (canRefundPrefills && isDefined(verifiedFill) && !isSlowFill(verifiedFill)) {
|
|
1038
|
-
validatedBundleV3Fills.push(__assign(__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
897
|
+
prefill = (_b.sent());
|
|
898
|
+
if (!isSlowFill(prefill)) {
|
|
899
|
+
validatedBundleV3Fills.push(__assign(__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1039
900
|
}
|
|
1040
|
-
|
|
1041
|
-
case
|
|
1042
|
-
|
|
1043
|
-
if (_depositIsExpired(deposit)) {
|
|
901
|
+
return [3 /*break*/, 4];
|
|
902
|
+
case 3:
|
|
903
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
1044
904
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1045
905
|
}
|
|
1046
906
|
// If slow fill requested, then issue a slow fill leaf for the deposit.
|
|
1047
907
|
else if (fillStatus === FillStatus.RequestedSlowFill) {
|
|
1048
908
|
// Input and Output tokens must be equivalent on the deposit for this to be slow filled.
|
|
1049
909
|
// Slow fill requests for deposits from or to lite chains are considered invalid
|
|
1050
|
-
if (
|
|
910
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
1051
911
|
// If deposit newly expired, then we can't create a slow fill leaf for it but we can
|
|
1052
912
|
// create a deposit refund for it.
|
|
1053
913
|
validatedBundleSlowFills.push(deposit);
|
|
1054
914
|
}
|
|
1055
915
|
}
|
|
1056
|
-
|
|
1057
|
-
case
|
|
916
|
+
_b.label = 4;
|
|
917
|
+
case 4: return [2 /*return*/];
|
|
1058
918
|
}
|
|
1059
919
|
});
|
|
1060
920
|
}); })];
|
|
1061
921
|
case 3:
|
|
1062
|
-
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
1063
|
-
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
1064
|
-
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
1065
|
-
// this "pre-fill" if the fill took place in a previous bundle.
|
|
1066
|
-
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
1067
|
-
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
1068
|
-
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
1069
|
-
// @todo Only start refunding pre-fills and slow fill requests after a config store version is activated. We
|
|
1070
|
-
// should remove this check once we've advanced far beyond the version bump block.
|
|
1071
922
|
_g.sent();
|
|
1072
923
|
// For all fills that came after a slow fill request, we can now check if the slow fill request
|
|
1073
924
|
// was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
|
|
1074
925
|
// leaf that is now unexecutable.
|
|
1075
926
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
1076
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
927
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1077
928
|
assert((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
1078
929
|
// Needed for TSC - are implicitely checking that deposit exists by making it to this point.
|
|
1079
|
-
if (!
|
|
930
|
+
if (!deposit) {
|
|
1080
931
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1081
932
|
}
|
|
1082
933
|
// We should never push fast fills involving lite chains here because slow fill requests for them are invalid:
|
|
1083
|
-
assert(
|
|
934
|
+
assert(!deposit.fromLiteChain && !deposit.toLiteChain, "fastFillsReplacingSlowFills should not contain lite chain deposits");
|
|
1084
935
|
var destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1085
936
|
if (
|
|
1086
|
-
// If
|
|
1087
|
-
//
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
937
|
+
// If the slow fill request that was replaced by this fill was in an older bundle, then we don't
|
|
938
|
+
// need to check if the slow fill request was valid since we can assume all bundles in the past
|
|
939
|
+
// were validated. However, we might as well double check.
|
|
940
|
+
_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
941
|
+
// If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
|
|
942
|
+
// created that would be considered excess.
|
|
943
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
944
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1091
945
|
}
|
|
1092
946
|
});
|
|
1093
947
|
return [2 /*return*/];
|
|
@@ -1131,31 +985,27 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1131
985
|
// For all deposits older than this bundle, we need to check if they expired in this bundle and if they did,
|
|
1132
986
|
// whether there was a slow fill created for it in a previous bundle that is now unexecutable and replaced
|
|
1133
987
|
// by a new expired deposit refund.
|
|
1134
|
-
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (
|
|
1135
|
-
var _a,
|
|
1136
|
-
return __generator(this, function (
|
|
1137
|
-
switch (
|
|
988
|
+
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (relayDataHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
989
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
990
|
+
return __generator(this, function (_b) {
|
|
991
|
+
switch (_b.label) {
|
|
1138
992
|
case 0:
|
|
1139
|
-
_a =
|
|
1140
|
-
|
|
1141
|
-
if (!deposits || deposits.length < 1) {
|
|
1142
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1143
|
-
}
|
|
1144
|
-
deposit = deposits[index];
|
|
993
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
994
|
+
assert(isDefined(deposit), "Deposit should exist in relay hash dictionary.");
|
|
1145
995
|
destinationChainId = deposit.destinationChainId;
|
|
1146
996
|
destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1147
997
|
if (!
|
|
1148
998
|
// If there is a valid fill that we saw matching this deposit, then it does not need a refund.
|
|
1149
999
|
(!fill &&
|
|
1150
1000
|
isDefined(deposit) && // Needed for TSC - we check this above.
|
|
1151
|
-
|
|
1001
|
+
deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1] &&
|
|
1152
1002
|
deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
|
|
1153
1003
|
spokePoolClients[destinationChainId] !== undefined))
|
|
1154
1004
|
// If there is a valid fill that we saw matching this deposit, then it does not need a refund.
|
|
1155
1005
|
return [3 /*break*/, 2];
|
|
1156
1006
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
1157
1007
|
case 1:
|
|
1158
|
-
fillStatus =
|
|
1008
|
+
fillStatus = _b.sent();
|
|
1159
1009
|
// If there is no matching fill and the deposit expired in this bundle and the fill status on-chain is not
|
|
1160
1010
|
// Filled, then we can to refund it as an expired deposit.
|
|
1161
1011
|
if (fillStatus !== FillStatus.Filled) {
|
|
@@ -1164,7 +1014,8 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1164
1014
|
// If fill status is RequestedSlowFill, then we might need to mark down an unexecutable
|
|
1165
1015
|
// slow fill that we're going to replace with an expired deposit refund.
|
|
1166
1016
|
// If deposit cannot be slow filled, then exit early.
|
|
1167
|
-
|
|
1017
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
1018
|
+
if (fillStatus !== FillStatus.RequestedSlowFill || deposit.fromLiteChain || deposit.toLiteChain) {
|
|
1168
1019
|
return [2 /*return*/];
|
|
1169
1020
|
}
|
|
1170
1021
|
// Now, check if there was a slow fill created for this deposit in a previous bundle which would now be
|
|
@@ -1172,12 +1023,17 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1172
1023
|
// slow fill request or the matching slow fill request took place in a previous bundle.
|
|
1173
1024
|
// If there is a slow fill request in this bundle, then the expired deposit refund will supercede
|
|
1174
1025
|
// the slow fill request. If there is no slow fill request seen or its older than this bundle, then we can
|
|
1175
|
-
// assume a slow fill leaf was created for it because
|
|
1176
|
-
//
|
|
1177
|
-
if (
|
|
1026
|
+
// assume a slow fill leaf was created for it because its tokens are equivalent. The slow fill request was
|
|
1027
|
+
// also sent before the fill deadline expired since we checked that above.
|
|
1028
|
+
if (
|
|
1029
|
+
// Since this deposit was requested for a slow fill in an older bundle at this point, we don't
|
|
1030
|
+
// technically need to check if the slow fill request was valid since we can assume all bundles in the past
|
|
1031
|
+
// were validated. However, we might as well double check.
|
|
1032
|
+
this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
1033
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
1178
1034
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1179
1035
|
}
|
|
1180
|
-
|
|
1036
|
+
_b.label = 2;
|
|
1181
1037
|
case 2: return [2 /*return*/];
|
|
1182
1038
|
}
|
|
1183
1039
|
});
|
|
@@ -1192,7 +1048,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1192
1048
|
promises = [
|
|
1193
1049
|
validatedBundleV3Fills.length > 0
|
|
1194
1050
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
1195
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1051
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1196
1052
|
assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1197
1053
|
var paymentChainId = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1198
1054
|
return __assign(__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1219,10 +1075,10 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1219
1075
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1220
1076
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1221
1077
|
var fill = validatedBundleV3Fills[idx];
|
|
1222
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1078
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1223
1079
|
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1224
1080
|
var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1225
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
1081
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1226
1082
|
});
|
|
1227
1083
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1228
1084
|
var lpFeePct = _a.realizedLpFeePct;
|
|
@@ -1265,17 +1121,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1265
1121
|
// spoke pool contract. However, this internal function is used to uniquely identify a bridging event
|
|
1266
1122
|
// for speed since its easier to build a string from the event data than to hash it.
|
|
1267
1123
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1268
|
-
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
|
|
1269
|
-
};
|
|
1270
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1271
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1272
|
-
return __generator(this, function (_a) {
|
|
1273
|
-
switch (_a.label) {
|
|
1274
|
-
case 0: return [4 /*yield*/, findFillEvent(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1275
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1276
|
-
}
|
|
1277
|
-
});
|
|
1278
|
-
});
|
|
1124
|
+
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);
|
|
1279
1125
|
};
|
|
1280
1126
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1281
1127
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1286,7 +1132,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1286
1132
|
case 0:
|
|
1287
1133
|
_b = (_a = Object).fromEntries;
|
|
1288
1134
|
return [4 /*yield*/, mapAsync(chainIds, function (chainId, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1289
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
1135
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1290
1136
|
return __generator(this, function (_c) {
|
|
1291
1137
|
switch (_c.label) {
|
|
1292
1138
|
case 0:
|
|
@@ -1301,7 +1147,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1301
1147
|
return [2 /*return*/];
|
|
1302
1148
|
}
|
|
1303
1149
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1304
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
1150
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1305
1151
|
return [4 /*yield*/, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1306
1152
|
case 1:
|
|
1307
1153
|
_b = [
|
|
@@ -1311,11 +1157,9 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1311
1157
|
case 2:
|
|
1312
1158
|
_a = _b.concat([
|
|
1313
1159
|
_c.sent()
|
|
1314
|
-
]), startTime = _a[0],
|
|
1315
|
-
endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
|
|
1316
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1160
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
1317
1161
|
// Sanity checks:
|
|
1318
|
-
assert(endTime >= startTime, "End time
|
|
1162
|
+
assert(endTime >= startTime, "End time should be greater than start time.");
|
|
1319
1163
|
assert(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1320
1164
|
return [2 /*return*/, [chainId, [startTime, endTime]]];
|
|
1321
1165
|
}
|