@across-protocol/sdk 4.0.0-beta.33 → 4.0.0-beta.4
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 +174 -336
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -47
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
- package/dist/cjs/clients/SpokePoolClient.js +1 -10
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +0 -1
- package/dist/cjs/providers/index.js +0 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +0 -2
- package/dist/cjs/utils/AddressUtils.js +1 -19
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.d.ts +1 -2
- package/dist/cjs/utils/DepositUtils.js +1 -10
- 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 +0 -1
- package/dist/cjs/utils/SpokeUtils.js +8 -15
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +0 -1
- package/dist/cjs/utils/common.js +1 -2
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +256 -439
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -54
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
- package/dist/esm/clients/SpokePoolClient.js +1 -17
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/providers/index.d.ts +0 -1
- package/dist/esm/providers/index.js +0 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +0 -2
- package/dist/esm/utils/AddressUtils.js +0 -25
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.d.ts +1 -2
- package/dist/esm/utils/DepositUtils.js +2 -11
- 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 +0 -1
- package/dist/esm/utils/SpokeUtils.js +8 -14
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/common.d.ts +0 -1
- package/dist/esm/utils/common.js +0 -1
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/types/clients/SpokePoolClient.d.ts +0 -8
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +0 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +0 -2
- 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/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 +0 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +224 -418
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -66
- package/src/clients/SpokePoolClient.ts +3 -16
- package/src/clients/mocks/MockSpokePoolClient.ts +1 -14
- package/src/constants.ts +3 -3
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -26
- package/src/utils/DepositUtils.ts +2 -11
- package/src/utils/EventUtils.ts +1 -29
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +9 -22
- 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
|
@@ -6,11 +6,9 @@ var lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
|
6
6
|
var interfaces_1 = require("../../interfaces");
|
|
7
7
|
var utils_1 = require("../../utils");
|
|
8
8
|
var utils_2 = require("./utils");
|
|
9
|
-
var constants_1 = require("../../constants");
|
|
10
9
|
exports.INFINITE_FILL_DEADLINE = utils_1.bnUint32Max;
|
|
11
10
|
function updateExpiredDepositsV3(dict, deposit) {
|
|
12
11
|
var _a;
|
|
13
|
-
(0, utils_1.assert)((0, utils_1.chainIsEvm)(deposit.originChainId) && (0, utils_1.isValidEvmAddress)(deposit.depositor), "expired depositor cannot be refunded");
|
|
14
12
|
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
15
13
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
16
14
|
(0, utils_1.assign)(dict, [originChainId, inputToken], []);
|
|
@@ -25,9 +23,8 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
25
23
|
}
|
|
26
24
|
dict[originChainId][inputToken].push(deposit);
|
|
27
25
|
}
|
|
28
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken
|
|
26
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
29
27
|
var _a, _b;
|
|
30
|
-
(0, utils_1.assert)((0, utils_1.chainIsEvm)(repaymentChainId) && (0, utils_2.isEvmRepaymentValid)(fill, repaymentChainId), "validatedBundleV3Fills dictionary should only contain fills with valid repayment information");
|
|
31
28
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
32
29
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
|
|
33
30
|
fills: [],
|
|
@@ -36,22 +33,22 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
36
33
|
refunds: {},
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct
|
|
36
|
+
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
|
|
40
37
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
41
38
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
42
|
-
var realizedLpFee =
|
|
39
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
|
|
43
40
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
44
|
-
if (!(0, utils_1.isSlowFill)(
|
|
45
|
-
var refundAmount =
|
|
41
|
+
if (!(0, utils_1.isSlowFill)(fill)) {
|
|
42
|
+
var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
|
|
46
43
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
47
44
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
48
45
|
: refundAmount;
|
|
49
46
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
50
|
-
if (refundObj.refunds[
|
|
51
|
-
refundObj.refunds[
|
|
47
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
48
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
52
49
|
}
|
|
53
50
|
else {
|
|
54
|
-
refundObj.refunds[
|
|
51
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}
|
|
@@ -65,7 +62,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
|
|
|
65
62
|
}
|
|
66
63
|
function updateBundleSlowFills(dict, deposit) {
|
|
67
64
|
var _a;
|
|
68
|
-
(0, utils_1.assert)((0, utils_1.chainIsEvm)(deposit.destinationChainId) && (0, utils_1.isValidEvmAddress)(deposit.recipient), "slow fill recipient cannot be paid");
|
|
69
65
|
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
70
66
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
71
67
|
(0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
|
|
@@ -150,7 +146,7 @@ var BundleDataClient = (function () {
|
|
|
150
146
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
151
147
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
152
148
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
153
|
-
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),
|
|
154
150
|
});
|
|
155
151
|
return [2, bundleData];
|
|
156
152
|
}
|
|
@@ -192,107 +188,64 @@ var BundleDataClient = (function () {
|
|
|
192
188
|
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
193
189
|
case 1:
|
|
194
190
|
arweaveData = _a.sent();
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
_a.label = 4;
|
|
209
|
-
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)];
|
|
210
204
|
}
|
|
211
205
|
});
|
|
212
206
|
});
|
|
213
207
|
};
|
|
214
208
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
228
|
-
return [2, "continue"];
|
|
229
|
-
}
|
|
230
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
231
|
-
return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
232
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
233
|
-
return tslib_1.__generator(this, function (_a) {
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0:
|
|
236
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
237
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
238
|
-
(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill)) {
|
|
239
|
-
return [2, false];
|
|
240
|
-
}
|
|
241
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
242
|
-
return [2, false];
|
|
243
|
-
}
|
|
244
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
245
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
246
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
247
|
-
if (!hasMatchingDeposit) return [3, 2];
|
|
248
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
|
|
249
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
250
|
-
.filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
|
|
251
|
-
case 1:
|
|
252
|
-
validRepayment = _a.sent();
|
|
253
|
-
if (!(0, utils_1.isDefined)(validRepayment)) {
|
|
254
|
-
return [2, false];
|
|
255
|
-
}
|
|
256
|
-
_a.label = 2;
|
|
257
|
-
case 2: return [2, hasMatchingDeposit];
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}); })];
|
|
261
|
-
case 1:
|
|
262
|
-
fillsToCount = _b.sent();
|
|
263
|
-
fillsToCount.forEach(function (fill) {
|
|
264
|
-
var _a, _b, _c;
|
|
265
|
-
var _d;
|
|
266
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
267
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
268
|
-
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
269
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
270
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
271
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
272
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
273
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
274
|
-
});
|
|
275
|
-
return [2];
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
this_1 = this;
|
|
280
|
-
_i = 0, chainIds_1 = chainIds;
|
|
281
|
-
_a.label = 1;
|
|
282
|
-
case 1:
|
|
283
|
-
if (!(_i < chainIds_1.length)) return [3, 4];
|
|
284
|
-
chainId = chainIds_1[_i];
|
|
285
|
-
return [5, _loop_1(chainId)];
|
|
286
|
-
case 2:
|
|
287
|
-
_a.sent();
|
|
288
|
-
_a.label = 3;
|
|
289
|
-
case 3:
|
|
290
|
-
_i++;
|
|
291
|
-
return [3, 1];
|
|
292
|
-
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;
|
|
293
221
|
}
|
|
222
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
223
|
+
return false;
|
|
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);
|
|
294
241
|
});
|
|
295
|
-
}
|
|
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;
|
|
296
249
|
};
|
|
297
250
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
298
251
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -335,10 +288,12 @@ var BundleDataClient = (function () {
|
|
|
335
288
|
case 1:
|
|
336
289
|
_a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
|
|
337
290
|
hubPoolClient = this.clients.hubPoolClient;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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();
|
|
342
297
|
return [2, {
|
|
343
298
|
root: root,
|
|
344
299
|
blockRanges: blockRanges,
|
|
@@ -362,39 +317,32 @@ var BundleDataClient = (function () {
|
|
|
362
317
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
363
318
|
});
|
|
364
319
|
}
|
|
365
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
366
|
-
return tslib_1.__generator(this, function (
|
|
367
|
-
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) {
|
|
368
323
|
case 0:
|
|
369
324
|
hubPoolClient = this.clients.hubPoolClient;
|
|
370
325
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
371
326
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
372
327
|
combinedRefunds = [];
|
|
373
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));
|
|
374
|
-
if (!hubPoolClient.hasPendingProposal()) return [3,
|
|
329
|
+
if (!hubPoolClient.hasPendingProposal()) return [3, 2];
|
|
375
330
|
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
376
331
|
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
377
332
|
case 1:
|
|
378
|
-
arweaveData =
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
387
|
-
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
388
|
-
_e.label = 4;
|
|
389
|
-
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
|
+
}
|
|
390
341
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
391
|
-
|
|
392
|
-
case
|
|
342
|
+
_a.label = 2;
|
|
343
|
+
case 2:
|
|
393
344
|
start = performance.now();
|
|
394
|
-
|
|
395
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
396
|
-
case 6:
|
|
397
|
-
_d.apply(_c, [_e.sent()]);
|
|
345
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
398
346
|
this.logger.debug({
|
|
399
347
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
400
348
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -525,7 +473,7 @@ var BundleDataClient = (function () {
|
|
|
525
473
|
};
|
|
526
474
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
527
475
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
528
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3,
|
|
476
|
+
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;
|
|
529
477
|
var _this = this;
|
|
530
478
|
return tslib_1.__generator(this, function (_c) {
|
|
531
479
|
switch (_c.label) {
|
|
@@ -545,7 +493,6 @@ var BundleDataClient = (function () {
|
|
|
545
493
|
bundleDepositsV3 = {};
|
|
546
494
|
bundleFillsV3 = {};
|
|
547
495
|
bundleInvalidFillsV3 = [];
|
|
548
|
-
bundleUnrepayableFillsV3 = [];
|
|
549
496
|
bundleSlowFillsV3 = {};
|
|
550
497
|
expiredDepositsToRefundV3 = {};
|
|
551
498
|
unexecutableSlowFills = {};
|
|
@@ -594,13 +541,7 @@ var BundleDataClient = (function () {
|
|
|
594
541
|
v3RelayHashes = {};
|
|
595
542
|
bundleDepositHashes = [];
|
|
596
543
|
olderDepositHashes = [];
|
|
597
|
-
|
|
598
|
-
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
599
|
-
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
600
|
-
};
|
|
601
|
-
startBlockForMainnet = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
|
|
602
|
-
versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
|
|
603
|
-
canRefundPrefills = versionAtProposalBlock >= constants_1.PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
|
|
544
|
+
depositCounter = 0;
|
|
604
545
|
_loop_2 = function (originChainId) {
|
|
605
546
|
var originClient = spokePoolClients[originChainId];
|
|
606
547
|
var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
@@ -613,27 +554,24 @@ var BundleDataClient = (function () {
|
|
|
613
554
|
if (deposit.blockNumber > originChainBlockRange[1] || (0, utils_1.isZeroValueDeposit)(deposit)) {
|
|
614
555
|
return;
|
|
615
556
|
}
|
|
557
|
+
depositCounter++;
|
|
616
558
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
617
559
|
if (!v3RelayHashes[relayDataHash]) {
|
|
618
560
|
v3RelayHashes[relayDataHash] = {
|
|
619
|
-
|
|
561
|
+
deposit: deposit,
|
|
620
562
|
fill: undefined,
|
|
621
563
|
slowFillRequest: undefined,
|
|
622
564
|
};
|
|
623
565
|
}
|
|
624
|
-
|
|
625
|
-
|
|
566
|
+
if (deposit.inputAmount.eq(0)) {
|
|
567
|
+
return;
|
|
626
568
|
}
|
|
627
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
628
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
629
|
-
(0, utils_1.assert)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
630
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
631
569
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
632
|
-
bundleDepositHashes.push(
|
|
570
|
+
bundleDepositHashes.push(relayDataHash);
|
|
633
571
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
634
572
|
}
|
|
635
573
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
636
|
-
olderDepositHashes.push(
|
|
574
|
+
olderDepositHashes.push(relayDataHash);
|
|
637
575
|
}
|
|
638
576
|
});
|
|
639
577
|
}
|
|
@@ -644,7 +582,7 @@ var BundleDataClient = (function () {
|
|
|
644
582
|
}
|
|
645
583
|
this.logger.debug({
|
|
646
584
|
at: "BundleDataClient#loadData",
|
|
647
|
-
message: "Processed ".concat(
|
|
585
|
+
message: "Processed ".concat(depositCounter, " deposits in ").concat(performance.now() - start, "ms."),
|
|
648
586
|
});
|
|
649
587
|
start = performance.now();
|
|
650
588
|
validatedBundleV3Fills = [];
|
|
@@ -658,7 +596,7 @@ var BundleDataClient = (function () {
|
|
|
658
596
|
case 0:
|
|
659
597
|
originClient = spokePoolClients[originChainId];
|
|
660
598
|
_loop_4 = function (destinationChainId) {
|
|
661
|
-
var destinationClient, destinationChainBlockRange,
|
|
599
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
662
600
|
return tslib_1.__generator(this, function (_g) {
|
|
663
601
|
switch (_g.label) {
|
|
664
602
|
case 0:
|
|
@@ -667,90 +605,58 @@ var BundleDataClient = (function () {
|
|
|
667
605
|
}
|
|
668
606
|
destinationClient = spokePoolClients[destinationChainId];
|
|
669
607
|
destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
670
|
-
originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
671
608
|
fastFillsReplacingSlowFills = [];
|
|
672
609
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
673
610
|
.getFillsForOriginChain(originChainId)
|
|
674
611
|
.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 () {
|
|
675
|
-
var relayDataHash,
|
|
612
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
676
613
|
return tslib_1.__generator(this, function (_a) {
|
|
677
614
|
switch (_a.label) {
|
|
678
615
|
case 0:
|
|
679
|
-
fillCounter++;
|
|
680
616
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
681
|
-
|
|
682
|
-
if (
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
else {
|
|
693
|
-
v3RelayHashes[relayDataHash].fill = fillToRefund_1;
|
|
694
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp }));
|
|
695
|
-
duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
|
|
696
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
697
|
-
if ((0, utils_1.isSlowFill)(fill)) {
|
|
698
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
|
|
617
|
+
fillCounter++;
|
|
618
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
619
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
620
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
621
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
622
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
623
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
624
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
625
|
+
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
|
|
626
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
627
|
+
}
|
|
702
628
|
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
706
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
707
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
629
|
+
}
|
|
630
|
+
return [2];
|
|
708
631
|
}
|
|
709
|
-
_a.label = 2;
|
|
710
|
-
case 2: return [3, 4];
|
|
711
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
712
|
-
case 4: return [2];
|
|
713
|
-
case 5:
|
|
714
632
|
v3RelayHashes[relayDataHash] = {
|
|
715
|
-
|
|
633
|
+
deposit: undefined,
|
|
716
634
|
fill: fill,
|
|
717
635
|
slowFillRequest: undefined,
|
|
718
636
|
};
|
|
719
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3,
|
|
637
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
720
638
|
if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
|
|
721
639
|
bundleInvalidFillsV3.push(fill);
|
|
722
640
|
return [2];
|
|
723
641
|
}
|
|
724
642
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
|
|
725
|
-
case
|
|
643
|
+
case 1:
|
|
726
644
|
historicalDeposit = _a.sent();
|
|
727
|
-
if (
|
|
728
|
-
bundleInvalidFillsV3.push(fill);
|
|
729
|
-
return [3, 9];
|
|
730
|
-
case 7:
|
|
731
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
732
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
645
|
+
if (!historicalDeposit.found) {
|
|
733
646
|
bundleInvalidFillsV3.push(fill);
|
|
734
|
-
return [2];
|
|
735
|
-
}
|
|
736
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
737
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
738
|
-
case 8:
|
|
739
|
-
fillToRefund = _a.sent();
|
|
740
|
-
if (!(0, utils_1.isDefined)(fillToRefund)) {
|
|
741
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
742
647
|
}
|
|
743
648
|
else {
|
|
649
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
744
650
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
745
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({},
|
|
746
|
-
v3RelayHashes[relayDataHash].
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
651
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
652
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
653
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
654
|
+
_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
655
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
656
|
+
}
|
|
751
657
|
}
|
|
752
|
-
_a.label =
|
|
753
|
-
case
|
|
658
|
+
_a.label = 2;
|
|
659
|
+
case 2: return [2];
|
|
754
660
|
}
|
|
755
661
|
});
|
|
756
662
|
}); })];
|
|
@@ -772,26 +678,23 @@ var BundleDataClient = (function () {
|
|
|
772
678
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
773
679
|
return [2];
|
|
774
680
|
}
|
|
775
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].
|
|
776
|
-
matchedDeposit = v3RelayHashes[relayDataHash].
|
|
681
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
682
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
777
683
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
778
684
|
_canCreateSlowFillLeaf(matchedDeposit) &&
|
|
779
685
|
!_depositIsExpired(matchedDeposit)) {
|
|
780
686
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
781
687
|
}
|
|
782
688
|
}
|
|
783
|
-
else {
|
|
784
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
785
|
-
}
|
|
786
689
|
return [2];
|
|
787
690
|
}
|
|
788
691
|
v3RelayHashes[relayDataHash] = {
|
|
789
|
-
|
|
692
|
+
deposit: undefined,
|
|
790
693
|
fill: undefined,
|
|
791
694
|
slowFillRequest: slowFillRequest,
|
|
792
695
|
};
|
|
793
|
-
if (!(
|
|
794
|
-
slowFillRequest.
|
|
696
|
+
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
697
|
+
exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3, 2];
|
|
795
698
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
|
|
796
699
|
case 1:
|
|
797
700
|
historicalDeposit = _a.sent();
|
|
@@ -799,12 +702,10 @@ var BundleDataClient = (function () {
|
|
|
799
702
|
return [2];
|
|
800
703
|
}
|
|
801
704
|
matchedDeposit = historicalDeposit.deposit;
|
|
802
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
803
|
-
return [2];
|
|
804
|
-
}
|
|
805
705
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
806
|
-
v3RelayHashes[relayDataHash].
|
|
807
|
-
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
706
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
707
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
708
|
+
_depositIsExpired(matchedDeposit)) {
|
|
808
709
|
return [2];
|
|
809
710
|
}
|
|
810
711
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
@@ -815,105 +716,71 @@ var BundleDataClient = (function () {
|
|
|
815
716
|
}); })];
|
|
816
717
|
case 2:
|
|
817
718
|
_g.sent();
|
|
818
|
-
return [4, (0, utils_1.mapAsync)(bundleDepositHashes
|
|
819
|
-
var
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
719
|
+
return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
|
|
720
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
721
|
+
return (deposit && deposit.originChainId === originChainId && deposit.destinationChainId === destinationChainId);
|
|
722
|
+
}), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
723
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
724
|
+
return tslib_1.__generator(this, function (_b) {
|
|
725
|
+
switch (_b.label) {
|
|
823
726
|
case 0:
|
|
824
|
-
_a =
|
|
825
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
826
|
-
if (!deposits || deposits.length === 0) {
|
|
827
|
-
throw new Error("Deposits should exist in relay hash dictionary.");
|
|
828
|
-
}
|
|
829
|
-
deposit = deposits[index];
|
|
727
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
830
728
|
if (!deposit)
|
|
831
729
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
832
|
-
if (
|
|
730
|
+
if (fill) {
|
|
731
|
+
if (fill.blockNumber < destinationChainBlockRange[0] && !(0, utils_1.isSlowFill)(fill)) {
|
|
732
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
733
|
+
}
|
|
833
734
|
return [2];
|
|
834
735
|
}
|
|
835
|
-
if (!fill) return [3, 3];
|
|
836
|
-
if (!(canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0])) return [3, 2];
|
|
837
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
|
|
838
|
-
case 1:
|
|
839
|
-
fillToRefund = _c.sent();
|
|
840
|
-
if (!(0, utils_1.isDefined)(fillToRefund)) {
|
|
841
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
842
|
-
}
|
|
843
|
-
else if (!(0, utils_1.isSlowFill)(fill)) {
|
|
844
|
-
v3RelayHashes[relayDataHash].fill = fillToRefund;
|
|
845
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
849
|
-
}
|
|
850
|
-
_c.label = 2;
|
|
851
|
-
case 2: return [2];
|
|
852
|
-
case 3:
|
|
853
736
|
if (slowFillRequest) {
|
|
854
737
|
if (_depositIsExpired(deposit)) {
|
|
855
738
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
856
739
|
}
|
|
857
|
-
else if (
|
|
858
|
-
|
|
859
|
-
_canCreateSlowFillLeaf(deposit) &&
|
|
860
|
-
validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
|
|
740
|
+
else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
741
|
+
_canCreateSlowFillLeaf(deposit)) {
|
|
861
742
|
validatedBundleSlowFills.push(deposit);
|
|
862
743
|
}
|
|
863
744
|
return [2];
|
|
864
745
|
}
|
|
865
746
|
return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
866
|
-
case
|
|
867
|
-
fillStatus =
|
|
868
|
-
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3,
|
|
869
|
-
return [4,
|
|
870
|
-
case
|
|
871
|
-
prefill =
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
if (!canRefundPrefills) return [3, 7];
|
|
875
|
-
return [4, (0, utils_2.verifyFillRepayment)(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
876
|
-
case 6:
|
|
877
|
-
verifiedFill = _c.sent();
|
|
878
|
-
if (!(0, utils_1.isDefined)(verifiedFill)) {
|
|
879
|
-
bundleUnrepayableFillsV3.push(prefill);
|
|
880
|
-
}
|
|
881
|
-
else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
|
|
882
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
883
|
-
}
|
|
884
|
-
else {
|
|
885
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
747
|
+
case 1:
|
|
748
|
+
fillStatus = _b.sent();
|
|
749
|
+
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
|
|
750
|
+
return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
751
|
+
case 2:
|
|
752
|
+
prefill = (_b.sent());
|
|
753
|
+
if (!(0, utils_1.isSlowFill)(prefill)) {
|
|
754
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
886
755
|
}
|
|
887
|
-
|
|
888
|
-
case
|
|
889
|
-
case 8:
|
|
756
|
+
return [3, 4];
|
|
757
|
+
case 3:
|
|
890
758
|
if (_depositIsExpired(deposit)) {
|
|
891
759
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
892
760
|
}
|
|
893
|
-
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill
|
|
894
|
-
|
|
895
|
-
if (canRefundPrefills && _canCreateSlowFillLeaf(deposit)) {
|
|
761
|
+
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
|
|
762
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
896
763
|
validatedBundleSlowFills.push(deposit);
|
|
897
764
|
}
|
|
898
765
|
}
|
|
899
|
-
|
|
900
|
-
case
|
|
766
|
+
_b.label = 4;
|
|
767
|
+
case 4: return [2];
|
|
901
768
|
}
|
|
902
769
|
});
|
|
903
770
|
}); })];
|
|
904
771
|
case 3:
|
|
905
772
|
_g.sent();
|
|
906
773
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
907
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
774
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
908
775
|
(0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
909
|
-
if (!
|
|
776
|
+
if (!deposit) {
|
|
910
777
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
911
778
|
}
|
|
912
|
-
(0, utils_1.assert)(_canCreateSlowFillLeaf(
|
|
779
|
+
(0, utils_1.assert)(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
|
|
913
780
|
var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
914
781
|
if (!slowFillRequest ||
|
|
915
782
|
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
916
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
783
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
917
784
|
}
|
|
918
785
|
});
|
|
919
786
|
return [2];
|
|
@@ -954,17 +821,13 @@ var BundleDataClient = (function () {
|
|
|
954
821
|
message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
|
|
955
822
|
});
|
|
956
823
|
start = performance.now();
|
|
957
|
-
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (
|
|
958
|
-
var _a,
|
|
959
|
-
return tslib_1.__generator(this, function (
|
|
960
|
-
switch (
|
|
824
|
+
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
825
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
826
|
+
return tslib_1.__generator(this, function (_b) {
|
|
827
|
+
switch (_b.label) {
|
|
961
828
|
case 0:
|
|
962
|
-
_a =
|
|
963
|
-
|
|
964
|
-
if (!deposits || deposits.length < 1) {
|
|
965
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
966
|
-
}
|
|
967
|
-
deposit = deposits[index];
|
|
829
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
830
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
968
831
|
destinationChainId = deposit.destinationChainId;
|
|
969
832
|
destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
970
833
|
if (!(!fill &&
|
|
@@ -974,7 +837,7 @@ var BundleDataClient = (function () {
|
|
|
974
837
|
spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
|
|
975
838
|
return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
976
839
|
case 1:
|
|
977
|
-
fillStatus =
|
|
840
|
+
fillStatus = _b.sent();
|
|
978
841
|
if (fillStatus !== interfaces_1.FillStatus.Filled) {
|
|
979
842
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
980
843
|
}
|
|
@@ -984,7 +847,7 @@ var BundleDataClient = (function () {
|
|
|
984
847
|
if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
985
848
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
986
849
|
}
|
|
987
|
-
|
|
850
|
+
_b.label = 2;
|
|
988
851
|
case 2: return [2];
|
|
989
852
|
}
|
|
990
853
|
});
|
|
@@ -995,7 +858,7 @@ var BundleDataClient = (function () {
|
|
|
995
858
|
promises = [
|
|
996
859
|
validatedBundleV3Fills.length > 0
|
|
997
860
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
998
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
861
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
999
862
|
(0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1000
863
|
var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1001
864
|
return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1022,19 +885,14 @@ var BundleDataClient = (function () {
|
|
|
1022
885
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1023
886
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1024
887
|
var fill = validatedBundleV3Fills[idx];
|
|
1025
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
888
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1026
889
|
(0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1027
890
|
var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1028
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
891
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1029
892
|
});
|
|
1030
893
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1031
894
|
var lpFeePct = _a.realizedLpFeePct;
|
|
1032
895
|
var deposit = validatedBundleSlowFills[idx];
|
|
1033
|
-
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
1034
|
-
if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
|
|
1035
|
-
return;
|
|
1036
|
-
}
|
|
1037
|
-
(0, utils_1.assert)(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
|
|
1038
896
|
updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1039
897
|
});
|
|
1040
898
|
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
@@ -1042,7 +900,7 @@ var BundleDataClient = (function () {
|
|
|
1042
900
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
1043
901
|
updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1044
902
|
});
|
|
1045
|
-
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
903
|
+
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1046
904
|
if (bundleInvalidFillsV3.length > 0) {
|
|
1047
905
|
this.logger.debug({
|
|
1048
906
|
at: "BundleDataClient#loadData",
|
|
@@ -1051,14 +909,6 @@ var BundleDataClient = (function () {
|
|
|
1051
909
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
1052
910
|
});
|
|
1053
911
|
}
|
|
1054
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
1055
|
-
this.logger.debug({
|
|
1056
|
-
at: "BundleDataClient#loadData",
|
|
1057
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable V3 fills in range",
|
|
1058
|
-
blockRangesForChains: blockRangesForChains,
|
|
1059
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
1060
|
-
});
|
|
1061
|
-
}
|
|
1062
912
|
this.logger.debug({
|
|
1063
913
|
at: "BundleDataClient#loadDataFromScratch",
|
|
1064
914
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -1079,16 +929,6 @@ var BundleDataClient = (function () {
|
|
|
1079
929
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1080
930
|
return "".concat(event.depositor, "-").concat(event.recipient, "-").concat(event.exclusiveRelayer, "-").concat(event.inputToken, "-").concat(event.outputToken, "-").concat(event.inputAmount, "-").concat(event.outputAmount, "-").concat(event.originChainId, "-").concat(event.depositId.toString(), "-").concat(event.fillDeadline, "-").concat(event.exclusivityDeadline, "-").concat(event.message, "-").concat(event.destinationChainId);
|
|
1081
931
|
};
|
|
1082
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1083
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1084
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1085
|
-
switch (_a.label) {
|
|
1086
|
-
case 0: return [4, (0, utils_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1087
|
-
case 1: return [2, _a.sent()];
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
});
|
|
1091
|
-
};
|
|
1092
932
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1093
933
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1094
934
|
var _a, _b;
|
|
@@ -1098,7 +938,7 @@ var BundleDataClient = (function () {
|
|
|
1098
938
|
case 0:
|
|
1099
939
|
_b = (_a = Object).fromEntries;
|
|
1100
940
|
return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1101
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
941
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1102
942
|
return tslib_1.__generator(this, function (_c) {
|
|
1103
943
|
switch (_c.label) {
|
|
1104
944
|
case 0:
|
|
@@ -1112,7 +952,7 @@ var BundleDataClient = (function () {
|
|
|
1112
952
|
return [2];
|
|
1113
953
|
}
|
|
1114
954
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1115
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
955
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1116
956
|
return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1117
957
|
case 1:
|
|
1118
958
|
_b = [
|
|
@@ -1122,10 +962,8 @@ var BundleDataClient = (function () {
|
|
|
1122
962
|
case 2:
|
|
1123
963
|
_a = _b.concat([
|
|
1124
964
|
_c.sent()
|
|
1125
|
-
]), startTime = _a[0],
|
|
1126
|
-
|
|
1127
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1128
|
-
(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, "."));
|
|
965
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
966
|
+
(0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
|
|
1129
967
|
(0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1130
968
|
return [2, [chainId, [startTime, endTime]]];
|
|
1131
969
|
}
|