@across-protocol/sdk 4.0.0-beta.27 → 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 +162 -318
- 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 +186 -382
- 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 -382
- 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
|
}
|
|
@@ -171,7 +162,8 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
171
162
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
172
163
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
173
164
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
174
|
-
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),
|
|
175
167
|
});
|
|
176
168
|
return [2 /*return*/, bundleData];
|
|
177
169
|
}
|
|
@@ -217,124 +209,77 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
217
209
|
return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
218
210
|
case 1:
|
|
219
211
|
arweaveData = _a.sent();
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
// The latest proposed bundle's refund leaves might have already been partially or entirely executed.
|
|
240
|
-
// We have to deduct the executed amounts from the total refund amounts.
|
|
241
|
-
return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
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)];
|
|
242
231
|
}
|
|
243
232
|
});
|
|
244
233
|
});
|
|
245
234
|
};
|
|
246
235
|
// @dev This helper function should probably be moved to the InventoryClient
|
|
247
236
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return [4 /*yield*/, filterAsync(this_1.spokePoolClients[chainId].getFills(), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
265
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
266
|
-
return __generator(this, function (_a) {
|
|
267
|
-
switch (_a.label) {
|
|
268
|
-
case 0:
|
|
269
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
270
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
271
|
-
isZeroValueFillOrSlowFillRequest(fill)) {
|
|
272
|
-
return [2 /*return*/, false];
|
|
273
|
-
}
|
|
274
|
-
// If origin spoke pool client isn't defined, we can't validate it.
|
|
275
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
276
|
-
return [2 /*return*/, false];
|
|
277
|
-
}
|
|
278
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
279
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
280
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
281
|
-
if (!hasMatchingDeposit) return [3 /*break*/, 2];
|
|
282
|
-
return [4 /*yield*/, verifyFillRepayment(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit,
|
|
283
|
-
// @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
|
|
284
|
-
// disabled block ranges.
|
|
285
|
-
this.clients.configStoreClient
|
|
286
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
287
|
-
.filter(function (_chainId, i) { return !isChainDisabled(blockRanges[i]); }))];
|
|
288
|
-
case 1:
|
|
289
|
-
validRepayment = _a.sent();
|
|
290
|
-
if (!isDefined(validRepayment)) {
|
|
291
|
-
return [2 /*return*/, false];
|
|
292
|
-
}
|
|
293
|
-
_a.label = 2;
|
|
294
|
-
case 2: return [2 /*return*/, hasMatchingDeposit];
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}); })];
|
|
298
|
-
case 1:
|
|
299
|
-
fillsToCount = _b.sent();
|
|
300
|
-
fillsToCount.forEach(function (fill) {
|
|
301
|
-
var _a, _b, _c;
|
|
302
|
-
var _d;
|
|
303
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
304
|
-
assert(isDefined(matchingDeposit), "Deposit not found for fill.");
|
|
305
|
-
var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
|
|
306
|
-
), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
307
|
-
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
|
|
308
|
-
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
|
|
309
|
-
// in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
|
|
310
|
-
// worst from the relayer's perspective.
|
|
311
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
312
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
313
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
314
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
|
|
315
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
316
|
-
});
|
|
317
|
-
return [2 /*return*/];
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
this_1 = this;
|
|
322
|
-
_i = 0, chainIds_1 = chainIds;
|
|
323
|
-
_a.label = 1;
|
|
324
|
-
case 1:
|
|
325
|
-
if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
|
|
326
|
-
chainId = chainIds_1[_i];
|
|
327
|
-
return [5 /*yield**/, _loop_1(chainId)];
|
|
328
|
-
case 2:
|
|
329
|
-
_a.sent();
|
|
330
|
-
_a.label = 3;
|
|
331
|
-
case 3:
|
|
332
|
-
_i++;
|
|
333
|
-
return [3 /*break*/, 1];
|
|
334
|
-
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;
|
|
335
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);
|
|
336
275
|
});
|
|
337
|
-
}
|
|
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;
|
|
338
283
|
};
|
|
339
284
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
340
285
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -426,40 +371,33 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
426
371
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
427
372
|
});
|
|
428
373
|
}
|
|
429
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
430
|
-
return __generator(this, function (
|
|
431
|
-
switch (
|
|
374
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
375
|
+
return __generator(this, function (_a) {
|
|
376
|
+
switch (_a.label) {
|
|
432
377
|
case 0:
|
|
433
378
|
hubPoolClient = this.clients.hubPoolClient;
|
|
434
379
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
435
380
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
436
381
|
combinedRefunds = [];
|
|
437
382
|
widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
438
|
-
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/,
|
|
383
|
+
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
|
|
439
384
|
pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
440
385
|
return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
441
386
|
case 1:
|
|
442
|
-
arweaveData =
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
451
|
-
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
452
|
-
_e.label = 4;
|
|
453
|
-
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
|
+
}
|
|
454
395
|
// Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
|
|
455
396
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
456
|
-
|
|
457
|
-
case
|
|
397
|
+
_a.label = 2;
|
|
398
|
+
case 2:
|
|
458
399
|
start = performance.now();
|
|
459
|
-
|
|
460
|
-
return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
461
|
-
case 6:
|
|
462
|
-
_d.apply(_c, [_e.sent()]);
|
|
400
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
463
401
|
this.logger.debug({
|
|
464
402
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
465
403
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -602,7 +540,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
602
540
|
};
|
|
603
541
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
604
542
|
return __awaiter(this, void 0, void 0, function () {
|
|
605
|
-
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;
|
|
606
544
|
var _this = this;
|
|
607
545
|
return __generator(this, function (_c) {
|
|
608
546
|
switch (_c.label) {
|
|
@@ -622,7 +560,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
622
560
|
bundleDepositsV3 = {};
|
|
623
561
|
bundleFillsV3 = {};
|
|
624
562
|
bundleInvalidFillsV3 = [];
|
|
625
|
-
bundleUnrepayableFillsV3 = [];
|
|
626
563
|
bundleSlowFillsV3 = {};
|
|
627
564
|
expiredDepositsToRefundV3 = {};
|
|
628
565
|
unexecutableSlowFills = {};
|
|
@@ -680,13 +617,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
680
617
|
v3RelayHashes = {};
|
|
681
618
|
bundleDepositHashes = [];
|
|
682
619
|
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
620
|
depositCounter = 0;
|
|
691
621
|
_loop_2 = function (originChainId) {
|
|
692
622
|
var originClient = spokePoolClients[originChainId];
|
|
@@ -707,14 +637,11 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
707
637
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
708
638
|
if (!v3RelayHashes[relayDataHash]) {
|
|
709
639
|
v3RelayHashes[relayDataHash] = {
|
|
710
|
-
|
|
640
|
+
deposit: deposit,
|
|
711
641
|
fill: undefined,
|
|
712
642
|
slowFillRequest: undefined,
|
|
713
643
|
};
|
|
714
644
|
}
|
|
715
|
-
else {
|
|
716
|
-
v3RelayHashes[relayDataHash].deposits.push(deposit);
|
|
717
|
-
}
|
|
718
645
|
// Once we've saved the deposit hash into v3RelayHashes, then we can exit early here if the inputAmount
|
|
719
646
|
// is 0 because there can be no expired amount to refund and no unexecutable slow fill amount to return
|
|
720
647
|
// if this deposit did expire. Input amount can only be zero at this point if the message is non-empty,
|
|
@@ -722,18 +649,12 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
722
649
|
if (deposit.inputAmount.eq(0)) {
|
|
723
650
|
return;
|
|
724
651
|
}
|
|
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
652
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
732
|
-
bundleDepositHashes.push(
|
|
653
|
+
bundleDepositHashes.push(relayDataHash);
|
|
733
654
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
734
655
|
}
|
|
735
656
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
736
|
-
olderDepositHashes.push(
|
|
657
|
+
olderDepositHashes.push(relayDataHash);
|
|
737
658
|
}
|
|
738
659
|
});
|
|
739
660
|
}
|
|
@@ -758,7 +679,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
758
679
|
case 0:
|
|
759
680
|
originClient = spokePoolClients[originChainId];
|
|
760
681
|
_loop_4 = function (destinationChainId) {
|
|
761
|
-
var destinationClient, destinationChainBlockRange,
|
|
682
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
|
|
762
683
|
return __generator(this, function (_g) {
|
|
763
684
|
switch (_g.label) {
|
|
764
685
|
case 0:
|
|
@@ -767,7 +688,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
767
688
|
}
|
|
768
689
|
destinationClient = spokePoolClients[destinationChainId];
|
|
769
690
|
destinationChainBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
770
|
-
originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
771
691
|
fastFillsReplacingSlowFills = [];
|
|
772
692
|
return [4 /*yield*/, forEachAsync(destinationClient
|
|
773
693
|
.getFillsForOriginChain(originChainId)
|
|
@@ -775,62 +695,40 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
775
695
|
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
|
|
776
696
|
// request for the deposit, we'd want to see the fill took place.
|
|
777
697
|
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
778
|
-
var relayDataHash,
|
|
698
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
779
699
|
return __generator(this, function (_a) {
|
|
780
700
|
switch (_a.label) {
|
|
781
701
|
case 0:
|
|
782
|
-
fillCounter++;
|
|
783
702
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
784
|
-
|
|
785
|
-
if (
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund_1), { quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp }));
|
|
802
|
-
duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
|
|
803
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
804
|
-
// If fill is a slow fill, refund deposit to depositor, otherwise refund to filler.
|
|
805
|
-
if (isSlowFill(fill)) {
|
|
806
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
807
|
-
}
|
|
808
|
-
else {
|
|
809
|
-
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
|
+
}
|
|
810
720
|
}
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
814
|
-
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
815
|
-
// events.
|
|
816
|
-
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
817
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
818
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
819
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
721
|
+
}
|
|
722
|
+
return [2 /*return*/];
|
|
820
723
|
}
|
|
821
|
-
_a.label = 2;
|
|
822
|
-
case 2: return [3 /*break*/, 4];
|
|
823
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
824
|
-
case 4: return [2 /*return*/];
|
|
825
|
-
case 5:
|
|
826
724
|
// At this point, there is no relay hash dictionary entry for this fill, so we need to
|
|
827
|
-
// instantiate the entry.
|
|
725
|
+
// instantiate the entry.
|
|
828
726
|
v3RelayHashes[relayDataHash] = {
|
|
829
|
-
|
|
727
|
+
deposit: undefined,
|
|
830
728
|
fill: fill,
|
|
831
729
|
slowFillRequest: undefined,
|
|
832
730
|
};
|
|
833
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/,
|
|
731
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
|
|
834
732
|
// Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
|
|
835
733
|
// to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
|
|
836
734
|
// skip the historical query.
|
|
@@ -839,47 +737,28 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
839
737
|
return [2 /*return*/];
|
|
840
738
|
}
|
|
841
739
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
|
|
842
|
-
case
|
|
740
|
+
case 1:
|
|
843
741
|
historicalDeposit = _a.sent();
|
|
844
|
-
if (
|
|
845
|
-
bundleInvalidFillsV3.push(fill);
|
|
846
|
-
return [3 /*break*/, 9];
|
|
847
|
-
case 7:
|
|
848
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
849
|
-
// If deposit is in a following bundle, then this fill will have to refunded once that deposit
|
|
850
|
-
// is in the current bundle.
|
|
851
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
742
|
+
if (!historicalDeposit.found) {
|
|
852
743
|
bundleInvalidFillsV3.push(fill);
|
|
853
|
-
return [2 /*return*/];
|
|
854
|
-
}
|
|
855
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
856
|
-
return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
857
|
-
case 8:
|
|
858
|
-
fillToRefund = _a.sent();
|
|
859
|
-
if (!isDefined(fillToRefund)) {
|
|
860
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
861
|
-
// Don't return yet as we still need to mark down any unexecutable slow fill leaves
|
|
862
|
-
// in case this fast fill replaced a slow fill request.
|
|
863
744
|
}
|
|
864
745
|
else {
|
|
746
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
865
747
|
// @dev Since queryHistoricalDepositForFill validates the fill by checking individual
|
|
866
748
|
// object property values against the deposit's, we
|
|
867
749
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
868
750
|
// historical deposit query is not working as expected.
|
|
869
751
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
870
|
-
validatedBundleV3Fills.push(__assign(__assign({},
|
|
871
|
-
v3RelayHashes[relayDataHash].
|
|
872
|
-
//
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
878
|
-
_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
879
|
-
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
|
+
}
|
|
880
759
|
}
|
|
881
|
-
_a.label =
|
|
882
|
-
case
|
|
760
|
+
_a.label = 2;
|
|
761
|
+
case 2: return [2 /*return*/];
|
|
883
762
|
}
|
|
884
763
|
});
|
|
885
764
|
}); })];
|
|
@@ -904,13 +783,11 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
904
783
|
v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
|
|
905
784
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
906
785
|
// If there is a fill matching the relay hash, then this slow fill request can't be used
|
|
907
|
-
// to create a slow fill for a filled deposit.
|
|
908
|
-
// slow fill requests must precede fills, so if there is a matching fill for this request's
|
|
909
|
-
// relay data, then this slow fill will be unexecutable.
|
|
786
|
+
// to create a slow fill for a filled deposit.
|
|
910
787
|
return [2 /*return*/];
|
|
911
788
|
}
|
|
912
|
-
assert(isDefined(v3RelayHashes[relayDataHash].
|
|
913
|
-
matchedDeposit = v3RelayHashes[relayDataHash].
|
|
789
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
790
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
914
791
|
// If there is no fill matching the relay hash, then this might be a valid slow fill request
|
|
915
792
|
// that we should produce a slow fill leaf for. Check if the slow fill request is in the
|
|
916
793
|
// destination chain block range.
|
|
@@ -923,19 +800,16 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
923
800
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
924
801
|
}
|
|
925
802
|
}
|
|
926
|
-
else {
|
|
927
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
928
|
-
}
|
|
929
803
|
return [2 /*return*/];
|
|
930
804
|
}
|
|
931
805
|
// Instantiate dictionary if there is neither a deposit nor fill matching it.
|
|
932
806
|
v3RelayHashes[relayDataHash] = {
|
|
933
|
-
|
|
807
|
+
deposit: undefined,
|
|
934
808
|
fill: undefined,
|
|
935
809
|
slowFillRequest: slowFillRequest,
|
|
936
810
|
};
|
|
937
|
-
if (!(
|
|
938
|
-
slowFillRequest.
|
|
811
|
+
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
812
|
+
INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3 /*break*/, 2];
|
|
939
813
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, slowFillRequest)];
|
|
940
814
|
case 1:
|
|
941
815
|
historicalDeposit = _a.sent();
|
|
@@ -944,17 +818,12 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
944
818
|
return [2 /*return*/];
|
|
945
819
|
}
|
|
946
820
|
matchedDeposit = historicalDeposit.deposit;
|
|
947
|
-
// If deposit is in a following bundle, then this slow fill request will have to be created
|
|
948
|
-
// once that deposit is in the current bundle.
|
|
949
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
950
|
-
return [2 /*return*/];
|
|
951
|
-
}
|
|
952
821
|
// @dev Since queryHistoricalDepositForFill validates the slow fill request by checking individual
|
|
953
822
|
// object property values against the deposit's, we
|
|
954
823
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
955
824
|
// historical deposit query is not working as expected.
|
|
956
825
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
957
|
-
v3RelayHashes[relayDataHash].
|
|
826
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
958
827
|
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
959
828
|
// Deposit must not have expired in this bundle.
|
|
960
829
|
_depositIsExpired(matchedDeposit)) {
|
|
@@ -970,29 +839,23 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
970
839
|
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
971
840
|
// for deposits that would expire in this bundle.
|
|
972
841
|
_g.sent();
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
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) {
|
|
984
855
|
case 0:
|
|
985
|
-
_a =
|
|
986
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
987
|
-
if (!deposits || deposits.length === 0) {
|
|
988
|
-
throw new Error("Deposits should exist in relay hash dictionary.");
|
|
989
|
-
}
|
|
990
|
-
deposit = deposits[index];
|
|
856
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
991
857
|
if (!deposit)
|
|
992
858
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
993
|
-
if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
|
|
994
|
-
return [2 /*return*/];
|
|
995
|
-
}
|
|
996
859
|
// We are willing to refund a pre-fill multiple times for each duplicate deposit.
|
|
997
860
|
// This is because a duplicate deposit for a pre-fill cannot get
|
|
998
861
|
// refunded to the depositor anymore because its fill status on-chain has changed to Filled. Therefore
|
|
@@ -1001,18 +864,11 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1001
864
|
// If fill exists in memory, then the only case in which we need to create a refund is if the
|
|
1002
865
|
// the fill occurred in a previous bundle. There are no expiry refunds for filled deposits.
|
|
1003
866
|
if (fill) {
|
|
1004
|
-
if (
|
|
867
|
+
if (fill.blockNumber < destinationChainBlockRange[0] && !isSlowFill(fill)) {
|
|
1005
868
|
// If fill is in the current bundle then we can assume there is already a refund for it, so only
|
|
1006
869
|
// include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
|
|
1007
870
|
// we won't consider it, following the previous treatment of fills after the bundle block range.
|
|
1008
|
-
|
|
1009
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1010
|
-
}
|
|
1011
|
-
else {
|
|
1012
|
-
// Slow fills cannot result in refunds to a relayer to refund the deposit. Slow fills also
|
|
1013
|
-
// were created after the deposit was sent, so we can assume this deposit is a duplicate.
|
|
1014
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1015
|
-
}
|
|
871
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1016
872
|
}
|
|
1017
873
|
return [2 /*return*/];
|
|
1018
874
|
}
|
|
@@ -1025,8 +881,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1025
881
|
if (_depositIsExpired(deposit)) {
|
|
1026
882
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1027
883
|
}
|
|
1028
|
-
else if (
|
|
1029
|
-
slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
884
|
+
else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
1030
885
|
_canCreateSlowFillLeaf(deposit)) {
|
|
1031
886
|
validatedBundleSlowFills.push(deposit);
|
|
1032
887
|
}
|
|
@@ -1034,31 +889,16 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1034
889
|
}
|
|
1035
890
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
1036
891
|
case 1:
|
|
1037
|
-
fillStatus =
|
|
1038
|
-
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/,
|
|
1039
|
-
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)];
|
|
1040
895
|
case 2:
|
|
1041
|
-
prefill =
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
if (!canRefundPrefills) return [3 /*break*/, 4];
|
|
1045
|
-
return [4 /*yield*/, verifyFillRepayment(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
1046
|
-
case 3:
|
|
1047
|
-
verifiedFill = _c.sent();
|
|
1048
|
-
if (!isDefined(verifiedFill)) {
|
|
1049
|
-
bundleUnrepayableFillsV3.push(prefill);
|
|
1050
|
-
}
|
|
1051
|
-
else if (!isSlowFill(verifiedFill)) {
|
|
1052
|
-
validatedBundleV3Fills.push(__assign(__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
// Slow fills cannot result in refunds to a relayer to refund the deposit. Slow fills also
|
|
1056
|
-
// were created after the deposit was sent, so we can assume this deposit is a duplicate.
|
|
1057
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
896
|
+
prefill = (_b.sent());
|
|
897
|
+
if (!isSlowFill(prefill)) {
|
|
898
|
+
validatedBundleV3Fills.push(__assign(__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1058
899
|
}
|
|
1059
|
-
|
|
1060
|
-
case
|
|
1061
|
-
case 5:
|
|
900
|
+
return [3 /*break*/, 4];
|
|
901
|
+
case 3:
|
|
1062
902
|
if (_depositIsExpired(deposit)) {
|
|
1063
903
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1064
904
|
}
|
|
@@ -1066,45 +906,38 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1066
906
|
else if (fillStatus === FillStatus.RequestedSlowFill) {
|
|
1067
907
|
// Input and Output tokens must be equivalent on the deposit for this to be slow filled.
|
|
1068
908
|
// Slow fill requests for deposits from or to lite chains are considered invalid
|
|
1069
|
-
if (
|
|
909
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
1070
910
|
// If deposit newly expired, then we can't create a slow fill leaf for it but we can
|
|
1071
911
|
// create a deposit refund for it.
|
|
1072
912
|
validatedBundleSlowFills.push(deposit);
|
|
1073
913
|
}
|
|
1074
914
|
}
|
|
1075
|
-
|
|
1076
|
-
case
|
|
915
|
+
_b.label = 4;
|
|
916
|
+
case 4: return [2 /*return*/];
|
|
1077
917
|
}
|
|
1078
918
|
});
|
|
1079
919
|
}); })];
|
|
1080
920
|
case 3:
|
|
1081
|
-
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
1082
|
-
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
1083
|
-
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
1084
|
-
// this "pre-fill" if the fill took place in a previous bundle.
|
|
1085
|
-
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
1086
|
-
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
1087
|
-
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
1088
921
|
_g.sent();
|
|
1089
922
|
// For all fills that came after a slow fill request, we can now check if the slow fill request
|
|
1090
923
|
// was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
|
|
1091
924
|
// leaf that is now unexecutable.
|
|
1092
925
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
1093
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
926
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1094
927
|
assert((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
1095
928
|
// Needed for TSC - are implicitely checking that deposit exists by making it to this point.
|
|
1096
|
-
if (!
|
|
929
|
+
if (!deposit) {
|
|
1097
930
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1098
931
|
}
|
|
1099
932
|
// We should never push fast fills involving lite chains here because slow fill requests for them are invalid:
|
|
1100
|
-
assert(_canCreateSlowFillLeaf(
|
|
933
|
+
assert(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
|
|
1101
934
|
var destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1102
935
|
if (
|
|
1103
936
|
// If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
|
|
1104
937
|
// created that would be considered excess.
|
|
1105
938
|
!slowFillRequest ||
|
|
1106
939
|
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1107
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
940
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1108
941
|
}
|
|
1109
942
|
});
|
|
1110
943
|
return [2 /*return*/];
|
|
@@ -1148,17 +981,13 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1148
981
|
// For all deposits older than this bundle, we need to check if they expired in this bundle and if they did,
|
|
1149
982
|
// whether there was a slow fill created for it in a previous bundle that is now unexecutable and replaced
|
|
1150
983
|
// by a new expired deposit refund.
|
|
1151
|
-
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (
|
|
1152
|
-
var _a,
|
|
1153
|
-
return __generator(this, function (
|
|
1154
|
-
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) {
|
|
1155
988
|
case 0:
|
|
1156
|
-
_a =
|
|
1157
|
-
|
|
1158
|
-
if (!deposits || deposits.length < 1) {
|
|
1159
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1160
|
-
}
|
|
1161
|
-
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.");
|
|
1162
991
|
destinationChainId = deposit.destinationChainId;
|
|
1163
992
|
destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1164
993
|
if (!
|
|
@@ -1172,7 +1001,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1172
1001
|
return [3 /*break*/, 2];
|
|
1173
1002
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
1174
1003
|
case 1:
|
|
1175
|
-
fillStatus =
|
|
1004
|
+
fillStatus = _b.sent();
|
|
1176
1005
|
// If there is no matching fill and the deposit expired in this bundle and the fill status on-chain is not
|
|
1177
1006
|
// Filled, then we can to refund it as an expired deposit.
|
|
1178
1007
|
if (fillStatus !== FillStatus.Filled) {
|
|
@@ -1194,7 +1023,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1194
1023
|
if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1195
1024
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1196
1025
|
}
|
|
1197
|
-
|
|
1026
|
+
_b.label = 2;
|
|
1198
1027
|
case 2: return [2 /*return*/];
|
|
1199
1028
|
}
|
|
1200
1029
|
});
|
|
@@ -1209,7 +1038,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1209
1038
|
promises = [
|
|
1210
1039
|
validatedBundleV3Fills.length > 0
|
|
1211
1040
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
1212
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1041
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1213
1042
|
assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1214
1043
|
var paymentChainId = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1215
1044
|
return __assign(__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1236,19 +1065,14 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1236
1065
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1237
1066
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1238
1067
|
var fill = validatedBundleV3Fills[idx];
|
|
1239
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1068
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1240
1069
|
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1241
1070
|
var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1242
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
1071
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1243
1072
|
});
|
|
1244
1073
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1245
1074
|
var lpFeePct = _a.realizedLpFeePct;
|
|
1246
1075
|
var deposit = validatedBundleSlowFills[idx];
|
|
1247
|
-
// We should not create slow fill leaves for duplicate deposit hashes:
|
|
1248
|
-
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
1249
|
-
if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
|
|
1250
|
-
return;
|
|
1251
|
-
}
|
|
1252
1076
|
updateBundleSlowFills(bundleSlowFillsV3, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1253
1077
|
});
|
|
1254
1078
|
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
@@ -1256,7 +1080,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1256
1080
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
1257
1081
|
updateBundleExcessSlowFills(unexecutableSlowFills, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1258
1082
|
});
|
|
1259
|
-
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1083
|
+
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1260
1084
|
if (bundleInvalidFillsV3.length > 0) {
|
|
1261
1085
|
this.logger.debug({
|
|
1262
1086
|
at: "BundleDataClient#loadData",
|
|
@@ -1265,14 +1089,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1265
1089
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
1266
1090
|
});
|
|
1267
1091
|
}
|
|
1268
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
1269
|
-
this.logger.debug({
|
|
1270
|
-
at: "BundleDataClient#loadData",
|
|
1271
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable V3 fills in range",
|
|
1272
|
-
blockRangesForChains: blockRangesForChains,
|
|
1273
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
1092
|
this.logger.debug({
|
|
1277
1093
|
at: "BundleDataClient#loadDataFromScratch",
|
|
1278
1094
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -1295,17 +1111,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1295
1111
|
// spoke pool contract. However, this internal function is used to uniquely identify a bridging event
|
|
1296
1112
|
// for speed since its easier to build a string from the event data than to hash it.
|
|
1297
1113
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1298
|
-
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
|
|
1299
|
-
};
|
|
1300
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1301
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1302
|
-
return __generator(this, function (_a) {
|
|
1303
|
-
switch (_a.label) {
|
|
1304
|
-
case 0: return [4 /*yield*/, findFillEvent(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1305
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
|
-
});
|
|
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);
|
|
1309
1115
|
};
|
|
1310
1116
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1311
1117
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1316,7 +1122,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1316
1122
|
case 0:
|
|
1317
1123
|
_b = (_a = Object).fromEntries;
|
|
1318
1124
|
return [4 /*yield*/, mapAsync(chainIds, function (chainId, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1319
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
1125
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1320
1126
|
return __generator(this, function (_c) {
|
|
1321
1127
|
switch (_c.label) {
|
|
1322
1128
|
case 0:
|
|
@@ -1331,7 +1137,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1331
1137
|
return [2 /*return*/];
|
|
1332
1138
|
}
|
|
1333
1139
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1334
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
1140
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1335
1141
|
return [4 /*yield*/, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1336
1142
|
case 1:
|
|
1337
1143
|
_b = [
|
|
@@ -1341,11 +1147,9 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1341
1147
|
case 2:
|
|
1342
1148
|
_a = _b.concat([
|
|
1343
1149
|
_c.sent()
|
|
1344
|
-
]), startTime = _a[0],
|
|
1345
|
-
endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
|
|
1346
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1150
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
1347
1151
|
// Sanity checks:
|
|
1348
|
-
assert(endTime >= startTime, "End time
|
|
1152
|
+
assert(endTime >= startTime, "End time should be greater than start time.");
|
|
1349
1153
|
assert(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1350
1154
|
return [2 /*return*/, [chainId, [startTime, endTime]]];
|
|
1351
1155
|
}
|