@marko00/routing-finder-mare 1.0.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/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +19 -0
- package/.idea/ratex-sdk.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE-MIT +21 -0
- package/README.md +209 -0
- package/contracts/abi/BalancerHelperAbi.ts +1 -0
- package/contracts/abi/CamelotHelperAbi.ts +1 -0
- package/contracts/abi/RateXAbi.ts +482 -0
- package/contracts/abi/SushiSwapHelperAbi.ts +1 -0
- package/contracts/abi/UniswapHelperAbi.ts +1 -0
- package/contracts/abi/UniswapV2HelperAbi.ts +1 -0
- package/contracts/addresses-arbitrum.ts +8 -0
- package/contracts/addresses-mainnet.ts +7 -0
- package/contracts/addresses-polkadot.ts +9 -0
- package/contracts/addresses-sei.ts +9 -0
- package/contracts/rateX/BalancerHelper.ts +13 -0
- package/contracts/rateX/CamelotHelper.ts +13 -0
- package/contracts/rateX/SushiSwapHelper.ts +13 -0
- package/contracts/rateX/UniswapHelper.ts +19 -0
- package/contracts/rateX/UniswapV2Helper.ts +19 -0
- package/dexes/dexIdsList.ts +9 -0
- package/dexes/graph_queries/BalancerV2.ts +150 -0
- package/dexes/graph_queries/CamelotV2.ts +202 -0
- package/dexes/graph_queries/SushiSwapV2.ts +283 -0
- package/dexes/graph_queries/UniswapV2.ts +252 -0
- package/dexes/graph_queries/UniswapV3.ts +229 -0
- package/dexes/graph_queries/graphQueryFilters.ts +41 -0
- package/dexes/graph_queries/x_template.ts +67 -0
- package/dexes/pools/Balancer/BalancerState.ts +34 -0
- package/dexes/pools/Balancer/BalancerWeightedPool.ts +96 -0
- package/dexes/pools/Camelot.ts +164 -0
- package/dexes/pools/SushiSwapV2.ts +35 -0
- package/dexes/pools/UniswapV2.ts +36 -0
- package/dexes/pools/uniswap/UniswapV3.ts +40 -0
- package/dexes/pools/uniswap/testUniswapOffchainQuoter.ts +169 -0
- package/dexes/pools/uniswap/types.ts +174 -0
- package/dexes/pools/uniswap/uniswapOffchainQuoter.ts +173 -0
- package/dexes/pools/uniswap/uniswapState.ts +56 -0
- package/dexes/pools/uniswap/utils.ts +71 -0
- package/dist/contracts/abi/BalancerHelperAbi.d.ts +25 -0
- package/dist/contracts/abi/BalancerHelperAbi.js +4 -0
- package/dist/contracts/abi/CamelotHelperAbi.d.ts +45 -0
- package/dist/contracts/abi/CamelotHelperAbi.js +4 -0
- package/dist/contracts/abi/RateXAbi.d.ts +71 -0
- package/dist/contracts/abi/RateXAbi.js +485 -0
- package/dist/contracts/abi/SushiSwapHelperAbi.d.ts +45 -0
- package/dist/contracts/abi/SushiSwapHelperAbi.js +4 -0
- package/dist/contracts/abi/UniswapHelperAbi.d.ts +39 -0
- package/dist/contracts/abi/UniswapHelperAbi.js +4 -0
- package/dist/contracts/abi/UniswapV2HelperAbi.d.ts +45 -0
- package/dist/contracts/abi/UniswapV2HelperAbi.js +4 -0
- package/dist/contracts/addresses-arbitrum.d.ts +6 -0
- package/dist/contracts/addresses-arbitrum.js +10 -0
- package/dist/contracts/addresses-mainnet.d.ts +6 -0
- package/dist/contracts/addresses-mainnet.js +10 -0
- package/dist/contracts/addresses-polkadot.d.ts +6 -0
- package/dist/contracts/addresses-polkadot.js +10 -0
- package/dist/contracts/addresses-sei.d.ts +6 -0
- package/dist/contracts/addresses-sei.js +10 -0
- package/dist/contracts/rateX/BalancerHelper.d.ts +26 -0
- package/dist/contracts/rateX/BalancerHelper.js +14 -0
- package/dist/contracts/rateX/CamelotHelper.d.ts +46 -0
- package/dist/contracts/rateX/CamelotHelper.js +14 -0
- package/dist/contracts/rateX/SushiSwapHelper.d.ts +46 -0
- package/dist/contracts/rateX/SushiSwapHelper.js +14 -0
- package/dist/contracts/rateX/UniswapHelper.d.ts +40 -0
- package/dist/contracts/rateX/UniswapHelper.js +22 -0
- package/dist/contracts/rateX/UniswapV2Helper.d.ts +46 -0
- package/dist/contracts/rateX/UniswapV2Helper.js +22 -0
- package/dist/dexes/dexIdsList.d.ts +9 -0
- package/dist/dexes/dexIdsList.js +12 -0
- package/dist/dexes/graph_queries/BalancerV2.d.ts +14 -0
- package/dist/dexes/graph_queries/BalancerV2.js +141 -0
- package/dist/dexes/graph_queries/CamelotV2.d.ts +14 -0
- package/dist/dexes/graph_queries/CamelotV2.js +183 -0
- package/dist/dexes/graph_queries/SushiSwapV2.d.ts +14 -0
- package/dist/dexes/graph_queries/SushiSwapV2.js +263 -0
- package/dist/dexes/graph_queries/UniswapV2.d.ts +14 -0
- package/dist/dexes/graph_queries/UniswapV2.js +217 -0
- package/dist/dexes/graph_queries/UniswapV3.d.ts +14 -0
- package/dist/dexes/graph_queries/UniswapV3.js +198 -0
- package/dist/dexes/graph_queries/graphQueryFilters.d.ts +19 -0
- package/dist/dexes/graph_queries/graphQueryFilters.js +40 -0
- package/dist/dexes/graph_queries/x_template.d.ts +12 -0
- package/dist/dexes/graph_queries/x_template.js +57 -0
- package/dist/dexes/pools/Balancer/BalancerState.d.ts +6 -0
- package/dist/dexes/pools/Balancer/BalancerState.js +32 -0
- package/dist/dexes/pools/Balancer/BalancerWeightedPool.d.ts +12 -0
- package/dist/dexes/pools/Balancer/BalancerWeightedPool.js +109 -0
- package/dist/dexes/pools/Camelot.d.ts +12 -0
- package/dist/dexes/pools/Camelot.js +135 -0
- package/dist/dexes/pools/SushiSwapV2.d.ts +9 -0
- package/dist/dexes/pools/SushiSwapV2.js +34 -0
- package/dist/dexes/pools/UniswapV2.d.ts +9 -0
- package/dist/dexes/pools/UniswapV2.js +34 -0
- package/dist/dexes/pools/uniswap/UniswapV3.d.ts +7 -0
- package/dist/dexes/pools/uniswap/UniswapV3.js +36 -0
- package/dist/dexes/pools/uniswap/types.d.ts +76 -0
- package/dist/dexes/pools/uniswap/types.js +111 -0
- package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.d.ts +13 -0
- package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.js +121 -0
- package/dist/dexes/pools/uniswap/uniswapState.d.ts +14 -0
- package/dist/dexes/pools/uniswap/uniswapState.js +51 -0
- package/dist/dexes/pools/uniswap/utils.d.ts +3 -0
- package/dist/dexes/pools/uniswap/utils.js +41 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +41 -0
- package/dist/routes.d.ts +1 -0
- package/dist/routes.js +20 -0
- package/dist/routing/iterative_spliting/main.d.ts +3 -0
- package/dist/routing/iterative_spliting/main.js +104 -0
- package/dist/routing/iterative_spliting/multiHopSwap.d.ts +4 -0
- package/dist/routing/iterative_spliting/multiHopSwap.js +83 -0
- package/dist/routing/main.d.ts +2 -0
- package/dist/routing/main.js +22 -0
- package/dist/routing/uni_like_algo/algo_config.d.ts +2 -0
- package/dist/routing/uni_like_algo/algo_config.js +8 -0
- package/dist/routing/uni_like_algo/amount_distribution.d.ts +2 -0
- package/dist/routing/uni_like_algo/amount_distribution.js +17 -0
- package/dist/routing/uni_like_algo/compute_routes_backtrack.d.ts +3 -0
- package/dist/routing/uni_like_algo/compute_routes_backtrack.js +44 -0
- package/dist/routing/uni_like_algo/main.d.ts +2 -0
- package/dist/routing/uni_like_algo/main.js +49 -0
- package/dist/routing/uni_like_algo/routes_quoter.d.ts +21 -0
- package/dist/routing/uni_like_algo/routes_quoter.js +53 -0
- package/dist/routing/uni_like_algo/swap_finder.d.ts +25 -0
- package/dist/routing/uni_like_algo/swap_finder.js +154 -0
- package/dist/routing/uni_like_algo/types.d.ts +40 -0
- package/dist/routing/uni_like_algo/types.js +12 -0
- package/dist/swap/graph_communication.d.ts +5 -0
- package/dist/swap/graph_communication.js +187 -0
- package/dist/swap/my_local_storage.d.ts +8 -0
- package/dist/swap/my_local_storage.js +16 -0
- package/dist/utils/addresses.d.ts +24 -0
- package/dist/utils/addresses.js +60 -0
- package/dist/utils/math/fixed-points.d.ts +14 -0
- package/dist/utils/math/fixed-points.js +123 -0
- package/dist/utils/math/log-exp.d.ts +5 -0
- package/dist/utils/math/log-exp.js +385 -0
- package/dist/utils/math/math.d.ts +12 -0
- package/dist/utils/math/math.js +50 -0
- package/dist/utils/types/types.d.ts +51 -0
- package/dist/utils/types/types.js +25 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +72 -0
- package/images/decenter_logo.png +0 -0
- package/index.ts +50 -0
- package/package.json +39 -0
- package/routes.ts +27 -0
- package/routing/iterative_spliting/main.ts +131 -0
- package/routing/iterative_spliting/multiHopSwap.ts +98 -0
- package/routing/main.ts +22 -0
- package/routing/uni_like_algo/algo_config.ts +7 -0
- package/routing/uni_like_algo/amount_distribution.ts +16 -0
- package/routing/uni_like_algo/compute_routes_backtrack.ts +81 -0
- package/routing/uni_like_algo/main.ts +65 -0
- package/routing/uni_like_algo/routes_quoter.ts +63 -0
- package/routing/uni_like_algo/swap_finder.ts +185 -0
- package/routing/uni_like_algo/types.ts +54 -0
- package/swap/graph_communication.ts +212 -0
- package/swap/my_local_storage.ts +27 -0
- package/tsconfig.json +26 -0
- package/utils/addresses.ts +64 -0
- package/utils/math/fixed-points.ts +88 -0
- package/utils/math/log-exp.ts +469 -0
- package/utils/math/math.ts +46 -0
- package/utils/types/types.ts +100 -0
- package/utils/utils.ts +125 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { Pool } from '../utils/types/types';
|
|
3
|
+
import { Dexes } from '../index';
|
|
4
|
+
declare function fetchPoolsData(tokenFrom: string, tokenTo: string, numFromToPools: number | undefined, numTopPools: number | undefined, chainId: number, rpcProvider: Web3, graphApiKey: string, dexes: Array<Dexes>): Promise<Pool[]>;
|
|
5
|
+
export { fetchPoolsData };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchPoolsData = fetchPoolsData;
|
|
7
|
+
const index_1 = require("../index");
|
|
8
|
+
const my_local_storage_1 = require("./my_local_storage");
|
|
9
|
+
const UniswapV2_1 = __importDefault(require("../dexes/graph_queries/UniswapV2"));
|
|
10
|
+
const SushiSwapV2_1 = __importDefault(require("../dexes/graph_queries/SushiSwapV2"));
|
|
11
|
+
const UniswapV3_1 = __importDefault(require("../dexes/graph_queries/UniswapV3"));
|
|
12
|
+
const BalancerV2_1 = __importDefault(require("../dexes/graph_queries/BalancerV2"));
|
|
13
|
+
const CamelotV2_1 = __importDefault(require("../dexes/graph_queries/CamelotV2"));
|
|
14
|
+
let initializedMainnet = false;
|
|
15
|
+
let initializedArbitrum = false;
|
|
16
|
+
let initializedSei = false;
|
|
17
|
+
let initializedPas = false;
|
|
18
|
+
let initializedDexes = [];
|
|
19
|
+
let dexesPools = new Map();
|
|
20
|
+
async function initializeDexes(chainId, graphApiKey, dexes) {
|
|
21
|
+
try {
|
|
22
|
+
// Clear Previous Dex Graph Mappings and Initialized DEX array
|
|
23
|
+
dexesPools.clear();
|
|
24
|
+
initializedDexes = [];
|
|
25
|
+
for (const dex of dexes) {
|
|
26
|
+
let Dex;
|
|
27
|
+
switch (dex) {
|
|
28
|
+
case index_1.Dexes.BALANCER:
|
|
29
|
+
Dex = BalancerV2_1.default;
|
|
30
|
+
break;
|
|
31
|
+
case index_1.Dexes.CAMELOT:
|
|
32
|
+
if (chainId === 1)
|
|
33
|
+
continue;
|
|
34
|
+
Dex = CamelotV2_1.default;
|
|
35
|
+
break;
|
|
36
|
+
case index_1.Dexes.SUSHISWAP_V2:
|
|
37
|
+
Dex = SushiSwapV2_1.default;
|
|
38
|
+
break;
|
|
39
|
+
case index_1.Dexes.UNISWAP_V2:
|
|
40
|
+
if (chainId === 42161)
|
|
41
|
+
continue;
|
|
42
|
+
Dex = UniswapV2_1.default;
|
|
43
|
+
break;
|
|
44
|
+
case index_1.Dexes.UNISWAP_V3:
|
|
45
|
+
Dex = UniswapV3_1.default;
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
throw Error("Invalid Dex value");
|
|
49
|
+
}
|
|
50
|
+
const dexInstance = Dex.initialize(my_local_storage_1.myLocalStorage);
|
|
51
|
+
dexInstance.setEndpoint(chainId, graphApiKey);
|
|
52
|
+
initializedDexes.push(dexInstance);
|
|
53
|
+
dexesPools.set(dexInstance, []);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error('Error reading directory dexes_graph:', err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function checkInitializedDexes(chainId, graphApiKey, dexes) {
|
|
61
|
+
if (chainId === 1 && !initializedMainnet) {
|
|
62
|
+
await initializeDexes(chainId, graphApiKey, dexes);
|
|
63
|
+
initializedArbitrum = false;
|
|
64
|
+
initializedSei = false;
|
|
65
|
+
initializedPas = false;
|
|
66
|
+
initializedMainnet = true;
|
|
67
|
+
}
|
|
68
|
+
if (chainId === 42161 && !initializedArbitrum) {
|
|
69
|
+
await initializeDexes(chainId, graphApiKey, dexes);
|
|
70
|
+
initializedMainnet = false;
|
|
71
|
+
initializedSei = false;
|
|
72
|
+
initializedPas = false;
|
|
73
|
+
initializedArbitrum = true;
|
|
74
|
+
}
|
|
75
|
+
if (chainId === 1329 && !initializedSei) {
|
|
76
|
+
await initializeDexes(chainId, graphApiKey, dexes);
|
|
77
|
+
initializedMainnet = false;
|
|
78
|
+
initializedArbitrum = false;
|
|
79
|
+
initializedPas = false;
|
|
80
|
+
initializedSei = true;
|
|
81
|
+
}
|
|
82
|
+
if (chainId === 420420417 && !initializedPas) {
|
|
83
|
+
await initializeDexes(chainId, graphApiKey, dexes);
|
|
84
|
+
initializedMainnet = false;
|
|
85
|
+
initializedArbitrum = false;
|
|
86
|
+
initializedSei = false;
|
|
87
|
+
initializedPas = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/* Returns dictionary of dexes and their poolIds for token1 and token2:
|
|
91
|
+
* UniswapV3: [poolId1, poolId2, ...],
|
|
92
|
+
* SushiSwapV2: [poolId1, poolId2, ...]
|
|
93
|
+
*/
|
|
94
|
+
async function getPoolIdsForTokenPairs(tokenA, tokenB, numPools = 3, chainId, graphApiKey, dexes) {
|
|
95
|
+
await checkInitializedDexes(chainId, graphApiKey, dexes);
|
|
96
|
+
const allPoolsPromises = initializedDexes.map((dex) => dex.getPoolsWithTokenPair(tokenA, tokenB, numPools));
|
|
97
|
+
const allPoolsResults = await Promise.all(allPoolsPromises);
|
|
98
|
+
initializedDexes.forEach((dex, index) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const pools = allPoolsResults[index];
|
|
101
|
+
if (dexesPools.has(dex)) {
|
|
102
|
+
(_a = dexesPools.get(dex)) === null || _a === void 0 ? void 0 : _a.push(...pools);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
dexesPools.set(dex, pools);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/* Get pools from each dex in initializedDexes list that have token as one of the tokens in the pool
|
|
110
|
+
* @param token: token address to match (for now the chain is Arbitrum -> param for the future)
|
|
111
|
+
* @param numPools: number of pools to return from each dex
|
|
112
|
+
* @param amountIn: amount of token1 to swap (in wei) - currently unused
|
|
113
|
+
* @returns: list of poolIds
|
|
114
|
+
*/
|
|
115
|
+
async function getPoolIdsForToken(token, numPools = 5, chainId, graphApiKey, dexes) {
|
|
116
|
+
await checkInitializedDexes(chainId, graphApiKey, dexes);
|
|
117
|
+
const allPoolsPromises = initializedDexes.map((dex) => dex.getPoolsWithToken(token, numPools));
|
|
118
|
+
const allPoolsResults = await Promise.all(allPoolsPromises);
|
|
119
|
+
initializedDexes.forEach((dex, index) => {
|
|
120
|
+
var _a;
|
|
121
|
+
const pools = allPoolsResults[index];
|
|
122
|
+
if (dexesPools.has(dex)) {
|
|
123
|
+
(_a = dexesPools.get(dex)) === null || _a === void 0 ? void 0 : _a.push(...pools);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
dexesPools.set(dex, pools);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/* Get top pools from each dex in initializedDexes list - returns a list of poolIds
|
|
131
|
+
* @param numPools: number of pools to return from each dex
|
|
132
|
+
* @param amountIn: amount of token1 to swap (in wei) - currently unused
|
|
133
|
+
* @returns: list of poolIds
|
|
134
|
+
*/
|
|
135
|
+
async function getTopPools(numPools = 5, chainId, graphApiKey, dexes) {
|
|
136
|
+
await checkInitializedDexes(chainId, graphApiKey, dexes);
|
|
137
|
+
const allPoolsPromises = initializedDexes.map((dex) => dex.getTopPools(numPools));
|
|
138
|
+
const allPoolsResults = await Promise.all(allPoolsPromises);
|
|
139
|
+
initializedDexes.forEach((dex, index) => {
|
|
140
|
+
var _a;
|
|
141
|
+
const pools = allPoolsResults[index];
|
|
142
|
+
if (dexesPools.has(dex)) {
|
|
143
|
+
(_a = dexesPools.get(dex)) === null || _a === void 0 ? void 0 : _a.push(...pools);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
dexesPools.set(dex, pools);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/* We are fetching pools from multiple dexes, so we might get duplicate pools
|
|
151
|
+
* top numTopPools pools for tokenFrom and tokenTo are fetched from each DEX
|
|
152
|
+
* top numTopPools by TVL from each DEX
|
|
153
|
+
* top numTopPools that contain tokenFrom and tokenTo from each DEX (possible direct swap)
|
|
154
|
+
*/
|
|
155
|
+
async function fetchPoolsData(tokenFrom, tokenTo, numFromToPools = 5, numTopPools = 5, chainId, rpcProvider, graphApiKey, dexes) {
|
|
156
|
+
let pools = [];
|
|
157
|
+
dexesPools.forEach((poolInfos, dex) => {
|
|
158
|
+
dexesPools.set(dex, []);
|
|
159
|
+
});
|
|
160
|
+
await checkInitializedDexes(chainId, graphApiKey, dexes);
|
|
161
|
+
// call Graph API
|
|
162
|
+
const promises = [];
|
|
163
|
+
promises.push(getPoolIdsForToken(tokenFrom, numFromToPools, chainId, graphApiKey, dexes));
|
|
164
|
+
promises.push(getPoolIdsForToken(tokenTo, numFromToPools, chainId, graphApiKey, dexes));
|
|
165
|
+
promises.push(getTopPools(numTopPools, chainId, graphApiKey, dexes));
|
|
166
|
+
promises.push(getPoolIdsForTokenPairs(tokenFrom, tokenTo, numFromToPools, chainId, graphApiKey, dexes));
|
|
167
|
+
await Promise.all(promises);
|
|
168
|
+
filterDuplicatePools();
|
|
169
|
+
// call Solidity for additional pool data
|
|
170
|
+
const dexPoolsPromises = [];
|
|
171
|
+
for (let [dex, poolInfos] of dexesPools.entries()) {
|
|
172
|
+
dexPoolsPromises.push(dex.getAdditionalPoolDataFromSolidity(poolInfos, rpcProvider));
|
|
173
|
+
}
|
|
174
|
+
const allPoolsData = await Promise.all(dexPoolsPromises);
|
|
175
|
+
allPoolsData.forEach((poolsData) => {
|
|
176
|
+
pools.push(...poolsData);
|
|
177
|
+
});
|
|
178
|
+
return pools;
|
|
179
|
+
}
|
|
180
|
+
function filterDuplicatePools() {
|
|
181
|
+
dexesPools.forEach((poolInfos, dex, self) => {
|
|
182
|
+
const filteredPoolInfos = poolInfos.filter((poolInfo, index, allPoolInfos) => {
|
|
183
|
+
return allPoolInfos.findIndex((pool2) => pool2.poolId === poolInfo.poolId) === index;
|
|
184
|
+
});
|
|
185
|
+
self.set(dex, filteredPoolInfos);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.myLocalStorage = void 0;
|
|
4
|
+
const values = {};
|
|
5
|
+
class MockLocalStorage {
|
|
6
|
+
setItem(key, value) {
|
|
7
|
+
values[key] = value;
|
|
8
|
+
}
|
|
9
|
+
getItem(key) {
|
|
10
|
+
return values[key] || null;
|
|
11
|
+
}
|
|
12
|
+
removeItem(key) {
|
|
13
|
+
delete values[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.myLocalStorage = new MockLocalStorage();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const addresses: {
|
|
2
|
+
name: string;
|
|
3
|
+
uniQuoterV2: string;
|
|
4
|
+
wethToken: string;
|
|
5
|
+
daiToken: string;
|
|
6
|
+
usdtToken: string;
|
|
7
|
+
wbtcToken: string;
|
|
8
|
+
usdcToken: string;
|
|
9
|
+
uniToken: string;
|
|
10
|
+
linkToken: string;
|
|
11
|
+
usdceToken: string;
|
|
12
|
+
gmxToken: string;
|
|
13
|
+
sushiRouter: string;
|
|
14
|
+
sushiFactory: string;
|
|
15
|
+
univ3_wbtc_eth_pool_0_05: string;
|
|
16
|
+
univ3_wbtc_eth_pool_0_3: string;
|
|
17
|
+
sushi_wbtc_eth_pool: string;
|
|
18
|
+
gmx_usdc_pool_0_1: string;
|
|
19
|
+
uni_weth_pool: string;
|
|
20
|
+
weth_link_pool: string;
|
|
21
|
+
dai_usdce_pool_0_0_1: string;
|
|
22
|
+
impersonate_weth: string;
|
|
23
|
+
impersonate_dai: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addresses = void 0;
|
|
4
|
+
// hardcode it like this for now
|
|
5
|
+
exports.addresses = {
|
|
6
|
+
// Acutally used.
|
|
7
|
+
name: "sei",
|
|
8
|
+
uniQuoterV2: "0x38F759cf0Af1D0dcAEd723a3967A3B658738eDe9",
|
|
9
|
+
wethToken: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
10
|
+
daiToken: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
11
|
+
usdtToken: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
12
|
+
wbtcToken: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
13
|
+
usdcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
14
|
+
uniToken: "0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0",
|
|
15
|
+
linkToken: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4",
|
|
16
|
+
usdceToken: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
|
|
17
|
+
gmxToken: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a",
|
|
18
|
+
sushiRouter: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",
|
|
19
|
+
sushiFactory: "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
|
|
20
|
+
// uniQuoter: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
|
|
21
|
+
// uniQuoterV2: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
22
|
+
// uniRouter: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
|
23
|
+
univ3_wbtc_eth_pool_0_05: "0x2f5e87C9312fa29aed5c179E456625D79015299c", // 0.05 fee
|
|
24
|
+
univ3_wbtc_eth_pool_0_3: "0x149e36E72726e0BceA5c59d40df2c43F60f5A22D", // 0.3 fee
|
|
25
|
+
sushi_wbtc_eth_pool: "0x515e252b2b5c22b4b2b6Df66c2eBeeA871AA4d69", // 0.3 fee always
|
|
26
|
+
gmx_usdc_pool_0_1: "0x0A36952Fb8C8dc6daeFB2fADb07C5212f560880e",
|
|
27
|
+
uni_weth_pool: "0xC24f7d8E51A64dc1238880BD00bb961D54cbeb29",
|
|
28
|
+
weth_link_pool: "0x468b88941e7Cc0B88c1869d68ab6b570bCEF62Ff",
|
|
29
|
+
dai_usdce_pool_0_0_1: "0xF0428617433652c9dc6D1093A42AdFbF30D29f74",
|
|
30
|
+
impersonate_weth: "0x0df5dfd95966753f01cb80e76dc20ea958238c46",
|
|
31
|
+
impersonate_dai: "0xd85e038593d7a098614721eae955ec2022b9b91b"
|
|
32
|
+
// name: "arbitrum",
|
|
33
|
+
//
|
|
34
|
+
// wethToken: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
35
|
+
// daiToken: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
36
|
+
// usdtToken: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
37
|
+
// wbtcToken: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
38
|
+
// usdcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
39
|
+
// uniToken: "0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0",
|
|
40
|
+
// linkToken: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4",
|
|
41
|
+
// usdceToken: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
|
|
42
|
+
// gmxToken: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a",
|
|
43
|
+
//
|
|
44
|
+
// sushiRouter: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",
|
|
45
|
+
// sushiFactory: "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
|
|
46
|
+
//
|
|
47
|
+
// uniQuoter: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
|
|
48
|
+
// uniQuoterV2: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
49
|
+
// uniRouter: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
|
50
|
+
// univ3_wbtc_eth_pool_0_05: "0x2f5e87C9312fa29aed5c179E456625D79015299c", // 0.05 fee
|
|
51
|
+
// univ3_wbtc_eth_pool_0_3: "0x149e36E72726e0BceA5c59d40df2c43F60f5A22D", // 0.3 fee
|
|
52
|
+
// sushi_wbtc_eth_pool: "0x515e252b2b5c22b4b2b6Df66c2eBeeA871AA4d69", // 0.3 fee always
|
|
53
|
+
// gmx_usdc_pool_0_1: "0x0A36952Fb8C8dc6daeFB2fADb07C5212f560880e",
|
|
54
|
+
// uni_weth_pool: "0xC24f7d8E51A64dc1238880BD00bb961D54cbeb29",
|
|
55
|
+
// weth_link_pool: "0x468b88941e7Cc0B88c1869d68ab6b570bCEF62Ff",
|
|
56
|
+
// dai_usdce_pool_0_0_1: "0xF0428617433652c9dc6D1093A42AdFbF30D29f74",
|
|
57
|
+
//
|
|
58
|
+
// impersonate_weth: "0x0df5dfd95966753f01cb80e76dc20ea958238c46",
|
|
59
|
+
// impersonate_dai: "0xd85e038593d7a098614721eae955ec2022b9b91b"
|
|
60
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
export declare const ZERO: BigNumber;
|
|
3
|
+
export declare const ONE: BigNumber;
|
|
4
|
+
export declare const MAX_POW_RELATIVE_ERROR: BigNumber;
|
|
5
|
+
export declare const MIN_POW_BASE_FREE_EXPONENT: BigNumber;
|
|
6
|
+
export declare const add: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
7
|
+
export declare const sub: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
8
|
+
export declare const mulDown: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
9
|
+
export declare const mulUp: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
10
|
+
export declare const divDown: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
11
|
+
export declare const divUp: (a: BigNumber, b: BigNumber) => BigNumber;
|
|
12
|
+
export declare const powDown: (x: BigNumber, y: BigNumber) => BigNumber;
|
|
13
|
+
export declare const powUp: (x: BigNumber, y: BigNumber) => BigNumber;
|
|
14
|
+
export declare const complement: (x: BigNumber) => BigNumber;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported from Solidity:
|
|
3
|
+
// https://github.com/balancer-labs/balancer-core-v2/blob/70843e6a61ad11208c1cfabf5cfe15be216ca8d3/pkg/solidity-utils/contracts/math/FixedPoint.sol
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.complement = exports.powUp = exports.powDown = exports.divUp = exports.divDown = exports.mulUp = exports.mulDown = exports.sub = exports.add = exports.MIN_POW_BASE_FREE_EXPONENT = exports.MAX_POW_RELATIVE_ERROR = exports.ONE = exports.ZERO = void 0;
|
|
42
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
|
+
const logExp = __importStar(require("./log-exp"));
|
|
44
|
+
exports.ZERO = new bignumber_js_1.default(0);
|
|
45
|
+
exports.ONE = new bignumber_js_1.default("1000000000000000000"); // 10^18
|
|
46
|
+
exports.MAX_POW_RELATIVE_ERROR = new bignumber_js_1.default(10000); // 10^(-14)
|
|
47
|
+
// Minimum base for the power function when the exponent is 'free' (larger than ONE)
|
|
48
|
+
exports.MIN_POW_BASE_FREE_EXPONENT = new bignumber_js_1.default("700000000000000000"); // 0.7e18
|
|
49
|
+
const add = (a, b) => {
|
|
50
|
+
// Fixed Point addition is the same as regular checked addition
|
|
51
|
+
return a.plus(b);
|
|
52
|
+
};
|
|
53
|
+
exports.add = add;
|
|
54
|
+
const sub = (a, b) => {
|
|
55
|
+
// Fixed Point subtraction is the same as regular checked subtraction
|
|
56
|
+
if (b.gt(a))
|
|
57
|
+
throw new Error("SUB_OVERFLOW");
|
|
58
|
+
return a.minus(b);
|
|
59
|
+
};
|
|
60
|
+
exports.sub = sub;
|
|
61
|
+
const mulDown = (a, b) => {
|
|
62
|
+
return a.times(b).idiv(exports.ONE);
|
|
63
|
+
};
|
|
64
|
+
exports.mulDown = mulDown;
|
|
65
|
+
const mulUp = (a, b) => {
|
|
66
|
+
const product = a.times(b);
|
|
67
|
+
if (product.isZero()) {
|
|
68
|
+
return product;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// The traditional divUp formula is:
|
|
72
|
+
// divUp(x, y) := (x + y - 1) / y
|
|
73
|
+
// To avoid intermediate overflow in the addition, we distribute the division and get:
|
|
74
|
+
// divUp(x, y) := (x - 1) / y + 1
|
|
75
|
+
// Note that this requires x != 0, which we already tested for
|
|
76
|
+
return product.minus(new bignumber_js_1.default(1)).idiv(exports.ONE).plus(new bignumber_js_1.default(1));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.mulUp = mulUp;
|
|
80
|
+
const divDown = (a, b) => {
|
|
81
|
+
if (b.isZero())
|
|
82
|
+
throw new Error("ZERO_DIVISION");
|
|
83
|
+
if (a.isZero())
|
|
84
|
+
return a;
|
|
85
|
+
else
|
|
86
|
+
return a.times(exports.ONE).idiv(b);
|
|
87
|
+
};
|
|
88
|
+
exports.divDown = divDown;
|
|
89
|
+
const divUp = (a, b) => {
|
|
90
|
+
if (b.isZero())
|
|
91
|
+
throw new Error("ZERO_DIVISION");
|
|
92
|
+
if (a.isZero())
|
|
93
|
+
return a;
|
|
94
|
+
else {
|
|
95
|
+
// The traditional divUp formula is:
|
|
96
|
+
// divUp(x, y) := (x + y - 1) / y
|
|
97
|
+
// To avoid intermediate overflow in the addition, we distribute the division and get:
|
|
98
|
+
// divUp(x, y) := (x - 1) / y + 1
|
|
99
|
+
// Note that this requires x != 0, which we already tested for.
|
|
100
|
+
return a.times(exports.ONE).minus(new bignumber_js_1.default(1)).idiv(b).plus(new bignumber_js_1.default(1));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.divUp = divUp;
|
|
104
|
+
const powDown = (x, y) => {
|
|
105
|
+
const raw = logExp.pow(x, y);
|
|
106
|
+
const maxError = (0, exports.add)((0, exports.mulUp)(raw, exports.MAX_POW_RELATIVE_ERROR), new bignumber_js_1.default(1));
|
|
107
|
+
if (raw.lt(maxError))
|
|
108
|
+
return new bignumber_js_1.default(0);
|
|
109
|
+
else {
|
|
110
|
+
return (0, exports.sub)(raw, maxError);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.powDown = powDown;
|
|
114
|
+
const powUp = (x, y) => {
|
|
115
|
+
const raw = logExp.pow(x, y);
|
|
116
|
+
const maxError = (0, exports.add)((0, exports.mulUp)(raw, exports.MAX_POW_RELATIVE_ERROR), new bignumber_js_1.default(1));
|
|
117
|
+
return (0, exports.add)(raw, maxError);
|
|
118
|
+
};
|
|
119
|
+
exports.powUp = powUp;
|
|
120
|
+
const complement = (x) => {
|
|
121
|
+
return x.lt(exports.ONE) ? exports.ONE.minus(x) : new bignumber_js_1.default(0);
|
|
122
|
+
};
|
|
123
|
+
exports.complement = complement;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
export declare const pow: (x: BigNumber, y: BigNumber) => BigNumber;
|
|
3
|
+
export declare const exp: (x: BigNumber) => BigNumber;
|
|
4
|
+
export declare const log: (arg: BigNumber, base: BigNumber) => BigNumber;
|
|
5
|
+
export declare const ln: (a: BigNumber) => BigNumber;
|