@across-protocol/sdk 4.0.0-beta.28 → 4.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +164 -326
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -33
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
- package/dist/cjs/clients/SpokePoolClient.js +4 -13
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +0 -1
- package/dist/cjs/providers/index.js +0 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +0 -1
- package/dist/cjs/utils/AddressUtils.js +1 -14
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/CachingUtils.js +1 -1
- package/dist/cjs/utils/CachingUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.d.ts +1 -2
- package/dist/cjs/utils/DepositUtils.js +4 -13
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.d.ts +0 -1
- package/dist/cjs/utils/NetworkUtils.js +1 -6
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.js +3 -3
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +188 -394
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -42
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
- package/dist/esm/clients/SpokePoolClient.js +4 -20
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/providers/index.d.ts +0 -1
- package/dist/esm/providers/index.js +0 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +0 -1
- package/dist/esm/utils/AddressUtils.js +0 -16
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/CachingUtils.js +1 -1
- package/dist/esm/utils/CachingUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.d.ts +1 -2
- package/dist/esm/utils/DepositUtils.js +5 -14
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.d.ts +0 -6
- package/dist/esm/utils/NetworkUtils.js +0 -10
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.js +4 -4
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient.d.ts +0 -8
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +0 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +0 -1
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts +1 -2
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/dist/types/utils/NetworkUtils.d.ts +0 -6
- package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +179 -395
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
- package/src/clients/SpokePoolClient.ts +6 -19
- package/src/constants.ts +3 -3
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -16
- package/src/utils/CachingUtils.ts +1 -1
- package/src/utils/DepositUtils.ts +5 -14
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +6 -6
- package/dist/cjs/providers/mockProvider.d.ts +0 -19
- package/dist/cjs/providers/mockProvider.js +0 -70
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/esm/providers/mockProvider.d.ts +0 -23
- package/dist/esm/providers/mockProvider.js +0 -73
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts +0 -24
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/src/providers/mockProvider.ts +0 -77
|
@@ -6,13 +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
|
-
if ((0, utils_1.chainIsEvm)(deposit.originChainId) && !(0, utils_1.isValidEvmAddress)(deposit.depositor)) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
12
|
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
17
13
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
18
14
|
(0, utils_1.assign)(dict, [originChainId, inputToken], []);
|
|
@@ -27,11 +23,8 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
27
23
|
}
|
|
28
24
|
dict[originChainId][inputToken].push(deposit);
|
|
29
25
|
}
|
|
30
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken
|
|
26
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
31
27
|
var _a, _b;
|
|
32
|
-
if ((0, utils_1.chainIsEvm)(repaymentChainId) && !(0, utils_1.isValidEvmAddress)(repaymentAddress)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
28
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
36
29
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
|
|
37
30
|
fills: [],
|
|
@@ -40,22 +33,22 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
40
33
|
refunds: {},
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
|
-
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct
|
|
36
|
+
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
|
|
44
37
|
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
45
38
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
46
|
-
var realizedLpFee =
|
|
39
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
|
|
47
40
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
48
|
-
if (!(0, utils_1.isSlowFill)(
|
|
49
|
-
var refundAmount =
|
|
41
|
+
if (!(0, utils_1.isSlowFill)(fill)) {
|
|
42
|
+
var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
|
|
50
43
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
51
44
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
52
45
|
: refundAmount;
|
|
53
46
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
54
|
-
if (refundObj.refunds[
|
|
55
|
-
refundObj.refunds[
|
|
47
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
48
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
56
49
|
}
|
|
57
50
|
else {
|
|
58
|
-
refundObj.refunds[
|
|
51
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
54
|
}
|
|
@@ -69,9 +62,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
|
|
|
69
62
|
}
|
|
70
63
|
function updateBundleSlowFills(dict, deposit) {
|
|
71
64
|
var _a;
|
|
72
|
-
if ((0, utils_1.chainIsEvm)(deposit.destinationChainId) && !(0, utils_1.isValidEvmAddress)(deposit.recipient)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
65
|
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
76
66
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
77
67
|
(0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
|
|
@@ -156,7 +146,7 @@ var BundleDataClient = (function () {
|
|
|
156
146
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
157
147
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
158
148
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
159
|
-
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),
|
|
160
150
|
});
|
|
161
151
|
return [2, bundleData];
|
|
162
152
|
}
|
|
@@ -198,107 +188,64 @@ var BundleDataClient = (function () {
|
|
|
198
188
|
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
199
189
|
case 1:
|
|
200
190
|
arweaveData = _a.sent();
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
_a.label = 4;
|
|
215
|
-
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)];
|
|
216
204
|
}
|
|
217
205
|
});
|
|
218
206
|
});
|
|
219
207
|
};
|
|
220
208
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
237
|
-
return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
238
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
239
|
-
return tslib_1.__generator(this, function (_a) {
|
|
240
|
-
switch (_a.label) {
|
|
241
|
-
case 0:
|
|
242
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
243
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
244
|
-
(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill)) {
|
|
245
|
-
return [2, false];
|
|
246
|
-
}
|
|
247
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
248
|
-
return [2, false];
|
|
249
|
-
}
|
|
250
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
251
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
252
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
253
|
-
if (!hasMatchingDeposit) return [3, 2];
|
|
254
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
|
|
255
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
256
|
-
.filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
|
|
257
|
-
case 1:
|
|
258
|
-
validRepayment = _a.sent();
|
|
259
|
-
if (!(0, utils_1.isDefined)(validRepayment)) {
|
|
260
|
-
return [2, false];
|
|
261
|
-
}
|
|
262
|
-
_a.label = 2;
|
|
263
|
-
case 2: return [2, hasMatchingDeposit];
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}); })];
|
|
267
|
-
case 1:
|
|
268
|
-
fillsToCount = _b.sent();
|
|
269
|
-
fillsToCount.forEach(function (fill) {
|
|
270
|
-
var _a, _b, _c;
|
|
271
|
-
var _d;
|
|
272
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
273
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
274
|
-
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
275
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
276
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
277
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
278
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
279
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
280
|
-
});
|
|
281
|
-
return [2];
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
this_1 = this;
|
|
286
|
-
_i = 0, chainIds_1 = chainIds;
|
|
287
|
-
_a.label = 1;
|
|
288
|
-
case 1:
|
|
289
|
-
if (!(_i < chainIds_1.length)) return [3, 4];
|
|
290
|
-
chainId = chainIds_1[_i];
|
|
291
|
-
return [5, _loop_1(chainId)];
|
|
292
|
-
case 2:
|
|
293
|
-
_a.sent();
|
|
294
|
-
_a.label = 3;
|
|
295
|
-
case 3:
|
|
296
|
-
_i++;
|
|
297
|
-
return [3, 1];
|
|
298
|
-
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;
|
|
299
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);
|
|
300
241
|
});
|
|
301
|
-
}
|
|
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;
|
|
302
249
|
};
|
|
303
250
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
304
251
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -370,39 +317,32 @@ var BundleDataClient = (function () {
|
|
|
370
317
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
371
318
|
});
|
|
372
319
|
}
|
|
373
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
374
|
-
return tslib_1.__generator(this, function (
|
|
375
|
-
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) {
|
|
376
323
|
case 0:
|
|
377
324
|
hubPoolClient = this.clients.hubPoolClient;
|
|
378
325
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
379
326
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
380
327
|
combinedRefunds = [];
|
|
381
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));
|
|
382
|
-
if (!hubPoolClient.hasPendingProposal()) return [3,
|
|
329
|
+
if (!hubPoolClient.hasPendingProposal()) return [3, 2];
|
|
383
330
|
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
384
331
|
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
385
332
|
case 1:
|
|
386
|
-
arweaveData =
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
395
|
-
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
396
|
-
_e.label = 4;
|
|
397
|
-
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
|
+
}
|
|
398
341
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
399
|
-
|
|
400
|
-
case
|
|
342
|
+
_a.label = 2;
|
|
343
|
+
case 2:
|
|
401
344
|
start = performance.now();
|
|
402
|
-
|
|
403
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
404
|
-
case 6:
|
|
405
|
-
_d.apply(_c, [_e.sent()]);
|
|
345
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
406
346
|
this.logger.debug({
|
|
407
347
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
408
348
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -533,7 +473,7 @@ var BundleDataClient = (function () {
|
|
|
533
473
|
};
|
|
534
474
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
535
475
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
536
|
-
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;
|
|
537
477
|
var _this = this;
|
|
538
478
|
return tslib_1.__generator(this, function (_c) {
|
|
539
479
|
switch (_c.label) {
|
|
@@ -553,7 +493,6 @@ var BundleDataClient = (function () {
|
|
|
553
493
|
bundleDepositsV3 = {};
|
|
554
494
|
bundleFillsV3 = {};
|
|
555
495
|
bundleInvalidFillsV3 = [];
|
|
556
|
-
bundleUnrepayableFillsV3 = [];
|
|
557
496
|
bundleSlowFillsV3 = {};
|
|
558
497
|
expiredDepositsToRefundV3 = {};
|
|
559
498
|
unexecutableSlowFills = {};
|
|
@@ -602,13 +541,6 @@ var BundleDataClient = (function () {
|
|
|
602
541
|
v3RelayHashes = {};
|
|
603
542
|
bundleDepositHashes = [];
|
|
604
543
|
olderDepositHashes = [];
|
|
605
|
-
decodeBundleDepositHash = function (depositHash) {
|
|
606
|
-
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
607
|
-
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
608
|
-
};
|
|
609
|
-
startBlockForMainnet = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
|
|
610
|
-
versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
|
|
611
|
-
canRefundPrefills = versionAtProposalBlock >= constants_1.PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
|
|
612
544
|
depositCounter = 0;
|
|
613
545
|
_loop_2 = function (originChainId) {
|
|
614
546
|
var originClient = spokePoolClients[originChainId];
|
|
@@ -626,27 +558,20 @@ var BundleDataClient = (function () {
|
|
|
626
558
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
627
559
|
if (!v3RelayHashes[relayDataHash]) {
|
|
628
560
|
v3RelayHashes[relayDataHash] = {
|
|
629
|
-
|
|
561
|
+
deposit: deposit,
|
|
630
562
|
fill: undefined,
|
|
631
563
|
slowFillRequest: undefined,
|
|
632
564
|
};
|
|
633
565
|
}
|
|
634
|
-
else {
|
|
635
|
-
v3RelayHashes[relayDataHash].deposits.push(deposit);
|
|
636
|
-
}
|
|
637
566
|
if (deposit.inputAmount.eq(0)) {
|
|
638
567
|
return;
|
|
639
568
|
}
|
|
640
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
641
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
642
|
-
(0, utils_1.assert)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
643
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
644
569
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
645
|
-
bundleDepositHashes.push(
|
|
570
|
+
bundleDepositHashes.push(relayDataHash);
|
|
646
571
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
647
572
|
}
|
|
648
573
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
649
|
-
olderDepositHashes.push(
|
|
574
|
+
olderDepositHashes.push(relayDataHash);
|
|
650
575
|
}
|
|
651
576
|
});
|
|
652
577
|
}
|
|
@@ -671,7 +596,7 @@ var BundleDataClient = (function () {
|
|
|
671
596
|
case 0:
|
|
672
597
|
originClient = spokePoolClients[originChainId];
|
|
673
598
|
_loop_4 = function (destinationChainId) {
|
|
674
|
-
var destinationClient, destinationChainBlockRange,
|
|
599
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
|
|
675
600
|
return tslib_1.__generator(this, function (_g) {
|
|
676
601
|
switch (_g.label) {
|
|
677
602
|
case 0:
|
|
@@ -680,90 +605,58 @@ var BundleDataClient = (function () {
|
|
|
680
605
|
}
|
|
681
606
|
destinationClient = spokePoolClients[destinationChainId];
|
|
682
607
|
destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
683
|
-
originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
684
608
|
fastFillsReplacingSlowFills = [];
|
|
685
609
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
686
610
|
.getFillsForOriginChain(originChainId)
|
|
687
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 () {
|
|
688
|
-
var relayDataHash,
|
|
612
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
689
613
|
return tslib_1.__generator(this, function (_a) {
|
|
690
614
|
switch (_a.label) {
|
|
691
615
|
case 0:
|
|
692
|
-
fillCounter++;
|
|
693
616
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
694
|
-
|
|
695
|
-
if (
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
else {
|
|
706
|
-
v3RelayHashes[relayDataHash].fill = fillToRefund_1;
|
|
707
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp }));
|
|
708
|
-
duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
|
|
709
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
710
|
-
if ((0, utils_1.isSlowFill)(fill)) {
|
|
711
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
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
|
+
}
|
|
715
628
|
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
719
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
720
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
629
|
+
}
|
|
630
|
+
return [2];
|
|
721
631
|
}
|
|
722
|
-
_a.label = 2;
|
|
723
|
-
case 2: return [3, 4];
|
|
724
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
725
|
-
case 4: return [2];
|
|
726
|
-
case 5:
|
|
727
632
|
v3RelayHashes[relayDataHash] = {
|
|
728
|
-
|
|
633
|
+
deposit: undefined,
|
|
729
634
|
fill: fill,
|
|
730
635
|
slowFillRequest: undefined,
|
|
731
636
|
};
|
|
732
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3,
|
|
637
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
733
638
|
if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
|
|
734
639
|
bundleInvalidFillsV3.push(fill);
|
|
735
640
|
return [2];
|
|
736
641
|
}
|
|
737
642
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
|
|
738
|
-
case
|
|
643
|
+
case 1:
|
|
739
644
|
historicalDeposit = _a.sent();
|
|
740
|
-
if (
|
|
741
|
-
bundleInvalidFillsV3.push(fill);
|
|
742
|
-
return [3, 9];
|
|
743
|
-
case 7:
|
|
744
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
745
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
645
|
+
if (!historicalDeposit.found) {
|
|
746
646
|
bundleInvalidFillsV3.push(fill);
|
|
747
|
-
return [2];
|
|
748
|
-
}
|
|
749
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
750
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
751
|
-
case 8:
|
|
752
|
-
fillToRefund = _a.sent();
|
|
753
|
-
if (!(0, utils_1.isDefined)(fillToRefund)) {
|
|
754
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
755
647
|
}
|
|
756
648
|
else {
|
|
649
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
757
650
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
758
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({},
|
|
759
|
-
v3RelayHashes[relayDataHash].
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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
|
+
}
|
|
764
657
|
}
|
|
765
|
-
_a.label =
|
|
766
|
-
case
|
|
658
|
+
_a.label = 2;
|
|
659
|
+
case 2: return [2];
|
|
767
660
|
}
|
|
768
661
|
});
|
|
769
662
|
}); })];
|
|
@@ -785,26 +678,23 @@ var BundleDataClient = (function () {
|
|
|
785
678
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
786
679
|
return [2];
|
|
787
680
|
}
|
|
788
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].
|
|
789
|
-
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;
|
|
790
683
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
791
684
|
_canCreateSlowFillLeaf(matchedDeposit) &&
|
|
792
685
|
!_depositIsExpired(matchedDeposit)) {
|
|
793
686
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
794
687
|
}
|
|
795
688
|
}
|
|
796
|
-
else {
|
|
797
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
798
|
-
}
|
|
799
689
|
return [2];
|
|
800
690
|
}
|
|
801
691
|
v3RelayHashes[relayDataHash] = {
|
|
802
|
-
|
|
692
|
+
deposit: undefined,
|
|
803
693
|
fill: undefined,
|
|
804
694
|
slowFillRequest: slowFillRequest,
|
|
805
695
|
};
|
|
806
|
-
if (!(
|
|
807
|
-
slowFillRequest.
|
|
696
|
+
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
697
|
+
exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3, 2];
|
|
808
698
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
|
|
809
699
|
case 1:
|
|
810
700
|
historicalDeposit = _a.sent();
|
|
@@ -812,11 +702,8 @@ var BundleDataClient = (function () {
|
|
|
812
702
|
return [2];
|
|
813
703
|
}
|
|
814
704
|
matchedDeposit = historicalDeposit.deposit;
|
|
815
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
816
|
-
return [2];
|
|
817
|
-
}
|
|
818
705
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
819
|
-
v3RelayHashes[relayDataHash].
|
|
706
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
820
707
|
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
821
708
|
_depositIsExpired(matchedDeposit)) {
|
|
822
709
|
return [2];
|
|
@@ -829,31 +716,26 @@ var BundleDataClient = (function () {
|
|
|
829
716
|
}); })];
|
|
830
717
|
case 2:
|
|
831
718
|
_g.sent();
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
var
|
|
835
|
-
return
|
|
836
|
-
|
|
719
|
+
originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
720
|
+
return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
|
|
721
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
722
|
+
return (deposit &&
|
|
723
|
+
deposit.originChainId === originChainId &&
|
|
724
|
+
deposit.destinationChainId === destinationChainId &&
|
|
725
|
+
deposit.blockNumber >= originBlockRange[0] &&
|
|
726
|
+
deposit.blockNumber <= originBlockRange[1] &&
|
|
727
|
+
!(0, utils_1.isZeroValueDeposit)(deposit));
|
|
728
|
+
}), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
729
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
730
|
+
return tslib_1.__generator(this, function (_b) {
|
|
731
|
+
switch (_b.label) {
|
|
837
732
|
case 0:
|
|
838
|
-
_a =
|
|
839
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
840
|
-
if (!deposits || deposits.length === 0) {
|
|
841
|
-
throw new Error("Deposits should exist in relay hash dictionary.");
|
|
842
|
-
}
|
|
843
|
-
deposit = deposits[index];
|
|
733
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
844
734
|
if (!deposit)
|
|
845
735
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
846
|
-
if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
|
|
847
|
-
return [2];
|
|
848
|
-
}
|
|
849
736
|
if (fill) {
|
|
850
|
-
if (
|
|
851
|
-
|
|
852
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
853
|
-
}
|
|
854
|
-
else {
|
|
855
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
856
|
-
}
|
|
737
|
+
if (fill.blockNumber < destinationChainBlockRange[0] && !(0, utils_1.isSlowFill)(fill)) {
|
|
738
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
857
739
|
}
|
|
858
740
|
return [2];
|
|
859
741
|
}
|
|
@@ -861,66 +743,50 @@ var BundleDataClient = (function () {
|
|
|
861
743
|
if (_depositIsExpired(deposit)) {
|
|
862
744
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
863
745
|
}
|
|
864
|
-
else if (
|
|
865
|
-
|
|
866
|
-
_canCreateSlowFillLeaf(deposit) &&
|
|
867
|
-
validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
|
|
746
|
+
else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
747
|
+
_canCreateSlowFillLeaf(deposit)) {
|
|
868
748
|
validatedBundleSlowFills.push(deposit);
|
|
869
749
|
}
|
|
870
750
|
return [2];
|
|
871
751
|
}
|
|
872
752
|
return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
873
753
|
case 1:
|
|
874
|
-
fillStatus =
|
|
875
|
-
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3,
|
|
876
|
-
return [4,
|
|
754
|
+
fillStatus = _b.sent();
|
|
755
|
+
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
|
|
756
|
+
return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
877
757
|
case 2:
|
|
878
|
-
prefill =
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
if (!canRefundPrefills) return [3, 4];
|
|
882
|
-
return [4, (0, utils_2.verifyFillRepayment)(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
883
|
-
case 3:
|
|
884
|
-
verifiedFill = _c.sent();
|
|
885
|
-
if (!(0, utils_1.isDefined)(verifiedFill)) {
|
|
886
|
-
bundleUnrepayableFillsV3.push(prefill);
|
|
887
|
-
}
|
|
888
|
-
else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
|
|
889
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
758
|
+
prefill = (_b.sent());
|
|
759
|
+
if (!(0, utils_1.isSlowFill)(prefill)) {
|
|
760
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
893
761
|
}
|
|
894
|
-
|
|
895
|
-
case
|
|
896
|
-
case 5:
|
|
762
|
+
return [3, 4];
|
|
763
|
+
case 3:
|
|
897
764
|
if (_depositIsExpired(deposit)) {
|
|
898
765
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
899
766
|
}
|
|
900
|
-
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill
|
|
901
|
-
|
|
902
|
-
if (canRefundPrefills && _canCreateSlowFillLeaf(deposit)) {
|
|
767
|
+
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
|
|
768
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
903
769
|
validatedBundleSlowFills.push(deposit);
|
|
904
770
|
}
|
|
905
771
|
}
|
|
906
|
-
|
|
907
|
-
case
|
|
772
|
+
_b.label = 4;
|
|
773
|
+
case 4: return [2];
|
|
908
774
|
}
|
|
909
775
|
});
|
|
910
776
|
}); })];
|
|
911
777
|
case 3:
|
|
912
778
|
_g.sent();
|
|
913
779
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
914
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
780
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
915
781
|
(0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
916
|
-
if (!
|
|
782
|
+
if (!deposit) {
|
|
917
783
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
918
784
|
}
|
|
919
|
-
(0, utils_1.assert)(_canCreateSlowFillLeaf(
|
|
785
|
+
(0, utils_1.assert)(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
|
|
920
786
|
var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
921
787
|
if (!slowFillRequest ||
|
|
922
788
|
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
923
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
789
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
924
790
|
}
|
|
925
791
|
});
|
|
926
792
|
return [2];
|
|
@@ -961,17 +827,13 @@ var BundleDataClient = (function () {
|
|
|
961
827
|
message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
|
|
962
828
|
});
|
|
963
829
|
start = performance.now();
|
|
964
|
-
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (
|
|
965
|
-
var _a,
|
|
966
|
-
return tslib_1.__generator(this, function (
|
|
967
|
-
switch (
|
|
830
|
+
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
831
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
832
|
+
return tslib_1.__generator(this, function (_b) {
|
|
833
|
+
switch (_b.label) {
|
|
968
834
|
case 0:
|
|
969
|
-
_a =
|
|
970
|
-
|
|
971
|
-
if (!deposits || deposits.length < 1) {
|
|
972
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
973
|
-
}
|
|
974
|
-
deposit = deposits[index];
|
|
835
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
836
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
975
837
|
destinationChainId = deposit.destinationChainId;
|
|
976
838
|
destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
977
839
|
if (!(!fill &&
|
|
@@ -981,7 +843,7 @@ var BundleDataClient = (function () {
|
|
|
981
843
|
spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
|
|
982
844
|
return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
983
845
|
case 1:
|
|
984
|
-
fillStatus =
|
|
846
|
+
fillStatus = _b.sent();
|
|
985
847
|
if (fillStatus !== interfaces_1.FillStatus.Filled) {
|
|
986
848
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
987
849
|
}
|
|
@@ -991,7 +853,7 @@ var BundleDataClient = (function () {
|
|
|
991
853
|
if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
992
854
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
993
855
|
}
|
|
994
|
-
|
|
856
|
+
_b.label = 2;
|
|
995
857
|
case 2: return [2];
|
|
996
858
|
}
|
|
997
859
|
});
|
|
@@ -1002,7 +864,7 @@ var BundleDataClient = (function () {
|
|
|
1002
864
|
promises = [
|
|
1003
865
|
validatedBundleV3Fills.length > 0
|
|
1004
866
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
1005
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
867
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1006
868
|
(0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1007
869
|
var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1008
870
|
return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1029,18 +891,14 @@ var BundleDataClient = (function () {
|
|
|
1029
891
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1030
892
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1031
893
|
var fill = validatedBundleV3Fills[idx];
|
|
1032
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
894
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1033
895
|
(0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1034
896
|
var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1035
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
897
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1036
898
|
});
|
|
1037
899
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1038
900
|
var lpFeePct = _a.realizedLpFeePct;
|
|
1039
901
|
var deposit = validatedBundleSlowFills[idx];
|
|
1040
|
-
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
1041
|
-
if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
|
|
1042
|
-
return;
|
|
1043
|
-
}
|
|
1044
902
|
updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1045
903
|
});
|
|
1046
904
|
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
@@ -1048,7 +906,7 @@ var BundleDataClient = (function () {
|
|
|
1048
906
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
1049
907
|
updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1050
908
|
});
|
|
1051
|
-
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
909
|
+
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1052
910
|
if (bundleInvalidFillsV3.length > 0) {
|
|
1053
911
|
this.logger.debug({
|
|
1054
912
|
at: "BundleDataClient#loadData",
|
|
@@ -1057,14 +915,6 @@ var BundleDataClient = (function () {
|
|
|
1057
915
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
1058
916
|
});
|
|
1059
917
|
}
|
|
1060
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
1061
|
-
this.logger.debug({
|
|
1062
|
-
at: "BundleDataClient#loadData",
|
|
1063
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable V3 fills in range",
|
|
1064
|
-
blockRangesForChains: blockRangesForChains,
|
|
1065
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
918
|
this.logger.debug({
|
|
1069
919
|
at: "BundleDataClient#loadDataFromScratch",
|
|
1070
920
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -1083,17 +933,7 @@ var BundleDataClient = (function () {
|
|
|
1083
933
|
});
|
|
1084
934
|
};
|
|
1085
935
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1086
|
-
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
|
|
1087
|
-
};
|
|
1088
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1089
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1090
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1091
|
-
switch (_a.label) {
|
|
1092
|
-
case 0: return [4, (0, utils_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1093
|
-
case 1: return [2, _a.sent()];
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
936
|
+
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);
|
|
1097
937
|
};
|
|
1098
938
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1099
939
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -1104,7 +944,7 @@ var BundleDataClient = (function () {
|
|
|
1104
944
|
case 0:
|
|
1105
945
|
_b = (_a = Object).fromEntries;
|
|
1106
946
|
return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1107
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
947
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1108
948
|
return tslib_1.__generator(this, function (_c) {
|
|
1109
949
|
switch (_c.label) {
|
|
1110
950
|
case 0:
|
|
@@ -1118,7 +958,7 @@ var BundleDataClient = (function () {
|
|
|
1118
958
|
return [2];
|
|
1119
959
|
}
|
|
1120
960
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1121
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
961
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1122
962
|
return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1123
963
|
case 1:
|
|
1124
964
|
_b = [
|
|
@@ -1128,10 +968,8 @@ var BundleDataClient = (function () {
|
|
|
1128
968
|
case 2:
|
|
1129
969
|
_a = _b.concat([
|
|
1130
970
|
_c.sent()
|
|
1131
|
-
]), startTime = _a[0],
|
|
1132
|
-
|
|
1133
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1134
|
-
(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, "."));
|
|
971
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
972
|
+
(0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
|
|
1135
973
|
(0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1136
974
|
return [2, [chainId, [startTime, endTime]]];
|
|
1137
975
|
}
|