@curvefi/api 2.28.0 → 2.28.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants/coins/ethereum.d.ts +0 -15
- package/lib/constants/coins/ethereum.js +39 -134
- package/lib/constants/coins/polygon.d.ts +0 -12
- package/lib/constants/coins/polygon.js +18 -45
- package/lib/factory/factory-api.js +4 -1
- package/lib/factory/factory-crypto.js +2 -1
- package/lib/factory/factory.js +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/interfaces.d.ts +5 -4
- package/lib/router.d.ts +2 -2
- package/lib/router.js +91 -82
- package/package.json +1 -1
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
export declare const BTC_COINS_ETHEREUM: {
|
|
2
|
-
[index: string]: string;
|
|
3
|
-
};
|
|
4
|
-
export declare const ETH_COINS_ETHEREUM: {
|
|
5
|
-
[index: string]: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const LINK_COINS_ETHEREUM: {
|
|
8
|
-
[index: string]: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const EUR_COINS_ETHEREUM: {
|
|
11
|
-
[index: string]: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const USD_COINS_ETHEREUM: {
|
|
14
|
-
[index: string]: string;
|
|
15
|
-
};
|
|
16
1
|
export declare const COINS_ETHEREUM: {
|
|
17
2
|
[index: string]: string;
|
|
18
3
|
};
|
|
@@ -1,50 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.aTokensEthereum = exports.ycTokensEthereum = exports.yTokensEthereum = exports.cTokensEthereum = exports.COINS_ETHEREUM =
|
|
3
|
+
exports.aTokensEthereum = exports.ycTokensEthereum = exports.yTokensEthereum = exports.cTokensEthereum = exports.COINS_ETHEREUM = void 0;
|
|
15
4
|
var utils_1 = require("../utils");
|
|
16
|
-
exports.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
wbtc: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
21
|
-
tbtc: "0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa",
|
|
22
|
-
pbtc: "0x5228a22e72ccC52d415EcFd199F99D0665E7733b",
|
|
23
|
-
bbtc: "0x9be89d2a4cd102d8fecc6bf9da793be995c22541",
|
|
24
|
-
obtc: "0x8064d9Ae6cDf087b1bcd5BDf3531bD5d8C537a68",
|
|
25
|
-
sbtc: "0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6", // sBTC
|
|
26
|
-
};
|
|
27
|
-
exports.ETH_COINS_ETHEREUM = {
|
|
28
|
-
steth: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
29
|
-
eth: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
30
|
-
ankreth: "0xE95A203B1a91a908F9B9CE46459d101078c2c3cb",
|
|
31
|
-
seth: "0x5e74c9036fb86bd7ecdcb084a0673efc32ea31cb",
|
|
32
|
-
reth: "0x9559aaa82d9649c7a7b220e7c461d2e74c9a3593",
|
|
33
|
-
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
34
|
-
frxeth: "0x5E8422345238F34275888049021821E8E08CAa1f",
|
|
35
|
-
xaut: "0x68749665ff8d2d112fa859aa293f07a622782f38", // XAUt TODO move to GOLD
|
|
36
|
-
};
|
|
37
|
-
exports.LINK_COINS_ETHEREUM = {
|
|
38
|
-
link: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
|
|
39
|
-
slink: "0xbBC455cb4F1B9e4bFC4B73970d360c8f032EfEE6", // sLINK
|
|
40
|
-
};
|
|
41
|
-
exports.EUR_COINS_ETHEREUM = {
|
|
42
|
-
eurs: "0xdB25f211AB05b1c97D595516F45794528a807ad8",
|
|
43
|
-
seur: "0xD71eCFF9342A5Ced620049e616c5035F1dB98620",
|
|
44
|
-
eurt: "0xC581b735A1688071A1746c968e0798D642EDE491",
|
|
45
|
-
euroc: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
46
|
-
};
|
|
47
|
-
exports.USD_COINS_ETHEREUM = {
|
|
5
|
+
exports.COINS_ETHEREUM = (0, utils_1.lowerCaseValues)({
|
|
6
|
+
crv: "0xD533a949740bb3306d119CC777fa900bA034cd52",
|
|
7
|
+
// --- USD ---
|
|
8
|
+
'3crv': "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490",
|
|
48
9
|
ycdai: "0x99d1Fa417f94dcD62BfE781a1213c092a47041Bc",
|
|
49
10
|
ycusdc: "0x9777d7E2b60bB01759D0E2f8be2095df444cb07E",
|
|
50
11
|
ycusdt: "0x1bE5d71F2dA660BFdee8012dDc58D024448A0A59",
|
|
@@ -87,96 +48,40 @@ exports.USD_COINS_ETHEREUM = {
|
|
|
87
48
|
mim: "0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3",
|
|
88
49
|
rai: "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919",
|
|
89
50
|
wormholeust: "0xa693B19d2931d498c5B318dF961919BB4aee87a5",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
"0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643": 8,
|
|
125
|
-
"0x39AA39c021dfbaE8faC545936693aC917d5E7563": 8,
|
|
126
|
-
"0x8e595470ed749b85c6f7669de83eae304c2ec68f": 8,
|
|
127
|
-
"0x76eb2fe28b36b3ee97f3adae0c69606eedb2a37c": 8,
|
|
128
|
-
"0x48759f220ed983db51fa7a8c0d2aab8f3ce4166a": 8,
|
|
129
|
-
"0xC2cB1040220768554cf699b0d863A3cd4324ce32": 18,
|
|
130
|
-
"0x26EA744E5B887E5205727f55dFBE8685e3b21951": 6,
|
|
131
|
-
"0xE6354ed5bC4b393a5Aad09f21c46E101e692d447": 6,
|
|
132
|
-
"0x04bC0Ab673d88aE9dbC9DA2380cB6B79C4BCa9aE": 18,
|
|
133
|
-
"0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01": 18,
|
|
134
|
-
"0xd6aD7a6750A7593E092a9B218d66C0A814a3436e": 6,
|
|
135
|
-
"0x83f798e925BcD4017Eb265844FDDAbb448f1707D": 6,
|
|
136
|
-
"0x73a052500105205d34Daf004eAb301916DA8190f": 18,
|
|
137
|
-
"0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd": 2,
|
|
138
|
-
"0xdF574c24545E5FfEcb9a659c229253D4111d87e1": 8,
|
|
139
|
-
"0x1c48f86ae57291F7686349F12601910BD8D470bb": 18,
|
|
140
|
-
"0xe2f2a5C287993345a840Db3B0845fbC70f5935a5": 18,
|
|
141
|
-
"0x196f4727526eA7FB1e17b2071B3d8eAA38486988": 18,
|
|
142
|
-
"0x5BC25f649fc4e26069dDF4cF4010F9f706c23831": 18,
|
|
143
|
-
"0xa47c8bf37f92abed4a126bda807a7b7498661acd": 18,
|
|
144
|
-
"0x1456688345527bE1f37E9e627DA0837D6f08C925": 18,
|
|
145
|
-
"0x674C6Ad92Fd080e4004b2312b45f796a192D27a0": 18,
|
|
146
|
-
"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f": 18,
|
|
147
|
-
"0x6B175474E89094C44Da98b954EedeAC495271d0F": 18,
|
|
148
|
-
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": 6,
|
|
149
|
-
"0xdAC17F958D2ee523a2206206994597C13D831ec7": 6,
|
|
150
|
-
"0x57Ab1ec28D129707052df4dF418D58a2D46d5f51": 18,
|
|
151
|
-
"0x0000000000085d4780B73119b644AE5ecd22b376": 18,
|
|
152
|
-
"0x853d955acef822db058eb8505911ed77f175b99e": 18,
|
|
153
|
-
"0x5f98805A4E8be255a32880FDeC7F6728C6568bA0": 18,
|
|
154
|
-
"0x4Fabb145d64652a948d72533023f6E7A623C7C53": 18,
|
|
155
|
-
"0xbc6da0fe9ad5f3b0d58160288917aa56653660e9": 18,
|
|
156
|
-
"0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3": 18,
|
|
157
|
-
"0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490": 18,
|
|
158
|
-
"0xD533a949740bb3306d119CC777fa900bA034cd52": 18,
|
|
159
|
-
"0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b": 18,
|
|
160
|
-
"0x68749665ff8d2d112fa859aa293f07a622782f38": 6,
|
|
161
|
-
"0x090185f2135308bad17527004364ebcc2d37e5f6": 18,
|
|
162
|
-
"0xCdF7028ceAB81fA0C6971208e83fa7872994beE5": 18,
|
|
163
|
-
"0xa693B19d2931d498c5B318dF961919BB4aee87a5": 6,
|
|
164
|
-
"0x03ab458634910aad20ef5f1c8ee96f1d6ac54919": 18,
|
|
165
|
-
// --- REWARD TOKENS ---
|
|
166
|
-
"0xa3BeD4E1c75D00fa6f4E5E6922DB7261B5E9AcD2": 18,
|
|
167
|
-
"0x8762db106B2c2A0bccB3A80d1Ed41273552616E8": 18,
|
|
168
|
-
"0x20c36f062a31865bED8a5B1e512D9a1A20AA333A": 18,
|
|
169
|
-
"0x89Ab32156e46F46D02ade3FEcbe5Fc4243B9AAeD": 18,
|
|
170
|
-
"0x3c9d6c1C73b31c837832c72E04D3152f051fc1A9": 18,
|
|
171
|
-
"0x4da27a545c0c5b758a6ba100e3a049001de870f5": 18,
|
|
172
|
-
"0x5a98fcbea516cf06857215779fd812ca3bef1b32": 18,
|
|
173
|
-
"0xe0ad1806fd3e7edf6ff52fdb822432e847411033": 18,
|
|
174
|
-
"0x8290333cef9e6d528dd5618fb97a76f268f3edd4": 18,
|
|
175
|
-
"0x3432b6a60d23ca0dfca7761b7ab56459d9c964d0": 18,
|
|
176
|
-
"0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d": 18,
|
|
177
|
-
"0xef3a930e1ffffacd2fc13434ac81bd278b0ecc8d": 18,
|
|
178
|
-
"0xdbdb4d16eda451d0503b854cf79d55697f90c8df": 18, // ALCX
|
|
179
|
-
};
|
|
51
|
+
// --- ETH ---
|
|
52
|
+
steth: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
53
|
+
eth: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
54
|
+
ankreth: "0xE95A203B1a91a908F9B9CE46459d101078c2c3cb",
|
|
55
|
+
seth: "0x5e74c9036fb86bd7ecdcb084a0673efc32ea31cb",
|
|
56
|
+
reth: "0x9559aaa82d9649c7a7b220e7c461d2e74c9a3593",
|
|
57
|
+
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
58
|
+
frxeth: "0x5E8422345238F34275888049021821E8E08CAa1f",
|
|
59
|
+
// --- BTC ---
|
|
60
|
+
sbtccrv: "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3",
|
|
61
|
+
hbtc: "0x0316EB71485b0Ab14103307bf65a021042c6d380",
|
|
62
|
+
renbtc: "0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D",
|
|
63
|
+
wbtc: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
64
|
+
tbtc: "0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa",
|
|
65
|
+
pbtc: "0x5228a22e72ccC52d415EcFd199F99D0665E7733b",
|
|
66
|
+
bbtc: "0x9be89d2a4cd102d8fecc6bf9da793be995c22541",
|
|
67
|
+
obtc: "0x8064d9Ae6cDf087b1bcd5BDf3531bD5d8C537a68",
|
|
68
|
+
sbtc: "0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6",
|
|
69
|
+
// --- EUR ---
|
|
70
|
+
eurs: "0xdB25f211AB05b1c97D595516F45794528a807ad8",
|
|
71
|
+
seur: "0xD71eCFF9342A5Ced620049e616c5035F1dB98620",
|
|
72
|
+
eurt: "0xC581b735A1688071A1746c968e0798D642EDE491",
|
|
73
|
+
euroc: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
74
|
+
// --- LINK ---
|
|
75
|
+
link: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
|
|
76
|
+
slink: "0xbBC455cb4F1B9e4bFC4B73970d360c8f032EfEE6",
|
|
77
|
+
// --- OTHER ---
|
|
78
|
+
cvx: "0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b",
|
|
79
|
+
cvxcrv: "0x62b9c7356a2dc64a1969e19c23e4f579f9810aa7",
|
|
80
|
+
snx: "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
|
|
81
|
+
spell: "0x090185f2135308bad17527004364ebcc2d37e5f6",
|
|
82
|
+
t: "0xCdF7028ceAB81fA0C6971208e83fa7872994beE5",
|
|
83
|
+
xaut: "0x68749665ff8d2d112fa859aa293f07a622782f38", // XAUt
|
|
84
|
+
});
|
|
180
85
|
exports.cTokensEthereum = [
|
|
181
86
|
'0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643',
|
|
182
87
|
'0x39AA39c021dfbaE8faC545936693aC917d5E7563',
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
export declare const BTC_COINS_POLYGON: {
|
|
2
|
-
[index: string]: string;
|
|
3
|
-
};
|
|
4
|
-
export declare const ETH_COINS_POLYGON: {
|
|
5
|
-
[index: string]: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const EUR_COINS_POLYGON: {
|
|
8
|
-
[index: string]: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const USD_COINS_POLYGON: {
|
|
11
|
-
[index: string]: string;
|
|
12
|
-
};
|
|
13
1
|
export declare const COINS_POLYGON: {
|
|
14
2
|
[index: string]: string;
|
|
15
3
|
};
|
|
@@ -1,57 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.aTokensPolygon = exports.ycTokensPolygon = exports.yTokensPolygon = exports.cTokensPolygon = exports.COINS_POLYGON =
|
|
3
|
+
exports.aTokensPolygon = exports.ycTokensPolygon = exports.yTokensPolygon = exports.cTokensPolygon = exports.COINS_POLYGON = void 0;
|
|
15
4
|
var utils_1 = require("../utils");
|
|
16
|
-
exports.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
amwbtc: "0x5c2ed810328349100A66B82b78a1791B101C9D61", // amWBTC
|
|
20
|
-
};
|
|
21
|
-
exports.ETH_COINS_POLYGON = {
|
|
22
|
-
weth: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
23
|
-
amweth: "0x28424507fefb6f7f8E9D3860F56504E4e5f5f390", // amWETH
|
|
24
|
-
};
|
|
25
|
-
exports.EUR_COINS_POLYGON = {
|
|
26
|
-
eurt: "0x7BDF330f423Ea880FF95fC41A280fD5eCFD3D09f", // EURT
|
|
27
|
-
};
|
|
28
|
-
exports.USD_COINS_POLYGON = {
|
|
5
|
+
exports.COINS_POLYGON = (0, utils_1.lowerCaseValues)({
|
|
6
|
+
crv: "0x172370d5cd63279efa6d502dab29171933a610af",
|
|
7
|
+
// -- USD ---
|
|
29
8
|
dai: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
|
|
30
9
|
usdc: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
|
|
31
10
|
usdt: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
|
|
32
11
|
amdai: "0x27F8D03b3a2196956ED754baDc28D73be8830A6e",
|
|
33
12
|
amusdc: "0x1a13F4Ca1d028320A707D99520AbFefca3998b7F",
|
|
34
13
|
amusdt: "0x60D55F02A771d515e077c9C2403a1ef324885CeC",
|
|
35
|
-
am3crv: "0xE7a24EF0C5e95Ffb0f6684b813A78F2a3AD7D171",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619": 18,
|
|
50
|
-
"0x28424507fefb6f7f8E9D3860F56504E4e5f5f390": 18,
|
|
51
|
-
"0x7BDF330f423Ea880FF95fC41A280fD5eCFD3D09f": 6,
|
|
52
|
-
"0x172370d5cd63279efa6d502dab29171933a610af": 18,
|
|
53
|
-
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE": 18, // MATIC
|
|
54
|
-
};
|
|
14
|
+
am3crv: "0xE7a24EF0C5e95Ffb0f6684b813A78F2a3AD7D171",
|
|
15
|
+
// --- ETH ---
|
|
16
|
+
weth: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
17
|
+
amweth: "0x28424507fefb6f7f8E9D3860F56504E4e5f5f390",
|
|
18
|
+
// --- BTC ---
|
|
19
|
+
wbtc: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
20
|
+
renbtc: "0xDBf31dF14B66535aF65AaC99C32e9eA844e14501",
|
|
21
|
+
amwbtc: "0x5c2ed810328349100A66B82b78a1791B101C9D61",
|
|
22
|
+
// --- MATIC ---
|
|
23
|
+
matic: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
24
|
+
wmatic: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
|
|
25
|
+
// --- EUR ---
|
|
26
|
+
eurt: "0x7BDF330f423Ea880FF95fC41A280fD5eCFD3D09f", // EURT
|
|
27
|
+
});
|
|
55
28
|
exports.cTokensPolygon = []; //.map((a) => a.toLowerCase());
|
|
56
29
|
exports.yTokensPolygon = []; //.map((a) => a.toLowerCase());
|
|
57
30
|
exports.ycTokensPolygon = []; //.map((a) => a.toLowerCase());
|
|
@@ -178,10 +178,13 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
178
178
|
common_1.setFactoryZapContracts.call(this, isCrypto);
|
|
179
179
|
FACTORY_POOLS_DATA = {};
|
|
180
180
|
rawPoolList.forEach(function (pool) {
|
|
181
|
+
var nativeToken = _this.constants.NATIVE_TOKEN;
|
|
181
182
|
var coinAddresses = pool.coins.map(function (c) { return c.address; });
|
|
183
|
+
if (_this.chainId === 137) {
|
|
184
|
+
coinAddresses = coinAddresses.map(function (a) { return a === "0x0000000000000000000000000000000000001010" ? nativeToken.wrappedAddress : a; });
|
|
185
|
+
}
|
|
182
186
|
var coinNames = pool.coins.map(function (c) { return c.symbol; });
|
|
183
187
|
var coinDecimals = pool.coins.map(function (c) { return Number(c.decimals); });
|
|
184
|
-
var nativeToken = _this.constants.NATIVE_TOKEN;
|
|
185
188
|
if (isCrypto) {
|
|
186
189
|
var wrappedCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol; });
|
|
187
190
|
var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol; });
|
|
@@ -219,6 +219,7 @@ function getCryptoFactorySymbolsAndNames(factoryTokenAddresses) {
|
|
|
219
219
|
function getCryptoFactoryCoinAddresses(factorySwapAddresses) {
|
|
220
220
|
return __awaiter(this, void 0, void 0, function () {
|
|
221
221
|
var factoryMulticallContract, calls, _i, factorySwapAddresses_3, addr;
|
|
222
|
+
var _this = this;
|
|
222
223
|
return __generator(this, function (_a) {
|
|
223
224
|
switch (_a.label) {
|
|
224
225
|
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].multicallContract];
|
|
@@ -230,7 +231,7 @@ function getCryptoFactoryCoinAddresses(factorySwapAddresses) {
|
|
|
230
231
|
calls.push(factoryMulticallContract.get_coins(addr));
|
|
231
232
|
}
|
|
232
233
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
233
|
-
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses.map(function (addr) { return addr.toLowerCase(); }); })];
|
|
234
|
+
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); })];
|
|
234
235
|
}
|
|
235
236
|
});
|
|
236
237
|
});
|
package/lib/factory/factory.js
CHANGED
|
@@ -244,6 +244,7 @@ function getFactoryReferenceAssets(factorySwapAddresses) {
|
|
|
244
244
|
function getFactoryCoinAddresses(factorySwapAddresses) {
|
|
245
245
|
return __awaiter(this, void 0, void 0, function () {
|
|
246
246
|
var factoryMulticallContract, calls, _i, factorySwapAddresses_5, addr;
|
|
247
|
+
var _this = this;
|
|
247
248
|
return __generator(this, function (_a) {
|
|
248
249
|
switch (_a.label) {
|
|
249
250
|
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
|
|
@@ -257,7 +258,7 @@ function getFactoryCoinAddresses(factorySwapAddresses) {
|
|
|
257
258
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
258
259
|
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses
|
|
259
260
|
.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
|
|
260
|
-
.map(function (addr) { return addr.toLowerCase(); }); })];
|
|
261
|
+
.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.address : addr.toLowerCase(); }); })];
|
|
261
262
|
}
|
|
262
263
|
});
|
|
263
264
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ declare const curve: {
|
|
|
117
117
|
};
|
|
118
118
|
router: {
|
|
119
119
|
getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<{
|
|
120
|
-
route: import("./interfaces").
|
|
120
|
+
route: import("./interfaces").IRoute;
|
|
121
121
|
output: string;
|
|
122
122
|
}>;
|
|
123
123
|
expected: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<string>;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -137,13 +137,14 @@ export interface IRouteStep {
|
|
|
137
137
|
swapType: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
138
138
|
swapAddress: string;
|
|
139
139
|
}
|
|
140
|
-
export
|
|
141
|
-
|
|
140
|
+
export type IRoute = IRouteStep[];
|
|
141
|
+
export interface IRouteTvl {
|
|
142
|
+
route: IRoute;
|
|
142
143
|
minTvl: number;
|
|
143
144
|
totalTvl: number;
|
|
144
145
|
}
|
|
145
|
-
export interface
|
|
146
|
-
|
|
146
|
+
export interface IRouteOutputAndCost {
|
|
147
|
+
route: IRoute;
|
|
147
148
|
_output: ethers.BigNumber;
|
|
148
149
|
outputUsd: number;
|
|
149
150
|
txCostUsd: number;
|
package/lib/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import {
|
|
2
|
+
import { IRoute } from "./interfaces";
|
|
3
3
|
export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<{
|
|
4
|
-
route:
|
|
4
|
+
route: IRoute;
|
|
5
5
|
output: string;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const swapExpected: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<string>;
|
package/lib/router.js
CHANGED
|
@@ -67,38 +67,38 @@ var curve_1 = require("./curve");
|
|
|
67
67
|
var utils_1 = require("./utils");
|
|
68
68
|
var pools_1 = require("./pools");
|
|
69
69
|
var utils_2 = require("./pools/utils");
|
|
70
|
-
var getNewRoute = function (
|
|
71
|
-
var routePoolIds = route.
|
|
70
|
+
var getNewRoute = function (routeTvl, poolId, poolAddress, inputCoinAddress, outputCoinAddress, i, j, swapType, swapAddress, tvl) {
|
|
71
|
+
var routePoolIds = routeTvl.route.map(function (s) { return s.poolId; });
|
|
72
72
|
// Steps <= 4
|
|
73
73
|
if (routePoolIds.length >= 4)
|
|
74
|
-
return {
|
|
74
|
+
return { route: [], minTvl: Infinity, totalTvl: 0 };
|
|
75
75
|
// Exclude such cases as cvxeth -> tricrypto2 -> tricrypto2 -> susd
|
|
76
76
|
if (routePoolIds.includes(poolId))
|
|
77
|
-
return {
|
|
77
|
+
return { route: [], minTvl: Infinity, totalTvl: 0 };
|
|
78
78
|
return {
|
|
79
|
-
|
|
80
|
-
minTvl: Math.min(tvl,
|
|
81
|
-
totalTvl:
|
|
79
|
+
route: __spreadArray(__spreadArray([], routeTvl.route, true), [{ poolId: poolId, poolAddress: poolAddress, inputCoinAddress: inputCoinAddress, outputCoinAddress: outputCoinAddress, i: i, j: j, swapType: swapType, swapAddress: swapAddress }], false),
|
|
80
|
+
minTvl: Math.min(tvl, routeTvl.minTvl),
|
|
81
|
+
totalTvl: routeTvl.totalTvl + tvl,
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
var MAX_ROUTES_FOR_ONE_COIN = 3;
|
|
85
85
|
var filterRoutes = function (routes, inputCoinAddress, sortFn) {
|
|
86
86
|
return routes
|
|
87
|
-
.filter(function (r) { return r.
|
|
88
|
-
.filter(function (r) { return r.
|
|
87
|
+
.filter(function (r) { return r.route.length > 0; })
|
|
88
|
+
.filter(function (r) { return r.route[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
89
89
|
.filter(function (r, i, _routes) {
|
|
90
|
-
var routesByPoolIds = _routes.map(function (r) { return r.
|
|
91
|
-
return routesByPoolIds.indexOf(r.
|
|
90
|
+
var routesByPoolIds = _routes.map(function (r) { return r.route.map(function (s) { return s.poolId; }).toString(); });
|
|
91
|
+
return routesByPoolIds.indexOf(r.route.map(function (s) { return s.poolId; }).toString()) === i;
|
|
92
92
|
}) // Route duplications
|
|
93
93
|
.sort(sortFn).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
94
94
|
};
|
|
95
|
-
var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.
|
|
96
|
-
var sortByLength = function (a, b) { return a.
|
|
95
|
+
var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.route.length - b.route.length; };
|
|
96
|
+
var sortByLength = function (a, b) { return a.route.length - b.route.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
|
|
97
97
|
// TODO REMOVE IT!!!
|
|
98
98
|
var filterMaticFactory83Route = function (routes) {
|
|
99
99
|
return routes
|
|
100
100
|
.filter(function (r) {
|
|
101
|
-
return !(r.
|
|
101
|
+
return !(r.route.length === 1 && r.route[0].poolId === "factory-crypto-83" && r.route[0].inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address);
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
104
|
// Inspired by Dijkstra's algorithm
|
|
@@ -118,10 +118,10 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
118
118
|
curCoins = [inputCoinAddress];
|
|
119
119
|
nextCoins = new Set();
|
|
120
120
|
routesByTvl = (_a = {},
|
|
121
|
-
_a[inputCoinAddress] = [{
|
|
121
|
+
_a[inputCoinAddress] = [{ route: [], minTvl: Infinity, totalTvl: 0 }],
|
|
122
122
|
_a);
|
|
123
123
|
routesByLength = (_b = {},
|
|
124
|
-
_b[inputCoinAddress] = [{
|
|
124
|
+
_b[inputCoinAddress] = [{ route: [], minTvl: Infinity, totalTvl: 0 }],
|
|
125
125
|
_b);
|
|
126
126
|
step = 0;
|
|
127
127
|
_s.label = 2;
|
|
@@ -337,26 +337,28 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
337
337
|
// TODO REMOVE IT!!!
|
|
338
338
|
if (curve_1.curve.chainId === 137)
|
|
339
339
|
routes = filterMaticFactory83Route(routes);
|
|
340
|
-
return [2 /*return*/, routes.map(function (r) { return r.
|
|
340
|
+
return [2 /*return*/, routes.map(function (r) { return r.route; })];
|
|
341
341
|
}
|
|
342
342
|
});
|
|
343
343
|
}); };
|
|
344
344
|
var _getRouteKey = function (route, inputCoinAddress, outputCoinAddress) {
|
|
345
345
|
var sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
|
|
346
346
|
var key = "".concat(sortedCoins[0], "-->");
|
|
347
|
-
for (var _i = 0,
|
|
348
|
-
var routeStep =
|
|
347
|
+
for (var _i = 0, route_1 = route; _i < route_1.length; _i++) {
|
|
348
|
+
var routeStep = route_1[_i];
|
|
349
349
|
key += "".concat(routeStep.poolId, "-->");
|
|
350
350
|
}
|
|
351
351
|
key += sortedCoins[1];
|
|
352
352
|
return key;
|
|
353
353
|
};
|
|
354
|
-
var _getExchangeMultipleArgs = function (
|
|
355
|
-
var _route = [
|
|
354
|
+
var _getExchangeMultipleArgs = function (route) {
|
|
355
|
+
var _route = [];
|
|
356
|
+
if (route.length > 0)
|
|
357
|
+
_route.push(route[0].inputCoinAddress);
|
|
356
358
|
var _swapParams = [];
|
|
357
359
|
var _factorySwapAddresses = [];
|
|
358
|
-
for (var _i = 0,
|
|
359
|
-
var routeStep =
|
|
360
|
+
for (var _i = 0, route_2 = route; _i < route_2.length; _i++) {
|
|
361
|
+
var routeStep = route_2[_i];
|
|
360
362
|
_route.push(routeStep.poolAddress, routeStep.outputCoinAddress);
|
|
361
363
|
_swapParams.push([routeStep.i, routeStep.j, routeStep.swapType]);
|
|
362
364
|
_factorySwapAddresses.push(routeStep.swapAddress);
|
|
@@ -382,7 +384,7 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
|
|
|
382
384
|
route = routes_1[_i];
|
|
383
385
|
routeKey = _getRouteKey(route, inputCoinAddress, outputCoinAddress);
|
|
384
386
|
gasPromise = void 0;
|
|
385
|
-
_a = _getExchangeMultipleArgs(
|
|
387
|
+
_a = _getExchangeMultipleArgs(route), _route = _a._route, _swapParams = _a._swapParams, _factorySwapAddresses = _a._factorySwapAddresses;
|
|
386
388
|
if ((((_b = _estimatedGasForDifferentRoutesCache[routeKey]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 3600000 < Date.now()) {
|
|
387
389
|
gasPromise = contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, 0, _factorySwapAddresses, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }));
|
|
388
390
|
}
|
|
@@ -409,23 +411,18 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
|
|
|
409
411
|
}
|
|
410
412
|
});
|
|
411
413
|
}); };
|
|
412
|
-
var
|
|
413
|
-
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1,
|
|
414
|
+
var _getBestRoute = (0, memoizee_1.default)(function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
415
|
+
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _factorySwapAddresses, _outputAmounts, i, err_2, promises, contract, _c, routesRaw_2, r, _d, _route, _swapParams, _factorySwapAddresses, res, i, _e, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd;
|
|
414
416
|
return __generator(this, function (_f) {
|
|
415
417
|
switch (_f.label) {
|
|
416
418
|
case 0:
|
|
417
419
|
_a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
418
420
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
419
421
|
if (_amount.eq(0))
|
|
420
|
-
return [2 /*return*/,
|
|
421
|
-
steps: [],
|
|
422
|
-
_output: ethers_1.ethers.BigNumber.from(0),
|
|
423
|
-
outputUsd: 0,
|
|
424
|
-
txCostUsd: 0,
|
|
425
|
-
}];
|
|
422
|
+
return [2 /*return*/, []];
|
|
426
423
|
return [4 /*yield*/, _findAllRoutes(inputCoinAddress, outputCoinAddress)];
|
|
427
424
|
case 1:
|
|
428
|
-
routesRaw = (_f.sent()).map(function (
|
|
425
|
+
routesRaw = (_f.sent()).map(function (route) { return ({ route: route, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 }); });
|
|
429
426
|
routes = [];
|
|
430
427
|
_f.label = 2;
|
|
431
428
|
case 2:
|
|
@@ -433,8 +430,8 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
|
|
|
433
430
|
calls = [];
|
|
434
431
|
multicallContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].multicallContract;
|
|
435
432
|
for (_i = 0, routesRaw_1 = routesRaw; _i < routesRaw_1.length; _i++) {
|
|
436
|
-
|
|
437
|
-
_b = _getExchangeMultipleArgs(
|
|
433
|
+
r = routesRaw_1[_i];
|
|
434
|
+
_b = _getExchangeMultipleArgs(r.route), _route = _b._route, _swapParams = _b._swapParams, _factorySwapAddresses = _b._factorySwapAddresses;
|
|
438
435
|
calls.push(multicallContract.get_exchange_multiple_amount(_route, _swapParams, _amount, _factorySwapAddresses));
|
|
439
436
|
}
|
|
440
437
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
@@ -450,8 +447,8 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
|
|
|
450
447
|
promises = [];
|
|
451
448
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].contract;
|
|
452
449
|
for (_c = 0, routesRaw_2 = routesRaw; _c < routesRaw_2.length; _c++) {
|
|
453
|
-
|
|
454
|
-
_d = _getExchangeMultipleArgs(
|
|
450
|
+
r = routesRaw_2[_c];
|
|
451
|
+
_d = _getExchangeMultipleArgs(r.route), _route = _d._route, _swapParams = _d._swapParams, _factorySwapAddresses = _d._factorySwapAddresses;
|
|
455
452
|
promises.push(contract.get_exchange_multiple_amount(_route, _swapParams, _amount, _factorySwapAddresses, curve_1.curve.constantOptions));
|
|
456
453
|
}
|
|
457
454
|
return [4 /*yield*/, Promise.allSettled(promises)];
|
|
@@ -459,7 +456,7 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
|
|
|
459
456
|
res = _f.sent();
|
|
460
457
|
for (i = 0; i < res.length; i++) {
|
|
461
458
|
if (res[i].status === 'rejected') {
|
|
462
|
-
console.log("Route ".concat((routesRaw[i].
|
|
459
|
+
console.log("Route ".concat((routesRaw[i].route.map(function (s) { return s.poolId; })).join(" --> "), " is unavailable"));
|
|
463
460
|
continue;
|
|
464
461
|
}
|
|
465
462
|
routesRaw[i]._output = res[i].value;
|
|
@@ -467,18 +464,12 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
|
|
|
467
464
|
}
|
|
468
465
|
return [3 /*break*/, 6];
|
|
469
466
|
case 6:
|
|
470
|
-
if (routes.length === 0)
|
|
471
|
-
return [2 /*return*/,
|
|
472
|
-
steps: [],
|
|
473
|
-
_output: ethers_1.ethers.BigNumber.from(0),
|
|
474
|
-
outputUsd: 0,
|
|
475
|
-
txCostUsd: 0,
|
|
476
|
-
}];
|
|
477
|
-
}
|
|
467
|
+
if (routes.length === 0)
|
|
468
|
+
return [2 /*return*/, []];
|
|
478
469
|
if (routes.length === 1)
|
|
479
|
-
return [2 /*return*/, routes[0]];
|
|
470
|
+
return [2 /*return*/, routes[0].route];
|
|
480
471
|
return [4 /*yield*/, Promise.all([
|
|
481
|
-
_estimateGasForDifferentRoutes(routes, inputCoinAddress, outputCoinAddress, _amount),
|
|
472
|
+
_estimateGasForDifferentRoutes(routes.map(function (r) { return r.route; }), inputCoinAddress, outputCoinAddress, _amount),
|
|
482
473
|
(0, utils_1._getUsdRate)(outputCoinAddress),
|
|
483
474
|
axios_1.default.get("https://api.curve.fi/api/getGas"),
|
|
484
475
|
(0, utils_1._getUsdRate)(utils_1.ETH_ADDRESS),
|
|
@@ -497,27 +488,45 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
|
|
|
497
488
|
var diff = (route1.outputUsd - route1.txCostUsd) - (route2.outputUsd - route2.txCostUsd);
|
|
498
489
|
if (diff > 0)
|
|
499
490
|
return route1;
|
|
500
|
-
if (diff === 0 && route1.
|
|
491
|
+
if (diff === 0 && route1.route.length < route2.route.length)
|
|
501
492
|
return route1;
|
|
502
493
|
return route2;
|
|
503
|
-
})];
|
|
494
|
+
}).route];
|
|
504
495
|
}
|
|
505
496
|
});
|
|
506
497
|
}); }, {
|
|
507
498
|
promise: true,
|
|
508
499
|
maxAge: 5 * 60 * 1000, // 5m
|
|
509
500
|
});
|
|
501
|
+
var _getOutputForRoute = (0, memoizee_1.default)(function (route, _amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
502
|
+
var contract, _a, _route, _swapParams, _factorySwapAddresses;
|
|
503
|
+
return __generator(this, function (_b) {
|
|
504
|
+
switch (_b.label) {
|
|
505
|
+
case 0:
|
|
506
|
+
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].contract;
|
|
507
|
+
_a = _getExchangeMultipleArgs(route), _route = _a._route, _swapParams = _a._swapParams, _factorySwapAddresses = _a._factorySwapAddresses;
|
|
508
|
+
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _amount, _factorySwapAddresses, curve_1.curve.constantOptions)];
|
|
509
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}); }, {
|
|
513
|
+
promise: true,
|
|
514
|
+
maxAge: 15 * 1000, // 15s
|
|
515
|
+
});
|
|
510
516
|
var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
511
|
-
var _a, inputCoinAddress, outputCoinAddress,
|
|
517
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route, _output;
|
|
512
518
|
return __generator(this, function (_c) {
|
|
513
519
|
switch (_c.label) {
|
|
514
520
|
case 0:
|
|
515
521
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
516
|
-
|
|
517
|
-
return [4 /*yield*/,
|
|
522
|
+
_b = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
|
|
523
|
+
return [4 /*yield*/, _getBestRoute(inputCoinAddress, outputCoinAddress, amount)];
|
|
518
524
|
case 1:
|
|
519
|
-
|
|
520
|
-
return [
|
|
525
|
+
route = _c.sent();
|
|
526
|
+
return [4 /*yield*/, _getOutputForRoute(route, (0, utils_1.parseUnits)(amount, inputCoinDecimals))];
|
|
527
|
+
case 2:
|
|
528
|
+
_output = _c.sent();
|
|
529
|
+
return [2 /*return*/, { route: route, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
|
|
521
530
|
}
|
|
522
531
|
});
|
|
523
532
|
}); };
|
|
@@ -532,37 +541,37 @@ var swapExpected = function (inputCoin, outputCoin, amount) { return __awaiter(v
|
|
|
532
541
|
}); };
|
|
533
542
|
exports.swapExpected = swapExpected;
|
|
534
543
|
var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
535
|
-
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount,
|
|
536
|
-
return __generator(this, function (
|
|
537
|
-
switch (
|
|
544
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount, _d, _route, _swapParams, _factorySwapAddresses, _smallOutput, e_1, priceImpactBN;
|
|
545
|
+
return __generator(this, function (_e) {
|
|
546
|
+
switch (_e.label) {
|
|
538
547
|
case 0:
|
|
539
548
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
540
549
|
_b = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
|
|
541
|
-
return [4 /*yield*/,
|
|
550
|
+
return [4 /*yield*/, (0, exports.getBestRouteAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
|
|
542
551
|
case 1:
|
|
543
|
-
|
|
552
|
+
_c = _e.sent(), route = _c.route, output = _c.output;
|
|
544
553
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
545
|
-
_output =
|
|
554
|
+
_output = (0, utils_1.parseUnits)(output, outputCoinDecimals);
|
|
546
555
|
smallAmountIntBN = (0, utils_1._get_small_x)(_amount, _output, inputCoinDecimals, outputCoinDecimals);
|
|
547
556
|
amountIntBN = (0, utils_1.toBN)(_amount, 0);
|
|
548
557
|
if (smallAmountIntBN.gte(amountIntBN))
|
|
549
558
|
return [2 /*return*/, 0];
|
|
550
559
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].contract;
|
|
551
560
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
552
|
-
|
|
553
|
-
|
|
561
|
+
_d = _getExchangeMultipleArgs(route), _route = _d._route, _swapParams = _d._swapParams, _factorySwapAddresses = _d._factorySwapAddresses;
|
|
562
|
+
_e.label = 2;
|
|
554
563
|
case 2:
|
|
555
|
-
|
|
564
|
+
_e.trys.push([2, 4, , 6]);
|
|
556
565
|
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _smallAmount, _factorySwapAddresses, curve_1.curve.constantOptions)];
|
|
557
566
|
case 3:
|
|
558
|
-
_smallOutput =
|
|
567
|
+
_smallOutput = _e.sent();
|
|
559
568
|
return [3 /*break*/, 6];
|
|
560
569
|
case 4:
|
|
561
|
-
e_1 =
|
|
570
|
+
e_1 = _e.sent();
|
|
562
571
|
_smallAmount = ethers_1.ethers.utils.parseUnits("1", inputCoinDecimals); // Dirty hack
|
|
563
572
|
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _smallAmount, _factorySwapAddresses, curve_1.curve.constantOptions)];
|
|
564
573
|
case 5:
|
|
565
|
-
_smallOutput =
|
|
574
|
+
_smallOutput = _e.sent();
|
|
566
575
|
return [3 /*break*/, 6];
|
|
567
576
|
case 6:
|
|
568
577
|
priceImpactBN = (0, utils_1._get_price_impact)(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
@@ -605,10 +614,10 @@ var swapEstimateGas = function (inputCoin, outputCoin, amount) { return __awaite
|
|
|
605
614
|
case 0:
|
|
606
615
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
607
616
|
inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress)[0];
|
|
608
|
-
return [4 /*yield*/,
|
|
617
|
+
return [4 /*yield*/, (0, exports.getBestRouteAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
|
|
609
618
|
case 1:
|
|
610
|
-
route = _b.sent();
|
|
611
|
-
if (route.
|
|
619
|
+
route = (_b.sent()).route;
|
|
620
|
+
if (route.length === 0)
|
|
612
621
|
return [2 /*return*/, 0];
|
|
613
622
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
614
623
|
return [4 /*yield*/, _estimateGasForDifferentRoutes([route], inputCoinAddress, outputCoinAddress, _amount)];
|
|
@@ -622,35 +631,35 @@ exports.swapEstimateGas = swapEstimateGas;
|
|
|
622
631
|
var swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
623
632
|
if (slippage === void 0) { slippage = 0.5; }
|
|
624
633
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
625
|
-
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route,
|
|
626
|
-
return __generator(this, function (
|
|
627
|
-
switch (
|
|
634
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _d, _route, _swapParams, _factorySwapAddresses, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
|
|
635
|
+
return __generator(this, function (_e) {
|
|
636
|
+
switch (_e.label) {
|
|
628
637
|
case 0:
|
|
629
638
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
630
639
|
_b = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
|
|
631
640
|
return [4 /*yield*/, (0, exports.swapApprove)(inputCoin, amount)];
|
|
632
641
|
case 1:
|
|
633
|
-
|
|
634
|
-
return [4 /*yield*/,
|
|
642
|
+
_e.sent();
|
|
643
|
+
return [4 /*yield*/, (0, exports.getBestRouteAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
|
|
635
644
|
case 2:
|
|
636
|
-
|
|
637
|
-
if (route.
|
|
645
|
+
_c = _e.sent(), route = _c.route, output = _c.output;
|
|
646
|
+
if (route.length === 0) {
|
|
638
647
|
throw new Error("This pair can't be exchanged");
|
|
639
648
|
}
|
|
640
|
-
|
|
649
|
+
_d = _getExchangeMultipleArgs(route), _route = _d._route, _swapParams = _d._swapParams, _factorySwapAddresses = _d._factorySwapAddresses;
|
|
641
650
|
_amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
|
|
642
|
-
minRecvAmountBN = (0, utils_1.
|
|
651
|
+
minRecvAmountBN = (0, utils_1.BN)(output).times(100 - slippage).div(100);
|
|
643
652
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
644
653
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].contract;
|
|
645
654
|
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
646
655
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
647
656
|
case 3:
|
|
648
|
-
|
|
657
|
+
_e.sent();
|
|
649
658
|
return [4 /*yield*/, contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _factorySwapAddresses, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
650
659
|
case 4:
|
|
651
|
-
gasLimit = (
|
|
660
|
+
gasLimit = (_e.sent()).mul(curve_1.curve.chainId === 1 ? 130 : 160).div(100);
|
|
652
661
|
return [4 /*yield*/, contract.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _factorySwapAddresses, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
653
|
-
case 5: return [2 /*return*/,
|
|
662
|
+
case 5: return [2 /*return*/, _e.sent()];
|
|
654
663
|
}
|
|
655
664
|
});
|
|
656
665
|
});
|