@across-protocol/sdk 4.0.0-beta.19 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +176 -308
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -33
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
- package/dist/cjs/clients/SpokePoolClient.js +4 -13
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +0 -1
- package/dist/cjs/constants.js +1 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +0 -1
- package/dist/cjs/providers/index.js +0 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +0 -1
- package/dist/cjs/utils/AddressUtils.js +1 -14
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/CachingUtils.js +1 -1
- package/dist/cjs/utils/CachingUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.d.ts +1 -2
- package/dist/cjs/utils/DepositUtils.js +3 -12
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.d.ts +0 -1
- package/dist/cjs/utils/NetworkUtils.js +1 -6
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.js +3 -3
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +214 -370
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -42
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
- package/dist/esm/clients/SpokePoolClient.js +4 -20
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +0 -1
- package/dist/esm/constants.js +1 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/providers/index.d.ts +0 -1
- package/dist/esm/providers/index.js +0 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +0 -1
- package/dist/esm/utils/AddressUtils.js +0 -16
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/CachingUtils.js +1 -1
- package/dist/esm/utils/CachingUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.d.ts +1 -2
- package/dist/esm/utils/DepositUtils.js +3 -12
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.d.ts +0 -6
- package/dist/esm/utils/NetworkUtils.js +0 -10
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.js +4 -4
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -3
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient.d.ts +0 -8
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +0 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +0 -1
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts +1 -2
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/dist/types/utils/NetworkUtils.d.ts +0 -6
- package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +215 -375
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -47
- package/src/clients/SpokePoolClient.ts +6 -19
- package/src/constants.ts +1 -3
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -16
- package/src/utils/CachingUtils.ts +1 -1
- package/src/utils/DepositUtils.ts +3 -12
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +5 -6
- package/dist/cjs/providers/mockProvider.d.ts +0 -19
- package/dist/cjs/providers/mockProvider.js +0 -70
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/esm/providers/mockProvider.d.ts +0 -23
- package/dist/esm/providers/mockProvider.js +0 -73
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts +0 -24
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/src/providers/mockProvider.ts +0 -77
|
@@ -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
|
}
|
|
@@ -195,107 +188,64 @@ var BundleDataClient = (function () {
|
|
|
195
188
|
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
196
189
|
case 1:
|
|
197
190
|
arweaveData = _a.sent();
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
_a.label = 4;
|
|
212
|
-
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)];
|
|
213
204
|
}
|
|
214
205
|
});
|
|
215
206
|
});
|
|
216
207
|
};
|
|
217
208
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
234
|
-
return [4, (0, utils_1.filterAsync)(this_1.spokePoolClients[chainId].getFills(), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
235
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
236
|
-
return tslib_1.__generator(this, function (_a) {
|
|
237
|
-
switch (_a.label) {
|
|
238
|
-
case 0:
|
|
239
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
240
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
241
|
-
(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill)) {
|
|
242
|
-
return [2, false];
|
|
243
|
-
}
|
|
244
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
245
|
-
return [2, false];
|
|
246
|
-
}
|
|
247
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
248
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
249
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
250
|
-
if (!hasMatchingDeposit) return [3, 2];
|
|
251
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit, this.clients.configStoreClient
|
|
252
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
253
|
-
.filter(function (_chainId, i) { return !(0, utils_2.isChainDisabled)(blockRanges[i]); }))];
|
|
254
|
-
case 1:
|
|
255
|
-
validRepayment = _a.sent();
|
|
256
|
-
if (!(0, utils_1.isDefined)(validRepayment)) {
|
|
257
|
-
return [2, false];
|
|
258
|
-
}
|
|
259
|
-
_a.label = 2;
|
|
260
|
-
case 2: return [2, hasMatchingDeposit];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}); })];
|
|
264
|
-
case 1:
|
|
265
|
-
fillsToCount = _b.sent();
|
|
266
|
-
fillsToCount.forEach(function (fill) {
|
|
267
|
-
var _a, _b, _c;
|
|
268
|
-
var _d;
|
|
269
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
270
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
271
|
-
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
272
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
273
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
274
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
275
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
276
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
277
|
-
});
|
|
278
|
-
return [2];
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
this_1 = this;
|
|
283
|
-
_i = 0, chainIds_1 = chainIds;
|
|
284
|
-
_a.label = 1;
|
|
285
|
-
case 1:
|
|
286
|
-
if (!(_i < chainIds_1.length)) return [3, 4];
|
|
287
|
-
chainId = chainIds_1[_i];
|
|
288
|
-
return [5, _loop_1(chainId)];
|
|
289
|
-
case 2:
|
|
290
|
-
_a.sent();
|
|
291
|
-
_a.label = 3;
|
|
292
|
-
case 3:
|
|
293
|
-
_i++;
|
|
294
|
-
return [3, 1];
|
|
295
|
-
case 4: return [2, refundsForChain];
|
|
209
|
+
var _this = this;
|
|
210
|
+
var refundsForChain = {};
|
|
211
|
+
var _loop_1 = function (chainId) {
|
|
212
|
+
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
213
|
+
return "continue";
|
|
214
|
+
}
|
|
215
|
+
var chainIndex = chainIds.indexOf(chainId);
|
|
216
|
+
this_1.spokePoolClients[chainId]
|
|
217
|
+
.getFills()
|
|
218
|
+
.filter(function (fill) {
|
|
219
|
+
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
223
|
+
return false;
|
|
296
224
|
}
|
|
225
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
226
|
+
var hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
227
|
+
_this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
|
|
228
|
+
return hasMatchingDeposit;
|
|
229
|
+
})
|
|
230
|
+
.forEach(function (fill) {
|
|
231
|
+
var _a, _b, _c;
|
|
232
|
+
var _d;
|
|
233
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
234
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
235
|
+
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
236
|
+
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
237
|
+
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
238
|
+
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
239
|
+
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
240
|
+
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
297
241
|
});
|
|
298
|
-
}
|
|
242
|
+
};
|
|
243
|
+
var this_1 = this;
|
|
244
|
+
for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
|
|
245
|
+
var chainId = chainIds_1[_i];
|
|
246
|
+
_loop_1(chainId);
|
|
247
|
+
}
|
|
248
|
+
return refundsForChain;
|
|
299
249
|
};
|
|
300
250
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
301
251
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -367,39 +317,32 @@ var BundleDataClient = (function () {
|
|
|
367
317
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
368
318
|
});
|
|
369
319
|
}
|
|
370
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
371
|
-
return tslib_1.__generator(this, function (
|
|
372
|
-
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) {
|
|
373
323
|
case 0:
|
|
374
324
|
hubPoolClient = this.clients.hubPoolClient;
|
|
375
325
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
376
326
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
377
327
|
combinedRefunds = [];
|
|
378
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));
|
|
379
|
-
if (!hubPoolClient.hasPendingProposal()) return [3,
|
|
329
|
+
if (!hubPoolClient.hasPendingProposal()) return [3, 2];
|
|
380
330
|
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
381
331
|
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
382
332
|
case 1:
|
|
383
|
-
arweaveData =
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
392
|
-
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
393
|
-
_e.label = 4;
|
|
394
|
-
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
|
+
}
|
|
395
341
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
396
|
-
|
|
397
|
-
case
|
|
342
|
+
_a.label = 2;
|
|
343
|
+
case 2:
|
|
398
344
|
start = performance.now();
|
|
399
|
-
|
|
400
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
401
|
-
case 6:
|
|
402
|
-
_d.apply(_c, [_e.sent()]);
|
|
345
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
403
346
|
this.logger.debug({
|
|
404
347
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
405
348
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -530,7 +473,7 @@ var BundleDataClient = (function () {
|
|
|
530
473
|
};
|
|
531
474
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
532
475
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
533
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf,
|
|
476
|
+
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, depositCounter, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
|
|
534
477
|
var _this = this;
|
|
535
478
|
return tslib_1.__generator(this, function (_c) {
|
|
536
479
|
switch (_c.label) {
|
|
@@ -562,9 +505,6 @@ var BundleDataClient = (function () {
|
|
|
562
505
|
!deposit.fromLiteChain &&
|
|
563
506
|
!deposit.toLiteChain);
|
|
564
507
|
};
|
|
565
|
-
_depositIsExpired = function (deposit) {
|
|
566
|
-
return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
|
|
567
|
-
};
|
|
568
508
|
_getFillStatusForDeposit = function (deposit, queryBlock) {
|
|
569
509
|
return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit, Math.min(queryBlock, spokePoolClients[deposit.destinationChainId].latestBlockSearched), deposit.destinationChainId);
|
|
570
510
|
};
|
|
@@ -598,13 +538,6 @@ var BundleDataClient = (function () {
|
|
|
598
538
|
v3RelayHashes = {};
|
|
599
539
|
bundleDepositHashes = [];
|
|
600
540
|
olderDepositHashes = [];
|
|
601
|
-
decodeBundleDepositHash = function (depositHash) {
|
|
602
|
-
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
603
|
-
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
604
|
-
};
|
|
605
|
-
startBlockForMainnet = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
|
|
606
|
-
versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
|
|
607
|
-
canRefundPrefills = versionAtProposalBlock >= constants_1.PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
|
|
608
541
|
depositCounter = 0;
|
|
609
542
|
_loop_2 = function (originChainId) {
|
|
610
543
|
var originClient = spokePoolClients[originChainId];
|
|
@@ -615,34 +548,27 @@ var BundleDataClient = (function () {
|
|
|
615
548
|
continue;
|
|
616
549
|
}
|
|
617
550
|
originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
|
|
618
|
-
if (
|
|
551
|
+
if ((0, utils_1.isZeroValueDeposit)(deposit) || deposit.blockNumber > originChainBlockRange[1]) {
|
|
619
552
|
return;
|
|
620
553
|
}
|
|
621
554
|
depositCounter++;
|
|
622
555
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
623
556
|
if (!v3RelayHashes[relayDataHash]) {
|
|
624
557
|
v3RelayHashes[relayDataHash] = {
|
|
625
|
-
|
|
558
|
+
deposit: deposit,
|
|
626
559
|
fill: undefined,
|
|
627
560
|
slowFillRequest: undefined,
|
|
628
561
|
};
|
|
629
562
|
}
|
|
630
|
-
else {
|
|
631
|
-
v3RelayHashes[relayDataHash].deposits.push(deposit);
|
|
632
|
-
}
|
|
633
563
|
if (deposit.inputAmount.eq(0)) {
|
|
634
564
|
return;
|
|
635
565
|
}
|
|
636
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
637
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
638
|
-
(0, utils_1.assert)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
639
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
640
566
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
641
|
-
bundleDepositHashes.push(
|
|
567
|
+
bundleDepositHashes.push(relayDataHash);
|
|
642
568
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
643
569
|
}
|
|
644
570
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
645
|
-
olderDepositHashes.push(
|
|
571
|
+
olderDepositHashes.push(relayDataHash);
|
|
646
572
|
}
|
|
647
573
|
});
|
|
648
574
|
}
|
|
@@ -667,7 +593,7 @@ var BundleDataClient = (function () {
|
|
|
667
593
|
case 0:
|
|
668
594
|
originClient = spokePoolClients[originChainId];
|
|
669
595
|
_loop_4 = function (destinationChainId) {
|
|
670
|
-
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
596
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills, originBlockRange;
|
|
671
597
|
return tslib_1.__generator(this, function (_g) {
|
|
672
598
|
switch (_g.label) {
|
|
673
599
|
case 0:
|
|
@@ -680,76 +606,56 @@ var BundleDataClient = (function () {
|
|
|
680
606
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
681
607
|
.getFillsForOriginChain(originChainId)
|
|
682
608
|
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill); }), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
683
|
-
var relayDataHash,
|
|
609
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
684
610
|
return tslib_1.__generator(this, function (_a) {
|
|
685
611
|
switch (_a.label) {
|
|
686
612
|
case 0:
|
|
687
|
-
fillCounter++;
|
|
688
613
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
689
|
-
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
705
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
706
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
614
|
+
fillCounter++;
|
|
615
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
616
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
617
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
618
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
619
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
620
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
621
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
622
|
+
!v3RelayHashes[relayDataHash].deposit.fromLiteChain &&
|
|
623
|
+
!v3RelayHashes[relayDataHash].deposit.toLiteChain) {
|
|
624
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return [2];
|
|
707
629
|
}
|
|
708
|
-
duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1);
|
|
709
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
710
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
711
|
-
});
|
|
712
|
-
_a.label = 2;
|
|
713
|
-
case 2: return [3, 4];
|
|
714
|
-
case 3: throw new Error("Duplicate fill detected.");
|
|
715
|
-
case 4: return [2];
|
|
716
|
-
case 5:
|
|
717
630
|
v3RelayHashes[relayDataHash] = {
|
|
718
|
-
|
|
631
|
+
deposit: undefined,
|
|
719
632
|
fill: fill,
|
|
720
633
|
slowFillRequest: undefined,
|
|
721
634
|
};
|
|
722
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3,
|
|
635
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
723
636
|
if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
|
|
724
637
|
bundleInvalidFillsV3.push(fill);
|
|
725
638
|
return [2];
|
|
726
639
|
}
|
|
727
640
|
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
|
|
728
|
-
case
|
|
641
|
+
case 1:
|
|
729
642
|
historicalDeposit = _a.sent();
|
|
730
|
-
if (
|
|
731
|
-
bundleInvalidFillsV3.push(fill);
|
|
732
|
-
return [3, 9];
|
|
733
|
-
case 7:
|
|
734
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
735
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
736
|
-
return [4, (0, utils_2.verifyFillRepayment)(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
737
|
-
case 8:
|
|
738
|
-
fillToRefund = _a.sent();
|
|
739
|
-
if (!(0, utils_1.isDefined)(fillToRefund)) {
|
|
643
|
+
if (!historicalDeposit.found) {
|
|
740
644
|
bundleInvalidFillsV3.push(fill);
|
|
741
645
|
}
|
|
742
646
|
else {
|
|
647
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
743
648
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
744
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({},
|
|
745
|
-
v3RelayHashes[relayDataHash].
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
649
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
650
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
651
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
|
|
652
|
+
!matchedDeposit.fromLiteChain &&
|
|
653
|
+
!matchedDeposit.toLiteChain) {
|
|
654
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
655
|
+
}
|
|
750
656
|
}
|
|
751
|
-
_a.label =
|
|
752
|
-
case
|
|
657
|
+
_a.label = 2;
|
|
658
|
+
case 2: return [2];
|
|
753
659
|
}
|
|
754
660
|
});
|
|
755
661
|
}); })];
|
|
@@ -771,21 +677,20 @@ var BundleDataClient = (function () {
|
|
|
771
677
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
772
678
|
return [2];
|
|
773
679
|
}
|
|
774
|
-
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].
|
|
775
|
-
matchedDeposit = v3RelayHashes[relayDataHash].
|
|
680
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
681
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
682
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
683
|
+
return [2];
|
|
684
|
+
}
|
|
776
685
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
777
|
-
|
|
778
|
-
!_depositIsExpired(matchedDeposit)) {
|
|
686
|
+
slowFillRequest.fillDeadline >= bundleBlockTimestamps[destinationChainId][1]) {
|
|
779
687
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
780
688
|
}
|
|
781
689
|
}
|
|
782
|
-
else {
|
|
783
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
784
|
-
}
|
|
785
690
|
return [2];
|
|
786
691
|
}
|
|
787
692
|
v3RelayHashes[relayDataHash] = {
|
|
788
|
-
|
|
693
|
+
deposit: undefined,
|
|
789
694
|
fill: undefined,
|
|
790
695
|
slowFillRequest: slowFillRequest,
|
|
791
696
|
};
|
|
@@ -799,9 +704,9 @@ var BundleDataClient = (function () {
|
|
|
799
704
|
}
|
|
800
705
|
matchedDeposit = historicalDeposit.deposit;
|
|
801
706
|
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
802
|
-
v3RelayHashes[relayDataHash].
|
|
707
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
803
708
|
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
804
|
-
|
|
709
|
+
slowFillRequest.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
805
710
|
return [2];
|
|
806
711
|
}
|
|
807
712
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
@@ -812,99 +717,77 @@ var BundleDataClient = (function () {
|
|
|
812
717
|
}); })];
|
|
813
718
|
case 2:
|
|
814
719
|
_g.sent();
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
720
|
+
originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
721
|
+
return [4, (0, utils_1.mapAsync)(bundleDepositHashes.filter(function (depositHash) {
|
|
722
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
723
|
+
return (deposit &&
|
|
724
|
+
deposit.originChainId === originChainId &&
|
|
725
|
+
deposit.destinationChainId === destinationChainId &&
|
|
726
|
+
deposit.blockNumber >= originBlockRange[0] &&
|
|
727
|
+
deposit.blockNumber <= originBlockRange[1] &&
|
|
728
|
+
!(0, utils_1.isZeroValueDeposit)(deposit));
|
|
729
|
+
}), function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
730
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
731
|
+
return tslib_1.__generator(this, function (_b) {
|
|
732
|
+
switch (_b.label) {
|
|
819
733
|
case 0:
|
|
820
|
-
_a =
|
|
821
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
822
|
-
deposit = deposits[index];
|
|
734
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
823
735
|
if (!deposit)
|
|
824
736
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
825
|
-
if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
|
|
826
|
-
return [2];
|
|
827
|
-
}
|
|
828
|
-
isDuplicateDepositInBundle = bundleDepositHashes
|
|
829
|
-
.slice(0, currentBundleDepositHashIndex)
|
|
830
|
-
.some(function (_depositHash) {
|
|
831
|
-
var _relayDataHash = decodeBundleDepositHash(_depositHash).relayDataHash;
|
|
832
|
-
return _relayDataHash === relayDataHash;
|
|
833
|
-
});
|
|
834
|
-
duplicateDepositsInBundle = deposits.slice(index + 1);
|
|
835
737
|
if (fill) {
|
|
836
|
-
if (!
|
|
837
|
-
|
|
838
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
839
|
-
});
|
|
840
|
-
if (canRefundPrefills) {
|
|
841
|
-
if (!(0, utils_1.isSlowFill)(fill)) {
|
|
842
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
843
|
-
}
|
|
844
|
-
}
|
|
738
|
+
if (!(0, utils_1.isSlowFill)(fill) && fill.blockNumber < destinationChainBlockRange[0]) {
|
|
739
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
845
740
|
}
|
|
846
741
|
return [2];
|
|
847
742
|
}
|
|
848
743
|
if (slowFillRequest) {
|
|
849
|
-
if (
|
|
744
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
850
745
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
851
746
|
}
|
|
852
|
-
else if (
|
|
853
|
-
|
|
854
|
-
slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
855
|
-
_canCreateSlowFillLeaf(deposit)) {
|
|
747
|
+
else if (_canCreateSlowFillLeaf(deposit) &&
|
|
748
|
+
slowFillRequest.blockNumber < destinationChainBlockRange[0]) {
|
|
856
749
|
validatedBundleSlowFills.push(deposit);
|
|
857
750
|
}
|
|
858
751
|
return [2];
|
|
859
752
|
}
|
|
860
753
|
return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
861
754
|
case 1:
|
|
862
|
-
fillStatus =
|
|
863
|
-
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3,
|
|
864
|
-
return [4,
|
|
755
|
+
fillStatus = _b.sent();
|
|
756
|
+
if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 3];
|
|
757
|
+
return [4, (0, utils_1.findFillEvent)(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
865
758
|
case 2:
|
|
866
|
-
prefill =
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
if (!!isDuplicateDepositInBundle) return [3, 4];
|
|
870
|
-
duplicateDepositsInBundle.forEach(function (duplicateDeposit) {
|
|
871
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
872
|
-
});
|
|
873
|
-
return [4, (0, utils_2.verifyFillRepayment)(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
874
|
-
case 3:
|
|
875
|
-
verifiedFill = _c.sent();
|
|
876
|
-
if (canRefundPrefills && (0, utils_1.isDefined)(verifiedFill) && !(0, utils_1.isSlowFill)(verifiedFill)) {
|
|
877
|
-
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
759
|
+
prefill = (_b.sent());
|
|
760
|
+
if (!(0, utils_1.isSlowFill)(prefill)) {
|
|
761
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
878
762
|
}
|
|
879
|
-
|
|
880
|
-
case
|
|
881
|
-
|
|
882
|
-
if (_depositIsExpired(deposit)) {
|
|
763
|
+
return [3, 4];
|
|
764
|
+
case 3:
|
|
765
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
883
766
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
884
767
|
}
|
|
885
768
|
else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill) {
|
|
886
|
-
if (
|
|
769
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
887
770
|
validatedBundleSlowFills.push(deposit);
|
|
888
771
|
}
|
|
889
772
|
}
|
|
890
|
-
|
|
891
|
-
case
|
|
773
|
+
_b.label = 4;
|
|
774
|
+
case 4: return [2];
|
|
892
775
|
}
|
|
893
776
|
});
|
|
894
777
|
}); })];
|
|
895
778
|
case 3:
|
|
896
779
|
_g.sent();
|
|
897
780
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
898
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
781
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
899
782
|
(0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
900
|
-
if (!
|
|
783
|
+
if (!deposit) {
|
|
901
784
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
902
785
|
}
|
|
903
|
-
(0, utils_1.assert)(
|
|
786
|
+
(0, utils_1.assert)(!deposit.fromLiteChain && !deposit.toLiteChain, "fastFillsReplacingSlowFills should not contain lite chain deposits");
|
|
904
787
|
var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
905
|
-
if (
|
|
906
|
-
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
907
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
788
|
+
if (_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
789
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
790
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
908
791
|
}
|
|
909
792
|
});
|
|
910
793
|
return [2];
|
|
@@ -945,37 +828,34 @@ var BundleDataClient = (function () {
|
|
|
945
828
|
message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
|
|
946
829
|
});
|
|
947
830
|
start = performance.now();
|
|
948
|
-
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (
|
|
949
|
-
var _a,
|
|
950
|
-
return tslib_1.__generator(this, function (
|
|
951
|
-
switch (
|
|
831
|
+
return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
832
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
833
|
+
return tslib_1.__generator(this, function (_b) {
|
|
834
|
+
switch (_b.label) {
|
|
952
835
|
case 0:
|
|
953
|
-
_a =
|
|
954
|
-
|
|
955
|
-
if (!deposits || deposits.length < 1) {
|
|
956
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
957
|
-
}
|
|
958
|
-
deposit = deposits[index];
|
|
836
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
837
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
959
838
|
destinationChainId = deposit.destinationChainId;
|
|
960
839
|
destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
961
840
|
if (!(!fill &&
|
|
962
841
|
(0, utils_1.isDefined)(deposit) &&
|
|
963
|
-
|
|
842
|
+
deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1] &&
|
|
964
843
|
deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
|
|
965
844
|
spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
|
|
966
845
|
return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
967
846
|
case 1:
|
|
968
|
-
fillStatus =
|
|
847
|
+
fillStatus = _b.sent();
|
|
969
848
|
if (fillStatus !== interfaces_1.FillStatus.Filled) {
|
|
970
849
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
971
850
|
}
|
|
972
|
-
if (fillStatus !== interfaces_1.FillStatus.RequestedSlowFill ||
|
|
851
|
+
if (fillStatus !== interfaces_1.FillStatus.RequestedSlowFill || deposit.fromLiteChain || deposit.toLiteChain) {
|
|
973
852
|
return [2];
|
|
974
853
|
}
|
|
975
|
-
if (
|
|
854
|
+
if (this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
855
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
976
856
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
977
857
|
}
|
|
978
|
-
|
|
858
|
+
_b.label = 2;
|
|
979
859
|
case 2: return [2];
|
|
980
860
|
}
|
|
981
861
|
});
|
|
@@ -986,7 +866,7 @@ var BundleDataClient = (function () {
|
|
|
986
866
|
promises = [
|
|
987
867
|
validatedBundleV3Fills.length > 0
|
|
988
868
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
989
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
869
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
990
870
|
(0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
991
871
|
var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
992
872
|
return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1013,10 +893,10 @@ var BundleDataClient = (function () {
|
|
|
1013
893
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1014
894
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1015
895
|
var fill = validatedBundleV3Fills[idx];
|
|
1016
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
896
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1017
897
|
(0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1018
898
|
var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1019
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
899
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1020
900
|
});
|
|
1021
901
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1022
902
|
var lpFeePct = _a.realizedLpFeePct;
|
|
@@ -1055,17 +935,7 @@ var BundleDataClient = (function () {
|
|
|
1055
935
|
});
|
|
1056
936
|
};
|
|
1057
937
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1058
|
-
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
|
|
1059
|
-
};
|
|
1060
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1061
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1062
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1063
|
-
switch (_a.label) {
|
|
1064
|
-
case 0: return [4, (0, utils_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1065
|
-
case 1: return [2, _a.sent()];
|
|
1066
|
-
}
|
|
1067
|
-
});
|
|
1068
|
-
});
|
|
938
|
+
return "".concat(event.depositor, "-").concat(event.recipient, "-").concat(event.exclusiveRelayer, "-").concat(event.inputToken, "-").concat(event.outputToken, "-").concat(event.inputAmount, "-").concat(event.outputAmount, "-").concat(event.originChainId, "-").concat(event.depositId, "-").concat(event.fillDeadline, "-").concat(event.exclusivityDeadline, "-").concat(event.message, "-").concat(event.destinationChainId);
|
|
1069
939
|
};
|
|
1070
940
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1071
941
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -1076,7 +946,7 @@ var BundleDataClient = (function () {
|
|
|
1076
946
|
case 0:
|
|
1077
947
|
_b = (_a = Object).fromEntries;
|
|
1078
948
|
return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1079
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
949
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1080
950
|
return tslib_1.__generator(this, function (_c) {
|
|
1081
951
|
switch (_c.label) {
|
|
1082
952
|
case 0:
|
|
@@ -1090,7 +960,7 @@ var BundleDataClient = (function () {
|
|
|
1090
960
|
return [2];
|
|
1091
961
|
}
|
|
1092
962
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1093
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
963
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1094
964
|
return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1095
965
|
case 1:
|
|
1096
966
|
_b = [
|
|
@@ -1100,10 +970,8 @@ var BundleDataClient = (function () {
|
|
|
1100
970
|
case 2:
|
|
1101
971
|
_a = _b.concat([
|
|
1102
972
|
_c.sent()
|
|
1103
|
-
]), startTime = _a[0],
|
|
1104
|
-
|
|
1105
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1106
|
-
(0, utils_1.assert)(endTime >= startTime, "End time for block ".concat(endBlockForChain, " should be greater than start time for block ").concat(startBlockForChain, ": ").concat(endTime, " >= ").concat(startTime, "."));
|
|
973
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
974
|
+
(0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
|
|
1107
975
|
(0, utils_1.assert)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1108
976
|
return [2, [chainId, [startTime, endTime]]];
|
|
1109
977
|
}
|