@across-protocol/sdk 3.1.27 → 3.1.28
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 +60 -0
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +929 -0
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/index.d.ts +2 -0
- package/dist/cjs/clients/BundleDataClient/index.js +6 -0
- package/dist/cjs/clients/BundleDataClient/index.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +15 -0
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +131 -0
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +6 -0
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +19 -0
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +3 -0
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +23 -0
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +24 -0
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +129 -0
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +302 -0
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +77 -0
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/index.d.ts +6 -0
- package/dist/cjs/clients/BundleDataClient/utils/index.js +10 -0
- package/dist/cjs/clients/BundleDataClient/utils/index.js.map +1 -0
- package/dist/cjs/clients/BundleDataClient/utils/shims.d.ts +8 -0
- package/dist/cjs/clients/BundleDataClient/utils/shims.js +3 -0
- package/dist/cjs/clients/BundleDataClient/utils/shims.js.map +1 -0
- package/dist/cjs/clients/index.d.ts +1 -0
- package/dist/cjs/clients/index.js +2 -1
- package/dist/cjs/clients/index.js.map +1 -1
- package/dist/cjs/interfaces/BundleData.d.ts +63 -0
- package/dist/cjs/interfaces/BundleData.js +3 -0
- package/dist/cjs/interfaces/BundleData.js.map +1 -0
- package/dist/cjs/interfaces/index.d.ts +1 -0
- package/dist/cjs/interfaces/index.js +1 -0
- package/dist/cjs/interfaces/index.js.map +1 -1
- package/dist/cjs/providers/alchemy.js +5 -5
- package/dist/cjs/providers/alchemy.js.map +1 -1
- package/dist/cjs/providers/drpc.d.ts +2 -0
- package/dist/cjs/providers/drpc.js +21 -0
- package/dist/cjs/providers/drpc.js.map +1 -0
- package/dist/cjs/providers/infura.js +5 -5
- package/dist/cjs/providers/infura.js.map +1 -1
- package/dist/cjs/providers/types.d.ts +1 -1
- package/dist/cjs/providers/utils.js +3 -1
- package/dist/cjs/providers/utils.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +1 -0
- package/dist/cjs/utils/AddressUtils.js +15 -1
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/ContractUtils.d.ts +1 -0
- package/dist/cjs/utils/ContractUtils.js +12 -0
- package/dist/cjs/utils/ContractUtils.js.map +1 -0
- package/dist/cjs/utils/Multicall.d.ts +3 -2
- package/dist/cjs/utils/Multicall.js +40 -41
- package/dist/cjs/utils/Multicall.js.map +1 -1
- package/dist/cjs/utils/ObjectUtils.d.ts +18 -0
- package/dist/cjs/utils/ObjectUtils.js +27 -1
- package/dist/cjs/utils/ObjectUtils.js.map +1 -1
- package/dist/cjs/utils/abi/contracts/index.d.ts +1 -0
- package/dist/cjs/utils/abi/contracts/index.js +9 -0
- package/dist/cjs/utils/abi/contracts/index.js.map +1 -0
- package/dist/cjs/utils/abi/typechain/Multicall3.d.ts +289 -0
- package/dist/cjs/utils/abi/typechain/Multicall3.js +3 -0
- package/dist/cjs/utils/abi/typechain/Multicall3.js.map +1 -0
- package/dist/cjs/utils/abi/typechain/common.d.ts +21 -0
- package/dist/cjs/utils/abi/typechain/common.js +3 -0
- package/dist/cjs/utils/abi/typechain/common.js.map +1 -0
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.d.ts +339 -0
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +458 -0
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -0
- package/dist/cjs/utils/abi/typechain/factories/index.d.ts +1 -0
- package/dist/cjs/utils/abi/typechain/factories/index.js +6 -0
- package/dist/cjs/utils/abi/typechain/factories/index.js.map +1 -0
- package/dist/cjs/utils/abi/typechain/index.d.ts +3 -0
- package/dist/cjs/utils/abi/typechain/index.js +8 -0
- package/dist/cjs/utils/abi/typechain/index.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +60 -0
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +1097 -0
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/index.d.ts +2 -0
- package/dist/esm/clients/BundleDataClient/index.js +3 -0
- package/dist/esm/clients/BundleDataClient/index.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +15 -0
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +182 -0
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +6 -0
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +20 -0
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +3 -0
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +20 -0
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +24 -0
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +157 -0
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +302 -0
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +79 -0
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/index.d.ts +6 -0
- package/dist/esm/clients/BundleDataClient/utils/index.js +7 -0
- package/dist/esm/clients/BundleDataClient/utils/index.js.map +1 -0
- package/dist/esm/clients/BundleDataClient/utils/shims.d.ts +8 -0
- package/dist/esm/clients/BundleDataClient/utils/shims.js +2 -0
- package/dist/esm/clients/BundleDataClient/utils/shims.js.map +1 -0
- package/dist/esm/clients/index.d.ts +1 -0
- package/dist/esm/clients/index.js +2 -0
- package/dist/esm/clients/index.js.map +1 -1
- package/dist/esm/interfaces/BundleData.d.ts +63 -0
- package/dist/esm/interfaces/BundleData.js +2 -0
- package/dist/esm/interfaces/BundleData.js.map +1 -0
- package/dist/esm/interfaces/index.d.ts +1 -0
- package/dist/esm/interfaces/index.js +1 -0
- package/dist/esm/interfaces/index.js.map +1 -1
- package/dist/esm/providers/alchemy.js +6 -6
- package/dist/esm/providers/alchemy.js.map +1 -1
- package/dist/esm/providers/drpc.d.ts +2 -0
- package/dist/esm/providers/drpc.js +18 -0
- package/dist/esm/providers/drpc.js.map +1 -0
- package/dist/esm/providers/infura.js +6 -6
- package/dist/esm/providers/infura.js.map +1 -1
- package/dist/esm/providers/types.d.ts +1 -1
- package/dist/esm/providers/utils.js +3 -1
- package/dist/esm/providers/utils.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +1 -0
- package/dist/esm/utils/AddressUtils.js +16 -1
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/ContractUtils.d.ts +1 -0
- package/dist/esm/utils/ContractUtils.js +8 -0
- package/dist/esm/utils/ContractUtils.js.map +1 -0
- package/dist/esm/utils/Multicall.d.ts +3 -2
- package/dist/esm/utils/Multicall.js +39 -42
- package/dist/esm/utils/Multicall.js.map +1 -1
- package/dist/esm/utils/ObjectUtils.d.ts +18 -0
- package/dist/esm/utils/ObjectUtils.js +24 -0
- package/dist/esm/utils/ObjectUtils.js.map +1 -1
- package/dist/esm/utils/abi/contracts/index.d.ts +1 -0
- package/dist/esm/utils/abi/contracts/index.js +2 -0
- package/dist/esm/utils/abi/contracts/index.js.map +1 -0
- package/dist/esm/utils/abi/typechain/Multicall3.d.ts +292 -0
- package/dist/esm/utils/abi/typechain/Multicall3.js +2 -0
- package/dist/esm/utils/abi/typechain/Multicall3.js.map +1 -0
- package/dist/esm/utils/abi/typechain/common.d.ts +21 -0
- package/dist/esm/utils/abi/typechain/common.js +2 -0
- package/dist/esm/utils/abi/typechain/common.js.map +1 -0
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.d.ts +339 -0
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +458 -0
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -0
- package/dist/esm/utils/abi/typechain/factories/index.d.ts +1 -0
- package/dist/esm/utils/abi/typechain/factories/index.js +5 -0
- package/dist/esm/utils/abi/typechain/factories/index.js.map +1 -0
- package/dist/esm/utils/abi/typechain/index.d.ts +3 -0
- package/dist/esm/utils/abi/typechain/index.js +4 -0
- package/dist/esm/utils/abi/typechain/index.js.map +1 -0
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +61 -0
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/index.d.ts +3 -0
- package/dist/types/clients/BundleDataClient/index.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +16 -0
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +7 -0
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts +4 -0
- package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +25 -0
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +303 -0
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/index.d.ts +7 -0
- package/dist/types/clients/BundleDataClient/utils/index.d.ts.map +1 -0
- package/dist/types/clients/BundleDataClient/utils/shims.d.ts +9 -0
- package/dist/types/clients/BundleDataClient/utils/shims.d.ts.map +1 -0
- package/dist/types/clients/index.d.ts +1 -0
- package/dist/types/clients/index.d.ts.map +1 -1
- package/dist/types/interfaces/BundleData.d.ts +64 -0
- package/dist/types/interfaces/BundleData.d.ts.map +1 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/interfaces/index.d.ts.map +1 -1
- package/dist/types/providers/drpc.d.ts +3 -0
- package/dist/types/providers/drpc.d.ts.map +1 -0
- package/dist/types/providers/types.d.ts +1 -1
- package/dist/types/providers/types.d.ts.map +1 -1
- package/dist/types/providers/utils.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +1 -0
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/ContractUtils.d.ts +2 -0
- package/dist/types/utils/ContractUtils.d.ts.map +1 -0
- package/dist/types/utils/Multicall.d.ts +3 -2
- package/dist/types/utils/Multicall.d.ts.map +1 -1
- package/dist/types/utils/ObjectUtils.d.ts +18 -0
- package/dist/types/utils/ObjectUtils.d.ts.map +1 -1
- package/dist/types/utils/abi/contracts/index.d.ts +2 -0
- package/dist/types/utils/abi/contracts/index.d.ts.map +1 -0
- package/dist/types/utils/abi/typechain/Multicall3.d.ts +293 -0
- package/dist/types/utils/abi/typechain/Multicall3.d.ts.map +1 -0
- package/dist/types/utils/abi/typechain/common.d.ts +22 -0
- package/dist/types/utils/abi/typechain/common.d.ts.map +1 -0
- package/dist/types/utils/abi/typechain/factories/Multicall3__factory.d.ts +340 -0
- package/dist/types/utils/abi/typechain/factories/Multicall3__factory.d.ts.map +1 -0
- package/dist/types/utils/abi/typechain/factories/index.d.ts +2 -0
- package/dist/types/utils/abi/typechain/factories/index.d.ts.map +1 -0
- package/dist/types/utils/abi/typechain/index.d.ts +4 -0
- package/dist/types/utils/abi/typechain/index.d.ts.map +1 -0
- package/package.json +6 -8
- package/src/clients/BundleDataClient/BundleDataClient.ts +1311 -0
- package/src/clients/BundleDataClient/index.ts +2 -0
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +268 -0
- package/src/clients/BundleDataClient/utils/FillUtils.ts +46 -0
- package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +26 -0
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +238 -0
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +132 -0
- package/src/clients/BundleDataClient/utils/index.ts +6 -0
- package/src/clients/BundleDataClient/utils/shims.ts +10 -0
- package/src/clients/index.ts +1 -0
- package/src/interfaces/BundleData.ts +68 -0
- package/src/interfaces/index.ts +1 -0
- package/src/providers/alchemy.ts +6 -6
- package/src/providers/drpc.ts +19 -0
- package/src/providers/infura.ts +6 -6
- package/src/providers/types.ts +1 -1
- package/src/providers/utils.ts +3 -1
- package/src/utils/AddressUtils.ts +15 -1
- package/src/utils/ContractUtils.ts +8 -0
- package/src/utils/Multicall.ts +38 -30
- package/src/utils/ObjectUtils.ts +23 -0
- package/src/utils/abi/contracts/index.ts +1 -0
- package/src/utils/abi/typechain/Multicall3.ts +433 -0
- package/src/utils/abi/typechain/common.ts +30 -0
- package/src/utils/abi/typechain/factories/Multicall3__factory.ts +458 -0
- package/src/utils/abi/typechain/factories/index.ts +4 -0
- package/src/utils/abi/typechain/index.ts +6 -0
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleDataClient = exports.INFINITE_FILL_DEADLINE = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
+
var interfaces_1 = require("../../interfaces");
|
|
7
|
+
var utils_1 = require("../../utils");
|
|
8
|
+
var ethers_1 = require("ethers");
|
|
9
|
+
var utils_2 = require("./utils");
|
|
10
|
+
exports.INFINITE_FILL_DEADLINE = utils_1.bnUint32Max;
|
|
11
|
+
function updateExpiredDepositsV3(dict, deposit) {
|
|
12
|
+
var _a;
|
|
13
|
+
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
14
|
+
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
15
|
+
(0, utils_1.assign)(dict, [originChainId, inputToken], []);
|
|
16
|
+
}
|
|
17
|
+
dict[originChainId][inputToken].push(deposit);
|
|
18
|
+
}
|
|
19
|
+
function updateBundleDepositsV3(dict, deposit) {
|
|
20
|
+
var _a;
|
|
21
|
+
var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
|
|
22
|
+
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[originChainId]) === null || _a === void 0 ? void 0 : _a[inputToken])) {
|
|
23
|
+
(0, utils_1.assign)(dict, [originChainId, inputToken], []);
|
|
24
|
+
}
|
|
25
|
+
dict[originChainId][inputToken].push(deposit);
|
|
26
|
+
}
|
|
27
|
+
function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[repaymentChainId]) === null || _a === void 0 ? void 0 : _a[repaymentToken])) {
|
|
30
|
+
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken], {
|
|
31
|
+
fills: [],
|
|
32
|
+
totalRefundAmount: utils_1.bnZero,
|
|
33
|
+
realizedLpFees: utils_1.bnZero,
|
|
34
|
+
refunds: {},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct });
|
|
38
|
+
(0, utils_1.assign)(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
39
|
+
var refundObj = dict[repaymentChainId][repaymentToken];
|
|
40
|
+
var realizedLpFee = fill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
|
|
41
|
+
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
42
|
+
if (!(0, utils_1.isSlowFill)(fill)) {
|
|
43
|
+
var refundAmount = fill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
|
|
44
|
+
refundObj.totalRefundAmount = refundObj.totalRefundAmount
|
|
45
|
+
? refundObj.totalRefundAmount.add(refundAmount)
|
|
46
|
+
: refundAmount;
|
|
47
|
+
(_b = refundObj.refunds) !== null && _b !== void 0 ? _b : (refundObj.refunds = {});
|
|
48
|
+
if (refundObj.refunds[fill.relayer]) {
|
|
49
|
+
refundObj.refunds[fill.relayer] = refundObj.refunds[fill.relayer].add(refundAmount);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
refundObj.refunds[fill.relayer] = refundAmount;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function updateBundleExcessSlowFills(dict, deposit) {
|
|
57
|
+
var _a;
|
|
58
|
+
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
59
|
+
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
60
|
+
(0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
|
|
61
|
+
}
|
|
62
|
+
dict[destinationChainId][outputToken].push(deposit);
|
|
63
|
+
}
|
|
64
|
+
function updateBundleSlowFills(dict, deposit) {
|
|
65
|
+
var _a;
|
|
66
|
+
var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
|
|
67
|
+
if (!((_a = dict === null || dict === void 0 ? void 0 : dict[destinationChainId]) === null || _a === void 0 ? void 0 : _a[outputToken])) {
|
|
68
|
+
(0, utils_1.assign)(dict, [destinationChainId, outputToken], []);
|
|
69
|
+
}
|
|
70
|
+
dict[destinationChainId][outputToken].push(deposit);
|
|
71
|
+
}
|
|
72
|
+
var BundleDataClient = (function () {
|
|
73
|
+
function BundleDataClient(logger, clients, spokePoolClients, chainIdListForBundleEvaluationBlockNumbers, blockRangeEndBlockBuffer) {
|
|
74
|
+
if (blockRangeEndBlockBuffer === void 0) { blockRangeEndBlockBuffer = {}; }
|
|
75
|
+
this.logger = logger;
|
|
76
|
+
this.clients = clients;
|
|
77
|
+
this.spokePoolClients = spokePoolClients;
|
|
78
|
+
this.chainIdListForBundleEvaluationBlockNumbers = chainIdListForBundleEvaluationBlockNumbers;
|
|
79
|
+
this.blockRangeEndBlockBuffer = blockRangeEndBlockBuffer;
|
|
80
|
+
this.loadDataCache = {};
|
|
81
|
+
this.arweaveDataCache = {};
|
|
82
|
+
this.bundleTimestampCache = {};
|
|
83
|
+
}
|
|
84
|
+
BundleDataClient.prototype.clearCache = function () {
|
|
85
|
+
this.loadDataCache = {};
|
|
86
|
+
};
|
|
87
|
+
BundleDataClient.prototype.loadDataFromCache = function (key) {
|
|
88
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
return tslib_1.__generator(this, function (_c) {
|
|
91
|
+
switch (_c.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
_b = (_a = lodash_1.default).cloneDeep;
|
|
94
|
+
return [4, this.loadDataCache[key]];
|
|
95
|
+
case 1: return [2, _b.apply(_a, [_c.sent()])];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
BundleDataClient.prototype.getBundleTimestampsFromCache = function (key) {
|
|
101
|
+
if (this.bundleTimestampCache[key]) {
|
|
102
|
+
return lodash_1.default.cloneDeep(this.bundleTimestampCache[key]);
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
};
|
|
106
|
+
BundleDataClient.prototype.setBundleTimestampsInCache = function (key, timestamps) {
|
|
107
|
+
this.bundleTimestampCache[key] = timestamps;
|
|
108
|
+
};
|
|
109
|
+
BundleDataClient.prototype.getArweaveClientKey = function (blockRangesForChains) {
|
|
110
|
+
return "bundles-".concat(blockRangesForChains);
|
|
111
|
+
};
|
|
112
|
+
BundleDataClient.prototype.loadPersistedDataFromArweave = function (blockRangesForChains) {
|
|
113
|
+
var _a;
|
|
114
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var start, persistedData, convertTypedStringRecordIntoNumericRecord, data, bundleData;
|
|
116
|
+
return tslib_1.__generator(this, function (_b) {
|
|
117
|
+
switch (_b.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
if (!(0, utils_1.isDefined)((_a = this.clients) === null || _a === void 0 ? void 0 : _a.arweaveClient)) {
|
|
120
|
+
return [2, undefined];
|
|
121
|
+
}
|
|
122
|
+
start = performance.now();
|
|
123
|
+
return [4, this.clients.arweaveClient.getByTopic(this.getArweaveClientKey(blockRangesForChains), utils_2.BundleDataSS)];
|
|
124
|
+
case 1:
|
|
125
|
+
persistedData = _b.sent();
|
|
126
|
+
if (!(0, utils_1.isDefined)(persistedData) || persistedData.length < 1) {
|
|
127
|
+
return [2, undefined];
|
|
128
|
+
}
|
|
129
|
+
convertTypedStringRecordIntoNumericRecord = function (data) {
|
|
130
|
+
return Object.keys(data).reduce(function (acc, chainId) {
|
|
131
|
+
acc[Number(chainId)] = data[chainId];
|
|
132
|
+
return acc;
|
|
133
|
+
}, {});
|
|
134
|
+
};
|
|
135
|
+
data = persistedData[0].data;
|
|
136
|
+
bundleData = {
|
|
137
|
+
bundleFillsV3: convertTypedStringRecordIntoNumericRecord(data.bundleFillsV3),
|
|
138
|
+
expiredDepositsToRefundV3: convertTypedStringRecordIntoNumericRecord(data.expiredDepositsToRefundV3),
|
|
139
|
+
bundleDepositsV3: convertTypedStringRecordIntoNumericRecord(data.bundleDepositsV3),
|
|
140
|
+
unexecutableSlowFills: convertTypedStringRecordIntoNumericRecord(data.unexecutableSlowFills),
|
|
141
|
+
bundleSlowFillsV3: convertTypedStringRecordIntoNumericRecord(data.bundleSlowFillsV3),
|
|
142
|
+
};
|
|
143
|
+
this.logger.debug({
|
|
144
|
+
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
145
|
+
message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
146
|
+
blockRanges: JSON.stringify(blockRangesForChains),
|
|
147
|
+
bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, [], bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
|
|
148
|
+
});
|
|
149
|
+
return [2, bundleData];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
BundleDataClient.prototype.getPendingRefundsFromValidBundles = function () {
|
|
155
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var refunds, bundle, _a, _b;
|
|
157
|
+
return tslib_1.__generator(this, function (_c) {
|
|
158
|
+
switch (_c.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
refunds = [];
|
|
161
|
+
if (!this.clients.hubPoolClient.isUpdated) {
|
|
162
|
+
throw new Error("BundleDataClient::getPendingRefundsFromValidBundles HubPoolClient not updated.");
|
|
163
|
+
}
|
|
164
|
+
bundle = this.clients.hubPoolClient.getLatestFullyExecutedRootBundle(this.clients.hubPoolClient.latestBlockSearched);
|
|
165
|
+
if (!(bundle !== undefined)) return [3, 2];
|
|
166
|
+
_b = (_a = refunds).push;
|
|
167
|
+
return [4, this.getPendingRefundsFromBundle(bundle)];
|
|
168
|
+
case 1:
|
|
169
|
+
_b.apply(_a, [_c.sent()]);
|
|
170
|
+
_c.label = 2;
|
|
171
|
+
case 2: return [2, refunds];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
BundleDataClient.prototype.getPendingRefundsFromBundle = function (bundle) {
|
|
177
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
178
|
+
var nextBundleMainnetStartBlock, chainIds, bundleEvaluationBlockRanges, combinedRefunds, arweaveData, bundleFillsV3, expiredDepositsToRefundV3;
|
|
179
|
+
var _this = this;
|
|
180
|
+
return tslib_1.__generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
nextBundleMainnetStartBlock = this.clients.hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, this.clients.hubPoolClient.latestBlockSearched, this.clients.hubPoolClient.chainId);
|
|
184
|
+
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
185
|
+
bundleEvaluationBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(this.clients.hubPoolClient, this.clients.configStoreClient, bundle);
|
|
186
|
+
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
187
|
+
case 1:
|
|
188
|
+
arweaveData = _a.sent();
|
|
189
|
+
if (arweaveData === undefined) {
|
|
190
|
+
combinedRefunds = this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
194
|
+
combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
|
|
195
|
+
Object.keys(combinedRefunds).forEach(function (chainId) {
|
|
196
|
+
if (_this.spokePoolClients[Number(chainId)] === undefined) {
|
|
197
|
+
delete combinedRefunds[Number(chainId)];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
207
|
+
var _this = this;
|
|
208
|
+
var refundsForChain = {};
|
|
209
|
+
var _loop_1 = function (chainId) {
|
|
210
|
+
if (this_1.spokePoolClients[chainId] === undefined) {
|
|
211
|
+
return "continue";
|
|
212
|
+
}
|
|
213
|
+
var chainIndex = chainIds.indexOf(chainId);
|
|
214
|
+
this_1.spokePoolClients[chainId]
|
|
215
|
+
.getFills()
|
|
216
|
+
.filter(function (fill) {
|
|
217
|
+
if (fill.blockNumber < blockRanges[chainIndex][0] || fill.blockNumber > blockRanges[chainIndex][1]) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (_this.spokePoolClients[fill.originChainId] === undefined) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
224
|
+
var hasMatchingDeposit = matchingDeposit !== undefined &&
|
|
225
|
+
_this.getRelayHashFromEvent(fill) === _this.getRelayHashFromEvent(matchingDeposit);
|
|
226
|
+
return hasMatchingDeposit;
|
|
227
|
+
})
|
|
228
|
+
.forEach(function (fill) {
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
var _d;
|
|
231
|
+
var matchingDeposit = _this.spokePoolClients[fill.originChainId].getDeposit(fill.depositId);
|
|
232
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(matchingDeposit), "Deposit not found for fill.");
|
|
233
|
+
var _e = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRanges, _this.chainIdListForBundleEvaluationBlockNumbers, matchingDeposit.fromLiteChain), chainToSendRefundTo = _e.chainToSendRefundTo, repaymentToken = _e.repaymentToken;
|
|
234
|
+
var relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
235
|
+
(_a = refundsForChain[chainToSendRefundTo]) !== null && _a !== void 0 ? _a : (refundsForChain[chainToSendRefundTo] = {});
|
|
236
|
+
(_b = (_d = refundsForChain[chainToSendRefundTo])[repaymentToken]) !== null && _b !== void 0 ? _b : (_d[repaymentToken] = {});
|
|
237
|
+
var existingRefundAmount = (_c = refundsForChain[chainToSendRefundTo][repaymentToken][relayer]) !== null && _c !== void 0 ? _c : utils_1.bnZero;
|
|
238
|
+
refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
var this_1 = this;
|
|
242
|
+
for (var _i = 0, chainIds_1 = chainIds; _i < chainIds_1.length; _i++) {
|
|
243
|
+
var chainId = chainIds_1[_i];
|
|
244
|
+
_loop_1(chainId);
|
|
245
|
+
}
|
|
246
|
+
return refundsForChain;
|
|
247
|
+
};
|
|
248
|
+
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
249
|
+
if (this.spokePoolClients[chainId] === undefined) {
|
|
250
|
+
return (0, utils_1.toBN)(0);
|
|
251
|
+
}
|
|
252
|
+
return this.spokePoolClients[chainId]
|
|
253
|
+
.getDeposits()
|
|
254
|
+
.filter(function (deposit) { return deposit.blockNumber > latestBlockToSearch && deposit.inputToken === l2Token; })
|
|
255
|
+
.reduce(function (acc, deposit) {
|
|
256
|
+
return acc.add(deposit.inputAmount);
|
|
257
|
+
}, (0, utils_1.toBN)(0));
|
|
258
|
+
};
|
|
259
|
+
BundleDataClient.prototype.getLatestProposedBundleData = function () {
|
|
260
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
261
|
+
var hubPoolClient, bundleBlockRanges;
|
|
262
|
+
var _a;
|
|
263
|
+
return tslib_1.__generator(this, function (_b) {
|
|
264
|
+
switch (_b.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
hubPoolClient = this.clients.hubPoolClient;
|
|
267
|
+
bundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.hasPendingProposal()
|
|
268
|
+
? hubPoolClient.getLatestProposedRootBundle()
|
|
269
|
+
: hubPoolClient.getLatestFullyExecutedRootBundle(hubPoolClient.latestBlockSearched));
|
|
270
|
+
_a = {
|
|
271
|
+
blockRanges: bundleBlockRanges
|
|
272
|
+
};
|
|
273
|
+
return [4, this.loadData(bundleBlockRanges, this.spokePoolClients, true)];
|
|
274
|
+
case 1: return [2, (_a.bundleData = _b.sent(),
|
|
275
|
+
_a)];
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
BundleDataClient.prototype.getLatestPoolRebalanceRoot = function () {
|
|
281
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
282
|
+
var _a, bundleData, blockRanges, hubPoolClient, root;
|
|
283
|
+
return tslib_1.__generator(this, function (_b) {
|
|
284
|
+
switch (_b.label) {
|
|
285
|
+
case 0: return [4, this.getLatestProposedBundleData()];
|
|
286
|
+
case 1:
|
|
287
|
+
_a = _b.sent(), bundleData = _a.bundleData, blockRanges = _a.blockRanges;
|
|
288
|
+
hubPoolClient = this.clients.hubPoolClient;
|
|
289
|
+
return [4, (0, utils_2._buildPoolRebalanceRoot)(hubPoolClient.latestBlockSearched, blockRanges[0][1], bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.unexecutableSlowFills, bundleData.expiredDepositsToRefundV3, {
|
|
290
|
+
hubPoolClient: hubPoolClient,
|
|
291
|
+
configStoreClient: hubPoolClient.configStoreClient,
|
|
292
|
+
})];
|
|
293
|
+
case 2:
|
|
294
|
+
root = _b.sent();
|
|
295
|
+
return [2, {
|
|
296
|
+
root: root,
|
|
297
|
+
blockRanges: blockRanges,
|
|
298
|
+
}];
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
BundleDataClient.prototype.getNextBundleRefunds = function () {
|
|
304
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
305
|
+
function getBlockRangeDelta(_pendingBlockRanges) {
|
|
306
|
+
return widestBundleBlockRanges.map(function (blockRange, index) {
|
|
307
|
+
var _a;
|
|
308
|
+
var initialBlockRange = (_a = _pendingBlockRanges[index]) !== null && _a !== void 0 ? _a : blockRange;
|
|
309
|
+
if (initialBlockRange[0] === initialBlockRange[1]) {
|
|
310
|
+
return initialBlockRange;
|
|
311
|
+
}
|
|
312
|
+
if (!(0, utils_1.isDefined)(blockRange[1]) || initialBlockRange[1] >= blockRange[1]) {
|
|
313
|
+
return [initialBlockRange[1], initialBlockRange[1]];
|
|
314
|
+
}
|
|
315
|
+
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, bundleFillsV3, expiredDepositsToRefundV3, start;
|
|
319
|
+
return tslib_1.__generator(this, function (_a) {
|
|
320
|
+
switch (_a.label) {
|
|
321
|
+
case 0:
|
|
322
|
+
hubPoolClient = this.clients.hubPoolClient;
|
|
323
|
+
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestBlockSearched, hubPoolClient.chainId);
|
|
324
|
+
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
325
|
+
combinedRefunds = [];
|
|
326
|
+
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));
|
|
327
|
+
if (!hubPoolClient.hasPendingProposal()) return [3, 2];
|
|
328
|
+
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
329
|
+
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
330
|
+
case 1:
|
|
331
|
+
arweaveData = _a.sent();
|
|
332
|
+
if (arweaveData === undefined) {
|
|
333
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges));
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
337
|
+
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
338
|
+
}
|
|
339
|
+
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
340
|
+
_a.label = 2;
|
|
341
|
+
case 2:
|
|
342
|
+
start = performance.now();
|
|
343
|
+
combinedRefunds.push(this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges));
|
|
344
|
+
this.logger.debug({
|
|
345
|
+
at: "BundleDataClient#getNextBundleRefunds",
|
|
346
|
+
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
347
|
+
blockRanges: JSON.stringify(widestBundleBlockRanges),
|
|
348
|
+
});
|
|
349
|
+
return [2, combinedRefunds];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
BundleDataClient.prototype.getExecutedRefunds = function (spokePoolClient, relayerRefundRoot) {
|
|
355
|
+
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
var bundle = lodash_1.default.findLast(spokePoolClient.getRootBundleRelays(), function (bundle) { return bundle.relayerRefundRoot === relayerRefundRoot; });
|
|
359
|
+
if (bundle === undefined) {
|
|
360
|
+
return {};
|
|
361
|
+
}
|
|
362
|
+
var executedRefundLeaves = spokePoolClient
|
|
363
|
+
.getRelayerRefundExecutions()
|
|
364
|
+
.filter(function (leaf) { return leaf.rootBundleId === bundle.rootBundleId; });
|
|
365
|
+
var executedRefunds = {};
|
|
366
|
+
for (var _i = 0, executedRefundLeaves_1 = executedRefundLeaves; _i < executedRefundLeaves_1.length; _i++) {
|
|
367
|
+
var refundLeaf = executedRefundLeaves_1[_i];
|
|
368
|
+
var tokenAddress = refundLeaf.l2TokenAddress;
|
|
369
|
+
if (executedRefunds[tokenAddress] === undefined) {
|
|
370
|
+
executedRefunds[tokenAddress] = {};
|
|
371
|
+
}
|
|
372
|
+
var executedTokenRefunds = executedRefunds[tokenAddress];
|
|
373
|
+
for (var i = 0; i < refundLeaf.refundAddresses.length; i++) {
|
|
374
|
+
var relayer = refundLeaf.refundAddresses[i];
|
|
375
|
+
var refundAmount = refundLeaf.refundAmounts[i];
|
|
376
|
+
if (executedTokenRefunds[relayer] === undefined) {
|
|
377
|
+
executedTokenRefunds[relayer] = utils_1.bnZero;
|
|
378
|
+
}
|
|
379
|
+
executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return executedRefunds;
|
|
383
|
+
};
|
|
384
|
+
BundleDataClient.prototype.deductExecutedRefunds = function (allRefunds, bundleContainingRefunds) {
|
|
385
|
+
for (var _i = 0, _a = Object.keys(allRefunds); _i < _a.length; _i++) {
|
|
386
|
+
var chainIdStr = _a[_i];
|
|
387
|
+
var chainId = Number(chainIdStr);
|
|
388
|
+
if (!(0, utils_1.isDefined)(this.spokePoolClients[chainId])) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
var executedRefunds = this.getExecutedRefunds(this.spokePoolClients[chainId], bundleContainingRefunds.relayerRefundRoot);
|
|
392
|
+
for (var _b = 0, _c = Object.keys(allRefunds[chainId]); _b < _c.length; _b++) {
|
|
393
|
+
var tokenAddress = _c[_b];
|
|
394
|
+
var refunds = allRefunds[chainId][tokenAddress];
|
|
395
|
+
if (executedRefunds[tokenAddress] === undefined || refunds === undefined) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
for (var _d = 0, _e = Object.keys(refunds); _d < _e.length; _d++) {
|
|
399
|
+
var relayer = _e[_d];
|
|
400
|
+
var executedAmount = executedRefunds[tokenAddress][relayer];
|
|
401
|
+
if (executedAmount === undefined) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
refunds[relayer] = utils_1.bnZero;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return allRefunds;
|
|
409
|
+
};
|
|
410
|
+
BundleDataClient.prototype.getRefundsFor = function (bundleRefunds, relayer, chainId, token) {
|
|
411
|
+
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
|
|
412
|
+
return ethers_1.BigNumber.from(0);
|
|
413
|
+
}
|
|
414
|
+
var allRefunds = bundleRefunds[chainId][token];
|
|
415
|
+
return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : ethers_1.BigNumber.from(0);
|
|
416
|
+
};
|
|
417
|
+
BundleDataClient.prototype.getTotalRefund = function (refunds, relayer, chainId, refundToken) {
|
|
418
|
+
var _this = this;
|
|
419
|
+
return refunds.reduce(function (totalRefund, refunds) {
|
|
420
|
+
return totalRefund.add(_this.getRefundsFor(refunds, relayer, chainId, refundToken));
|
|
421
|
+
}, utils_1.bnZero);
|
|
422
|
+
};
|
|
423
|
+
BundleDataClient.prototype.loadArweaveData = function (blockRangesForChains) {
|
|
424
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
425
|
+
var arweaveKey, arweaveData, _a, _b;
|
|
426
|
+
return tslib_1.__generator(this, function (_c) {
|
|
427
|
+
switch (_c.label) {
|
|
428
|
+
case 0:
|
|
429
|
+
arweaveKey = this.getArweaveClientKey(blockRangesForChains);
|
|
430
|
+
if (!this.arweaveDataCache[arweaveKey]) {
|
|
431
|
+
this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains);
|
|
432
|
+
}
|
|
433
|
+
_b = (_a = lodash_1.default).cloneDeep;
|
|
434
|
+
return [4, this.arweaveDataCache[arweaveKey]];
|
|
435
|
+
case 1:
|
|
436
|
+
arweaveData = _b.apply(_a, [_c.sent()]);
|
|
437
|
+
return [2, arweaveData];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
BundleDataClient.prototype.loadData = function (blockRangesForChains, spokePoolClients, attemptArweaveLoad) {
|
|
443
|
+
if (attemptArweaveLoad === void 0) { attemptArweaveLoad = false; }
|
|
444
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
445
|
+
var key, arweaveData, data;
|
|
446
|
+
return tslib_1.__generator(this, function (_a) {
|
|
447
|
+
switch (_a.label) {
|
|
448
|
+
case 0:
|
|
449
|
+
key = JSON.stringify(blockRangesForChains);
|
|
450
|
+
if (!!this.loadDataCache[key]) return [3, 4];
|
|
451
|
+
arweaveData = void 0;
|
|
452
|
+
if (!attemptArweaveLoad) return [3, 2];
|
|
453
|
+
return [4, this.loadArweaveData(blockRangesForChains)];
|
|
454
|
+
case 1:
|
|
455
|
+
arweaveData = _a.sent();
|
|
456
|
+
return [3, 3];
|
|
457
|
+
case 2:
|
|
458
|
+
arweaveData = undefined;
|
|
459
|
+
_a.label = 3;
|
|
460
|
+
case 3:
|
|
461
|
+
data = (0, utils_1.isDefined)(arweaveData)
|
|
462
|
+
?
|
|
463
|
+
Promise.resolve(arweaveData)
|
|
464
|
+
: this.loadDataFromScratch(blockRangesForChains, spokePoolClients);
|
|
465
|
+
this.loadDataCache[key] = data;
|
|
466
|
+
_a.label = 4;
|
|
467
|
+
case 4: return [2, this.loadDataFromCache(key)];
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
473
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
474
|
+
var start, key, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _isChainDisabled, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, expiredBundleDepositHashes, olderDepositHashes, depositCounter, _loop_2, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_3, _a, allChainIds_2, originChainId, promises, _b, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable;
|
|
475
|
+
var _this = this;
|
|
476
|
+
return tslib_1.__generator(this, function (_c) {
|
|
477
|
+
switch (_c.label) {
|
|
478
|
+
case 0:
|
|
479
|
+
start = performance.now();
|
|
480
|
+
key = JSON.stringify(blockRangesForChains);
|
|
481
|
+
if (!this.clients.configStoreClient.isUpdated) {
|
|
482
|
+
throw new Error("ConfigStoreClient not updated");
|
|
483
|
+
}
|
|
484
|
+
else if (!this.clients.hubPoolClient.isUpdated) {
|
|
485
|
+
throw new Error("HubPoolClient not updated");
|
|
486
|
+
}
|
|
487
|
+
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(blockRangesForChains[0][0]);
|
|
488
|
+
if (blockRangesForChains.length > chainIds.length) {
|
|
489
|
+
throw new Error("Unexpected block range list length of ".concat(blockRangesForChains.length, ", should be <= ").concat(chainIds.length));
|
|
490
|
+
}
|
|
491
|
+
bundleDepositsV3 = {};
|
|
492
|
+
bundleFillsV3 = {};
|
|
493
|
+
bundleInvalidFillsV3 = [];
|
|
494
|
+
bundleSlowFillsV3 = {};
|
|
495
|
+
expiredDepositsToRefundV3 = {};
|
|
496
|
+
unexecutableSlowFills = {};
|
|
497
|
+
_isChainDisabled = function (chainId) {
|
|
498
|
+
var blockRangeForChain = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, chainId, chainIds);
|
|
499
|
+
return (0, utils_2.isChainDisabled)(blockRangeForChain);
|
|
500
|
+
};
|
|
501
|
+
allChainIds = blockRangesForChains
|
|
502
|
+
.map(function (_blockRange, index) { return chainIds[index]; })
|
|
503
|
+
.filter(function (chainId) { return !_isChainDisabled(chainId) && spokePoolClients[chainId] !== undefined; });
|
|
504
|
+
allChainIds.forEach(function (chainId) {
|
|
505
|
+
var spokePoolClient = spokePoolClients[chainId];
|
|
506
|
+
if (!spokePoolClient.isUpdated) {
|
|
507
|
+
throw new Error("SpokePoolClient for chain ".concat(chainId, " not updated."));
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
_cachedBundleTimestamps = this.getBundleTimestampsFromCache(key);
|
|
511
|
+
bundleBlockTimestamps = {};
|
|
512
|
+
if (!!_cachedBundleTimestamps) return [3, 2];
|
|
513
|
+
return [4, this.getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients)];
|
|
514
|
+
case 1:
|
|
515
|
+
bundleBlockTimestamps = _c.sent();
|
|
516
|
+
this.setBundleTimestampsInCache(key, bundleBlockTimestamps);
|
|
517
|
+
this.logger.debug({
|
|
518
|
+
at: "BundleDataClient#loadData",
|
|
519
|
+
message: "Bundle block timestamps",
|
|
520
|
+
bundleBlockTimestamps: bundleBlockTimestamps,
|
|
521
|
+
blockRangesForChains: JSON.stringify(blockRangesForChains),
|
|
522
|
+
});
|
|
523
|
+
return [3, 3];
|
|
524
|
+
case 2:
|
|
525
|
+
bundleBlockTimestamps = _cachedBundleTimestamps;
|
|
526
|
+
_c.label = 3;
|
|
527
|
+
case 3:
|
|
528
|
+
v3RelayHashes = {};
|
|
529
|
+
expiredBundleDepositHashes = new Set();
|
|
530
|
+
olderDepositHashes = new Set();
|
|
531
|
+
depositCounter = 0;
|
|
532
|
+
_loop_2 = function (originChainId) {
|
|
533
|
+
var originClient = spokePoolClients[originChainId];
|
|
534
|
+
var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
535
|
+
var _loop_4 = function (destinationChainId) {
|
|
536
|
+
if (originChainId === destinationChainId) {
|
|
537
|
+
return "continue";
|
|
538
|
+
}
|
|
539
|
+
originClient.getDepositsForDestinationChain(destinationChainId).forEach(function (deposit) {
|
|
540
|
+
depositCounter++;
|
|
541
|
+
var relayDataHash = _this.getRelayHashFromEvent(deposit);
|
|
542
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
v3RelayHashes[relayDataHash] = {
|
|
546
|
+
deposit: deposit,
|
|
547
|
+
fill: undefined,
|
|
548
|
+
slowFillRequest: undefined,
|
|
549
|
+
};
|
|
550
|
+
if (deposit.blockNumber >= originChainBlockRange[0] && deposit.blockNumber <= originChainBlockRange[1]) {
|
|
551
|
+
updateBundleDepositsV3(bundleDepositsV3, deposit);
|
|
552
|
+
if (deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
553
|
+
expiredBundleDepositHashes.add(relayDataHash);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else if (deposit.blockNumber < originChainBlockRange[0]) {
|
|
557
|
+
olderDepositHashes.add(relayDataHash);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
for (var _d = 0, allChainIds_3 = allChainIds; _d < allChainIds_3.length; _d++) {
|
|
562
|
+
var destinationChainId = allChainIds_3[_d];
|
|
563
|
+
_loop_4(destinationChainId);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
|
|
567
|
+
originChainId = allChainIds_1[_i];
|
|
568
|
+
_loop_2(originChainId);
|
|
569
|
+
}
|
|
570
|
+
this.logger.debug({
|
|
571
|
+
at: "BundleDataClient#loadData",
|
|
572
|
+
message: "Processed ".concat(depositCounter, " deposits in ").concat(performance.now() - start, "ms."),
|
|
573
|
+
});
|
|
574
|
+
start = performance.now();
|
|
575
|
+
validatedBundleV3Fills = [];
|
|
576
|
+
validatedBundleSlowFills = [];
|
|
577
|
+
validatedBundleUnexecutableSlowFills = [];
|
|
578
|
+
fillCounter = 0;
|
|
579
|
+
_loop_3 = function (originChainId) {
|
|
580
|
+
var originClient, _loop_5, _e, allChainIds_4, destinationChainId;
|
|
581
|
+
return tslib_1.__generator(this, function (_f) {
|
|
582
|
+
switch (_f.label) {
|
|
583
|
+
case 0:
|
|
584
|
+
originClient = spokePoolClients[originChainId];
|
|
585
|
+
_loop_5 = function (destinationChainId) {
|
|
586
|
+
var destinationClient, destinationChainBlockRange, fastFillsReplacingSlowFills;
|
|
587
|
+
return tslib_1.__generator(this, function (_g) {
|
|
588
|
+
switch (_g.label) {
|
|
589
|
+
case 0:
|
|
590
|
+
if (originChainId === destinationChainId) {
|
|
591
|
+
return [2, "continue"];
|
|
592
|
+
}
|
|
593
|
+
destinationClient = spokePoolClients[destinationChainId];
|
|
594
|
+
destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
595
|
+
fastFillsReplacingSlowFills = [];
|
|
596
|
+
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
597
|
+
.getFillsForOriginChain(originChainId)
|
|
598
|
+
.filter(function (fill) { return fill.blockNumber <= destinationChainBlockRange[1]; }), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
599
|
+
var relayDataHash, historicalDeposit, matchedDeposit;
|
|
600
|
+
return tslib_1.__generator(this, function (_a) {
|
|
601
|
+
switch (_a.label) {
|
|
602
|
+
case 0:
|
|
603
|
+
relayDataHash = this.getRelayHashFromEvent(fill);
|
|
604
|
+
fillCounter++;
|
|
605
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
606
|
+
if (!v3RelayHashes[relayDataHash].fill) {
|
|
607
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
608
|
+
v3RelayHashes[relayDataHash].fill = fill;
|
|
609
|
+
if (fill.blockNumber >= destinationChainBlockRange[0]) {
|
|
610
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: v3RelayHashes[relayDataHash].deposit.quoteTimestamp }));
|
|
611
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill) {
|
|
612
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return [2];
|
|
617
|
+
}
|
|
618
|
+
v3RelayHashes[relayDataHash] = {
|
|
619
|
+
deposit: undefined,
|
|
620
|
+
fill: fill,
|
|
621
|
+
slowFillRequest: undefined,
|
|
622
|
+
};
|
|
623
|
+
if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
624
|
+
if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
|
|
625
|
+
bundleInvalidFillsV3.push(fill);
|
|
626
|
+
return [2];
|
|
627
|
+
}
|
|
628
|
+
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
|
|
629
|
+
case 1:
|
|
630
|
+
historicalDeposit = _a.sent();
|
|
631
|
+
if (!historicalDeposit.found) {
|
|
632
|
+
bundleInvalidFillsV3.push(fill);
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
636
|
+
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Relay hashes should match.");
|
|
637
|
+
validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fill), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
|
|
638
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
639
|
+
if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill) {
|
|
640
|
+
fastFillsReplacingSlowFills.push(relayDataHash);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
_a.label = 2;
|
|
644
|
+
case 2: return [2];
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}); })];
|
|
648
|
+
case 1:
|
|
649
|
+
_g.sent();
|
|
650
|
+
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
651
|
+
.getSlowFillRequestsForOriginChain(originChainId)
|
|
652
|
+
.filter(function (request) { return request.blockNumber <= destinationChainBlockRange[1]; }), function (slowFillRequest) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
653
|
+
var relayDataHash, matchedDeposit, historicalDeposit, matchedDeposit;
|
|
654
|
+
var _a, _b;
|
|
655
|
+
return tslib_1.__generator(this, function (_c) {
|
|
656
|
+
switch (_c.label) {
|
|
657
|
+
case 0:
|
|
658
|
+
relayDataHash = this.getRelayHashFromEvent(slowFillRequest);
|
|
659
|
+
if (v3RelayHashes[relayDataHash]) {
|
|
660
|
+
if (!v3RelayHashes[relayDataHash].slowFillRequest) {
|
|
661
|
+
v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
|
|
662
|
+
if (v3RelayHashes[relayDataHash].fill) {
|
|
663
|
+
return [2];
|
|
664
|
+
}
|
|
665
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(v3RelayHashes[relayDataHash].deposit), "Deposit should exist in relay hash dictionary.");
|
|
666
|
+
matchedDeposit = v3RelayHashes[relayDataHash].deposit;
|
|
667
|
+
if (!this.clients.hubPoolClient.areTokensEquivalent(matchedDeposit.inputToken, matchedDeposit.originChainId, matchedDeposit.outputToken, matchedDeposit.destinationChainId, matchedDeposit.quoteBlockNumber)) {
|
|
668
|
+
return [2];
|
|
669
|
+
}
|
|
670
|
+
if (((_a = v3RelayHashes[relayDataHash].deposit) === null || _a === void 0 ? void 0 : _a.fromLiteChain) ||
|
|
671
|
+
((_b = v3RelayHashes[relayDataHash].deposit) === null || _b === void 0 ? void 0 : _b.toLiteChain)) {
|
|
672
|
+
return [2];
|
|
673
|
+
}
|
|
674
|
+
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
|
|
675
|
+
slowFillRequest.fillDeadline >= bundleBlockTimestamps[destinationChainId][1]) {
|
|
676
|
+
validatedBundleSlowFills.push(matchedDeposit);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return [2];
|
|
680
|
+
}
|
|
681
|
+
v3RelayHashes[relayDataHash] = {
|
|
682
|
+
deposit: undefined,
|
|
683
|
+
fill: undefined,
|
|
684
|
+
slowFillRequest: slowFillRequest,
|
|
685
|
+
};
|
|
686
|
+
if (!(exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline) &&
|
|
687
|
+
slowFillRequest.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
|
|
688
|
+
return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
|
|
689
|
+
case 1:
|
|
690
|
+
historicalDeposit = _c.sent();
|
|
691
|
+
if (!historicalDeposit.found) {
|
|
692
|
+
return [2];
|
|
693
|
+
}
|
|
694
|
+
matchedDeposit = historicalDeposit.deposit;
|
|
695
|
+
(0, utils_1.assert)(this.getRelayHashFromEvent(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
|
|
696
|
+
if (matchedDeposit.fromLiteChain || matchedDeposit.toLiteChain) {
|
|
697
|
+
return [2];
|
|
698
|
+
}
|
|
699
|
+
v3RelayHashes[relayDataHash].deposit = matchedDeposit;
|
|
700
|
+
if (!this.clients.hubPoolClient.areTokensEquivalent(matchedDeposit.inputToken, matchedDeposit.originChainId, matchedDeposit.outputToken, matchedDeposit.destinationChainId, matchedDeposit.quoteBlockNumber) ||
|
|
701
|
+
slowFillRequest.fillDeadline < bundleBlockTimestamps[destinationChainId][1]) {
|
|
702
|
+
return [2];
|
|
703
|
+
}
|
|
704
|
+
validatedBundleSlowFills.push(matchedDeposit);
|
|
705
|
+
_c.label = 2;
|
|
706
|
+
case 2: return [2];
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}); })];
|
|
710
|
+
case 2:
|
|
711
|
+
_g.sent();
|
|
712
|
+
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
713
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
714
|
+
(0, utils_1.assert)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
715
|
+
if (!deposit) {
|
|
716
|
+
throw new Error("Deposit should exist in relay hash dictionary.");
|
|
717
|
+
}
|
|
718
|
+
var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
719
|
+
if (_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
720
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
721
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
return [2];
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
_e = 0, allChainIds_4 = allChainIds;
|
|
729
|
+
_f.label = 1;
|
|
730
|
+
case 1:
|
|
731
|
+
if (!(_e < allChainIds_4.length)) return [3, 4];
|
|
732
|
+
destinationChainId = allChainIds_4[_e];
|
|
733
|
+
return [5, _loop_5(destinationChainId)];
|
|
734
|
+
case 2:
|
|
735
|
+
_f.sent();
|
|
736
|
+
_f.label = 3;
|
|
737
|
+
case 3:
|
|
738
|
+
_e++;
|
|
739
|
+
return [3, 1];
|
|
740
|
+
case 4: return [2];
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
_a = 0, allChainIds_2 = allChainIds;
|
|
745
|
+
_c.label = 4;
|
|
746
|
+
case 4:
|
|
747
|
+
if (!(_a < allChainIds_2.length)) return [3, 7];
|
|
748
|
+
originChainId = allChainIds_2[_a];
|
|
749
|
+
return [5, _loop_3(originChainId)];
|
|
750
|
+
case 5:
|
|
751
|
+
_c.sent();
|
|
752
|
+
_c.label = 6;
|
|
753
|
+
case 6:
|
|
754
|
+
_a++;
|
|
755
|
+
return [3, 4];
|
|
756
|
+
case 7:
|
|
757
|
+
this.logger.debug({
|
|
758
|
+
at: "BundleDataClient#loadData",
|
|
759
|
+
message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
|
|
760
|
+
});
|
|
761
|
+
start = performance.now();
|
|
762
|
+
expiredBundleDepositHashes.forEach(function (relayDataHash) {
|
|
763
|
+
var _a = v3RelayHashes[relayDataHash], deposit = _a.deposit, fill = _a.fill;
|
|
764
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
765
|
+
if (!fill &&
|
|
766
|
+
(0, utils_1.isDefined)(deposit)) {
|
|
767
|
+
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
return [4, (0, utils_1.forEachAsync)(Array.from(olderDepositHashes), function (relayDataHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
771
|
+
var _a, deposit, slowFillRequest, fill, destinationChainId, destinationBlockRange, fillStatus;
|
|
772
|
+
return tslib_1.__generator(this, function (_b) {
|
|
773
|
+
switch (_b.label) {
|
|
774
|
+
case 0:
|
|
775
|
+
_a = v3RelayHashes[relayDataHash], deposit = _a.deposit, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
776
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(deposit), "Deposit should exist in relay hash dictionary.");
|
|
777
|
+
destinationChainId = deposit.destinationChainId;
|
|
778
|
+
destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
779
|
+
if (!(!fill &&
|
|
780
|
+
(0, utils_1.isDefined)(deposit) &&
|
|
781
|
+
deposit.fillDeadline < bundleBlockTimestamps[destinationChainId][1] &&
|
|
782
|
+
deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
|
|
783
|
+
spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
|
|
784
|
+
return [4, (0, utils_1.relayFillStatus)(spokePoolClients[destinationChainId].spokePool, deposit, Math.min(destinationBlockRange[1], spokePoolClients[destinationChainId].latestBlockSearched), destinationChainId)];
|
|
785
|
+
case 1:
|
|
786
|
+
fillStatus = _b.sent();
|
|
787
|
+
if (fillStatus !== interfaces_1.FillStatus.Filled) {
|
|
788
|
+
updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
|
|
789
|
+
}
|
|
790
|
+
if (fillStatus !== interfaces_1.FillStatus.RequestedSlowFill) {
|
|
791
|
+
return [2];
|
|
792
|
+
}
|
|
793
|
+
if (this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, deposit.quoteBlockNumber) &&
|
|
794
|
+
(!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
|
|
795
|
+
validatedBundleUnexecutableSlowFills.push(deposit);
|
|
796
|
+
}
|
|
797
|
+
_b.label = 2;
|
|
798
|
+
case 2: return [2];
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
}); })];
|
|
802
|
+
case 8:
|
|
803
|
+
_c.sent();
|
|
804
|
+
start = performance.now();
|
|
805
|
+
promises = [
|
|
806
|
+
validatedBundleV3Fills.length > 0
|
|
807
|
+
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
|
|
808
|
+
var matchedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
809
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
810
|
+
var paymentChainId = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, matchedDeposit.fromLiteChain).chainToSendRefundTo;
|
|
811
|
+
return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
|
|
812
|
+
}))
|
|
813
|
+
: [],
|
|
814
|
+
validatedBundleSlowFills.length > 0
|
|
815
|
+
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleSlowFills.map(function (deposit) {
|
|
816
|
+
return tslib_1.__assign(tslib_1.__assign({}, deposit), { paymentChainId: deposit.destinationChainId });
|
|
817
|
+
}))
|
|
818
|
+
: [],
|
|
819
|
+
validatedBundleUnexecutableSlowFills.length > 0
|
|
820
|
+
? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleUnexecutableSlowFills.map(function (deposit) {
|
|
821
|
+
return tslib_1.__assign(tslib_1.__assign({}, deposit), { paymentChainId: deposit.destinationChainId });
|
|
822
|
+
}))
|
|
823
|
+
: [],
|
|
824
|
+
];
|
|
825
|
+
return [4, Promise.all(promises)];
|
|
826
|
+
case 9:
|
|
827
|
+
_b = _c.sent(), v3FillLpFees = _b[0], v3SlowFillLpFees = _b[1], v3UnexecutableSlowFillLpFees = _b[2];
|
|
828
|
+
this.logger.debug({
|
|
829
|
+
at: "BundleDataClient#loadData",
|
|
830
|
+
message: "Computed batch async LP fees in ".concat(performance.now() - start, "ms."),
|
|
831
|
+
});
|
|
832
|
+
v3FillLpFees.forEach(function (_a, idx) {
|
|
833
|
+
var realizedLpFeePct = _a.realizedLpFeePct;
|
|
834
|
+
var fill = validatedBundleV3Fills[idx];
|
|
835
|
+
var associatedDeposit = v3RelayHashes[_this.getRelayHashFromEvent(fill)].deposit;
|
|
836
|
+
(0, utils_1.assert)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
|
|
837
|
+
var _b = (0, utils_2.getRefundInformationFromFill)(fill, _this.clients.hubPoolClient, blockRangesForChains, chainIds, associatedDeposit.fromLiteChain), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
|
|
838
|
+
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken);
|
|
839
|
+
});
|
|
840
|
+
v3SlowFillLpFees.forEach(function (_a, idx) {
|
|
841
|
+
var lpFeePct = _a.realizedLpFeePct;
|
|
842
|
+
var deposit = validatedBundleSlowFills[idx];
|
|
843
|
+
updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
844
|
+
});
|
|
845
|
+
v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
|
|
846
|
+
var lpFeePct = _a.realizedLpFeePct;
|
|
847
|
+
var deposit = validatedBundleUnexecutableSlowFills[idx];
|
|
848
|
+
updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
|
|
849
|
+
});
|
|
850
|
+
v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
|
|
851
|
+
if (bundleInvalidFillsV3.length > 0) {
|
|
852
|
+
this.logger.debug({
|
|
853
|
+
at: "BundleDataClient#loadData",
|
|
854
|
+
message: "Finished loading V3 spoke pool data and found some invalid V3 fills in range",
|
|
855
|
+
blockRangesForChains: blockRangesForChains,
|
|
856
|
+
bundleInvalidFillsV3: bundleInvalidFillsV3,
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
this.logger.debug({
|
|
860
|
+
at: "BundleDataClient#loadDataFromScratch",
|
|
861
|
+
message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
862
|
+
blockRangesForChains: JSON.stringify(blockRangesForChains),
|
|
863
|
+
v3SpokeEventsReadable: v3SpokeEventsReadable,
|
|
864
|
+
});
|
|
865
|
+
return [2, {
|
|
866
|
+
bundleDepositsV3: bundleDepositsV3,
|
|
867
|
+
expiredDepositsToRefundV3: expiredDepositsToRefundV3,
|
|
868
|
+
bundleFillsV3: bundleFillsV3,
|
|
869
|
+
unexecutableSlowFills: unexecutableSlowFills,
|
|
870
|
+
bundleSlowFillsV3: bundleSlowFillsV3,
|
|
871
|
+
}];
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
BundleDataClient.prototype.getRelayHashFromEvent = function (event) {
|
|
877
|
+
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);
|
|
878
|
+
};
|
|
879
|
+
BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
|
|
880
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
881
|
+
var _a, _b;
|
|
882
|
+
var _this = this;
|
|
883
|
+
return tslib_1.__generator(this, function (_c) {
|
|
884
|
+
switch (_c.label) {
|
|
885
|
+
case 0:
|
|
886
|
+
_b = (_a = Object).fromEntries;
|
|
887
|
+
return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
888
|
+
var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, endTime, _b, _c, _d;
|
|
889
|
+
return tslib_1.__generator(this, function (_e) {
|
|
890
|
+
switch (_e.label) {
|
|
891
|
+
case 0:
|
|
892
|
+
blockRangeForChain = blockRangesForChains[index];
|
|
893
|
+
if (!(0, utils_1.isDefined)(blockRangeForChain) || (0, utils_2.isChainDisabled)(blockRangeForChain)) {
|
|
894
|
+
return [2];
|
|
895
|
+
}
|
|
896
|
+
_startBlockForChain = blockRangeForChain[0], _endBlockForChain = blockRangeForChain[1];
|
|
897
|
+
spokePoolClient = spokePoolClients[chainId];
|
|
898
|
+
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
899
|
+
return [2];
|
|
900
|
+
}
|
|
901
|
+
startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
902
|
+
endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
903
|
+
_b = Number;
|
|
904
|
+
return [4, spokePoolClient.spokePool.provider.getBlock(startBlockForChain)];
|
|
905
|
+
case 1:
|
|
906
|
+
_c = [
|
|
907
|
+
_b.apply(void 0, [(_e.sent()).timestamp])
|
|
908
|
+
];
|
|
909
|
+
_d = Number;
|
|
910
|
+
return [4, spokePoolClient.spokePool.provider.getBlock(endBlockForChain)];
|
|
911
|
+
case 2:
|
|
912
|
+
_a = _c.concat([
|
|
913
|
+
_d.apply(void 0, [(_e.sent()).timestamp])
|
|
914
|
+
]), startTime = _a[0], endTime = _a[1];
|
|
915
|
+
(0, utils_1.assert)(endTime >= startTime, "End time should be greater than start time.");
|
|
916
|
+
(0, utils_1.assert)(startTime > 0, "Start time should be greater than 0.");
|
|
917
|
+
return [2, [chainId, [startTime, endTime]]];
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
}); })];
|
|
921
|
+
case 1: return [2, _b.apply(_a, [(_c.sent()).filter(utils_1.isDefined)])];
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
});
|
|
925
|
+
};
|
|
926
|
+
return BundleDataClient;
|
|
927
|
+
}());
|
|
928
|
+
exports.BundleDataClient = BundleDataClient;
|
|
929
|
+
//# sourceMappingURL=BundleDataClient.js.map
|