@across-protocol/sdk 4.0.0-beta.34 → 4.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +175 -355
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -47
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/cjs/clients/SpokePoolClient.d.ts +0 -1
- package/dist/cjs/clients/SpokePoolClient.js +1 -10
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +0 -1
- package/dist/cjs/providers/index.js +0 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +0 -2
- package/dist/cjs/utils/AddressUtils.js +1 -19
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.d.ts +1 -2
- package/dist/cjs/utils/DepositUtils.js +1 -10
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +0 -21
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.d.ts +0 -1
- package/dist/cjs/utils/NetworkUtils.js +1 -6
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +0 -1
- package/dist/cjs/utils/SpokeUtils.js +8 -15
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +0 -1
- package/dist/cjs/utils/common.js +1 -2
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +257 -459
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +3 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -54
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/esm/clients/SpokePoolClient.d.ts +0 -8
- package/dist/esm/clients/SpokePoolClient.js +1 -17
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +1 -11
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/providers/index.d.ts +0 -1
- package/dist/esm/providers/index.js +0 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +0 -2
- package/dist/esm/utils/AddressUtils.js +0 -25
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.d.ts +1 -2
- package/dist/esm/utils/DepositUtils.js +2 -11
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +1 -29
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.d.ts +0 -6
- package/dist/esm/utils/NetworkUtils.js +0 -10
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +0 -1
- package/dist/esm/utils/SpokeUtils.js +8 -14
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/common.d.ts +0 -1
- package/dist/esm/utils/common.js +0 -1
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -5
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -5
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +4 -4
- package/dist/types/clients/SpokePoolClient.d.ts +0 -8
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +1 -2
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +0 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +0 -2
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts +1 -2
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/dist/types/utils/NetworkUtils.d.ts +0 -6
- package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +0 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +227 -433
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +8 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -66
- package/src/clients/SpokePoolClient.ts +3 -16
- package/src/clients/mocks/MockSpokePoolClient.ts +1 -14
- package/src/constants.ts +3 -3
- package/src/providers/index.ts +0 -1
- package/src/utils/AddressUtils.ts +0 -26
- package/src/utils/DepositUtils.ts +2 -11
- package/src/utils/EventUtils.ts +1 -29
- package/src/utils/NetworkUtils.ts +0 -11
- package/src/utils/SpokeUtils.ts +9 -22
- package/src/utils/common.ts +0 -2
- package/dist/cjs/providers/mockProvider.d.ts +0 -19
- package/dist/cjs/providers/mockProvider.js +0 -70
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/esm/providers/mockProvider.d.ts +0 -23
- package/dist/esm/providers/mockProvider.js +0 -73
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts +0 -24
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/src/providers/mockProvider.ts +0 -77
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import _ from "lodash";
|
|
3
3
|
import { FillType, FillStatus, } from "../../interfaces";
|
|
4
|
-
import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync,
|
|
5
|
-
import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled,
|
|
6
|
-
import { PRE_FILL_MIN_CONFIG_STORE_VERSION } from "../../constants";
|
|
4
|
+
import { BigNumber, bnZero, queryHistoricalDepositForFill, assign, assert, fixedPointAdjustment, isDefined, toBN, forEachAsync, getBlockRangeForChain, getImpliedBundleBlockRanges, isSlowFill, mapAsync, bnUint32Max, isZeroValueDeposit, findFillEvent, isZeroValueFillOrSlowFillRequest, } from "../../utils";
|
|
5
|
+
import { _buildPoolRebalanceRoot, BundleDataSS, getEndBlockBuffers, getRefundInformationFromFill, getRefundsFromBundle, getWidestPossibleExpectedBlockRange, isChainDisabled, prettyPrintV3SpokePoolEvents, } from "./utils";
|
|
7
6
|
// max(uint256) - 1
|
|
8
7
|
export var INFINITE_FILL_DEADLINE = bnUint32Max;
|
|
9
8
|
// V3 dictionary helper functions
|
|
10
9
|
function updateExpiredDepositsV3(dict, deposit) {
|
|
11
10
|
var _a;
|
|
12
|
-
// A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
|
|
13
|
-
if (chainIsEvm(deposit.originChainId) && !isValidEvmAddress(deposit.depositor)) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
11
|
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
17
12
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
18
13
|
assign(dict, [originChainId, inputToken], []);
|
|
@@ -27,10 +22,8 @@ function updateBundleDepositsV3(dict, deposit) {
|
|
|
27
22
|
}
|
|
28
23
|
dict[originChainId][inputToken].push(deposit);
|
|
29
24
|
}
|
|
30
|
-
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken
|
|
25
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
31
26
|
var _a, _b;
|
|
32
|
-
// We shouldn't pass any unrepayable fills into this function, so we perform an extra safety check.
|
|
33
|
-
assert(chainIsEvm(repaymentChainId) && isEvmRepaymentValid(fill, repaymentChainId), "validatedBundleV3Fills dictionary should only contain fills with valid repayment information");
|
|
34
27
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
35
28
|
assign(dict, [repaymentChainId, repaymentToken], {
|
|
36
29
|
fills: [],
|
|
@@ -39,26 +32,26 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
|
|
|
39
32
|
refunds: {},
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
|
-
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct
|
|
35
|
+
var bundleFill = __assign(__assign({}, fill), { lpFeePct: lpFeePct });
|
|
43
36
|
// Add all fills, slow and fast, to dictionary.
|
|
44
37
|
assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
45
38
|
// All fills update the bundle LP fees.
|
|
46
39
|
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
47
|
-
var realizedLpFee =
|
|
40
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
|
|
48
41
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
49
42
|
// Only fast fills get refunded.
|
|
50
|
-
if (!isSlowFill(
|
|
51
|
-
var refundAmount =
|
|
43
|
+
if (!isSlowFill(fill)) {
|
|
44
|
+
var refundAmount = fill.inputAmount.mul(fixedPointAdjustment.sub(lpFeePct)).div(fixedPointAdjustment);
|
|
52
45
|
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
53
46
|
? refundObj.totalRefundAmount.add(refundAmount)
|
|
54
47
|
: refundAmount;
|
|
55
48
|
// Instantiate dictionary if it doesn't exist.
|
|
56
49
|
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
57
|
-
if (refundObj.refunds[
|
|
58
|
-
refundObj.refunds[
|
|
50
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
51
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
59
52
|
}
|
|
60
53
|
else {
|
|
61
|
-
refundObj.refunds[
|
|
54
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
}
|
|
@@ -72,9 +65,6 @@ function updateBundleExcessSlowFills(dict, deposit) {
|
|
|
72
65
|
}
|
|
73
66
|
function updateBundleSlowFills(dict, deposit) {
|
|
74
67
|
var _a;
|
|
75
|
-
if (chainIsEvm(deposit.destinationChainId) && !isValidEvmAddress(deposit.recipient)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
68
|
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
79
69
|
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
80
70
|
assign(dict, [destinationChainId, outputToken], []);
|
|
@@ -172,7 +162,8 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
172
162
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
173
163
|
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
174
164
|
blockRanges: JSON.stringify(blockRangesForChains),
|
|
175
|
-
bundleData: prettyPrintV3SpokePoolEvents(bundleData.bundleDepositsV3, bundleData.bundleFillsV3,
|
|
165
|
+
bundleData: prettyPrintV3SpokePoolEvents(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], // Invalid fills are not persisted to Arweave.
|
|
166
|
+
bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
|
|
176
167
|
});
|
|
177
168
|
return [2 /*return*/, bundleData];
|
|
178
169
|
}
|
|
@@ -218,124 +209,77 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
218
209
|
return [4 /*yield*/, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
219
210
|
case 1:
|
|
220
211
|
arweaveData = _a.sent();
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// The latest proposed bundle's refund leaves might have already been partially or entirely executed.
|
|
241
|
-
// We have to deduct the executed amounts from the total refund amounts.
|
|
242
|
-
return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
212
|
+
if (arweaveData === undefined) {
|
|
213
|
+
combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
217
|
+
combinedRefunds = getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3);
|
|
218
|
+
// If we don't have a spoke pool client for a chain, then we won't be able to deduct refunds correctly for this
|
|
219
|
+
// chain. For most of the pending bundle's liveness period, these past refunds are already executed so this is
|
|
220
|
+
// a reasonable assumption. This empty refund chain also matches what the alternative
|
|
221
|
+
// `getApproximateRefundsForBlockRange` would return.
|
|
222
|
+
Object.keys(combinedRefunds).forEach(function (chainId) {
|
|
223
|
+
if (_this.spokePoolClients[Number(chainId)] === undefined) {
|
|
224
|
+
delete combinedRefunds[Number(chainId)];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// The latest proposed bundle's refund leaves might have already been partially or entirely executed.
|
|
229
|
+
// We have to deduct the executed amounts from the total refund amounts.
|
|
230
|
+
return [2 /*return*/, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
243
231
|
}
|
|
244
232
|
});
|
|
245
233
|
});
|
|
246
234
|
};
|
|
247
235
|
// @dev This helper function should probably be moved to the InventoryClient
|
|
248
236
|
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
262
|
-
return [2 /*return*/, "continue"];
|
|
263
|
-
}
|
|
264
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
265
|
-
return [4 /*yield*/, filterAsync(this_1.spokePoolClients[chainId].getFills(), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
266
|
-
var matchingDeposit, hasMatchingDeposit, validRepayment;
|
|
267
|
-
return __generator(this, function (_a) {
|
|
268
|
-
switch (_a.label) {
|
|
269
|
-
case 0:
|
|
270
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
271
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
272
|
-
isZeroValueFillOrSlowFillRequest(fill)) {
|
|
273
|
-
return [2 /*return*/, false];
|
|
274
|
-
}
|
|
275
|
-
// If origin spoke pool client isn't defined, we can't validate it.
|
|
276
|
-
if (this.spokePoolClients[fill.originChainId] === undefined) {
|
|
277
|
-
return [2 /*return*/, false];
|
|
278
|
-
}
|
|
279
|
-
matchingDeposit = this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
280
|
-
hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
281
|
-
this.getRelayHashFromEvent(fill) === this.getRelayHashFromEvent(matchingDeposit);
|
|
282
|
-
if (!hasMatchingDeposit) return [3 /*break*/, 2];
|
|
283
|
-
return [4 /*yield*/, verifyFillRepayment(fill, this.spokePoolClients[fill.destinationChainId].spokePool.provider, matchingDeposit,
|
|
284
|
-
// @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
|
|
285
|
-
// disabled block ranges.
|
|
286
|
-
this.clients.configStoreClient
|
|
287
|
-
.getChainIdIndicesForBlock(blockRanges[0][1])
|
|
288
|
-
.filter(function (_chainId, i) { return !isChainDisabled(blockRanges[i]); }))];
|
|
289
|
-
case 1:
|
|
290
|
-
validRepayment = _a.sent();
|
|
291
|
-
if (!isDefined(validRepayment)) {
|
|
292
|
-
return [2 /*return*/, false];
|
|
293
|
-
}
|
|
294
|
-
_a.label = 2;
|
|
295
|
-
case 2: return [2 /*return*/, hasMatchingDeposit];
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}); })];
|
|
299
|
-
case 1:
|
|
300
|
-
fillsToCount = _b.sent();
|
|
301
|
-
fillsToCount.forEach(function (fill) {
|
|
302
|
-
var _a, _b, _c;
|
|
303
|
-
var _d;
|
|
304
|
-
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
305
|
-
assert(isDefined(matchingDeposit), "Deposit not found for fill.");
|
|
306
|
-
var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
|
|
307
|
-
), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
308
|
-
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
|
|
309
|
-
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
|
|
310
|
-
// in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
|
|
311
|
-
// worst from the relayer's perspective.
|
|
312
|
-
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
313
|
-
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
314
|
-
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
315
|
-
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
|
|
316
|
-
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
317
|
-
});
|
|
318
|
-
return [2 /*return*/];
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
};
|
|
322
|
-
this_1 = this;
|
|
323
|
-
_i = 0, chainIds_1 = chainIds;
|
|
324
|
-
_a.label = 1;
|
|
325
|
-
case 1:
|
|
326
|
-
if (!(_i < chainIds_1.length)) return [3 /*break*/, 4];
|
|
327
|
-
chainId = chainIds_1[_i];
|
|
328
|
-
return [5 /*yield**/, _loop_1(chainId)];
|
|
329
|
-
case 2:
|
|
330
|
-
_a.sent();
|
|
331
|
-
_a.label = 3;
|
|
332
|
-
case 3:
|
|
333
|
-
_i++;
|
|
334
|
-
return [3 /*break*/, 1];
|
|
335
|
-
case 4: return [2 /*return*/, refundsForChain];
|
|
237
|
+
var _this = this;
|
|
238
|
+
var refundsForChain = {};
|
|
239
|
+
var _loop_1 = function (chainId) {
|
|
240
|
+
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
241
|
+
return "continue";
|
|
242
|
+
}
|
|
243
|
+
var chainIndex = chainIds.indexOf(chainId);
|
|
244
|
+
this_1.spokePoolClients[chainId]
|
|
245
|
+
.getFills()
|
|
246
|
+
.filter(function (fill) {
|
|
247
|
+
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
248
|
+
return false;
|
|
336
249
|
}
|
|
250
|
+
// If origin spoke pool client isn't defined, we can't validate it.
|
|
251
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
255
|
+
var hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
256
|
+
_this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
|
|
257
|
+
return hasMatchingDeposit;
|
|
258
|
+
})
|
|
259
|
+
.forEach(function (fill) {
|
|
260
|
+
var _a, _b, _c;
|
|
261
|
+
var _d;
|
|
262
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
263
|
+
assert(isDefined(matchingDeposit), "Deposit not found for fill.");
|
|
264
|
+
var _e = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
|
|
265
|
+
), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
266
|
+
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
|
|
267
|
+
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
|
|
268
|
+
// in slight over estimations of refunds, but its not clear whether underestimating or overestimating is
|
|
269
|
+
// worst from the relayer's perspective.
|
|
270
|
+
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
271
|
+
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
272
|
+
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
273
|
+
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : bnZero;
|
|
274
|
+
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
337
275
|
});
|
|
338
|
-
}
|
|
276
|
+
};
|
|
277
|
+
var this_1 = this;
|
|
278
|
+
for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
|
|
279
|
+
var chainId = chainIds_1[_i];
|
|
280
|
+
_loop_1(chainId);
|
|
281
|
+
}
|
|
282
|
+
return refundsForChain;
|
|
339
283
|
};
|
|
340
284
|
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
341
285
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
@@ -380,10 +324,12 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
380
324
|
case 1:
|
|
381
325
|
_a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
|
|
382
326
|
hubPoolClient = this.clients.hubPoolClient;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
327
|
+
return [4 /*yield*/, _buildPoolRebalanceRoot(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
|
|
328
|
+
hubPoolClient: hubPoolClient,
|
|
329
|
+
configStoreClient: hubPoolClient.configStoreClient,
|
|
330
|
+
})];
|
|
331
|
+
case 2:
|
|
332
|
+
root = _b.sent();
|
|
387
333
|
return [2 /*return*/, {
|
|
388
334
|
root: root,
|
|
389
335
|
blockRanges: blockRanges,
|
|
@@ -425,40 +371,33 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
425
371
|
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
426
372
|
});
|
|
427
373
|
}
|
|
428
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData,
|
|
429
|
-
return __generator(this, function (
|
|
430
|
-
switch (
|
|
374
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
375
|
+
return __generator(this, function (_a) {
|
|
376
|
+
switch (_a.label) {
|
|
431
377
|
case 0:
|
|
432
378
|
hubPoolClient = this.clients.hubPoolClient;
|
|
433
379
|
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
434
380
|
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
435
381
|
combinedRefunds = [];
|
|
436
382
|
widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(chainIds, this.spokePoolClients, getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestBlockSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched));
|
|
437
|
-
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/,
|
|
383
|
+
if (!hubPoolClient.hasPendingProposal()) return [3 /*break*/, 2];
|
|
438
384
|
pendingBundleBlockRanges = getImpliedBundleBlockRanges(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
439
385
|
return [4 /*yield*/, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
440
386
|
case 1:
|
|
441
|
-
arweaveData =
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
450
|
-
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
451
|
-
_e.label = 4;
|
|
452
|
-
case 4:
|
|
387
|
+
arweaveData = _a.sent();
|
|
388
|
+
if (arweaveData === undefined) {
|
|
389
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
393
|
+
combinedRefunds.push(getRefundsFromBundle(bundleFillsV3, expiredDepositsToRefundV3));
|
|
394
|
+
}
|
|
453
395
|
// Shorten the widestBundleBlockRanges now to not double count the pending bundle blocks.
|
|
454
396
|
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
455
|
-
|
|
456
|
-
case
|
|
397
|
+
_a.label = 2;
|
|
398
|
+
case 2:
|
|
457
399
|
start = performance.now();
|
|
458
|
-
|
|
459
|
-
return [4 /*yield*/, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
460
|
-
case 6:
|
|
461
|
-
_d.apply(_c, [_e.sent()]);
|
|
400
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
462
401
|
this.logger.debug({
|
|
463
402
|
at: "BundleDataClient#getNextBundleRefunds",
|
|
464
403
|
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -601,7 +540,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
601
540
|
};
|
|
602
541
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
603
542
|
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
-
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3,
|
|
543
|
+
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, depositCounter, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
|
|
605
544
|
var _this = this;
|
|
606
545
|
return __generator(this, function (_c) {
|
|
607
546
|
switch (_c.label) {
|
|
@@ -621,8 +560,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
621
560
|
bundleDepositsV3 = {};
|
|
622
561
|
bundleFillsV3 = {};
|
|
623
562
|
bundleInvalidFillsV3 = [];
|
|
624
|
-
bundleUnrepayableFillsV3 = [];
|
|
625
|
-
bundleInvalidSlowFillRequests = [];
|
|
626
563
|
bundleSlowFillsV3 = {};
|
|
627
564
|
expiredDepositsToRefundV3 = {};
|
|
628
565
|
unexecutableSlowFills = {};
|
|
@@ -680,13 +617,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
680
617
|
v3RelayHashes = {};
|
|
681
618
|
bundleDepositHashes = [];
|
|
682
619
|
olderDepositHashes = [];
|
|
683
|
-
|
|
684
|
-
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
685
|
-
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
686
|
-
};
|
|
687
|
-
startBlockForMainnet = getBlockRangeForChain(blockRangesForChains, this.clients.hubPoolClient.chainId, this.chainIdListForBundleEvaluationBlockNumbers)[0];
|
|
688
|
-
versionAtProposalBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(startBlockForMainnet);
|
|
689
|
-
canRefundPrefills = versionAtProposalBlock >= PRE_FILL_MIN_CONFIG_STORE_VERSION || process.env.FORCE_REFUND_PREFILLS === "true";
|
|
620
|
+
depositCounter = 0;
|
|
690
621
|
_loop_2 = function (originChainId) {
|
|
691
622
|
var originClient = spokePoolClients[originChainId];
|
|
692
623
|
var originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
@@ -696,45 +627,48 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
696
627
|
continue;
|
|
697
628
|
}
|
|
698
629
|
originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
|
|
630
|
+
// Only evaluate deposits that are in this bundle or in previous bundles. This means we cannot issue fill
|
|
631
|
+
// refunds or slow fills here for deposits that are in future bundles (i.e. "pre-fills"). Instead, we'll
|
|
632
|
+
// evaluate these pre-fills once the deposit is inside the "current" bundle block range.
|
|
699
633
|
if (deposit.blockNumber > originChainBlockRange[1] || isZeroValueDeposit(deposit)) {
|
|
700
634
|
return;
|
|
701
635
|
}
|
|
636
|
+
depositCounter++;
|
|
702
637
|
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
638
|
+
// Duplicate deposits are treated like normal deposits.
|
|
703
639
|
if (!v3RelayHashes[relayDataHash]) {
|
|
704
640
|
v3RelayHashes[relayDataHash] = {
|
|
705
|
-
|
|
641
|
+
deposit: deposit,
|
|
706
642
|
fill: undefined,
|
|
707
643
|
slowFillRequest: undefined,
|
|
708
644
|
};
|
|
709
645
|
}
|
|
710
|
-
|
|
711
|
-
|
|
646
|
+
// Once we've saved the deposit hash into v3RelayHashes, then we can exit early here if the inputAmount
|
|
647
|
+
// is 0 because there can be no expired amount to refund and no unexecutable slow fill amount to return
|
|
648
|
+
// if this deposit did expire. Input amount can only be zero at this point if the message is non-empty,
|
|
649
|
+
// but the message doesn't matter for expired deposits and unexecutable slow fills.
|
|
650
|
+
if (deposit.inputAmount.eq(0)) {
|
|
651
|
+
return;
|
|
712
652
|
}
|
|
713
|
-
//
|
|
714
|
-
// we
|
|
715
|
-
var newBundleDepositHash = "".concat(relayDataHash, "@").concat(v3RelayHashes[relayDataHash].deposits.length - 1);
|
|
716
|
-
var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
|
|
717
|
-
assert(decodedBundleDepositHash.relayDataHash === relayDataHash &&
|
|
718
|
-
decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key");
|
|
653
|
+
// Evaluate all expired deposits after fetching fill statuses,
|
|
654
|
+
// since we can't know for certain whether an expired deposit was filled a long time ago.
|
|
719
655
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
720
|
-
bundleDepositHashes.push(
|
|
656
|
+
bundleDepositHashes.push(relayDataHash);
|
|
721
657
|
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
722
658
|
}
|
|
723
659
|
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
724
|
-
olderDepositHashes.push(
|
|
660
|
+
olderDepositHashes.push(relayDataHash);
|
|
725
661
|
}
|
|
726
662
|
});
|
|
727
663
|
}
|
|
728
664
|
};
|
|
729
|
-
// Prerequisite step: Load all deposit events from the current or older bundles into the v3RelayHashes dictionary
|
|
730
|
-
// for convenient matching with fills.
|
|
731
665
|
for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
|
|
732
666
|
originChainId = allChainIds_1[_i];
|
|
733
667
|
_loop_2(originChainId);
|
|
734
668
|
}
|
|
735
669
|
this.logger.debug({
|
|
736
670
|
at: "BundleDataClient#loadData",
|
|
737
|
-
message: "Processed ".concat(
|
|
671
|
+
message: "Processed ".concat(depositCounter, " deposits in ").concat(performance.now() - start, "ms."),
|
|
738
672
|
});
|
|
739
673
|
start = performance.now();
|
|
740
674
|
validatedBundleV3Fills = [];
|
|
@@ -748,7 +682,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
748
682
|
case 0:
|
|
749
683
|
originClient = spokePoolClients[originChainId];
|
|
750
684
|
_loop_4 = function (destinationChainId) {
|
|
751
|
-
var destinationClient, destinationChainBlockRange,
|
|
685
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
752
686
|
return __generator(this, function (_g) {
|
|
753
687
|
switch (_g.label) {
|
|
754
688
|
case 0:
|
|
@@ -757,7 +691,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
757
691
|
}
|
|
758
692
|
destinationClient = spokePoolClients[destinationChainId];
|
|
759
693
|
destinationChainBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
760
|
-
originChainBlockRange = getBlockRangeForChain(blockRangesForChains, originChainId, chainIds);
|
|
761
694
|
fastFillsReplacingSlowFills = [];
|
|
762
695
|
return [4 /*yield*/, forEachAsync(destinationClient
|
|
763
696
|
.getFillsForOriginChain(originChainId)
|
|
@@ -765,58 +698,40 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
765
698
|
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
|
|
766
699
|
// request for the deposit, we'd want to see the fill took place.
|
|
767
700
|
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill); }), function (fill) { return __awaiter(_this, void 0, void 0, function () {
|
|
768
|
-
var relayDataHash,
|
|
701
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
769
702
|
return __generator(this, function (_a) {
|
|
770
703
|
switch (_a.label) {
|
|
771
704
|
case 0:
|
|
772
|
-
fillCounter++;
|
|
773
705
|
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
duplicateDeposits.forEach(function (duplicateDeposit) {
|
|
792
|
-
if (isSlowFill(fill)) {
|
|
793
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
|
|
706
|
+
fillCounter++;
|
|
707
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
708
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
709
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
710
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
711
|
+
// so this fill is validated.
|
|
712
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
713
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
714
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
715
|
+
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
716
|
+
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
717
|
+
// events.
|
|
718
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
719
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
720
|
+
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposit)) {
|
|
721
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
722
|
+
}
|
|
797
723
|
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
// If fill replaced a slow fill request, then mark it as one that might have created an
|
|
801
|
-
// unexecutable slow fill. We can't know for sure until we check the slow fill request
|
|
802
|
-
// events.
|
|
803
|
-
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
804
|
-
_canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0])) {
|
|
805
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
724
|
+
}
|
|
725
|
+
return [2 /*return*/];
|
|
806
726
|
}
|
|
807
|
-
_a.label = 2;
|
|
808
|
-
case 2: return [3 /*break*/, 4];
|
|
809
|
-
case 3: throw new Error("Duplicate fill detected");
|
|
810
|
-
case 4: return [2 /*return*/];
|
|
811
|
-
case 5:
|
|
812
727
|
// At this point, there is no relay hash dictionary entry for this fill, so we need to
|
|
813
|
-
// instantiate the entry.
|
|
728
|
+
// instantiate the entry.
|
|
814
729
|
v3RelayHashes[relayDataHash] = {
|
|
815
|
-
|
|
730
|
+
deposit: undefined,
|
|
816
731
|
fill: fill,
|
|
817
732
|
slowFillRequest: undefined,
|
|
818
733
|
};
|
|
819
|
-
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/,
|
|
734
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3 /*break*/, 2];
|
|
820
735
|
// Fill has a non-infinite expiry, and we can assume our spoke pool clients have old enough deposits
|
|
821
736
|
// to conclude that this fill is invalid if we haven't found a matching deposit in memory, so
|
|
822
737
|
// skip the historical query.
|
|
@@ -825,57 +740,35 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
825
740
|
return [2 /*return*/];
|
|
826
741
|
}
|
|
827
742
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, fill)];
|
|
828
|
-
case
|
|
743
|
+
case 1:
|
|
829
744
|
historicalDeposit = _a.sent();
|
|
830
|
-
if (
|
|
831
|
-
bundleInvalidFillsV3.push(fill);
|
|
832
|
-
return [3 /*break*/, 9];
|
|
833
|
-
case 7:
|
|
834
|
-
matchedDeposit = historicalDeposit.deposit;
|
|
835
|
-
// If deposit is in a following bundle, then this fill will have to be refunded once that deposit
|
|
836
|
-
// is in the current bundle.
|
|
837
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
745
|
+
if (!historicalDeposit.found) {
|
|
838
746
|
bundleInvalidFillsV3.push(fill);
|
|
839
|
-
return [2 /*return*/];
|
|
840
|
-
}
|
|
841
|
-
v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
|
|
842
|
-
return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, matchedDeposit, allChainIds)];
|
|
843
|
-
case 8:
|
|
844
|
-
fillToRefund = _a.sent();
|
|
845
|
-
if (!isDefined(fillToRefund)) {
|
|
846
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
847
|
-
// Don't return yet as we still need to mark down any unexecutable slow fill leaves
|
|
848
|
-
// in case this fast fill replaced a slow fill request.
|
|
849
747
|
}
|
|
850
748
|
else {
|
|
749
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
851
750
|
// @dev Since queryHistoricalDepositForFill validates the fill by checking individual
|
|
852
751
|
// object property values against the deposit's, we
|
|
853
752
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
854
753
|
// historical deposit query is not working as expected.
|
|
855
754
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
856
|
-
validatedBundleV3Fills.push(__assign(__assign({},
|
|
857
|
-
v3RelayHashes[relayDataHash].
|
|
858
|
-
//
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
755
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
756
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
757
|
+
// slow fill requests for deposits from or to lite chains are considered invalid
|
|
758
|
+
if (fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
|
|
759
|
+
_canCreateSlowFillLeaf(matchedDeposit)) {
|
|
760
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
761
|
+
}
|
|
864
762
|
}
|
|
865
|
-
_a.label =
|
|
866
|
-
case
|
|
763
|
+
_a.label = 2;
|
|
764
|
+
case 2: return [2 /*return*/];
|
|
867
765
|
}
|
|
868
766
|
});
|
|
869
767
|
}); })];
|
|
870
768
|
case 1:
|
|
871
769
|
_g.sent();
|
|
872
|
-
// Process slow fill requests
|
|
873
|
-
//
|
|
874
|
-
// - Slow fill leaves cannot be produced for deposits that have been filled.
|
|
875
|
-
// Assumptions about fills:
|
|
876
|
-
// - Duplicate slow fill requests for the same relay data hash are impossible to send.
|
|
877
|
-
// - Slow fill requests can only be sent before the deposit's fillDeadline.
|
|
878
|
-
// - Slow fill requests for a deposit that has been filled.
|
|
770
|
+
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
771
|
+
// for deposits that would expire in this bundle.
|
|
879
772
|
return [4 /*yield*/, forEachAsync(destinationClient
|
|
880
773
|
.getSlowFillRequestsForOriginChain(originChainId)
|
|
881
774
|
.filter(function (request) {
|
|
@@ -888,58 +781,55 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
888
781
|
relayDataHash = this.getRelayHashFromEvent(slowFillRequest);
|
|
889
782
|
if (v3RelayHashes[relayDataHash]) {
|
|
890
783
|
if (!v3RelayHashes[relayDataHash].slowFillRequest) {
|
|
784
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is either a matching
|
|
785
|
+
// fill or deposit.
|
|
891
786
|
v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
|
|
892
787
|
if (v3RelayHashes[relayDataHash].fill) {
|
|
893
|
-
//
|
|
894
|
-
//
|
|
895
|
-
// for a fill older than this slow fill request.
|
|
788
|
+
// If there is a fill matching the relay hash, then this slow fill request can't be used
|
|
789
|
+
// to create a slow fill for a filled deposit.
|
|
896
790
|
return [2 /*return*/];
|
|
897
791
|
}
|
|
898
|
-
assert(isDefined(v3RelayHashes[relayDataHash].
|
|
899
|
-
matchedDeposit = v3RelayHashes[relayDataHash].
|
|
792
|
+
assert(isDefined(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
793
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
794
|
+
// If there is no fill matching the relay hash, then this might be a valid slow fill request
|
|
795
|
+
// that we should produce a slow fill leaf for. Check if the slow fill request is in the
|
|
796
|
+
// destination chain block range.
|
|
900
797
|
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
901
798
|
_canCreateSlowFillLeaf(matchedDeposit) &&
|
|
799
|
+
// Deposit must not have expired in this bundle.
|
|
902
800
|
!_depositIsExpired(matchedDeposit)) {
|
|
801
|
+
// At this point, the v3RelayHashes entry already existed meaning that there is a matching deposit,
|
|
802
|
+
// so this slow fill request relay data is correct.
|
|
903
803
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
904
804
|
}
|
|
905
805
|
}
|
|
906
|
-
else {
|
|
907
|
-
throw new Error("Duplicate slow fill request detected.");
|
|
908
|
-
}
|
|
909
806
|
return [2 /*return*/];
|
|
910
807
|
}
|
|
911
808
|
// Instantiate dictionary if there is neither a deposit nor fill matching it.
|
|
912
809
|
v3RelayHashes[relayDataHash] = {
|
|
913
|
-
|
|
810
|
+
deposit: undefined,
|
|
914
811
|
fill: undefined,
|
|
915
812
|
slowFillRequest: slowFillRequest,
|
|
916
813
|
};
|
|
917
|
-
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0]
|
|
918
|
-
|
|
919
|
-
bundleInvalidSlowFillRequests.push(slowFillRequest);
|
|
920
|
-
return [2 /*return*/];
|
|
921
|
-
}
|
|
814
|
+
if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
815
|
+
INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline))) return [3 /*break*/, 2];
|
|
922
816
|
return [4 /*yield*/, queryHistoricalDepositForFill(originClient, slowFillRequest)];
|
|
923
817
|
case 1:
|
|
924
818
|
historicalDeposit = _a.sent();
|
|
925
819
|
if (!historicalDeposit.found) {
|
|
926
|
-
|
|
820
|
+
// TODO: Invalid slow fill request. Maybe worth logging.
|
|
927
821
|
return [2 /*return*/];
|
|
928
822
|
}
|
|
929
823
|
matchedDeposit = historicalDeposit.deposit;
|
|
930
|
-
// If deposit is in a following bundle, then this slow fill request will have to be created
|
|
931
|
-
// once that deposit is in the current bundle.
|
|
932
|
-
if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
|
|
933
|
-
bundleInvalidSlowFillRequests.push(slowFillRequest);
|
|
934
|
-
return [2 /*return*/];
|
|
935
|
-
}
|
|
936
824
|
// @dev Since queryHistoricalDepositForFill validates the slow fill request by checking individual
|
|
937
825
|
// object property values against the deposit's, we
|
|
938
826
|
// sanity check it here by comparing the full relay hashes. If there's an error here then the
|
|
939
827
|
// historical deposit query is not working as expected.
|
|
940
828
|
assert(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
941
|
-
v3RelayHashes[relayDataHash].
|
|
942
|
-
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
829
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
830
|
+
if (!_canCreateSlowFillLeaf(matchedDeposit) ||
|
|
831
|
+
// Deposit must not have expired in this bundle.
|
|
832
|
+
_depositIsExpired(matchedDeposit)) {
|
|
943
833
|
return [2 /*return*/];
|
|
944
834
|
}
|
|
945
835
|
validatedBundleSlowFills.push(matchedDeposit);
|
|
@@ -949,167 +839,116 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
949
839
|
});
|
|
950
840
|
}); })];
|
|
951
841
|
case 2:
|
|
952
|
-
// Process slow fill requests
|
|
953
|
-
//
|
|
954
|
-
// - Slow fill leaves cannot be produced for deposits that have been filled.
|
|
955
|
-
// Assumptions about fills:
|
|
956
|
-
// - Duplicate slow fill requests for the same relay data hash are impossible to send.
|
|
957
|
-
// - Slow fill requests can only be sent before the deposit's fillDeadline.
|
|
958
|
-
// - Slow fill requests for a deposit that has been filled.
|
|
842
|
+
// Process slow fill requests. One invariant we need to maintain is that we cannot create slow fill requests
|
|
843
|
+
// for deposits that would expire in this bundle.
|
|
959
844
|
_g.sent();
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
//
|
|
963
|
-
// -
|
|
964
|
-
//
|
|
965
|
-
// -
|
|
966
|
-
//
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// - If the deposit has a matching fill or slow fill request in the bundle then we have already stored
|
|
975
|
-
// it in the relay hashes dictionary.
|
|
976
|
-
// - We've created refunds for all fills in this bundle matching a deposit.
|
|
977
|
-
// - We've created slow fill leaves for all slow fill requests in this bundle matching an unfilled deposit.
|
|
978
|
-
// - Deposits for the same relay data hash can be sent an arbitrary amount of times.
|
|
979
|
-
// - Deposits can be sent an arbitrary amount of time after a fill has been sent for the matching relay data.
|
|
980
|
-
return [4 /*yield*/, mapAsync(bundleDepositHashes, function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
981
|
-
var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, fillToRefund, fillStatus, prefill, verifiedFill;
|
|
982
|
-
var _this = this;
|
|
983
|
-
return __generator(this, function (_c) {
|
|
984
|
-
switch (_c.label) {
|
|
845
|
+
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
846
|
+
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
847
|
+
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
848
|
+
// this "pre-fill" if the fill took place in a previous bundle.
|
|
849
|
+
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
850
|
+
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
851
|
+
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
852
|
+
return [4 /*yield*/, mapAsync(bundleDepositHashes.filter(function (depositHash) {
|
|
853
|
+
var deposit = v3RelayHashes[depositHash].deposit;
|
|
854
|
+
return (deposit && deposit.originChainId === originChainId && deposit.destinationChainId === destinationChainId);
|
|
855
|
+
}), function (depositHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
856
|
+
var _a, deposit, fill, slowFillRequest, fillStatus, prefill;
|
|
857
|
+
return __generator(this, function (_b) {
|
|
858
|
+
switch (_b.label) {
|
|
985
859
|
case 0:
|
|
986
|
-
_a =
|
|
987
|
-
_b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
|
|
988
|
-
if (!deposits || deposits.length === 0) {
|
|
989
|
-
throw new Error("Deposits should exist in relay hash dictionary.");
|
|
990
|
-
}
|
|
991
|
-
deposit = deposits[index];
|
|
860
|
+
_a = v3RelayHashes[depositHash], deposit = _a.deposit, fill = _a.fill, slowFillRequest = _a.slowFillRequest;
|
|
992
861
|
if (!deposit)
|
|
993
862
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
994
|
-
|
|
863
|
+
// We are willing to refund a pre-fill multiple times for each duplicate deposit.
|
|
864
|
+
// This is because a duplicate deposit for a pre-fill cannot get
|
|
865
|
+
// refunded to the depositor anymore because its fill status on-chain has changed to Filled. Therefore
|
|
866
|
+
// any duplicate deposits result in a net loss of funds for the depositor and effectively pay out
|
|
867
|
+
// the pre-filler.
|
|
868
|
+
// If fill exists in memory, then the only case in which we need to create a refund is if the
|
|
869
|
+
// the fill occurred in a previous bundle. There are no expiry refunds for filled deposits.
|
|
870
|
+
if (fill) {
|
|
871
|
+
if (fill.blockNumber < destinationChainBlockRange[0] && !isSlowFill(fill)) {
|
|
872
|
+
// If fill is in the current bundle then we can assume there is already a refund for it, so only
|
|
873
|
+
// include this pre fill if the fill is in an older bundle. If fill is after this current bundle, then
|
|
874
|
+
// we won't consider it, following the previous treatment of fills after the bundle block range.
|
|
875
|
+
validatedBundleV3Fills.push(__assign(__assign({}, fill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
876
|
+
}
|
|
995
877
|
return [2 /*return*/];
|
|
996
878
|
}
|
|
997
|
-
if (!fill) return [3 /*break*/, 3];
|
|
998
|
-
if (!(canRefundPrefills && fill.blockNumber < destinationChainBlockRange[0])) return [3 /*break*/, 2];
|
|
999
|
-
return [4 /*yield*/, verifyFillRepayment(fill, destinationClient.spokePool.provider, v3RelayHashes[relayDataHash].deposits[0], allChainIds)];
|
|
1000
|
-
case 1:
|
|
1001
|
-
fillToRefund = _c.sent();
|
|
1002
|
-
if (!isDefined(fillToRefund)) {
|
|
1003
|
-
bundleUnrepayableFillsV3.push(fill);
|
|
1004
|
-
}
|
|
1005
|
-
else if (!isSlowFill(fill)) {
|
|
1006
|
-
v3RelayHashes[relayDataHash].fill = fillToRefund;
|
|
1007
|
-
validatedBundleV3Fills.push(__assign(__assign({}, fillToRefund), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1008
|
-
}
|
|
1009
|
-
else {
|
|
1010
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1011
|
-
}
|
|
1012
|
-
_c.label = 2;
|
|
1013
|
-
case 2: return [2 /*return*/];
|
|
1014
|
-
case 3:
|
|
1015
879
|
// If a slow fill request exists in memory, then we know the deposit has not been filled because fills
|
|
1016
|
-
// must follow slow fill requests and we would have seen the fill already if it existed
|
|
1017
|
-
//
|
|
1018
|
-
//
|
|
1019
|
-
// in
|
|
880
|
+
// must follow slow fill requests and we would have seen the fill already if it existed. Therefore,
|
|
881
|
+
// we can conclude that either the deposit has expired and we need to create a deposit expiry refund, or
|
|
882
|
+
// we need to create a slow fill leaf for the deposit. The latter should only happen if the slow fill request
|
|
883
|
+
// took place in a prior bundle otherwise we would have already created a slow fill leaf for it.
|
|
1020
884
|
if (slowFillRequest) {
|
|
1021
885
|
if (_depositIsExpired(deposit)) {
|
|
1022
886
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1023
887
|
}
|
|
1024
|
-
else if (
|
|
1025
|
-
|
|
1026
|
-
_canCreateSlowFillLeaf(deposit) &&
|
|
1027
|
-
validatedBundleSlowFills.every(function (d) { return _this.getRelayHashFromEvent(d) !== relayDataHash; })) {
|
|
888
|
+
else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
|
|
889
|
+
_canCreateSlowFillLeaf(deposit)) {
|
|
1028
890
|
validatedBundleSlowFills.push(deposit);
|
|
1029
891
|
}
|
|
1030
892
|
return [2 /*return*/];
|
|
1031
893
|
}
|
|
1032
894
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
|
|
1033
|
-
case
|
|
1034
|
-
fillStatus =
|
|
1035
|
-
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/,
|
|
1036
|
-
return [4 /*yield*/,
|
|
1037
|
-
case
|
|
1038
|
-
prefill =
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (!canRefundPrefills) return [3 /*break*/, 7];
|
|
1042
|
-
return [4 /*yield*/, verifyFillRepayment(prefill, destinationClient.spokePool.provider, deposit, allChainIds)];
|
|
1043
|
-
case 6:
|
|
1044
|
-
verifiedFill = _c.sent();
|
|
1045
|
-
if (!isDefined(verifiedFill)) {
|
|
1046
|
-
bundleUnrepayableFillsV3.push(prefill);
|
|
1047
|
-
}
|
|
1048
|
-
else if (!isSlowFill(verifiedFill)) {
|
|
1049
|
-
validatedBundleV3Fills.push(__assign(__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
895
|
+
case 1:
|
|
896
|
+
fillStatus = _b.sent();
|
|
897
|
+
if (!(fillStatus === FillStatus.Filled)) return [3 /*break*/, 3];
|
|
898
|
+
return [4 /*yield*/, findFillEvent(destinationClient.spokePool, deposit, destinationClient.deploymentBlock, destinationClient.latestBlockSearched)];
|
|
899
|
+
case 2:
|
|
900
|
+
prefill = (_b.sent());
|
|
901
|
+
if (!isSlowFill(prefill)) {
|
|
902
|
+
validatedBundleV3Fills.push(__assign(__assign({}, prefill), { quoteTimestamp: deposit.quoteTimestamp }));
|
|
1053
903
|
}
|
|
1054
|
-
|
|
1055
|
-
case
|
|
1056
|
-
case 8:
|
|
904
|
+
return [3 /*break*/, 4];
|
|
905
|
+
case 3:
|
|
1057
906
|
if (_depositIsExpired(deposit)) {
|
|
1058
907
|
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
1059
908
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
909
|
+
// If slow fill requested, then issue a slow fill leaf for the deposit.
|
|
910
|
+
else if (fillStatus === FillStatus.RequestedSlowFill) {
|
|
911
|
+
// Input and Output tokens must be equivalent on the deposit for this to be slow filled.
|
|
912
|
+
// Slow fill requests for deposits from or to lite chains are considered invalid
|
|
913
|
+
if (_canCreateSlowFillLeaf(deposit)) {
|
|
914
|
+
// If deposit newly expired, then we can't create a slow fill leaf for it but we can
|
|
915
|
+
// create a deposit refund for it.
|
|
1064
916
|
validatedBundleSlowFills.push(deposit);
|
|
1065
917
|
}
|
|
1066
918
|
}
|
|
1067
|
-
|
|
1068
|
-
case
|
|
919
|
+
_b.label = 4;
|
|
920
|
+
case 4: return [2 /*return*/];
|
|
1069
921
|
}
|
|
1070
922
|
});
|
|
1071
923
|
}); })];
|
|
1072
924
|
case 3:
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
//
|
|
1076
|
-
// -
|
|
1077
|
-
//
|
|
1078
|
-
// -
|
|
1079
|
-
//
|
|
1080
|
-
// - An expired deposit cannot be refunded if the deposit was filled.
|
|
1081
|
-
// - If a deposit from a prior bundle expired in this bundle, had a slow fill request created for it
|
|
1082
|
-
// in a prior bundle, and has not been filled yet, then an unexecutable slow fill leaf has been created
|
|
1083
|
-
// and needs to be refunded to the HubPool.
|
|
1084
|
-
// - Deposits matching slow fill requests from previous bundle block ranges should produce slow fills
|
|
1085
|
-
// if the deposit has not been filled.
|
|
1086
|
-
// Assumptions:
|
|
1087
|
-
// - If the deposit has a matching fill or slow fill request in the bundle then we have already stored
|
|
1088
|
-
// it in the relay hashes dictionary.
|
|
1089
|
-
// - We've created refunds for all fills in this bundle matching a deposit.
|
|
1090
|
-
// - We've created slow fill leaves for all slow fill requests in this bundle matching an unfilled deposit.
|
|
1091
|
-
// - Deposits for the same relay data hash can be sent an arbitrary amount of times.
|
|
1092
|
-
// - Deposits can be sent an arbitrary amount of time after a fill has been sent for the matching relay data.
|
|
925
|
+
// Deposits can be submitted an arbitrary amount of time after matching fills and slow fill requests.
|
|
926
|
+
// Therefore, let's go through each deposit in this bundle again and check a few things in order:
|
|
927
|
+
// - Has the deposit been filled ? If so, then we need to issue a relayer refund for
|
|
928
|
+
// this "pre-fill" if the fill took place in a previous bundle.
|
|
929
|
+
// - Or, has the deposit expired in this bundle? If so, then we need to issue an expiry refund.
|
|
930
|
+
// - And finally, has the deposit been slow filled? If so, then we need to issue a slow fill leaf
|
|
931
|
+
// for this "pre-slow-fill-request" if this request took place in a previous bundle.
|
|
1093
932
|
_g.sent();
|
|
1094
933
|
// For all fills that came after a slow fill request, we can now check if the slow fill request
|
|
1095
934
|
// was a valid one and whether it was created in a previous bundle. If so, then it created a slow fill
|
|
1096
935
|
// leaf that is now unexecutable.
|
|
1097
936
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
1098
|
-
var _a = v3RelayHashes[relayDataHash],
|
|
937
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1099
938
|
assert((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
1100
939
|
// Needed for TSC - are implicitely checking that deposit exists by making it to this point.
|
|
1101
|
-
if (!
|
|
940
|
+
if (!deposit) {
|
|
1102
941
|
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1103
942
|
}
|
|
1104
943
|
// We should never push fast fills involving lite chains here because slow fill requests for them are invalid:
|
|
1105
|
-
assert(_canCreateSlowFillLeaf(
|
|
944
|
+
assert(_canCreateSlowFillLeaf(deposit), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
|
|
1106
945
|
var destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1107
946
|
if (
|
|
1108
947
|
// If there is a slow fill request in this bundle that matches the relay hash, then there was no slow fill
|
|
1109
948
|
// created that would be considered excess.
|
|
1110
949
|
!slowFillRequest ||
|
|
1111
950
|
slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1112
|
-
validatedBundleUnexecutableSlowFills.push(
|
|
951
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1113
952
|
}
|
|
1114
953
|
});
|
|
1115
954
|
return [2 /*return*/];
|
|
@@ -1153,17 +992,13 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1153
992
|
// For all deposits older than this bundle, we need to check if they expired in this bundle and if they did,
|
|
1154
993
|
// whether there was a slow fill created for it in a previous bundle that is now unexecutable and replaced
|
|
1155
994
|
// by a new expired deposit refund.
|
|
1156
|
-
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (
|
|
1157
|
-
var _a,
|
|
1158
|
-
return __generator(this, function (
|
|
1159
|
-
switch (
|
|
995
|
+
return [4 /*yield*/, forEachAsync(olderDepositHashes, function (relayDataHash) { return __awaiter(_this, void 0, void 0, function () {
|
|
996
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
997
|
+
return __generator(this, function (_b) {
|
|
998
|
+
switch (_b.label) {
|
|
1160
999
|
case 0:
|
|
1161
|
-
_a =
|
|
1162
|
-
|
|
1163
|
-
if (!deposits || deposits.length < 1) {
|
|
1164
|
-
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
1165
|
-
}
|
|
1166
|
-
deposit = deposits[index];
|
|
1000
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
1001
|
+
assert(isDefined(deposit), "Deposit should exist in relay hash dictionary.");
|
|
1167
1002
|
destinationChainId = deposit.destinationChainId;
|
|
1168
1003
|
destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);
|
|
1169
1004
|
if (!
|
|
@@ -1177,7 +1012,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1177
1012
|
return [3 /*break*/, 2];
|
|
1178
1013
|
return [4 /*yield*/, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
|
|
1179
1014
|
case 1:
|
|
1180
|
-
fillStatus =
|
|
1015
|
+
fillStatus = _b.sent();
|
|
1181
1016
|
// If there is no matching fill and the deposit expired in this bundle and the fill status on-chain is not
|
|
1182
1017
|
// Filled, then we can to refund it as an expired deposit.
|
|
1183
1018
|
if (fillStatus !== FillStatus.Filled) {
|
|
@@ -1199,7 +1034,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1199
1034
|
if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
|
|
1200
1035
|
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
1201
1036
|
}
|
|
1202
|
-
|
|
1037
|
+
_b.label = 2;
|
|
1203
1038
|
case 2: return [2 /*return*/];
|
|
1204
1039
|
}
|
|
1205
1040
|
});
|
|
@@ -1214,7 +1049,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1214
1049
|
promises = [
|
|
1215
1050
|
validatedBundleV3Fills.length > 0
|
|
1216
1051
|
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
1217
|
-
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1052
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1218
1053
|
assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1219
1054
|
var paymentChainId = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
1220
1055
|
return __assign(__assign({}, fill), { paymentChainId: paymentChainId });
|
|
@@ -1241,23 +1076,14 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1241
1076
|
v3FillLpFees.forEach(function (_a, idx) {
|
|
1242
1077
|
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
1243
1078
|
var fill = validatedBundleV3Fills[idx];
|
|
1244
|
-
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].
|
|
1079
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
1245
1080
|
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
1246
1081
|
var _b = getRefundInformationFromFill(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
1247
|
-
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken
|
|
1082
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
1248
1083
|
});
|
|
1249
1084
|
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
1250
1085
|
var lpFeePct = _a.realizedLpFeePct;
|
|
1251
1086
|
var deposit = validatedBundleSlowFills[idx];
|
|
1252
|
-
// We should not create slow fill leaves for duplicate deposit hashes and we should only create a slow
|
|
1253
|
-
// fill leaf for the first deposit (the quote timestamp of the deposit determines the LP fee, so its
|
|
1254
|
-
// important we pick out the correct deposit). Deposits are pushed into validatedBundleSlowFills in ascending
|
|
1255
|
-
// order so the following slice will only match the first deposit.
|
|
1256
|
-
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
1257
|
-
if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return _this.getRelayHashFromEvent(d) === relayDataHash; })) {
|
|
1258
|
-
return;
|
|
1259
|
-
}
|
|
1260
|
-
assert(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
|
|
1261
1087
|
updateBundleSlowFills(bundleSlowFillsV3, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1262
1088
|
});
|
|
1263
1089
|
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
@@ -1265,31 +1091,15 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1265
1091
|
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
1266
1092
|
updateBundleExcessSlowFills(unexecutableSlowFills, __assign(__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
1267
1093
|
});
|
|
1268
|
-
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1094
|
+
v3SpokeEventsReadable = prettyPrintV3SpokePoolEvents(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
1269
1095
|
if (bundleInvalidFillsV3.length > 0) {
|
|
1270
1096
|
this.logger.debug({
|
|
1271
1097
|
at: "BundleDataClient#loadData",
|
|
1272
|
-
message: "Finished loading V3 spoke pool data and found some invalid fills in range",
|
|
1098
|
+
message: "Finished loading V3 spoke pool data and found some invalid V3 fills in range",
|
|
1273
1099
|
blockRangesForChains: blockRangesForChains,
|
|
1274
1100
|
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
1275
1101
|
});
|
|
1276
1102
|
}
|
|
1277
|
-
if (bundleUnrepayableFillsV3.length > 0) {
|
|
1278
|
-
this.logger.debug({
|
|
1279
|
-
at: "BundleDataClient#loadData",
|
|
1280
|
-
message: "Finished loading V3 spoke pool data and found some unrepayable fills in range",
|
|
1281
|
-
blockRangesForChains: blockRangesForChains,
|
|
1282
|
-
bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
if (bundleInvalidSlowFillRequests.length > 0) {
|
|
1286
|
-
this.logger.debug({
|
|
1287
|
-
at: "BundleDataClient#loadData",
|
|
1288
|
-
message: "Finished loading V3 spoke pool data and found some invalid slow fill requests in range",
|
|
1289
|
-
blockRangesForChains: blockRangesForChains,
|
|
1290
|
-
bundleInvalidSlowFillRequests: bundleInvalidSlowFillRequests,
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
1103
|
this.logger.debug({
|
|
1294
1104
|
at: "BundleDataClient#loadDataFromScratch",
|
|
1295
1105
|
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
@@ -1314,16 +1124,6 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1314
1124
|
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
1315
1125
|
return "".concat(event.depositor, "-").concat(event.recipient, "-").concat(event.exclusiveRelayer, "-").concat(event.inputToken, "-").concat(event.outputToken, "-").concat(event.inputAmount, "-").concat(event.outputAmount, "-").concat(event.originChainId, "-").concat(event.depositId.toString(), "-").concat(event.fillDeadline, "-").concat(event.exclusivityDeadline, "-").concat(event.message, "-").concat(event.destinationChainId);
|
|
1316
1126
|
};
|
|
1317
|
-
BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
|
|
1318
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1319
|
-
return __generator(this, function (_a) {
|
|
1320
|
-
switch (_a.label) {
|
|
1321
|
-
case 0: return [4 /*yield*/, findFillEvent(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestBlockSearched)];
|
|
1322
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
});
|
|
1326
|
-
};
|
|
1327
1127
|
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
1328
1128
|
return __awaiter(this, void 0, void 0, function () {
|
|
1329
1129
|
var _a, _b;
|
|
@@ -1333,7 +1133,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1333
1133
|
case 0:
|
|
1334
1134
|
_b = (_a = Object).fromEntries;
|
|
1335
1135
|
return [4 /*yield*/, mapAsync(chainIds, function (chainId, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1336
|
-
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime,
|
|
1136
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b;
|
|
1337
1137
|
return __generator(this, function (_c) {
|
|
1338
1138
|
switch (_c.label) {
|
|
1339
1139
|
case 0:
|
|
@@ -1348,7 +1148,7 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1348
1148
|
return [2 /*return*/];
|
|
1349
1149
|
}
|
|
1350
1150
|
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1351
|
-
endBlockForChain = Math.min(_endBlockForChain
|
|
1151
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1352
1152
|
return [4 /*yield*/, spokePoolClient.getTimestampForBlock(startBlockForChain)];
|
|
1353
1153
|
case 1:
|
|
1354
1154
|
_b = [
|
|
@@ -1358,11 +1158,9 @@ var BundleDataClient = /** @class */ (function () {
|
|
|
1358
1158
|
case 2:
|
|
1359
1159
|
_a = _b.concat([
|
|
1360
1160
|
_c.sent()
|
|
1361
|
-
]), startTime = _a[0],
|
|
1362
|
-
endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
|
|
1363
|
-
endTime = Math.max(0, _endTime - endBlockDelta);
|
|
1161
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
1364
1162
|
// Sanity checks:
|
|
1365
|
-
assert(endTime >= startTime, "End time
|
|
1163
|
+
assert(endTime >= startTime, "End time should be greater than start time.");
|
|
1366
1164
|
assert(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
|
|
1367
1165
|
return [2 /*return*/, [chainId, [startTime, endTime]]];
|
|
1368
1166
|
}
|