@across-protocol/sdk 3.4.20 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +219 -258
- 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/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/dist/cjs/clients/SpokePoolClient.d.ts +4 -0
- package/dist/cjs/clients/SpokePoolClient.js +10 -3
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +0 -12
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +2 -1
- 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 -2
- package/dist/cjs/utils/AddressUtils.js +1 -19
- 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 +3 -2
- package/dist/cjs/utils/DepositUtils.js +12 -13
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +0 -21
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/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.d.ts +2 -2
- package/dist/cjs/utils/SpokeUtils.js +53 -19
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +0 -1
- package/dist/cjs/utils/common.js +1 -2
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +280 -328
- 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/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/dist/esm/clients/SpokePoolClient.d.ts +12 -1
- package/dist/esm/clients/SpokePoolClient.js +18 -4
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +0 -12
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +1 -0
- 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 -2
- package/dist/esm/utils/AddressUtils.js +0 -25
- 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 +3 -2
- package/dist/esm/utils/DepositUtils.js +10 -13
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +1 -29
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/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.d.ts +2 -2
- package/dist/esm/utils/SpokeUtils.js +53 -18
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/abi/typechain/Multicall3.d.ts +1 -4
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
- package/dist/esm/utils/common.d.ts +0 -1
- package/dist/esm/utils/common.js +0 -1
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +1 -1
- 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/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/dist/types/clients/SpokePoolClient.d.ts +12 -1
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -0
- 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 -2
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts +3 -2
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.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 +2 -2
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/abi/typechain/Multicall3.d.ts +1 -4
- package/dist/types/utils/abi/typechain/Multicall3.d.ts.map +1 -1
- package/dist/types/utils/abi/typechain/common.d.ts.map +1 -1
- package/dist/types/utils/abi/typechain/factories/Multicall3__factory.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +246 -314
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
- package/src/clients/SpokePoolClient.ts +21 -4
- package/src/clients/mocks/MockSpokePoolClient.ts +0 -15
- package/src/constants.ts +2 -0
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -26
- package/src/utils/CachingUtils.ts +1 -1
- package/src/utils/DepositUtils.ts +12 -13
- package/src/utils/EventUtils.ts +1 -29
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +48 -29
- package/src/utils/common.ts +0 -2
- package/dist/cjs/providers/mockProvider.d.ts +0 -19
- package/dist/cjs/providers/mockProvider.js +0 -70
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/esm/providers/mockProvider.d.ts +0 -23
- package/dist/esm/providers/mockProvider.js +0 -73
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts +0 -24
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/src/providers/mockProvider.ts +0 -77
|
@@ -9,9 +9,6 @@ var utils_2 = require("./utils");
|
|
|
9
9
|
exports.INFINITE_FILL_DEADLINE = utils_1.bnUint32Max;
|
|
10
10
|
function updateExpiredDepositsV3(dict, deposit) {
|
|
11
11
|
var _a;
|
|
12
|
-
if ((0, utils_1.chainIsEvm)(deposit.originChainId) && !(0, utils_1.isValidEvmAddress)(deposit.depositor)) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
12
|
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
16
13
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
17
14
|
(0, utils_1.assign)(dict, [originChainId, inputToken], []);
|
|
@@ -26,11 +23,8 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
26
23
|
}
|
|
27
24
|
dict[originChainId][inputToken].push(deposit);
|
|
28
25
|
}
|
|
29
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken
|
|
26
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
30
27
|
var _a, _b;
|
|
31
|
-
if ((0, utils_1.chainIsEvm)(repaymentChainId) && !(0, utils_1.isValidEvmAddress)(repaymentAddress)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
28
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
35
29
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
|
|
36
30
|
fills: [],
|
|
@@ -39,22 +33,22 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
39
33
|
refunds: {},
|
|
40
34
|
});
|
|
41
35
|
}
|
|
42
|
-
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct
|
|
36
|
+
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
|
|
43
37
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
44
38
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
45
|
-
var realizedLpFee =
|
|
39
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
|
|
46
40
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
47
|
-
if (!(0, utils_1.isSlowFill)(
|
|
48
|
-
var refundAmount =
|
|
41
|
+
if (!(0, utils_1.isSlowFill)(fill)) {
|
|
42
|
+
var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
|
|
49
43
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
50
44
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
51
45
|
: refundAmount;
|
|
52
46
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
53
|
-
if (refundObj.refunds[
|
|
54
|
-
refundObj.refunds[
|
|
47
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
48
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
55
49
|
}
|
|
56
50
|
else {
|
|
57
|
-
refundObj.refunds[
|
|
51
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
54
|
}
|
|
@@ -68,9 +62,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
|
|
|
68
62
|
}
|
|
69
63
|
function updateBundleSlowFills(dict, deposit) {
|
|
70
64
|
var _a;
|
|
71
|
-
if ((0, utils_1.chainIsEvm)(deposit.destinationChainId) && !(0, utils_1.isValidEvmAddress)(deposit.recipient)) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
65
|
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
75
66
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
76
67
|
(0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
|
|
@@ -155,7 +146,7 @@ var BundleDataClient = (function () {
|
|
|
155
146
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
156
147
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
157
148
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
158
|
-
bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
|
|
149
|
+
bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
|
|
159
150
|
});
|
|
160
151
|
return [2, bundleData];
|
|
161
152
|
}
|
|
@@ -197,105 +188,64 @@ var BundleDataClient = (function () {
|
|
|
197
188
|
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
198
189
|
case 1:
|
|
199
190
|
arweaveData = _a.sent();
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
_a.label = 4;
|
|
214
|
-
case 4: return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
191
|
+
if (arweaveData === undefined) {
|
|
192
|
+
combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
196
|
+
combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
|
|
197
|
+
Object.keys(combinedRefunds).forEach(function (chainId) {
|
|
198
|
+
if (_this.spokePoolClients[Number(chainId)] === undefined) {
|
|
199
|
+
delete combinedRefunds[Number(chainId)];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
215
204
|
}
|
|
216
205
|
});
|
|
217
206
|
});
|
|
218
207
|
};
|
|
219
208
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
236
|
-
return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
237
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
238
|
-
return tslib_1.__generator(this, function (_a) {
|
|
239
|
-
switch (_a.label) {
|
|
240
|
-
case 0:
|
|
241
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
242
|
-
return [2, false];
|
|
243
|
-
}
|
|
244
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
245
|
-
return [2, false];
|
|
246
|
-
}
|
|
247
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
248
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
249
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
250
|
-
if (!hasMatchingDeposit) return [3, 2];
|
|
251
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
|
|
252
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
253
|
-
.filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
|
|
254
|
-
case 1:
|
|
255
|
-
validRepayment = _a.sent();
|
|
256
|
-
if (!(0, utils_1.isDefined)(validRepayment)) {
|
|
257
|
-
return [2, false];
|
|
258
|
-
}
|
|
259
|
-
_a.label = 2;
|
|
260
|
-
case 2: return [2, hasMatchingDeposit];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}); })];
|
|
264
|
-
case 1:
|
|
265
|
-
fillsToCount = _b.sent();
|
|
266
|
-
fillsToCount.forEach(function (fill) {
|
|
267
|
-
var _a, _b, _c;
|
|
268
|
-
var _d;
|
|
269
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
270
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
271
|
-
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
272
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
273
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
274
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
275
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
276
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
277
|
-
});
|
|
278
|
-
return [2];
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
this_1 = this;
|
|
283
|
-
_i = 0, chainIds_1 = chainIds;
|
|
284
|
-
_a.label = 1;
|
|
285
|
-
case 1:
|
|
286
|
-
if (!(_i < chainIds_1.length)) return [3, 4];
|
|
287
|
-
chainId = chainIds_1[_i];
|
|
288
|
-
return [5, _loop_1(chainId)];
|
|
289
|
-
case 2:
|
|
290
|
-
_a.sent();
|
|
291
|
-
_a.label = 3;
|
|
292
|
-
case 3:
|
|
293
|
-
_i++;
|
|
294
|
-
return [3, 1];
|
|
295
|
-
case 4: return [2, refundsForChain];
|
|
209
|
+
var _this = this;
|
|
210
|
+
var refundsForChain = {};
|
|
211
|
+
var _loop_1 = function (chainId) {
|
|
212
|
+
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
213
|
+
return "continue";
|
|
214
|
+
}
|
|
215
|
+
var chainIndex = chainIds.indexOf(chainId);
|
|
216
|
+
this_1.spokePoolClients[chainId]
|
|
217
|
+
.getFills()
|
|
218
|
+
.filter(function (fill) {
|
|
219
|
+
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
223
|
+
return false;
|
|
296
224
|
}
|
|
225
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
226
|
+
var hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
227
|
+
_this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
|
|
228
|
+
return hasMatchingDeposit;
|
|
229
|
+
})
|
|
230
|
+
.forEach(function (fill) {
|
|
231
|
+
var _a, _b, _c;
|
|
232
|
+
var _d;
|
|
233
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
234
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
235
|
+
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
236
|
+
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
237
|
+
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
238
|
+
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
239
|
+
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
240
|
+
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
297
241
|
});
|
|
298
|
-
}
|
|
242
|
+
};
|
|
243
|
+
var this_1 = this;
|
|
244
|
+
for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
|
|
245
|
+
var chainId = chainIds_1[_i];
|
|
246
|
+
_loop_1(chainId);
|
|
247
|
+
}
|
|
248
|
+
return refundsForChain;
|
|
299
249
|
};
|
|
300
250
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
301
251
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -338,10 +288,12 @@ var BundleDataClient = (function () {
|
|
|
338
288
|
case 1:
|
|
339
289
|
_a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
|
|
340
290
|
hubPoolClient = this.clients.hubPoolClient;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
291
|
+
return [4, (0, utils_2._buildPoolRebalanceRoot)(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
|
|
292
|
+
hubPoolClient: hubPoolClient,
|
|
293
|
+
configStoreClient: hubPoolClient.configStoreClient,
|
|
294
|
+
})];
|
|
295
|
+
case 2:
|
|
296
|
+
root = _b.sent();
|
|
345
297
|
return [2, {
|
|
346
298
|
root: root,
|
|
347
299
|
blockRanges: blockRanges,
|
|
@@ -365,39 +317,32 @@ var BundleDataClient = (function () {
|
|
|
365
317
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
366
318
|
});
|
|
367
319
|
}
|
|
368
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
369
|
-
return tslib_1.__generator(this, function (
|
|
370
|
-
switch (
|
|
320
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
321
|
+
return tslib_1.__generator(this, function (_a) {
|
|
322
|
+
switch (_a.label) {
|
|
371
323
|
case 0:
|
|
372
324
|
hubPoolClient = this.clients.hubPoolClient;
|
|
373
325
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
374
326
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
375
327
|
combinedRefunds = [];
|
|
376
328
|
widestBundleBlockRanges = (0, utils_2.getWidestPossibleExpectedBlockRange)(chainIds, this.spokePoolClients, (0, utils_2.getEndBlockBuffers)(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
377
|
-
if (!hubPoolClient.hasPendingProposal()) return [3,
|
|
329
|
+
if (!hubPoolClient.hasPendingProposal()) return [3, 2];
|
|
378
330
|
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
379
331
|
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
380
332
|
case 1:
|
|
381
|
-
arweaveData =
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
390
|
-
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
391
|
-
_e.label = 4;
|
|
392
|
-
case 4:
|
|
333
|
+
arweaveData = _a.sent();
|
|
334
|
+
if (arweaveData === undefined) {
|
|
335
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
339
|
+
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
340
|
+
}
|
|
393
341
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
394
|
-
|
|
395
|
-
case
|
|
342
|
+
_a.label = 2;
|
|
343
|
+
case 2:
|
|
396
344
|
start = performance.now();
|
|
397
|
-
|
|
398
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
399
|
-
case 6:
|
|
400
|
-
_d.apply(_c, [_e.sent()]);
|
|
345
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
401
346
|
this.logger.debug({
|
|
402
347
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
403
348
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -528,7 +473,7 @@ var BundleDataClient = (function () {
|
|
|
528
473
|
};
|
|
529
474
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
530
475
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
531
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3,
|
|
476
|
+
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;
|
|
532
477
|
var _this = this;
|
|
533
478
|
return tslib_1.__generator(this, function (_c) {
|
|
534
479
|
switch (_c.label) {
|
|
@@ -548,7 +493,6 @@ var BundleDataClient = (function () {
|
|
|
548
493
|
bundleDepositsV3 = {};
|
|
549
494
|
bundleFillsV3 = {};
|
|
550
495
|
bundleInvalidFillsV3 = [];
|
|
551
|
-
bundleUnrepayableFillsV3 = [];
|
|
552
496
|
bundleSlowFillsV3 = {};
|
|
553
497
|
expiredDepositsToRefundV3 = {};
|
|
554
498
|
unexecutableSlowFills = {};
|
|
@@ -556,6 +500,14 @@ var BundleDataClient = (function () {
|
|
|
556
500
|
var blockRangeForChain = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, chainId, chainIds);
|
|
557
501
|
return (0, utils_2.isChainDisabled)(blockRangeForChain);
|
|
558
502
|
};
|
|
503
|
+
_canCreateSlowFillLeaf = function (deposit) {
|
|
504
|
+
return (_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
505
|
+
!deposit.fromLiteChain &&
|
|
506
|
+
!deposit.toLiteChain);
|
|
507
|
+
};
|
|
508
|
+
_getFillStatusForDeposit = function (deposit, queryBlock) {
|
|
509
|
+
return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit, Math.min(queryBlock, spokePoolClients[deposit.destinationChainId].latestBlockSearched), deposit.destinationChainId);
|
|
510
|
+
};
|
|
559
511
|
allChainIds = blockRangesForChains
|
|
560
512
|
.map(function (_blockRange, index) { return chainIds[index]; })
|
|
561
513
|
.filter(function (chainId) { return !_isChainDisabled(chainId) && spokePoolClients[chainId] !== undefined; });
|
|
@@ -584,47 +536,41 @@ var BundleDataClient = (function () {
|
|
|
584
536
|
_c.label = 3;
|
|
585
537
|
case 3:
|
|
586
538
|
v3RelayHashes = {};
|
|
587
|
-
|
|
588
|
-
olderDepositHashes =
|
|
539
|
+
bundleDepositHashes = [];
|
|
540
|
+
olderDepositHashes = [];
|
|
589
541
|
depositCounter = 0;
|
|
590
542
|
_loop_2 = function (originChainId) {
|
|
591
543
|
var originClient = spokePoolClients[originChainId];
|
|
592
544
|
var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
593
|
-
var
|
|
545
|
+
for (var _d = 0, allChainIds_3 = allChainIds; _d < allChainIds_3.length; _d++) {
|
|
546
|
+
var destinationChainId = allChainIds_3[_d];
|
|
594
547
|
if (originChainId === destinationChainId) {
|
|
595
|
-
|
|
548
|
+
continue;
|
|
596
549
|
}
|
|
597
|
-
originClient.
|
|
598
|
-
if ((0, utils_1.isZeroValueDeposit)(deposit)) {
|
|
550
|
+
originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
|
|
551
|
+
if ((0, utils_1.isZeroValueDeposit)(deposit) || deposit.blockNumber > originChainBlockRange[1]) {
|
|
599
552
|
return;
|
|
600
553
|
}
|
|
601
554
|
depositCounter++;
|
|
602
555
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
603
|
-
if (v3RelayHashes[relayDataHash]) {
|
|
604
|
-
|
|
556
|
+
if (!v3RelayHashes[relayDataHash]) {
|
|
557
|
+
v3RelayHashes[relayDataHash] = {
|
|
558
|
+
deposit: deposit,
|
|
559
|
+
fill: undefined,
|
|
560
|
+
slowFillRequest: undefined,
|
|
561
|
+
};
|
|
605
562
|
}
|
|
606
|
-
v3RelayHashes[relayDataHash] = {
|
|
607
|
-
deposit: deposit,
|
|
608
|
-
fill: undefined,
|
|
609
|
-
slowFillRequest: undefined,
|
|
610
|
-
};
|
|
611
563
|
if (deposit.inputAmount.eq(0)) {
|
|
612
564
|
return;
|
|
613
565
|
}
|
|
614
|
-
if (deposit.blockNumber >= originChainBlockRange[0]
|
|
566
|
+
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
567
|
+
bundleDepositHashes.push(relayDataHash);
|
|
615
568
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
616
|
-
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
617
|
-
expiredBundleDepositHashes.add(relayDataHash);
|
|
618
|
-
}
|
|
619
569
|
}
|
|
620
570
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
621
|
-
olderDepositHashes.
|
|
571
|
+
olderDepositHashes.push(relayDataHash);
|
|
622
572
|
}
|
|
623
573
|
});
|
|
624
|
-
};
|
|
625
|
-
for (var _d = 0, allChainIds_3 = allChainIds; _d < allChainIds_3.length; _d++) {
|
|
626
|
-
var destinationChainId = allChainIds_3[_d];
|
|
627
|
-
_loop_4(destinationChainId);
|
|
628
574
|
}
|
|
629
575
|
};
|
|
630
576
|
for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
|
|
@@ -641,13 +587,13 @@ var BundleDataClient = (function () {
|
|
|
641
587
|
validatedBundleUnexecutableSlowFills = [];
|
|
642
588
|
fillCounter = 0;
|
|
643
589
|
_loop_3 = function (originChainId) {
|
|
644
|
-
var originClient,
|
|
590
|
+
var originClient, _loop_4, _e, allChainIds_4, destinationChainId;
|
|
645
591
|
return tslib_1.__generator(this, function (_f) {
|
|
646
592
|
switch (_f.label) {
|
|
647
593
|
case 0:
|
|
648
594
|
originClient = spokePoolClients[originChainId];
|
|
649
|
-
|
|
650
|
-
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
595
|
+
_loop_4 = function (destinationChainId) {
|
|
596
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
|
|
651
597
|
return tslib_1.__generator(this, function (_g) {
|
|
652
598
|
switch (_g.label) {
|
|
653
599
|
case 0:
|
|
@@ -659,75 +605,57 @@ var BundleDataClient = (function () {
|
|
|
659
605
|
fastFillsReplacingSlowFills = [];
|
|
660
606
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
661
607
|
.getFillsForOriginChain(originChainId)
|
|
662
|
-
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !(0, utils_1.
|
|
663
|
-
var relayDataHash,
|
|
608
|
+
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill); }), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
609
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
664
610
|
return tslib_1.__generator(this, function (_a) {
|
|
665
611
|
switch (_a.label) {
|
|
666
612
|
case 0:
|
|
667
|
-
fillCounter++;
|
|
668
613
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
669
|
-
|
|
670
|
-
if (
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
685
|
-
!v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
|
|
686
|
-
!v3RelayHashes[relayDataHash].deposit.toLiteChain) {
|
|
687
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
614
|
+
fillCounter++;
|
|
615
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
616
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
617
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
618
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
619
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
620
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
621
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
622
|
+
!v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
|
|
623
|
+
!v3RelayHashes[relayDataHash].deposit.toLiteChain) {
|
|
624
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return [2];
|
|
688
629
|
}
|
|
689
|
-
_a.label = 2;
|
|
690
|
-
case 2: return [3, 4];
|
|
691
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
692
|
-
case 4: return [2];
|
|
693
|
-
case 5:
|
|
694
630
|
v3RelayHashes[relayDataHash] = {
|
|
695
631
|
deposit: undefined,
|
|
696
632
|
fill: fill,
|
|
697
633
|
slowFillRequest: undefined,
|
|
698
634
|
};
|
|
699
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3,
|
|
635
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
700
636
|
if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
|
|
701
637
|
bundleInvalidFillsV3.push(fill);
|
|
702
638
|
return [2];
|
|
703
639
|
}
|
|
704
640
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
|
|
705
|
-
case
|
|
641
|
+
case 1:
|
|
706
642
|
historicalDeposit = _a.sent();
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
return [3, 9];
|
|
710
|
-
case 7:
|
|
711
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
712
|
-
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
713
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
714
|
-
case 8:
|
|
715
|
-
fillToRefund = _a.sent();
|
|
716
|
-
if (!(0, utils_1.isDefined)(fillToRefund)) {
|
|
717
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
643
|
+
if (!historicalDeposit.found) {
|
|
644
|
+
bundleInvalidFillsV3.push(fill);
|
|
718
645
|
}
|
|
719
646
|
else {
|
|
647
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
720
648
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
721
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({},
|
|
722
|
-
v3RelayHashes[relayDataHash].
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
649
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
650
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
651
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
652
|
+
!matchedDeposit.fromLiteChain &&
|
|
653
|
+
!matchedDeposit.toLiteChain) {
|
|
654
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
655
|
+
}
|
|
728
656
|
}
|
|
729
|
-
_a.label =
|
|
730
|
-
case
|
|
657
|
+
_a.label = 2;
|
|
658
|
+
case 2: return [2];
|
|
731
659
|
}
|
|
732
660
|
});
|
|
733
661
|
}); })];
|
|
@@ -735,11 +663,12 @@ var BundleDataClient = (function () {
|
|
|
735
663
|
_g.sent();
|
|
736
664
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
737
665
|
.getSlowFillRequestsForOriginChain(originChainId)
|
|
738
|
-
.filter(function (request) {
|
|
666
|
+
.filter(function (request) {
|
|
667
|
+
return request.blockNumber <= destinationChainBlockRange[1] && !(0, utils_1.isZeroValueFillOrSlowFillRequest)(request);
|
|
668
|
+
}), function (slowFillRequest) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
739
669
|
var relayDataHash, matchedDeposit, historicalDeposit, matchedDeposit;
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
switch (_c.label) {
|
|
670
|
+
return tslib_1.__generator(this, function (_a) {
|
|
671
|
+
switch (_a.label) {
|
|
743
672
|
case 0:
|
|
744
673
|
relayDataHash = this.getRelayHashFromEvent(slowFillRequest);
|
|
745
674
|
if (v3RelayHashes[relayDataHash]) {
|
|
@@ -750,11 +679,7 @@ var BundleDataClient = (function () {
|
|
|
750
679
|
}
|
|
751
680
|
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
752
681
|
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
753
|
-
if (!
|
|
754
|
-
return [2];
|
|
755
|
-
}
|
|
756
|
-
if (((_a = v3RelayHashes[relayDataHash].deposit) === null || _a === void 0 ? void 0 : _a.fromLiteChain) ||
|
|
757
|
-
((_b = v3RelayHashes[relayDataHash].deposit) === null || _b === void 0 ? void 0 : _b.toLiteChain)) {
|
|
682
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
758
683
|
return [2];
|
|
759
684
|
}
|
|
760
685
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
@@ -762,9 +687,6 @@ var BundleDataClient = (function () {
|
|
|
762
687
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
763
688
|
}
|
|
764
689
|
}
|
|
765
|
-
else {
|
|
766
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
767
|
-
}
|
|
768
690
|
return [2];
|
|
769
691
|
}
|
|
770
692
|
v3RelayHashes[relayDataHash] = {
|
|
@@ -776,27 +698,84 @@ var BundleDataClient = (function () {
|
|
|
776
698
|
slowFillRequest.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
777
699
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
|
|
778
700
|
case 1:
|
|
779
|
-
historicalDeposit =
|
|
701
|
+
historicalDeposit = _a.sent();
|
|
780
702
|
if (!historicalDeposit.found) {
|
|
781
703
|
return [2];
|
|
782
704
|
}
|
|
783
705
|
matchedDeposit = historicalDeposit.deposit;
|
|
784
706
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
785
|
-
if (matchedDeposit.fromLiteChain || matchedDeposit.toLiteChain) {
|
|
786
|
-
return [2];
|
|
787
|
-
}
|
|
788
707
|
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
789
|
-
if (!
|
|
708
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
790
709
|
slowFillRequest.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
791
710
|
return [2];
|
|
792
711
|
}
|
|
793
712
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
794
|
-
|
|
713
|
+
_a.label = 2;
|
|
795
714
|
case 2: return [2];
|
|
796
715
|
}
|
|
797
716
|
});
|
|
798
717
|
}); })];
|
|
799
718
|
case 2:
|
|
719
|
+
_g.sent();
|
|
720
|
+
originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
721
|
+
return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
|
|
722
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
723
|
+
return (deposit &&
|
|
724
|
+
deposit.originChainId === originChainId &&
|
|
725
|
+
deposit.destinationChainId === destinationChainId &&
|
|
726
|
+
deposit.blockNumber >= originBlockRange[0] &&
|
|
727
|
+
deposit.blockNumber <= originBlockRange[1] &&
|
|
728
|
+
!(0, utils_1.isZeroValueDeposit)(deposit));
|
|
729
|
+
}), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
730
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
731
|
+
return tslib_1.__generator(this, function (_b) {
|
|
732
|
+
switch (_b.label) {
|
|
733
|
+
case 0:
|
|
734
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
735
|
+
if (!deposit)
|
|
736
|
+
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
737
|
+
if (fill) {
|
|
738
|
+
if (!(0, utils_1.isSlowFill)(fill) && fill.blockNumber < destinationChainBlockRange[0]) {
|
|
739
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
740
|
+
}
|
|
741
|
+
return [2];
|
|
742
|
+
}
|
|
743
|
+
if (slowFillRequest) {
|
|
744
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
745
|
+
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
746
|
+
}
|
|
747
|
+
else if (_canCreateSlowFillLeaf(deposit) &&
|
|
748
|
+
slowFillRequest.blockNumber < destinationChainBlockRange[0]) {
|
|
749
|
+
validatedBundleSlowFills.push(deposit);
|
|
750
|
+
}
|
|
751
|
+
return [2];
|
|
752
|
+
}
|
|
753
|
+
return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
754
|
+
case 1:
|
|
755
|
+
fillStatus = _b.sent();
|
|
756
|
+
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
|
|
757
|
+
return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
758
|
+
case 2:
|
|
759
|
+
prefill = (_b.sent());
|
|
760
|
+
if (!(0, utils_1.isSlowFill)(prefill)) {
|
|
761
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
762
|
+
}
|
|
763
|
+
return [3, 4];
|
|
764
|
+
case 3:
|
|
765
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
766
|
+
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
767
|
+
}
|
|
768
|
+
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
|
|
769
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
770
|
+
validatedBundleSlowFills.push(deposit);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
_b.label = 4;
|
|
774
|
+
case 4: return [2];
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}); })];
|
|
778
|
+
case 3:
|
|
800
779
|
_g.sent();
|
|
801
780
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
802
781
|
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
@@ -820,7 +799,7 @@ var BundleDataClient = (function () {
|
|
|
820
799
|
case 1:
|
|
821
800
|
if (!(_e < allChainIds_4.length)) return [3, 4];
|
|
822
801
|
destinationChainId = allChainIds_4[_e];
|
|
823
|
-
return [5,
|
|
802
|
+
return [5, _loop_4(destinationChainId)];
|
|
824
803
|
case 2:
|
|
825
804
|
_f.sent();
|
|
826
805
|
_f.label = 3;
|
|
@@ -849,15 +828,7 @@ var BundleDataClient = (function () {
|
|
|
849
828
|
message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
|
|
850
829
|
});
|
|
851
830
|
start = performance.now();
|
|
852
|
-
|
|
853
|
-
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, fill = _a.fill;
|
|
854
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
855
|
-
if (!fill &&
|
|
856
|
-
(0, utils_1.isDefined)(deposit)) {
|
|
857
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
return [4, (0, utils_1.forEachAsync)(Array.from(olderDepositHashes), function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
831
|
+
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
861
832
|
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
862
833
|
return tslib_1.__generator(this, function (_b) {
|
|
863
834
|
switch (_b.label) {
|
|
@@ -871,7 +842,7 @@ var BundleDataClient = (function () {
|
|
|
871
842
|
deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1] &&
|
|
872
843
|
deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
|
|
873
844
|
spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
|
|
874
|
-
return [4,
|
|
845
|
+
return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
875
846
|
case 1:
|
|
876
847
|
fillStatus = _b.sent();
|
|
877
848
|
if (fillStatus !== interfaces_1.FillStatus.Filled) {
|
|
@@ -925,7 +896,7 @@ var BundleDataClient = (function () {
|
|
|
925
896
|
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
926
897
|
(0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
927
898
|
var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
928
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
899
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
929
900
|
});
|
|
930
901
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
931
902
|
var lpFeePct = _a.realizedLpFeePct;
|
|
@@ -937,7 +908,7 @@ var BundleDataClient = (function () {
|
|
|
937
908
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
938
909
|
updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
939
910
|
});
|
|
940
|
-
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
911
|
+
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
941
912
|
if (bundleInvalidFillsV3.length > 0) {
|
|
942
913
|
this.logger.debug({
|
|
943
914
|
at: "BundleDataClient#loadData",
|
|
@@ -946,14 +917,6 @@ var BundleDataClient = (function () {
|
|
|
946
917
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
947
918
|
});
|
|
948
919
|
}
|
|
949
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
950
|
-
this.logger.debug({
|
|
951
|
-
at: "BundleDataClient#loadData",
|
|
952
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable V3 fills in range",
|
|
953
|
-
blockRangesForChains: blockRangesForChains,
|
|
954
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
920
|
this.logger.debug({
|
|
958
921
|
at: "BundleDataClient#loadDataFromScratch",
|
|
959
922
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -972,7 +935,7 @@ var BundleDataClient = (function () {
|
|
|
972
935
|
});
|
|
973
936
|
};
|
|
974
937
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
975
|
-
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
|
|
938
|
+
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);
|
|
976
939
|
};
|
|
977
940
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
978
941
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -983,7 +946,7 @@ var BundleDataClient = (function () {
|
|
|
983
946
|
case 0:
|
|
984
947
|
_b = (_a = Object).fromEntries;
|
|
985
948
|
return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
986
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
949
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
987
950
|
return tslib_1.__generator(this, function (_c) {
|
|
988
951
|
switch (_c.label) {
|
|
989
952
|
case 0:
|
|
@@ -997,7 +960,7 @@ var BundleDataClient = (function () {
|
|
|
997
960
|
return [2];
|
|
998
961
|
}
|
|
999
962
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1000
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
963
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1001
964
|
return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1002
965
|
case 1:
|
|
1003
966
|
_b = [
|
|
@@ -1007,10 +970,8 @@ var BundleDataClient = (function () {
|
|
|
1007
970
|
case 2:
|
|
1008
971
|
_a = _b.concat([
|
|
1009
972
|
_c.sent()
|
|
1010
|
-
]), startTime = _a[0],
|
|
1011
|
-
|
|
1012
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1013
|
-
(0, utils_1.assert)(endTime >= startTime, "End time for block ".concat(endBlockForChain, " should be greater than start time for block ").concat(startBlockForChain, ": ").concat(endTime, " >= ").concat(startTime, "."));
|
|
973
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
974
|
+
(0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
|
|
1014
975
|
(0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1015
976
|
return [2, [chainId, [startTime, endTime]]];
|
|
1016
977
|
}
|