@paraswap/dex-lib 4.7.12-multi-wrapper-non-zero-sender.0 → 4.7.13-from-amount-pos.0
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/build/abi/PendleRouterStatic.json +19 -0
- package/build/abi/{MStableAsset.json → apex-defi/ApexDefiFactory.abi.json} +992 -788
- package/build/abi/{BProtocol.json → apex-defi/ApexDefiRouter.abi.json} +539 -574
- package/build/abi/apex-defi/ApexDefiToken.abi.json +229 -0
- package/build/abi/apex-defi/ApexDefiWrapper.abi.json +92 -0
- package/build/abi/{OneInchLp.json → apex-defi/ApexDefiWrapperFactory.abi.json} +577 -774
- package/build/abi/pangolin-v3/PangolinV3StateMulticall.abi.json +796 -0
- package/build/abi/pendle/pendle-deployer.abi.json +520 -0
- package/build/abi/pendle/pendle-oracle.abi.json +413 -0
- package/build/abi/ring-v2/few-wrapped-token.json +587 -0
- package/build/abi/ring-v2/ring-v2-factory.json +125 -0
- package/build/abi/ring-v2/ring-v2-pool.json +461 -0
- package/build/abi/ring-v2/ring-v2-router.json +332 -0
- package/build/abi/stabull/stabull-curve.json +738 -0
- package/build/abi/stabull/stabull-router.json +76 -0
- package/build/abi/uniswap-v4/hooks/SpotDynamicFeeManager.json +26 -0
- package/build/abi/uniswap-v4/hooks/SpotHook.json +54 -0
- package/build/abi/uniswap-v4/hooks/SpotPolicyManager.json +45 -0
- package/build/abi/uniswap-v4/hooks/cabalcoin-hook.abi.json +682 -0
- package/build/abi/uniswap-v4/hooks/fee-hook.abi.json +1335 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.d.ts +29 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js +153 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js.map +1 -0
- package/build/dex/{usual-bond/usual-bond.d.ts → aave-pt-to-underlying/aave-pt-to-underlying.d.ts} +23 -18
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js +323 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/config.d.ts +3 -0
- package/build/dex/aave-pt-to-underlying/config.js +24 -0
- package/build/dex/aave-pt-to-underlying/config.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/constants.d.ts +2 -0
- package/build/dex/aave-pt-to-underlying/constants.js +6 -0
- package/build/dex/aave-pt-to-underlying/constants.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/types.d.ts +24 -0
- package/build/dex/aave-pt-to-underlying/types.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.d.ts +39 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js +244 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/config.d.ts +3 -0
- package/build/dex/aave-pt-to-usdc/config.js +47 -0
- package/build/dex/aave-pt-to-usdc/config.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/constants.d.ts +2 -0
- package/build/dex/aave-pt-to-usdc/constants.js +6 -0
- package/build/dex/aave-pt-to-usdc/constants.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/types.d.ts +22 -0
- package/build/dex/aave-pt-to-usdc/types.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-factory.d.ts +26 -0
- package/build/dex/apex-defi/apex-defi-factory.js +53 -0
- package/build/dex/apex-defi/apex-defi-factory.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-pool.d.ts +55 -0
- package/build/dex/apex-defi/apex-defi-pool.js +247 -0
- package/build/dex/apex-defi/apex-defi-pool.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.d.ts +57 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.js +250 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.js.map +1 -0
- package/build/dex/apex-defi/apex-defi.d.ts +97 -0
- package/build/dex/apex-defi/apex-defi.js +1021 -0
- package/build/dex/apex-defi/apex-defi.js.map +1 -0
- package/build/dex/apex-defi/config.d.ts +4 -0
- package/build/dex/apex-defi/config.js +138 -0
- package/build/dex/apex-defi/config.js.map +1 -0
- package/build/dex/apex-defi/types.d.ts +32 -0
- package/build/dex/apex-defi/types.js +3 -0
- package/build/dex/{usual-bond → apex-defi}/types.js.map +1 -1
- package/build/dex/apex-defi/utils.d.ts +46 -0
- package/build/dex/apex-defi/utils.js +133 -0
- package/build/dex/apex-defi/utils.js.map +1 -0
- package/build/dex/maker-psm/maker-psm-event-pool.d.ts +43 -0
- package/build/dex/maker-psm/maker-psm-event-pool.js +132 -0
- package/build/dex/maker-psm/maker-psm-event-pool.js.map +1 -0
- package/build/dex/miro-migrator/miro-migrator-state.d.ts +27 -0
- package/build/dex/miro-migrator/miro-migrator-state.js +89 -0
- package/build/dex/miro-migrator/miro-migrator-state.js.map +1 -0
- package/build/dex/{usual-bond → stabull}/config.d.ts +1 -1
- package/build/dex/stabull/config.js +177 -0
- package/build/dex/stabull/config.js.map +1 -0
- package/build/dex/{se-vlr/se-vlr-pool.d.ts → stabull/stabull-pool.d.ts} +13 -6
- package/build/dex/stabull/stabull-pool.js +113 -0
- package/build/dex/stabull/stabull-pool.js.map +1 -0
- package/build/dex/stabull/stabull.d.ts +55 -0
- package/build/dex/stabull/stabull.js +286 -0
- package/build/dex/stabull/stabull.js.map +1 -0
- package/build/dex/stabull/types.d.ts +21 -0
- package/build/dex/stabull/types.js +3 -0
- package/build/dex/stabull/types.js.map +1 -0
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js +56 -0
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/Position.d.ts +6 -0
- package/build/dex/uniswap-v4/contract-math/Position.js +29 -0
- package/build/dex/uniswap-v4/contract-math/Position.js.map +1 -1
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.d.ts +7 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js +28 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.d.ts +0 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js +2 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.d.ts +7 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js +28 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.d.ts +0 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.js +2 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/index.d.ts +1 -0
- package/build/dex/uniswap-v4/hooks/index.js +9 -0
- package/build/dex/uniswap-v4/hooks/index.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/spot.d.ts +15 -0
- package/build/dex/uniswap-v4/hooks/spot.js +109 -0
- package/build/dex/uniswap-v4/hooks/spot.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/template.d.ts +150 -0
- package/build/dex/uniswap-v4/hooks/template.js +104 -0
- package/build/dex/uniswap-v4/hooks/template.js.map +1 -0
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.d.ts +26 -0
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.js +75 -0
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.js.map +1 -0
- package/build/dex/usual/usual-usdc-usdc.d.ts +17 -0
- package/build/dex/usual/usual-usdc-usdc.js +59 -0
- package/build/dex/usual/usual-usdc-usdc.js.map +1 -0
- package/build/dex/{se-vlr → yo}/config.d.ts +1 -1
- package/build/dex/yo/config.js +21 -0
- package/build/dex/yo/config.js.map +1 -0
- package/build/dex/yo/types.d.ts +13 -0
- package/build/dex/yo/types.js +3 -0
- package/build/dex/{se-vlr → yo}/types.js.map +1 -1
- package/build/dex/yo/yo-pool.d.ts +13 -0
- package/build/dex/yo/yo-pool.js +26 -0
- package/build/dex/yo/yo-pool.js.map +1 -0
- package/build/dex/yo/yo.d.ts +39 -0
- package/build/dex/yo/yo.js +248 -0
- package/build/dex/yo/yo.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.js +10 -4
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/implementations/api-paraswap-sdk.d.ts +25 -0
- package/build/implementations/api-paraswap-sdk.js +102 -0
- package/build/implementations/api-paraswap-sdk.js.map +1 -0
- package/package.json +1 -1
- package/build/abi/Jarvis.json +0 -1172
- package/build/abi/Onebit.json +0 -736
- package/build/abi/Shell.json +0 -1294
- package/build/abi/TraderJoeV2Router.json +0 -50
- package/build/abi/wUSDM.json +0 -757
- package/build/abi/zrx.v2.json +0 -1967
- package/build/abi/zrx.v3.json +0 -3454
- package/build/abi/zrx.v4.json +0 -2193
- package/build/dex/OneInchLp.d.ts +0 -24
- package/build/dex/OneInchLp.js +0 -43
- package/build/dex/OneInchLp.js.map +0 -1
- package/build/dex/bProtocol/bProtocol.d.ts +0 -15
- package/build/dex/bProtocol/bProtocol.js +0 -56
- package/build/dex/bProtocol/bProtocol.js.map +0 -1
- package/build/dex/bProtocol/types.d.ts +0 -11
- package/build/dex/bProtocol/types.js +0 -8
- package/build/dex/bProtocol/types.js.map +0 -1
- package/build/dex/jarvis.d.ts +0 -56
- package/build/dex/jarvis.js +0 -163
- package/build/dex/jarvis.js.map +0 -1
- package/build/dex/mStable.d.ts +0 -44
- package/build/dex/mStable.js +0 -75
- package/build/dex/mStable.js.map +0 -1
- package/build/dex/onebit/onebit.d.ts +0 -16
- package/build/dex/onebit/onebit.js +0 -61
- package/build/dex/onebit/onebit.js.map +0 -1
- package/build/dex/onebit/types.d.ts +0 -14
- package/build/dex/onebit/types.js +0 -8
- package/build/dex/onebit/types.js.map +0 -1
- package/build/dex/se-vlr/config.js +0 -24
- package/build/dex/se-vlr/config.js.map +0 -1
- package/build/dex/se-vlr/se-vlr-pool.js +0 -70
- package/build/dex/se-vlr/se-vlr-pool.js.map +0 -1
- package/build/dex/se-vlr/se-vlr.d.ts +0 -35
- package/build/dex/se-vlr/se-vlr.js +0 -131
- package/build/dex/se-vlr/se-vlr.js.map +0 -1
- package/build/dex/se-vlr/types.d.ts +0 -6
- package/build/dex/shell.d.ts +0 -25
- package/build/dex/shell.js +0 -41
- package/build/dex/shell.js.map +0 -1
- package/build/dex/trader-joe-v2.d.ts +0 -40
- package/build/dex/trader-joe-v2.js +0 -74
- package/build/dex/trader-joe-v2.js.map +0 -1
- package/build/dex/uniswap-v3/uniswap-v3-new.d.ts +0 -94
- package/build/dex/uniswap-v3/uniswap-v3-new.js +0 -923
- package/build/dex/uniswap-v3/uniswap-v3-new.js.map +0 -1
- package/build/dex/usual-bond/config.js +0 -13
- package/build/dex/usual-bond/config.js.map +0 -1
- package/build/dex/usual-bond/types.d.ts +0 -7
- package/build/dex/usual-bond/usual-bond.js +0 -176
- package/build/dex/usual-bond/usual-bond.js.map +0 -1
- package/build/dex/wusdm/config.d.ts +0 -3
- package/build/dex/wusdm/config.js +0 -43
- package/build/dex/wusdm/config.js.map +0 -1
- package/build/dex/wusdm/constants.d.ts +0 -2
- package/build/dex/wusdm/constants.js +0 -6
- package/build/dex/wusdm/constants.js.map +0 -1
- package/build/dex/wusdm/types.d.ts +0 -18
- package/build/dex/wusdm/types.js +0 -11
- package/build/dex/wusdm/types.js.map +0 -1
- package/build/dex/wusdm/wusdm-pool.d.ts +0 -21
- package/build/dex/wusdm/wusdm-pool.js +0 -74
- package/build/dex/wusdm/wusdm-pool.js.map +0 -1
- package/build/dex/wusdm/wusdm.d.ts +0 -46
- package/build/dex/wusdm/wusdm.js +0 -243
- package/build/dex/wusdm/wusdm.js.map +0 -1
- package/build/dex/zerox/config.d.ts +0 -2
- package/build/dex/zerox/config.js +0 -33
- package/build/dex/zerox/config.js.map +0 -1
- package/build/dex/zerox/index.d.ts +0 -22
- package/build/dex/zerox/index.js +0 -225
- package/build/dex/zerox/index.js.map +0 -1
- package/build/dex/zerox/order.d.ts +0 -88
- package/build/dex/zerox/order.js +0 -53
- package/build/dex/zerox/order.js.map +0 -1
- package/build/dex/zerox/types.d.ts +0 -73
- package/build/dex/zerox/types.js +0 -21
- package/build/dex/zerox/types.js.map +0 -1
- /package/build/dex/{se-vlr → aave-pt-to-underlying}/types.js +0 -0
- /package/build/dex/{usual-bond → aave-pt-to-usdc}/types.js +0 -0
|
@@ -1,923 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.UniswapV3 = exports.UNISWAPV3_QUOTE_GASLIMIT = exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = exports.PoolsRegistryHashKey = void 0;
|
|
40
|
-
const abi_1 = require("@ethersproject/abi");
|
|
41
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
42
|
-
const solidity_1 = require("@ethersproject/solidity");
|
|
43
|
-
const constants_1 = require("../../constants");
|
|
44
|
-
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
45
|
-
const utils_1 = require("../../utils");
|
|
46
|
-
const types_1 = require("./types");
|
|
47
|
-
const simple_exchange_1 = require("../simple-exchange");
|
|
48
|
-
const config_1 = require("./config");
|
|
49
|
-
const uniswap_v3_pool_1 = require("./uniswap-v3-pool");
|
|
50
|
-
const UniswapV3Router_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3Router.abi.json"));
|
|
51
|
-
const UniswapV3QuoterV2_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3QuoterV2.abi.json"));
|
|
52
|
-
const UniswapMulti_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapMulti.abi.json"));
|
|
53
|
-
const DirectSwap_json_1 = __importDefault(require("../../abi/DirectSwap.json"));
|
|
54
|
-
const UniswapV3StateMulticall_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json"));
|
|
55
|
-
const constants_2 = require("./constants");
|
|
56
|
-
const ts_essentials_1 = require("ts-essentials");
|
|
57
|
-
const uniswap_v3_math_1 = require("./contract-math/uniswap-v3-math");
|
|
58
|
-
const uniswap_v3_factory_1 = require("./uniswap-v3-factory");
|
|
59
|
-
const utils_2 = require("ethers/lib/utils");
|
|
60
|
-
const utils_3 = require("../../executor/utils");
|
|
61
|
-
const utils_4 = require("../../lib/tokens/utils");
|
|
62
|
-
exports.PoolsRegistryHashKey = `${constants_1.CACHE_PREFIX}_poolsRegistry`;
|
|
63
|
-
exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|
64
|
-
exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
|
|
65
|
-
exports.UNISWAPV3_QUOTE_GASLIMIT = 200_000;
|
|
66
|
-
class UniswapV3 extends simple_exchange_1.SimpleExchange {
|
|
67
|
-
network;
|
|
68
|
-
dexHelper;
|
|
69
|
-
adapters;
|
|
70
|
-
routerIface;
|
|
71
|
-
quoterIface;
|
|
72
|
-
config;
|
|
73
|
-
poolsToPreload;
|
|
74
|
-
factory;
|
|
75
|
-
isFeeOnTransferSupported = false;
|
|
76
|
-
eventPools = {};
|
|
77
|
-
hasConstantPriceLargeAmounts = false;
|
|
78
|
-
needWrapNative = true;
|
|
79
|
-
directSwapIface = new abi_1.Interface(DirectSwap_json_1.default);
|
|
80
|
-
intervalTask;
|
|
81
|
-
static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(lodash_1.default.pick(config_1.UniswapV3Config, [
|
|
82
|
-
'UniswapV3',
|
|
83
|
-
'SushiSwapV3',
|
|
84
|
-
'QuickSwapV3.1',
|
|
85
|
-
'SpookySwapV3',
|
|
86
|
-
'RamsesV2',
|
|
87
|
-
'ChronosV3',
|
|
88
|
-
'Retro',
|
|
89
|
-
'BaseswapV3',
|
|
90
|
-
'PharaohV2',
|
|
91
|
-
'AlienBaseV3',
|
|
92
|
-
'OkuTradeV3',
|
|
93
|
-
]));
|
|
94
|
-
logger;
|
|
95
|
-
uniswapMulti;
|
|
96
|
-
stateMultiContract;
|
|
97
|
-
notExistingPoolSetKey;
|
|
98
|
-
constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, routerIface = new abi_1.Interface(UniswapV3Router_abi_json_1.default), quoterIface = new abi_1.Interface(UniswapV3QuoterV2_abi_json_1.default), config = config_1.UniswapV3Config[dexKey][network], poolsToPreload = config_1.PoolsToPreload[dexKey]?.[network] || []) {
|
|
99
|
-
super(dexHelper, dexKey);
|
|
100
|
-
this.network = network;
|
|
101
|
-
this.dexHelper = dexHelper;
|
|
102
|
-
this.adapters = adapters;
|
|
103
|
-
this.routerIface = routerIface;
|
|
104
|
-
this.quoterIface = quoterIface;
|
|
105
|
-
this.config = config;
|
|
106
|
-
this.poolsToPreload = poolsToPreload;
|
|
107
|
-
this.logger = dexHelper.getLogger(dexKey + '-' + network);
|
|
108
|
-
this.uniswapMulti = new this.dexHelper.web3Provider.eth.Contract(UniswapMulti_abi_json_1.default, this.config.uniswapMulticall);
|
|
109
|
-
this.stateMultiContract = new this.dexHelper.web3Provider.eth.Contract(this.config.stateMultiCallAbi !== undefined
|
|
110
|
-
? this.config.stateMultiCallAbi
|
|
111
|
-
: UniswapV3StateMulticall_abi_json_1.default, this.config.stateMulticall);
|
|
112
|
-
// To receive revert reasons
|
|
113
|
-
this.dexHelper.web3Provider.eth.handleRevert = false;
|
|
114
|
-
// Normalize once all config addresses and use across all scenarios
|
|
115
|
-
this.config = this._toLowerForAllConfigAddresses();
|
|
116
|
-
this.notExistingPoolSetKey =
|
|
117
|
-
`${constants_1.CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
|
|
118
|
-
this.factory = this.getFactoryInstance();
|
|
119
|
-
}
|
|
120
|
-
get supportedFees() {
|
|
121
|
-
return this.config.supportedFees;
|
|
122
|
-
}
|
|
123
|
-
getAdapters(side) {
|
|
124
|
-
return this.adapters[side] ? this.adapters[side] : null;
|
|
125
|
-
}
|
|
126
|
-
getPoolIdentifier(srcAddress, destAddress, fee, tickSpacing) {
|
|
127
|
-
const tokenAddresses = this._sortTokens(srcAddress, destAddress).join('_');
|
|
128
|
-
if (tickSpacing) {
|
|
129
|
-
return `${this.dexKey}_${tokenAddresses}_${fee}_${tickSpacing}`;
|
|
130
|
-
}
|
|
131
|
-
return `${this.dexKey}_${tokenAddresses}_${fee}`;
|
|
132
|
-
}
|
|
133
|
-
async initializePricing(blockNumber) {
|
|
134
|
-
// Init listening to new pools creation
|
|
135
|
-
await this.factory.initialize(blockNumber);
|
|
136
|
-
// This is only for testing, because cold pool fetching is goes out of
|
|
137
|
-
// FETCH_POOL_INDENTIFIER_TIMEOUT range
|
|
138
|
-
await Promise.all(this.poolsToPreload.map(async (pool) => Promise.all(this.config.supportedFees.map(async (fee) => this.getPool(pool.token0, pool.token1, fee, blockNumber)))));
|
|
139
|
-
if (!this.dexHelper.config.isSlave) {
|
|
140
|
-
const cleanExpiredNotExistingPoolsKeys = async () => {
|
|
141
|
-
const maxTimestamp = Date.now() - exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS;
|
|
142
|
-
await this.dexHelper.cache.zremrangebyscore(this.notExistingPoolSetKey, 0, maxTimestamp);
|
|
143
|
-
};
|
|
144
|
-
void cleanExpiredNotExistingPoolsKeys();
|
|
145
|
-
this.intervalTask = setInterval(cleanExpiredNotExistingPoolsKeys.bind(this), exports.UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/*
|
|
149
|
-
* When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
|
|
150
|
-
* Once the pool is created, it gets immediately flagged
|
|
151
|
-
*/
|
|
152
|
-
onPoolCreatedDeleteFromNonExistingSet() {
|
|
153
|
-
return async ({ token0, token1, fee }) => {
|
|
154
|
-
const logPrefix = '[onPoolCreatedDeleteFromNonExistingSet]';
|
|
155
|
-
const [_token0, _token1] = this._sortTokens(token0, token1);
|
|
156
|
-
const poolKey = `${_token0}_${_token1}_${fee}`;
|
|
157
|
-
// consider doing it only from master pool for less calls to distant cache
|
|
158
|
-
// delete entry locally to let local instance discover the pool
|
|
159
|
-
delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
|
|
160
|
-
try {
|
|
161
|
-
this.logger.info(`${logPrefix} delete pool from not existing set=${this.notExistingPoolSetKey}; key=${poolKey}`);
|
|
162
|
-
// delete pool record from set
|
|
163
|
-
const result = await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
|
|
164
|
-
this.logger.info(`${logPrefix} delete pool from not existing set=${this.notExistingPoolSetKey}; key=${poolKey}; result: ${result}`);
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
this.logger.error(`${logPrefix} ERROR: failed to delete pool from set: set=${this.notExistingPoolSetKey}; key=${poolKey}`, error);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async getPool(srcAddress, destAddress, fee, blockNumber, tickSpacing) {
|
|
172
|
-
let pool = this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee, tickSpacing)];
|
|
173
|
-
if (pool === null)
|
|
174
|
-
return null;
|
|
175
|
-
if (pool) {
|
|
176
|
-
if (!pool.initFailed) {
|
|
177
|
-
return pool;
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
// if init failed then prefer to early return pool with empty state to fallback to rpc call
|
|
181
|
-
if (++pool.initRetryAttemptCount % this.config.initRetryFrequency !==
|
|
182
|
-
0) {
|
|
183
|
-
return pool;
|
|
184
|
-
}
|
|
185
|
-
// else pursue with re-try initialization
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const [token0, token1] = this._sortTokens(srcAddress, destAddress);
|
|
189
|
-
let key = `${token0}_${token1}_${fee}`.toLowerCase();
|
|
190
|
-
if (tickSpacing) {
|
|
191
|
-
key = `${key}_${tickSpacing}`;
|
|
192
|
-
}
|
|
193
|
-
if (!pool) {
|
|
194
|
-
const notExistingPoolScore = await this.dexHelper.cache.zscore(this.notExistingPoolSetKey, key);
|
|
195
|
-
const poolDoesNotExist = notExistingPoolScore !== null;
|
|
196
|
-
if (poolDoesNotExist) {
|
|
197
|
-
this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee, tickSpacing)] = null;
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
this.logger.trace(`starting to listen to new pool: ${key}`);
|
|
202
|
-
pool = pool || this.getPoolInstance(token0, token1, fee, tickSpacing);
|
|
203
|
-
try {
|
|
204
|
-
await pool.initialize(blockNumber, {
|
|
205
|
-
initCallback: (state) => {
|
|
206
|
-
//really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
|
|
207
|
-
pool.addressesSubscribed[0] = state.pool;
|
|
208
|
-
pool.poolAddress = state.pool;
|
|
209
|
-
pool.initFailed = false;
|
|
210
|
-
pool.initRetryAttemptCount = 0;
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
catch (e) {
|
|
215
|
-
if (e instanceof Error && e.message.endsWith('Pool does not exist')) {
|
|
216
|
-
// no need to await we want the set to have the pool key but it's not blocking
|
|
217
|
-
this.dexHelper.cache.zadd(this.notExistingPoolSetKey, [Date.now(), key], 'NX');
|
|
218
|
-
// Pool does not exist for this feeCode, so we can set it to null
|
|
219
|
-
// to prevent more requests for this pool
|
|
220
|
-
pool = null;
|
|
221
|
-
this.logger.trace(`${this.dexHelper}: Pool: srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} not found`, e);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
// on unknown error mark as failed and increase retryCount for retry init strategy
|
|
225
|
-
// note: state would be null by default which allows to fallback
|
|
226
|
-
this.logger.warn(`${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool.initRetryAttemptCount}`, e);
|
|
227
|
-
pool.initFailed = true;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (pool !== null) {
|
|
231
|
-
const allEventPools = Object.values(this.eventPools);
|
|
232
|
-
// if pool was created, delete pool record from non existing set
|
|
233
|
-
this.dexHelper.cache
|
|
234
|
-
.zrem(this.notExistingPoolSetKey, [key])
|
|
235
|
-
.catch(() => { });
|
|
236
|
-
this.logger.info(`starting to listen to new non-null pool: ${key}. Already following ${allEventPools
|
|
237
|
-
// Not that I like this reduce, but since it is done only on initialization, expect this to be ok
|
|
238
|
-
.reduce((acc, curr) => (curr !== null ? ++acc : acc), 0)} non-null pools or ${allEventPools.length} total pools`);
|
|
239
|
-
}
|
|
240
|
-
this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee, tickSpacing)] = pool;
|
|
241
|
-
return pool;
|
|
242
|
-
}
|
|
243
|
-
getPoolInstance(token0, token1, fee, tickSpacing) {
|
|
244
|
-
const poolImplementation = this.config.eventPoolImplementation !== undefined
|
|
245
|
-
? this.config.eventPoolImplementation
|
|
246
|
-
: uniswap_v3_pool_1.UniswapV3EventPool;
|
|
247
|
-
return new poolImplementation(this.dexHelper, this.dexKey, this.stateMultiContract, this.config.decodeStateMultiCallResultWithRelativeBitmaps, this.erc20Interface, this.config.factory, fee, token0, token1, this.logger, this.cacheStateKey, this.config.initHash, tickSpacing);
|
|
248
|
-
}
|
|
249
|
-
getFactoryInstance() {
|
|
250
|
-
const factoryImplementation = this.config.factoryImplementation !== undefined
|
|
251
|
-
? this.config.factoryImplementation
|
|
252
|
-
: uniswap_v3_factory_1.UniswapV3Factory;
|
|
253
|
-
return new factoryImplementation(this.dexHelper, this.dexKey, this.config.factory, this.logger, this.onPoolCreatedDeleteFromNonExistingSet().bind(this));
|
|
254
|
-
}
|
|
255
|
-
async addMasterPool(poolKey, blockNumber) {
|
|
256
|
-
const _pairs = await this.dexHelper.cache.hget(exports.PoolsRegistryHashKey, `${this.cacheStateKey}_${poolKey}`);
|
|
257
|
-
if (!_pairs) {
|
|
258
|
-
this.logger.warn(`did not find poolConfig in for key ${exports.PoolsRegistryHashKey} ${this.cacheStateKey}_${poolKey}`);
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
const poolInfo = JSON.parse(_pairs);
|
|
262
|
-
const pool = await this.getPool(poolInfo.token0, poolInfo.token1, BigInt(poolInfo.fee), blockNumber, poolInfo.tickSpacing !== undefined
|
|
263
|
-
? BigInt(poolInfo.tickSpacing)
|
|
264
|
-
: undefined);
|
|
265
|
-
if (!pool) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
271
|
-
const _srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
272
|
-
const _destToken = this.dexHelper.config.wrapETH(destToken);
|
|
273
|
-
const [_srcAddress, _destAddress] = this._getLoweredAddresses(_srcToken, _destToken);
|
|
274
|
-
if (_srcAddress === _destAddress)
|
|
275
|
-
return [];
|
|
276
|
-
const pools = (await this.getPoolsForIdentifiers(_srcAddress, _destAddress, blockNumber)).filter(pool => pool);
|
|
277
|
-
if (pools.length === 0)
|
|
278
|
-
return [];
|
|
279
|
-
return pools.map(pool => this.getPoolIdentifier(_srcAddress, _destAddress, pool.feeCode, pool.tickSpacing));
|
|
280
|
-
}
|
|
281
|
-
async getPoolsForIdentifiers(srcAddress, destAddress, blockNumber) {
|
|
282
|
-
return Promise.all(this.supportedFees.map(async (fee) => this.getPool(srcAddress, destAddress, fee, blockNumber)));
|
|
283
|
-
}
|
|
284
|
-
async getPricingFromRpc(from, to, amounts, side, pools, states) {
|
|
285
|
-
if (pools.length === 0) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
this.logger.warn(`fallback to rpc for ${pools.length} pool(s)`);
|
|
289
|
-
const unitVolume = (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? from : to).decimals);
|
|
290
|
-
const chunks = amounts.length - 1;
|
|
291
|
-
const _width = Math.floor(chunks / this.config.chunksCount);
|
|
292
|
-
const _amounts = [unitVolume].concat(Array.from(Array(this.config.chunksCount).keys()).map(i => amounts[(i + 1) * _width]));
|
|
293
|
-
// for each pool:
|
|
294
|
-
// 1 balanceOf call
|
|
295
|
-
// {amounts.length quote calls
|
|
296
|
-
const calldata = pools.map(pool => {
|
|
297
|
-
const balanceCall = {
|
|
298
|
-
target: side == constants_1.SwapSide.SELL ? from.address : to.address,
|
|
299
|
-
gasLimit: 10_000,
|
|
300
|
-
calldata: (0, utils_4.getBalanceERC20)(pool.poolAddress),
|
|
301
|
-
};
|
|
302
|
-
const quoteCalls = _amounts.map(_amount => ({
|
|
303
|
-
target: this.config.quoter,
|
|
304
|
-
gasLimit: exports.UNISWAPV3_QUOTE_GASLIMIT,
|
|
305
|
-
callData: side === constants_1.SwapSide.SELL
|
|
306
|
-
? this.quoterIface.encodeFunctionData('quoteExactInputSingle', [
|
|
307
|
-
[
|
|
308
|
-
from.address,
|
|
309
|
-
to.address,
|
|
310
|
-
_amount.toString(),
|
|
311
|
-
pool.feeCodeAsString,
|
|
312
|
-
0, //sqrtPriceLimitX96
|
|
313
|
-
],
|
|
314
|
-
])
|
|
315
|
-
: this.quoterIface.encodeFunctionData('quoteExactOutputSingle', [
|
|
316
|
-
[
|
|
317
|
-
from.address,
|
|
318
|
-
to.address,
|
|
319
|
-
_amount.toString(),
|
|
320
|
-
pool.feeCodeAsString,
|
|
321
|
-
0, //sqrtPriceLimitX96
|
|
322
|
-
],
|
|
323
|
-
]),
|
|
324
|
-
}));
|
|
325
|
-
return [
|
|
326
|
-
// balanceCall,
|
|
327
|
-
...quoteCalls,
|
|
328
|
-
];
|
|
329
|
-
});
|
|
330
|
-
const data = await this.uniswapMulti.methods
|
|
331
|
-
.multicall(calldata.flat())
|
|
332
|
-
.call();
|
|
333
|
-
const decode = (j) => {
|
|
334
|
-
if (!data.returnData[j].success) {
|
|
335
|
-
return 0n;
|
|
336
|
-
}
|
|
337
|
-
const decoded = abi_1.defaultAbiCoder.decode(['uint256'], data.returnData[j].returnData);
|
|
338
|
-
return BigInt(decoded[0].toString());
|
|
339
|
-
};
|
|
340
|
-
let i = 0;
|
|
341
|
-
return pools
|
|
342
|
-
.map((pool, index) => {
|
|
343
|
-
const balance = decode(i++);
|
|
344
|
-
console.log(pool.poolAddress, balance);
|
|
345
|
-
if (balance < amounts[amounts.length - 1]) {
|
|
346
|
-
this.logger.warn(`[${this.network}][${pool.parentName}] have no balance ${pool.poolAddress} ${from.address} ${to.address}. (Balance: ${balance})`);
|
|
347
|
-
// move index to the next pool
|
|
348
|
-
i += amounts.length;
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
const _rates = _amounts.map(() => decode(i++));
|
|
352
|
-
const unit = _rates[0];
|
|
353
|
-
const prices = (0, utils_1.interpolate)(_amounts.slice(1), _rates.slice(1), amounts, side);
|
|
354
|
-
return {
|
|
355
|
-
prices,
|
|
356
|
-
unit,
|
|
357
|
-
data: {
|
|
358
|
-
path: [
|
|
359
|
-
{
|
|
360
|
-
tokenIn: from.address,
|
|
361
|
-
tokenOut: to.address,
|
|
362
|
-
fee: pool.feeCodeAsString,
|
|
363
|
-
currentFee: states[index]?.fee.toString(),
|
|
364
|
-
},
|
|
365
|
-
],
|
|
366
|
-
exchange: pool.poolAddress,
|
|
367
|
-
},
|
|
368
|
-
poolIdentifier: this.getPoolIdentifier(pool.token0, pool.token1, pool.feeCode, pool.tickSpacing),
|
|
369
|
-
exchange: this.dexKey,
|
|
370
|
-
gasCost: prices.map(p => (p === 0n ? 0 : exports.UNISWAPV3_QUOTE_GASLIMIT)),
|
|
371
|
-
poolAddresses: [pool.poolAddress],
|
|
372
|
-
};
|
|
373
|
-
})
|
|
374
|
-
.filter(prices => prices !== null);
|
|
375
|
-
}
|
|
376
|
-
async getSelectedPools(srcAddress, destAddress, blockNumber) {
|
|
377
|
-
return Promise.all(this.supportedFees.map(async (fee) => {
|
|
378
|
-
const locallyFoundPool = this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)];
|
|
379
|
-
if (locallyFoundPool)
|
|
380
|
-
return locallyFoundPool;
|
|
381
|
-
const newlyFetchedPool = await this.getPool(srcAddress, destAddress, fee, blockNumber);
|
|
382
|
-
return newlyFetchedPool;
|
|
383
|
-
}));
|
|
384
|
-
}
|
|
385
|
-
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
386
|
-
try {
|
|
387
|
-
const _srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
388
|
-
const _destToken = this.dexHelper.config.wrapETH(destToken);
|
|
389
|
-
const [_srcAddress, _destAddress] = this._getLoweredAddresses(_srcToken, _destToken);
|
|
390
|
-
if (_srcAddress === _destAddress)
|
|
391
|
-
return null;
|
|
392
|
-
let selectedPools = [];
|
|
393
|
-
if (!limitPools) {
|
|
394
|
-
selectedPools = (await this.getSelectedPools(_srcAddress, _destAddress, blockNumber)).filter(utils_1.isTruthy);
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
const pairIdentifierWithoutFee = this.getPoolIdentifier(_srcAddress, _destAddress, 0n).slice(0, -1);
|
|
398
|
-
const poolIdentifiers = limitPools.filter(identifier => identifier.startsWith(pairIdentifierWithoutFee));
|
|
399
|
-
selectedPools = (await Promise.all(poolIdentifiers.map(async (identifier) => {
|
|
400
|
-
let locallyFoundPool = this.eventPools[identifier];
|
|
401
|
-
if (locallyFoundPool)
|
|
402
|
-
return locallyFoundPool;
|
|
403
|
-
const [, srcAddress, destAddress, fee, tickSpacing] = identifier.split('_');
|
|
404
|
-
const newlyFetchedPool = await this.getPool(srcAddress, destAddress, BigInt(fee), blockNumber, tickSpacing !== undefined ? BigInt(tickSpacing) : undefined);
|
|
405
|
-
return newlyFetchedPool;
|
|
406
|
-
}))).filter(utils_1.isTruthy);
|
|
407
|
-
}
|
|
408
|
-
if (selectedPools.length === 0)
|
|
409
|
-
return null;
|
|
410
|
-
await Promise.all(selectedPools.map(pool => pool.checkState(blockNumber)));
|
|
411
|
-
const poolsToUse = selectedPools.reduce((acc, pool) => {
|
|
412
|
-
let state = pool.getState(blockNumber);
|
|
413
|
-
if (state === null) {
|
|
414
|
-
this.logger.trace(`${this.dexKey}: State === null. Fallback to rpc ${pool.name}`);
|
|
415
|
-
// as we generate state (if nullified) in previous Promise.all, here should only be pools with failed initialization
|
|
416
|
-
acc.poolWithoutState.push(pool);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
acc.poolWithState.push(pool);
|
|
420
|
-
}
|
|
421
|
-
return acc;
|
|
422
|
-
}, {
|
|
423
|
-
poolWithState: [],
|
|
424
|
-
poolWithoutState: [],
|
|
425
|
-
});
|
|
426
|
-
poolsToUse.poolWithoutState.forEach(pool => {
|
|
427
|
-
this.logger.warn(`UniV3: Pool ${pool.name} on ${this.dexKey} has no state. Fallback to rpc`);
|
|
428
|
-
});
|
|
429
|
-
const states = poolsToUse.poolWithState.map(p => p.getState(blockNumber));
|
|
430
|
-
const rpcResultsPromise = this.getPricingFromRpc(_srcToken, _destToken, amounts, side, this.network === constants_1.Network.ZKEVM ? [] : poolsToUse.poolWithoutState, this.network === constants_1.Network.ZKEVM ? [] : states);
|
|
431
|
-
const unitAmount = (0, utils_1.getBigIntPow)(side == constants_1.SwapSide.SELL ? _srcToken.decimals : _destToken.decimals);
|
|
432
|
-
const _amounts = [...amounts.slice(1)];
|
|
433
|
-
const [token0] = this._sortTokens(_srcAddress, _destAddress);
|
|
434
|
-
const zeroForOne = token0 === _srcAddress ? true : false;
|
|
435
|
-
const result = await Promise.all(poolsToUse.poolWithState.map(async (pool, i) => {
|
|
436
|
-
const state = states[i];
|
|
437
|
-
if (state.liquidity <= 0n) {
|
|
438
|
-
if (state.liquidity < 0) {
|
|
439
|
-
this.logger.error(`${this.dexKey}-${this.network}: ${pool.poolAddress} pool has negative liquidity: ${state.liquidity}. Find with key: ${pool.mapKey}`);
|
|
440
|
-
}
|
|
441
|
-
this.logger.trace(`pool have 0 liquidity`);
|
|
442
|
-
return null;
|
|
443
|
-
}
|
|
444
|
-
const balanceDestToken = _destAddress === pool.token0 ? state.balance0 : state.balance1;
|
|
445
|
-
const unitResult = this._getOutputs(state, [unitAmount], zeroForOne, side, balanceDestToken);
|
|
446
|
-
const pricesResult = this._getOutputs(state, _amounts, zeroForOne, side, balanceDestToken);
|
|
447
|
-
if (!unitResult || !pricesResult) {
|
|
448
|
-
this.logger.debug('Prices or unit is not calculated');
|
|
449
|
-
return null;
|
|
450
|
-
}
|
|
451
|
-
const prices = [0n, ...pricesResult.outputs];
|
|
452
|
-
const gasCost = [
|
|
453
|
-
0,
|
|
454
|
-
...pricesResult.outputs.map((p, index) => {
|
|
455
|
-
if (p == 0n) {
|
|
456
|
-
return 0;
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
return (constants_2.UNISWAPV3_POOL_SEARCH_OVERHEAD +
|
|
460
|
-
constants_2.UNISWAPV3_TICK_BASE_OVERHEAD +
|
|
461
|
-
pricesResult.tickCounts[index] * constants_2.UNISWAPV3_TICK_GAS_COST);
|
|
462
|
-
}
|
|
463
|
-
}),
|
|
464
|
-
];
|
|
465
|
-
return {
|
|
466
|
-
unit: unitResult.outputs[0],
|
|
467
|
-
prices,
|
|
468
|
-
data: this.prepareData(_srcAddress, _destAddress, pool, state),
|
|
469
|
-
poolIdentifier: this.getPoolIdentifier(pool.token0, pool.token1, pool.feeCode, pool.tickSpacing),
|
|
470
|
-
exchange: this.dexKey,
|
|
471
|
-
gasCost: gasCost,
|
|
472
|
-
poolAddresses: [pool.poolAddress],
|
|
473
|
-
};
|
|
474
|
-
}));
|
|
475
|
-
const rpcResults = await rpcResultsPromise;
|
|
476
|
-
const notNullResult = result.filter(res => res !== null);
|
|
477
|
-
if (rpcResults) {
|
|
478
|
-
rpcResults.forEach(r => {
|
|
479
|
-
if (r) {
|
|
480
|
-
notNullResult.push(r);
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
return notNullResult;
|
|
485
|
-
}
|
|
486
|
-
catch (e) {
|
|
487
|
-
this.logger.error(`Error_getPricesVolume ${srcToken.symbol || srcToken.address}, ${destToken.symbol || destToken.address}, ${side}:`, e);
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
prepareData(srcAddress, destAddress, pool, state) {
|
|
492
|
-
return {
|
|
493
|
-
path: [
|
|
494
|
-
{
|
|
495
|
-
tokenIn: srcAddress,
|
|
496
|
-
tokenOut: destAddress,
|
|
497
|
-
fee: pool.feeCode.toString(),
|
|
498
|
-
currentFee: state.fee.toString(),
|
|
499
|
-
},
|
|
500
|
-
],
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
getCalldataGasCost(poolPrices) {
|
|
504
|
-
const gasCost = CALLDATA_GAS_COST.DEX_OVERHEAD +
|
|
505
|
-
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
506
|
-
// ParentStruct header
|
|
507
|
-
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
508
|
-
// ParentStruct -> path header
|
|
509
|
-
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
510
|
-
// ParentStruct -> deadline
|
|
511
|
-
CALLDATA_GAS_COST.TIMESTAMP +
|
|
512
|
-
// ParentStruct -> path (20+3+20 = 43 = 32+11 bytes)
|
|
513
|
-
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
514
|
-
CALLDATA_GAS_COST.FULL_WORD +
|
|
515
|
-
CALLDATA_GAS_COST.wordNonZeroBytes(11);
|
|
516
|
-
const arr = new Array(poolPrices.prices.length);
|
|
517
|
-
poolPrices.prices.forEach((p, index) => {
|
|
518
|
-
if (p == 0n) {
|
|
519
|
-
arr[index] = 0;
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
arr[index] = gasCost;
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
return arr;
|
|
526
|
-
}
|
|
527
|
-
getTokenFromAddress(address) {
|
|
528
|
-
// In this Dex decimals are not used
|
|
529
|
-
return { address, decimals: 0 };
|
|
530
|
-
}
|
|
531
|
-
async preProcessTransaction(optimalSwapExchange, srcToken, _0, _1, options) {
|
|
532
|
-
if (!options.isDirectMethod) {
|
|
533
|
-
return [
|
|
534
|
-
optimalSwapExchange,
|
|
535
|
-
{
|
|
536
|
-
deadline: BigInt((0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)()),
|
|
537
|
-
},
|
|
538
|
-
];
|
|
539
|
-
}
|
|
540
|
-
(0, ts_essentials_1.assert)(optimalSwapExchange.data !== undefined, `preProcessTransaction: data field is missing`);
|
|
541
|
-
let isApproved;
|
|
542
|
-
try {
|
|
543
|
-
isApproved = await this.dexHelper.augustusApprovals.hasApproval(options.executionContractAddress, this.dexHelper.config.wrapETH(srcToken).address, this.config.router);
|
|
544
|
-
}
|
|
545
|
-
catch (e) {
|
|
546
|
-
this.logger.error(`preProcessTransaction failed to retrieve allowance info: `, e);
|
|
547
|
-
}
|
|
548
|
-
return [
|
|
549
|
-
{
|
|
550
|
-
...optimalSwapExchange,
|
|
551
|
-
data: {
|
|
552
|
-
...optimalSwapExchange.data,
|
|
553
|
-
isApproved,
|
|
554
|
-
},
|
|
555
|
-
},
|
|
556
|
-
{
|
|
557
|
-
deadline: BigInt((0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)()),
|
|
558
|
-
},
|
|
559
|
-
];
|
|
560
|
-
}
|
|
561
|
-
getDirectParam(srcToken, destToken, srcAmount, destAmount, expectedAmount, data, side, permit, uuid, feePercent, deadline, partner, beneficiary, contractMethod) {
|
|
562
|
-
if (!UniswapV3.getDirectFunctionName().includes(contractMethod)) {
|
|
563
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
564
|
-
}
|
|
565
|
-
let isApproved = !!data.isApproved;
|
|
566
|
-
if (data.isApproved === undefined) {
|
|
567
|
-
this.logger.warn(`isApproved is undefined, defaulting to false`);
|
|
568
|
-
}
|
|
569
|
-
const path = this._encodePath(data.path, side);
|
|
570
|
-
const swapParams = [
|
|
571
|
-
srcToken,
|
|
572
|
-
destToken,
|
|
573
|
-
this.config.router,
|
|
574
|
-
srcAmount,
|
|
575
|
-
destAmount,
|
|
576
|
-
expectedAmount,
|
|
577
|
-
feePercent,
|
|
578
|
-
deadline,
|
|
579
|
-
partner,
|
|
580
|
-
isApproved,
|
|
581
|
-
beneficiary,
|
|
582
|
-
path,
|
|
583
|
-
permit,
|
|
584
|
-
(0, utils_1.uuidToBytes16)(uuid),
|
|
585
|
-
];
|
|
586
|
-
const encoder = (...params) => {
|
|
587
|
-
return this.directSwapIface.encodeFunctionData(side === constants_1.SwapSide.SELL
|
|
588
|
-
? constants_2.DirectMethods.directSell
|
|
589
|
-
: constants_2.DirectMethods.directBuy, [params]);
|
|
590
|
-
};
|
|
591
|
-
return {
|
|
592
|
-
params: swapParams,
|
|
593
|
-
encoder,
|
|
594
|
-
networkFee: '0',
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
static getDirectFunctionName() {
|
|
598
|
-
return [constants_2.DirectMethods.directSell, constants_2.DirectMethods.directBuy];
|
|
599
|
-
}
|
|
600
|
-
getDirectParamV6(srcToken, destToken, fromAmount, toAmount, quotedAmount, data, side, permit, uuid, partnerAndFee, beneficiary, blockNumber, contractMethod) {
|
|
601
|
-
if (!UniswapV3.getDirectFunctionNameV6().includes(contractMethod)) {
|
|
602
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
603
|
-
}
|
|
604
|
-
const path = this._encodePathV6(data.path, side);
|
|
605
|
-
const metadata = (0, utils_2.hexConcat)([
|
|
606
|
-
(0, utils_2.hexZeroPad)((0, utils_1.uuidToBytes16)(uuid), 16),
|
|
607
|
-
(0, utils_2.hexZeroPad)((0, utils_2.hexlify)(blockNumber), 16),
|
|
608
|
-
]);
|
|
609
|
-
const uniData = [
|
|
610
|
-
srcToken,
|
|
611
|
-
destToken,
|
|
612
|
-
fromAmount,
|
|
613
|
-
toAmount,
|
|
614
|
-
quotedAmount,
|
|
615
|
-
metadata,
|
|
616
|
-
// uuidToBytes16(uuid),
|
|
617
|
-
beneficiary,
|
|
618
|
-
path,
|
|
619
|
-
];
|
|
620
|
-
const swapParams = [uniData, partnerAndFee, permit];
|
|
621
|
-
const encoder = (...params) => {
|
|
622
|
-
return this.augustusV6Interface.encodeFunctionData(side === constants_1.SwapSide.SELL
|
|
623
|
-
? constants_2.DirectMethodsV6.directSell
|
|
624
|
-
: constants_2.DirectMethodsV6.directBuy, [...params]);
|
|
625
|
-
};
|
|
626
|
-
return {
|
|
627
|
-
params: swapParams,
|
|
628
|
-
encoder,
|
|
629
|
-
networkFee: '0',
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
static getDirectFunctionNameV6() {
|
|
633
|
-
return [constants_2.DirectMethodsV6.directSell, constants_2.DirectMethodsV6.directBuy];
|
|
634
|
-
}
|
|
635
|
-
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
636
|
-
const { path: rawPath } = data;
|
|
637
|
-
const path = this._encodePath(rawPath, side);
|
|
638
|
-
const payload = this.abiCoder.encodeParameter({
|
|
639
|
-
ParentStruct: {
|
|
640
|
-
path: 'bytes',
|
|
641
|
-
deadline: 'uint256',
|
|
642
|
-
},
|
|
643
|
-
}, {
|
|
644
|
-
path,
|
|
645
|
-
deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
646
|
-
});
|
|
647
|
-
return {
|
|
648
|
-
targetExchange: this.config.router,
|
|
649
|
-
payload,
|
|
650
|
-
networkFee: '0',
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
|
|
654
|
-
const swapFunction = side === constants_1.SwapSide.SELL
|
|
655
|
-
? types_1.UniswapV3Functions.exactInput
|
|
656
|
-
: types_1.UniswapV3Functions.exactOutput;
|
|
657
|
-
const path = this._encodePath(data.path, side);
|
|
658
|
-
const swapFunctionParams = side === constants_1.SwapSide.SELL
|
|
659
|
-
? {
|
|
660
|
-
recipient,
|
|
661
|
-
deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
662
|
-
amountIn: srcAmount,
|
|
663
|
-
amountOutMinimum: destAmount,
|
|
664
|
-
path,
|
|
665
|
-
}
|
|
666
|
-
: {
|
|
667
|
-
recipient,
|
|
668
|
-
deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
669
|
-
amountOut: destAmount,
|
|
670
|
-
amountInMaximum: srcAmount,
|
|
671
|
-
path,
|
|
672
|
-
};
|
|
673
|
-
const exchangeData = this.routerIface.encodeFunctionData(swapFunction, [
|
|
674
|
-
swapFunctionParams,
|
|
675
|
-
]);
|
|
676
|
-
return {
|
|
677
|
-
needWrapNative: this.needWrapNative,
|
|
678
|
-
dexFuncHasRecipient: true,
|
|
679
|
-
exchangeData,
|
|
680
|
-
targetExchange: this.config.router,
|
|
681
|
-
returnAmountPos: side === constants_1.SwapSide.SELL
|
|
682
|
-
? (0, utils_3.extractReturnAmountPosition)(this.routerIface, swapFunction, 'amountOut')
|
|
683
|
-
: undefined,
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
687
|
-
const swapFunction = side === constants_1.SwapSide.SELL
|
|
688
|
-
? types_1.UniswapV3Functions.exactInput
|
|
689
|
-
: types_1.UniswapV3Functions.exactOutput;
|
|
690
|
-
const path = this._encodePath(data.path, side);
|
|
691
|
-
const swapFunctionParams = side === constants_1.SwapSide.SELL
|
|
692
|
-
? {
|
|
693
|
-
recipient: this.augustusAddress,
|
|
694
|
-
deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
695
|
-
amountIn: srcAmount,
|
|
696
|
-
amountOutMinimum: destAmount,
|
|
697
|
-
path,
|
|
698
|
-
}
|
|
699
|
-
: {
|
|
700
|
-
recipient: this.augustusAddress,
|
|
701
|
-
deadline: (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
702
|
-
amountOut: destAmount,
|
|
703
|
-
amountInMaximum: srcAmount,
|
|
704
|
-
path,
|
|
705
|
-
};
|
|
706
|
-
const swapData = this.routerIface.encodeFunctionData(swapFunction, [
|
|
707
|
-
swapFunctionParams,
|
|
708
|
-
]);
|
|
709
|
-
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, this.config.router);
|
|
710
|
-
}
|
|
711
|
-
async getTopPoolsForToken(tokenAddress, limit) {
|
|
712
|
-
if (!this.config.subgraphURL)
|
|
713
|
-
return [];
|
|
714
|
-
const _tokenAddress = tokenAddress.toLowerCase();
|
|
715
|
-
const res = await this._querySubgraph(`query ($token: Bytes!, $count: Int) {
|
|
716
|
-
pools0: pools(first: $count, orderBy: totalValueLockedUSD, orderDirection: desc, where: {token0: $token}) {
|
|
717
|
-
id
|
|
718
|
-
token0 {
|
|
719
|
-
id
|
|
720
|
-
decimals
|
|
721
|
-
}
|
|
722
|
-
token1 {
|
|
723
|
-
id
|
|
724
|
-
decimals
|
|
725
|
-
}
|
|
726
|
-
totalValueLockedUSD
|
|
727
|
-
}
|
|
728
|
-
pools1: pools(first: $count, orderBy: totalValueLockedUSD, orderDirection: desc, where: {token1: $token}) {
|
|
729
|
-
id
|
|
730
|
-
token0 {
|
|
731
|
-
id
|
|
732
|
-
decimals
|
|
733
|
-
}
|
|
734
|
-
token1 {
|
|
735
|
-
id
|
|
736
|
-
decimals
|
|
737
|
-
}
|
|
738
|
-
totalValueLockedUSD
|
|
739
|
-
}
|
|
740
|
-
}`, {
|
|
741
|
-
token: _tokenAddress,
|
|
742
|
-
count: limit,
|
|
743
|
-
});
|
|
744
|
-
if (!(res && res.pools0 && res.pools1)) {
|
|
745
|
-
this.logger.error(`Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`);
|
|
746
|
-
return [];
|
|
747
|
-
}
|
|
748
|
-
const pools0 = lodash_1.default.map(res.pools0, pool => ({
|
|
749
|
-
exchange: this.dexKey,
|
|
750
|
-
address: pool.id.toLowerCase(),
|
|
751
|
-
connectorTokens: [
|
|
752
|
-
{
|
|
753
|
-
address: pool.token1.id.toLowerCase(),
|
|
754
|
-
decimals: parseInt(pool.token1.decimals),
|
|
755
|
-
},
|
|
756
|
-
],
|
|
757
|
-
liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.UNISWAPV3_EFFICIENCY_FACTOR,
|
|
758
|
-
}));
|
|
759
|
-
const pools1 = lodash_1.default.map(res.pools1, pool => ({
|
|
760
|
-
exchange: this.dexKey,
|
|
761
|
-
address: pool.id.toLowerCase(),
|
|
762
|
-
connectorTokens: [
|
|
763
|
-
{
|
|
764
|
-
address: pool.token0.id.toLowerCase(),
|
|
765
|
-
decimals: parseInt(pool.token0.decimals),
|
|
766
|
-
},
|
|
767
|
-
],
|
|
768
|
-
liquidityUSD: parseFloat(pool.totalValueLockedUSD) * constants_2.UNISWAPV3_EFFICIENCY_FACTOR,
|
|
769
|
-
}));
|
|
770
|
-
const pools = lodash_1.default.slice(lodash_1.default.sortBy(lodash_1.default.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]), 0, limit);
|
|
771
|
-
return pools;
|
|
772
|
-
}
|
|
773
|
-
async _getPoolsFromIdentifiers(poolIdentifiers, blockNumber) {
|
|
774
|
-
const pools = await Promise.all(poolIdentifiers.map(async (identifier) => {
|
|
775
|
-
const [, srcAddress, destAddress, fee] = identifier.split('_');
|
|
776
|
-
return this.getPool(srcAddress, destAddress, BigInt(fee), blockNumber);
|
|
777
|
-
}));
|
|
778
|
-
return pools.filter(pool => pool);
|
|
779
|
-
}
|
|
780
|
-
_getLoweredAddresses(srcToken, destToken) {
|
|
781
|
-
return [srcToken.address.toLowerCase(), destToken.address.toLowerCase()];
|
|
782
|
-
}
|
|
783
|
-
_sortTokens(srcAddress, destAddress) {
|
|
784
|
-
return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
|
|
785
|
-
}
|
|
786
|
-
_toLowerForAllConfigAddresses() {
|
|
787
|
-
// If new config property will be added, the TS will throw compile error
|
|
788
|
-
const newConfig = {
|
|
789
|
-
router: this.config.router.toLowerCase(),
|
|
790
|
-
quoter: this.config.quoter.toLowerCase(),
|
|
791
|
-
factory: this.config.factory.toLowerCase(),
|
|
792
|
-
supportedFees: this.config.supportedFees,
|
|
793
|
-
stateMulticall: this.config.stateMulticall.toLowerCase(),
|
|
794
|
-
chunksCount: this.config.chunksCount,
|
|
795
|
-
initRetryFrequency: this.config.initRetryFrequency,
|
|
796
|
-
uniswapMulticall: this.config.uniswapMulticall,
|
|
797
|
-
deployer: this.config.deployer?.toLowerCase(),
|
|
798
|
-
initHash: this.config.initHash,
|
|
799
|
-
subgraphURL: this.config.subgraphURL,
|
|
800
|
-
stateMultiCallAbi: this.config.stateMultiCallAbi,
|
|
801
|
-
eventPoolImplementation: this.config.eventPoolImplementation,
|
|
802
|
-
factoryImplementation: this.config.factoryImplementation,
|
|
803
|
-
decodeStateMultiCallResultWithRelativeBitmaps: this.config.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
804
|
-
};
|
|
805
|
-
return newConfig;
|
|
806
|
-
}
|
|
807
|
-
_getOutputs(state, amounts, zeroForOne, side, destTokenBalance) {
|
|
808
|
-
try {
|
|
809
|
-
const outputsResult = uniswap_v3_math_1.uniswapV3Math.queryOutputs(state, amounts, zeroForOne, side);
|
|
810
|
-
if (side === constants_1.SwapSide.SELL) {
|
|
811
|
-
if (outputsResult.outputs[0] > destTokenBalance) {
|
|
812
|
-
return null;
|
|
813
|
-
}
|
|
814
|
-
for (let i = 0; i < outputsResult.outputs.length; i++) {
|
|
815
|
-
if (outputsResult.outputs[i] > destTokenBalance) {
|
|
816
|
-
outputsResult.outputs[i] = 0n;
|
|
817
|
-
outputsResult.tickCounts[i] = 0;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
else {
|
|
822
|
-
if (amounts[0] > destTokenBalance) {
|
|
823
|
-
return null;
|
|
824
|
-
}
|
|
825
|
-
// This may be improved by first checking outputs and requesting outputs
|
|
826
|
-
// only for amounts that makes more sense, but I don't think this is really
|
|
827
|
-
// important now
|
|
828
|
-
for (let i = 0; i < amounts.length; i++) {
|
|
829
|
-
if (amounts[i] > destTokenBalance) {
|
|
830
|
-
outputsResult.outputs[i] = 0n;
|
|
831
|
-
outputsResult.tickCounts[i] = 0;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
return outputsResult;
|
|
836
|
-
}
|
|
837
|
-
catch (e) {
|
|
838
|
-
this.logger.debug(`${this.dexKey}: received error in _getOutputs while calculating outputs`, e);
|
|
839
|
-
return null;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
async _querySubgraph(query, variables, timeout = 30000) {
|
|
843
|
-
if (!this.config.subgraphURL)
|
|
844
|
-
return [];
|
|
845
|
-
try {
|
|
846
|
-
const res = await this.dexHelper.httpRequest.querySubgraph(this.config.subgraphURL, { query, variables }, { timeout });
|
|
847
|
-
return res?.data ?? {};
|
|
848
|
-
}
|
|
849
|
-
catch (e) {
|
|
850
|
-
this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
|
|
851
|
-
return {};
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
_encodePath(path, side) {
|
|
855
|
-
if (path.length === 0) {
|
|
856
|
-
this.logger.error(`${this.dexKey}: Received invalid path=${path} for side=${side} to encode`);
|
|
857
|
-
return '0x';
|
|
858
|
-
}
|
|
859
|
-
const { _path, types } = path.reduce(({ _path, types }, curr, index) => {
|
|
860
|
-
if (index === 0) {
|
|
861
|
-
return {
|
|
862
|
-
types: ['address', 'uint24', 'address'],
|
|
863
|
-
_path: [curr.tokenIn, curr.fee, curr.tokenOut],
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
else {
|
|
867
|
-
return {
|
|
868
|
-
types: [...types, 'uint24', 'address'],
|
|
869
|
-
_path: [..._path, curr.fee, curr.tokenOut],
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
}, { _path: [], types: [] });
|
|
873
|
-
return side === constants_1.SwapSide.BUY
|
|
874
|
-
? (0, solidity_1.pack)(types.reverse(), _path.reverse())
|
|
875
|
-
: (0, solidity_1.pack)(types, _path);
|
|
876
|
-
}
|
|
877
|
-
_encodePathV6(path, side) {
|
|
878
|
-
let result = '0x';
|
|
879
|
-
if (path.length === 0) {
|
|
880
|
-
this.logger.error(`${this.dexKey}: Received invalid path=${path} for side=${side} to encode`);
|
|
881
|
-
return result;
|
|
882
|
-
}
|
|
883
|
-
if (side === constants_1.SwapSide.SELL) {
|
|
884
|
-
for (const p of path) {
|
|
885
|
-
const poolEncoded = this._encodePool(p.tokenIn, p.tokenOut, p.fee);
|
|
886
|
-
result += poolEncoded;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
// For buy order of pools should be reversed
|
|
891
|
-
for (let i = path.length - 1; i >= 0; i--) {
|
|
892
|
-
const p = path[i];
|
|
893
|
-
const poolEncoded = this._encodePool(p.tokenIn, p.tokenOut, p.fee);
|
|
894
|
-
result += poolEncoded;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
return result;
|
|
898
|
-
}
|
|
899
|
-
_encodePool(t0, t1, fee) {
|
|
900
|
-
// v6 expects weth for eth in pools
|
|
901
|
-
if ((0, utils_1.isETHAddress)(t0)) {
|
|
902
|
-
t0 = this.dexHelper.config.data.wrappedNativeTokenAddress;
|
|
903
|
-
}
|
|
904
|
-
if ((0, utils_1.isETHAddress)(t1)) {
|
|
905
|
-
t1 = this.dexHelper.config.data.wrappedNativeTokenAddress;
|
|
906
|
-
}
|
|
907
|
-
// contract expects tokens to be sorted, and direction switched in case sorting changes src/dest order
|
|
908
|
-
const [tokenInSorted, tokenOutSorted] = BigInt(t0) > BigInt(t1) ? [t1, t0] : [t0, t1];
|
|
909
|
-
const directionEncoded = (tokenInSorted === t0 ? '8' : '0').padEnd(24, '0');
|
|
910
|
-
const token0Encoded = tokenInSorted.slice(2).padEnd(64, '0');
|
|
911
|
-
const token1Encoded = tokenOutSorted.slice(2).padEnd(64, '0');
|
|
912
|
-
const feeEncoded = (0, utils_2.hexZeroPad)((0, utils_2.hexValue)(parseInt(fee)), 20).slice(2);
|
|
913
|
-
return directionEncoded + token0Encoded + token1Encoded + feeEncoded;
|
|
914
|
-
}
|
|
915
|
-
releaseResources() {
|
|
916
|
-
if (this.intervalTask !== undefined) {
|
|
917
|
-
clearInterval(this.intervalTask);
|
|
918
|
-
this.intervalTask = undefined;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
exports.UniswapV3 = UniswapV3;
|
|
923
|
-
//# sourceMappingURL=uniswap-v3-new.js.map
|