@curvefi/api 2.60.5 → 2.61.1
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/abis/router-ng-pools-only.json +145 -0
- package/lib/constants/aliases.js +14 -14
- package/lib/constants/coins/fraxtal.js +1 -1
- package/lib/curve.js +6 -1
- package/lib/factory/factory-api.js +4 -4
- package/lib/factory/factory-tricrypto.js +1 -0
- package/lib/factory/factory-twocrypto.js +1 -0
- package/lib/factory/factory.js +2 -2
- package/lib/index.d.ts +5 -5
- package/lib/interfaces.d.ts +2 -2
- package/lib/pools/PoolTemplate.d.ts +1 -1
- package/lib/pools/PoolTemplate.js +37 -33
- package/lib/router.d.ts +5 -5
- package/lib/router.js +142 -76
- package/lib/utils.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "Exchange",
|
|
4
|
+
"inputs": [
|
|
5
|
+
{
|
|
6
|
+
"name": "sender",
|
|
7
|
+
"type": "address",
|
|
8
|
+
"indexed": true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "receiver",
|
|
12
|
+
"type": "address",
|
|
13
|
+
"indexed": true
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "route",
|
|
17
|
+
"type": "address[11]",
|
|
18
|
+
"indexed": false
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "swap_params",
|
|
22
|
+
"type": "uint256[4][5]",
|
|
23
|
+
"indexed": false
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "in_amount",
|
|
27
|
+
"type": "uint256",
|
|
28
|
+
"indexed": false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "out_amount",
|
|
32
|
+
"type": "uint256",
|
|
33
|
+
"indexed": false
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"anonymous": false,
|
|
37
|
+
"type": "event"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"stateMutability": "payable",
|
|
41
|
+
"type": "fallback"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"stateMutability": "nonpayable",
|
|
45
|
+
"type": "constructor",
|
|
46
|
+
"inputs": [
|
|
47
|
+
{
|
|
48
|
+
"name": "_weth",
|
|
49
|
+
"type": "address"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"outputs": []
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"stateMutability": "payable",
|
|
56
|
+
"type": "function",
|
|
57
|
+
"name": "exchange",
|
|
58
|
+
"inputs": [
|
|
59
|
+
{
|
|
60
|
+
"name": "_route",
|
|
61
|
+
"type": "address[11]"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "_swap_params",
|
|
65
|
+
"type": "uint256[4][5]"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "_amount",
|
|
69
|
+
"type": "uint256"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "_min_dy",
|
|
73
|
+
"type": "uint256"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"outputs": [
|
|
77
|
+
{
|
|
78
|
+
"name": "",
|
|
79
|
+
"type": "uint256"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"stateMutability": "view",
|
|
85
|
+
"type": "function",
|
|
86
|
+
"name": "get_dy",
|
|
87
|
+
"inputs": [
|
|
88
|
+
{
|
|
89
|
+
"name": "_route",
|
|
90
|
+
"type": "address[11]"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "_swap_params",
|
|
94
|
+
"type": "uint256[4][5]"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "_amount",
|
|
98
|
+
"type": "uint256"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"outputs": [
|
|
102
|
+
{
|
|
103
|
+
"name": "",
|
|
104
|
+
"type": "uint256"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"stateMutability": "view",
|
|
110
|
+
"type": "function",
|
|
111
|
+
"name": "get_dx",
|
|
112
|
+
"inputs": [
|
|
113
|
+
{
|
|
114
|
+
"name": "_route",
|
|
115
|
+
"type": "address[11]"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "_swap_params",
|
|
119
|
+
"type": "uint256[4][5]"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "_out_amount",
|
|
123
|
+
"type": "uint256"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"outputs": [
|
|
127
|
+
{
|
|
128
|
+
"name": "",
|
|
129
|
+
"type": "uint256"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"stateMutability": "view",
|
|
135
|
+
"type": "function",
|
|
136
|
+
"name": "version",
|
|
137
|
+
"inputs": [],
|
|
138
|
+
"outputs": [
|
|
139
|
+
{
|
|
140
|
+
"name": "",
|
|
141
|
+
"type": "string"
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
]
|
package/lib/constants/aliases.js
CHANGED
|
@@ -9,7 +9,7 @@ export var ALIASES_ETHEREUM = lowerCaseValues({
|
|
|
9
9
|
"fee_distributor_crvusd": "0xD16d5eC345Dd86Fb63C6a9C43c517210F1027914",
|
|
10
10
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
11
11
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
12
|
-
"router": "
|
|
12
|
+
"router": "0x16C6521Dff6baB339122a0FE25a9116693265353",
|
|
13
13
|
"deposit_and_stake": "0x56C526b0159a258887e0d79ec3a80dfb940d0cD7",
|
|
14
14
|
"stable_calc": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
15
15
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -32,7 +32,7 @@ export var ALIASES_POLYGON = lowerCaseValues({
|
|
|
32
32
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
33
33
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
34
34
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
35
|
-
"router": "
|
|
35
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
36
36
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
37
37
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
38
38
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -52,7 +52,7 @@ export var ALIASES_FANTOM = lowerCaseValues({
|
|
|
52
52
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
53
53
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
54
54
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
55
|
-
"router": "
|
|
55
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
56
56
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
57
57
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
58
58
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -72,7 +72,7 @@ export var ALIASES_AVALANCHE = lowerCaseValues({
|
|
|
72
72
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
73
73
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
74
74
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
75
|
-
"router": "
|
|
75
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
76
76
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
77
77
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
78
78
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -92,7 +92,7 @@ export var ALIASES_ARBITRUM = lowerCaseValues({
|
|
|
92
92
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
93
93
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
94
94
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
95
|
-
"router": "
|
|
95
|
+
"router": "0x2191718CD32d02B8E60BAdFFeA33E4B5DD9A0A0D",
|
|
96
96
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
97
97
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
98
98
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -112,7 +112,7 @@ export var ALIASES_OPTIMISM = lowerCaseValues({
|
|
|
112
112
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
113
113
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
114
114
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
115
|
-
"router": "
|
|
115
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
116
116
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
117
117
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
118
118
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -134,7 +134,7 @@ export var ALIASES_XDAI = lowerCaseValues({
|
|
|
134
134
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
135
135
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
136
136
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
137
|
-
"router": "
|
|
137
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
138
138
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
139
139
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
140
140
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -194,7 +194,7 @@ export var ALIASES_KAVA = lowerCaseValues({
|
|
|
194
194
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
195
195
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
196
196
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
197
|
-
"router": "
|
|
197
|
+
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
|
|
198
198
|
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
|
|
199
199
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
200
200
|
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
|
|
@@ -234,7 +234,7 @@ export var ALIASES_ZKSYNC = lowerCaseValues({
|
|
|
234
234
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
235
235
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
236
236
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
237
|
-
"router": "
|
|
237
|
+
"router": "0x7C915390e109CA66934f1eB285854375D1B127FA",
|
|
238
238
|
"deposit_and_stake": "0x0000000000000000000000000000000000000000",
|
|
239
239
|
"stable_calc": "0x0000000000000000000000000000000000000000",
|
|
240
240
|
"crypto_calc": '0x0000000000000000000000000000000000000000',
|
|
@@ -254,7 +254,7 @@ export var ALIASES_BASE = lowerCaseValues({
|
|
|
254
254
|
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
|
|
255
255
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
256
256
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
257
|
-
"router": "
|
|
257
|
+
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
|
|
258
258
|
"deposit_and_stake": "0x69522fb5337663d3B4dFB0030b881c1A750Adb4f",
|
|
259
259
|
"stable_calc": "0x5552b631e2aD801fAa129Aacf4B701071cC9D1f7",
|
|
260
260
|
"crypto_calc": '0xEfadDdE5B43917CcC738AdE6962295A0B343f7CE',
|
|
@@ -276,7 +276,7 @@ export var ALIASES_BSC = lowerCaseValues({
|
|
|
276
276
|
"fee_distributor": "0x0000000000000000000000000000000000000000",
|
|
277
277
|
"gauge_controller": "0x0000000000000000000000000000000000000000",
|
|
278
278
|
"address_provider": "0x0000000000000000000000000000000000000000",
|
|
279
|
-
"router": "
|
|
279
|
+
"router": "0xA72C85C258A81761433B4e8da60505Fe3Dd551CC",
|
|
280
280
|
"deposit_and_stake": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
|
|
281
281
|
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
|
|
282
282
|
"crypto_calc": '0xd6681e74eEA20d196c15038C580f721EF2aB6320',
|
|
@@ -296,7 +296,7 @@ export var ALIASES_FRAXTAL = lowerCaseValues({
|
|
|
296
296
|
"fee_distributor": "0x0000000000000000000000000000000000000000",
|
|
297
297
|
"gauge_controller": "0x0000000000000000000000000000000000000000",
|
|
298
298
|
"address_provider": "0x0000000000000000000000000000000000000000",
|
|
299
|
-
"router": "
|
|
299
|
+
"router": "0x9f2Fa7709B30c75047980a0d70A106728f0Ef2db",
|
|
300
300
|
"deposit_and_stake": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
|
|
301
301
|
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
302
302
|
"crypto_calc": '0x69522fb5337663d3B4dFB0030b881c1A750Adb4f',
|
|
@@ -316,7 +316,7 @@ export var ALIASES_XLAYER = lowerCaseValues({
|
|
|
316
316
|
"fee_distributor": "0x0000000000000000000000000000000000000000",
|
|
317
317
|
"gauge_controller": "0x0000000000000000000000000000000000000000",
|
|
318
318
|
"address_provider": "0x0000000000000000000000000000000000000000",
|
|
319
|
-
"router": "
|
|
319
|
+
"router": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855",
|
|
320
320
|
"deposit_and_stake": "0x5552b631e2aD801fAa129Aacf4B701071cC9D1f7",
|
|
321
321
|
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
|
|
322
322
|
"crypto_calc": '0x69522fb5337663d3B4dFB0030b881c1A750Adb4f',
|
|
@@ -336,7 +336,7 @@ export var ALIASES_MANTLE = lowerCaseValues({
|
|
|
336
336
|
"fee_distributor": "0x0000000000000000000000000000000000000000",
|
|
337
337
|
"gauge_controller": "0x0000000000000000000000000000000000000000",
|
|
338
338
|
"address_provider": "0x0000000000000000000000000000000000000000",
|
|
339
|
-
"router": "
|
|
339
|
+
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
|
|
340
340
|
"deposit_and_stake": "0x5552b631e2ad801faa129aacf4b701071cc9d1f7",
|
|
341
341
|
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
|
|
342
342
|
"crypto_calc": '0xd6681e74eEA20d196c15038C580f721EF2aB6320',
|
|
@@ -2,7 +2,7 @@ import { lowerCaseValues } from "../utils.js";
|
|
|
2
2
|
export var COINS_FRAXTAL = lowerCaseValues({
|
|
3
3
|
crv: '0x331B9182088e2A7d6D3Fe4742AbA1fB231aEcc56',
|
|
4
4
|
// --- FRAXTAL ---
|
|
5
|
-
|
|
5
|
+
frxeth: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
6
6
|
});
|
|
7
7
|
export var cTokensFraxtal = []; //.map((a) => a.toLowerCase());
|
|
8
8
|
export var yTokensFraxtal = []; //.map((a) => a.toLowerCase());
|
package/lib/curve.js
CHANGED
|
@@ -79,6 +79,7 @@ import cryptoCalcZapABI from './constants/abis/crypto_calc.json' assert { type:
|
|
|
79
79
|
import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type: 'json' };
|
|
80
80
|
import routerABI from './constants/abis/router.json' assert { type: 'json' };
|
|
81
81
|
import routerPolygonABI from './constants/abis/routerPolygon.json' assert { type: 'json' };
|
|
82
|
+
import routerNgPoolsOnlyABI from './constants/abis/router-ng-pools-only.json' assert { type: 'json' };
|
|
82
83
|
import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
|
|
83
84
|
import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
|
|
84
85
|
import factoryEywaABI from './constants/abis/factory-eywa.json' assert { type: 'json' };
|
|
@@ -418,6 +419,7 @@ export var NETWORK_CONSTANTS = {
|
|
|
418
419
|
aTokens: aTokensAurora,
|
|
419
420
|
},
|
|
420
421
|
};
|
|
422
|
+
var OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
|
|
421
423
|
var Curve = /** @class */ (function () {
|
|
422
424
|
function Curve() {
|
|
423
425
|
var _this = this;
|
|
@@ -1129,9 +1131,12 @@ var Curve = /** @class */ (function () {
|
|
|
1129
1131
|
if (this.chainId == 137) {
|
|
1130
1132
|
this.setContract(this.constants.ALIASES.router, routerPolygonABI);
|
|
1131
1133
|
}
|
|
1132
|
-
else {
|
|
1134
|
+
else if (OLD_CHAINS.includes(this.chainId)) {
|
|
1133
1135
|
this.setContract(this.constants.ALIASES.router, routerABI);
|
|
1134
1136
|
}
|
|
1137
|
+
else {
|
|
1138
|
+
this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
|
|
1139
|
+
}
|
|
1135
1140
|
this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
|
|
1136
1141
|
this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
|
|
1137
1142
|
this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
|
|
@@ -258,7 +258,7 @@ export function getFactoryPoolsDataFromApi(factoryType) {
|
|
|
258
258
|
gauge_abi: _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
259
259
|
deposit_abi: basePoolZap.ABI,
|
|
260
260
|
in_api: true,
|
|
261
|
-
|
|
261
|
+
is_ng: false,
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
else {
|
|
@@ -282,7 +282,7 @@ export function getFactoryPoolsDataFromApi(factoryType) {
|
|
|
282
282
|
swap_abi: getSwapAbiByFactoryType(factoryType, pool),
|
|
283
283
|
gauge_abi: _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
284
284
|
in_api: true,
|
|
285
|
-
|
|
285
|
+
is_ng: factoryType === "factory-tricrypto" || factoryType === "factory-twocrypto",
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
288
|
}
|
|
@@ -322,7 +322,7 @@ export function getFactoryPoolsDataFromApi(factoryType) {
|
|
|
322
322
|
gauge_abi: _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
323
323
|
deposit_abi: basePoolZap.ABI,
|
|
324
324
|
in_api: true,
|
|
325
|
-
|
|
325
|
+
is_ng: factoryType === 'factory-stable-ng',
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
328
|
else {
|
|
@@ -347,7 +347,7 @@ export function getFactoryPoolsDataFromApi(factoryType) {
|
|
|
347
347
|
swap_abi: implementationABIDict[pool.implementationAddress],
|
|
348
348
|
gauge_abi: _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
349
349
|
in_api: true,
|
|
350
|
-
|
|
350
|
+
is_ng: factoryType === 'factory-stable-ng',
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
353
|
});
|
|
@@ -333,6 +333,7 @@ export function getTricryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
|
333
333
|
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
334
334
|
swap_abi: tricryptoFactorySwapABI,
|
|
335
335
|
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
336
|
+
is_ng: true,
|
|
336
337
|
};
|
|
337
338
|
};
|
|
338
339
|
this_1 = this;
|
|
@@ -321,6 +321,7 @@ export function getTwocryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
|
321
321
|
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
322
322
|
swap_abi: twocryptoFactorySwapABI,
|
|
323
323
|
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
324
|
+
is_ng: true,
|
|
324
325
|
};
|
|
325
326
|
}
|
|
326
327
|
return [2 /*return*/, TWOCRYPTO_FACTORY_POOLS_DATA];
|
package/lib/factory/factory.js
CHANGED
|
@@ -420,7 +420,7 @@ export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
|
|
|
420
420
|
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
421
421
|
swap_abi: swapABIs[i],
|
|
422
422
|
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
423
|
-
|
|
423
|
+
is_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,
|
|
424
424
|
};
|
|
425
425
|
}
|
|
426
426
|
else {
|
|
@@ -459,7 +459,7 @@ export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
|
|
|
459
459
|
swap_abi: swapABIs[i],
|
|
460
460
|
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
461
461
|
deposit_abi: basePoolZap.ABI,
|
|
462
|
-
|
|
462
|
+
is_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,
|
|
463
463
|
};
|
|
464
464
|
}
|
|
465
465
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -236,11 +236,11 @@ declare const curve: {
|
|
|
236
236
|
getArgs: (route: import("./interfaces.js").IRoute) => {
|
|
237
237
|
_route: string[];
|
|
238
238
|
_swapParams: number[][];
|
|
239
|
-
_pools
|
|
240
|
-
_basePools
|
|
241
|
-
_baseTokens
|
|
242
|
-
_secondBasePools
|
|
243
|
-
_secondBaseTokens
|
|
239
|
+
_pools?: string[] | undefined;
|
|
240
|
+
_basePools?: string[] | undefined;
|
|
241
|
+
_baseTokens?: string[] | undefined;
|
|
242
|
+
_secondBasePools?: string[] | undefined;
|
|
243
|
+
_secondBaseTokens?: string[] | undefined;
|
|
244
244
|
};
|
|
245
245
|
expected: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<string>;
|
|
246
246
|
required: (inputCoin: string, outputCoin: string, outAmount: string | number) => Promise<string>;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Contract as MulticallContract, Provider as MulticallProvider } from "@c
|
|
|
3
3
|
export interface IDict<T> {
|
|
4
4
|
[index: string]: T;
|
|
5
5
|
}
|
|
6
|
-
export type INetworkName = "ethereum" | "
|
|
6
|
+
export type INetworkName = "ethereum" | "optimism" | "bsc" | "xdai" | "polygon" | "x-layer" | "fantom" | "fraxtal" | "zksync" | "moonbeam" | "kava" | "mantle" | "base" | "arbitrum" | "celo" | "avalanche" | "aurora";
|
|
7
7
|
export type IChainId = 1 | 10 | 56 | 100 | 137 | 196 | 250 | 252 | 324 | 1284 | 2222 | 5000 | 8453 | 42161 | 42220 | 43114 | 1313161554;
|
|
8
8
|
export type IFactoryPoolType = "factory" | "factory-crvusd" | "factory-eywa" | "factory-crypto" | "factory-twocrypto" | "factory-tricrypto" | "factory-stable-ng";
|
|
9
9
|
export type IPoolType = "main" | "crypto" | IFactoryPoolType;
|
|
@@ -28,7 +28,7 @@ export interface IPoolData {
|
|
|
28
28
|
is_fake?: boolean;
|
|
29
29
|
is_factory?: boolean;
|
|
30
30
|
is_llamma?: boolean;
|
|
31
|
-
|
|
31
|
+
is_ng?: boolean;
|
|
32
32
|
base_pool?: string;
|
|
33
33
|
meta_coin_idx?: number;
|
|
34
34
|
underlying_coins: string[];
|
|
@@ -1168,7 +1168,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1168
1168
|
this.isFake = poolData.is_fake || false;
|
|
1169
1169
|
this.isFactory = poolData.is_factory || false;
|
|
1170
1170
|
this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
|
|
1171
|
-
this.
|
|
1171
|
+
this.isNg = poolData.is_ng || false;
|
|
1172
1172
|
this.isLlamma = poolData.is_llamma || false;
|
|
1173
1173
|
this.basePool = poolData.base_pool || '';
|
|
1174
1174
|
this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
|
|
@@ -2351,7 +2351,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2351
2351
|
_minMintAmount = fromBN(minAmountBN);
|
|
2352
2352
|
ethIndex = getEthIndex(coinAddresses);
|
|
2353
2353
|
value = _amounts[ethIndex] || curve.parseUnits("0");
|
|
2354
|
-
return [4 /*yield*/, contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, (this.
|
|
2354
|
+
return [4 /*yield*/, contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg), this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
2355
2355
|
case 17:
|
|
2356
2356
|
_gas = (_q.sent());
|
|
2357
2357
|
if (estimateGas)
|
|
@@ -2360,7 +2360,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2360
2360
|
case 18:
|
|
2361
2361
|
_q.sent();
|
|
2362
2362
|
gasLimit = DIGas(_gas) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
|
|
2363
|
-
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, (this.
|
|
2363
|
+
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg), this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
|
|
2364
2364
|
case 19: return [2 /*return*/, (_q.sent()).hash];
|
|
2365
2365
|
}
|
|
2366
2366
|
});
|
|
@@ -3107,52 +3107,56 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
3107
3107
|
return __generator(this, function (_c) {
|
|
3108
3108
|
switch (_c.label) {
|
|
3109
3109
|
case 0:
|
|
3110
|
-
if (!this.isCrypto) return [3 /*break*/,
|
|
3110
|
+
if (!this.isCrypto) return [3 /*break*/, 11];
|
|
3111
|
+
if (!this.isNg) return [3 /*break*/, 2];
|
|
3112
|
+
return [4 /*yield*/, curve.contracts[this.address].contract.get_dx(i, j, _amount, curve.constantOptions)];
|
|
3113
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
3114
|
+
case 2:
|
|
3111
3115
|
contract = curve.contracts[curve.constants.ALIASES.crypto_calc].contract;
|
|
3112
|
-
if (!(this.isMeta && isUnderlying)) return [3 /*break*/,
|
|
3116
|
+
if (!(this.isMeta && isUnderlying)) return [3 /*break*/, 8];
|
|
3113
3117
|
basePool = new PoolTemplate(this.basePool);
|
|
3114
|
-
if (!(this.wrappedCoins.length === 3)) return [3 /*break*/,
|
|
3118
|
+
if (!(this.wrappedCoins.length === 3)) return [3 /*break*/, 4];
|
|
3115
3119
|
return [4 /*yield*/, contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)];
|
|
3116
|
-
case
|
|
3117
|
-
case
|
|
3118
|
-
if (!basePool.isFake) return [3 /*break*/,
|
|
3120
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
3121
|
+
case 4:
|
|
3122
|
+
if (!basePool.isFake) return [3 /*break*/, 6];
|
|
3119
3123
|
secondPool = new PoolTemplate(basePool.basePool);
|
|
3120
3124
|
return [4 /*yield*/, contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, curve.constantOptions)];
|
|
3121
|
-
case 3: return [2 /*return*/, _c.sent()];
|
|
3122
|
-
case 4: return [4 /*yield*/, contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)];
|
|
3123
3125
|
case 5: return [2 /*return*/, _c.sent()];
|
|
3124
|
-
case 6: return [4 /*yield*/, contract.
|
|
3126
|
+
case 6: return [4 /*yield*/, contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)];
|
|
3125
3127
|
case 7: return [2 /*return*/, _c.sent()];
|
|
3126
|
-
case 8: return [
|
|
3127
|
-
case 9:
|
|
3128
|
-
|
|
3128
|
+
case 8: return [4 /*yield*/, contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions)];
|
|
3129
|
+
case 9: return [2 /*return*/, _c.sent()];
|
|
3130
|
+
case 10: return [3 /*break*/, 27];
|
|
3131
|
+
case 11:
|
|
3132
|
+
if (!this.isNg) return [3 /*break*/, 18];
|
|
3129
3133
|
contract_1 = curve.contracts[this.address].contract;
|
|
3130
|
-
if (!this.isMeta) return [3 /*break*/,
|
|
3131
|
-
if (!isUnderlying) return [3 /*break*/,
|
|
3134
|
+
if (!this.isMeta) return [3 /*break*/, 16];
|
|
3135
|
+
if (!isUnderlying) return [3 /*break*/, 13];
|
|
3132
3136
|
return [4 /*yield*/, contract_1.get_dx_underlying(i, j, _amount, curve.constantOptions)];
|
|
3133
|
-
case 10: return [2 /*return*/, _c.sent()];
|
|
3134
|
-
case 11: return [4 /*yield*/, contract_1.get_dx(i, j, _amount, curve.constantOptions)];
|
|
3135
3137
|
case 12: return [2 /*return*/, _c.sent()];
|
|
3136
|
-
case 13: return [
|
|
3137
|
-
case 14: return [
|
|
3138
|
-
case 15: return [
|
|
3139
|
-
case 16:
|
|
3138
|
+
case 13: return [4 /*yield*/, contract_1.get_dx(i, j, _amount, curve.constantOptions)];
|
|
3139
|
+
case 14: return [2 /*return*/, _c.sent()];
|
|
3140
|
+
case 15: return [3 /*break*/, 18];
|
|
3141
|
+
case 16: return [4 /*yield*/, contract_1.get_dx(i, j, _amount, curve.constantOptions)];
|
|
3142
|
+
case 17: return [2 /*return*/, _c.sent()];
|
|
3143
|
+
case 18:
|
|
3140
3144
|
contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
|
|
3141
|
-
if (!this.isMeta) return [3 /*break*/,
|
|
3145
|
+
if (!this.isMeta) return [3 /*break*/, 23];
|
|
3142
3146
|
basePool = new PoolTemplate(this.basePool);
|
|
3143
|
-
if (!isUnderlying) return [3 /*break*/,
|
|
3147
|
+
if (!isUnderlying) return [3 /*break*/, 20];
|
|
3144
3148
|
return [4 /*yield*/, contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)];
|
|
3145
|
-
case 17: return [2 /*return*/, _c.sent()];
|
|
3146
|
-
case 18: return [4 /*yield*/, contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, curve.constantOptions)];
|
|
3147
3149
|
case 19: return [2 /*return*/, _c.sent()];
|
|
3148
|
-
case 20: return [
|
|
3149
|
-
case 21:
|
|
3150
|
-
|
|
3150
|
+
case 20: return [4 /*yield*/, contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, curve.constantOptions)];
|
|
3151
|
+
case 21: return [2 /*return*/, _c.sent()];
|
|
3152
|
+
case 22: return [3 /*break*/, 27];
|
|
3153
|
+
case 23:
|
|
3154
|
+
if (!(isUnderlying && this.isLending)) return [3 /*break*/, 25];
|
|
3151
3155
|
return [4 /*yield*/, contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length, curve.constantOptions)];
|
|
3152
|
-
case 22: return [2 /*return*/, _c.sent()];
|
|
3153
|
-
case 23: return [4 /*yield*/, contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions)];
|
|
3154
3156
|
case 24: return [2 /*return*/, _c.sent()];
|
|
3155
|
-
case 25: return [
|
|
3157
|
+
case 25: return [4 /*yield*/, contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions)];
|
|
3158
|
+
case 26: return [2 /*return*/, _c.sent()];
|
|
3159
|
+
case 27: return [2 /*return*/];
|
|
3156
3160
|
}
|
|
3157
3161
|
});
|
|
3158
3162
|
});
|
package/lib/router.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: stri
|
|
|
7
7
|
export declare const getArgs: (route: IRoute) => {
|
|
8
8
|
_route: string[];
|
|
9
9
|
_swapParams: number[][];
|
|
10
|
-
_pools
|
|
11
|
-
_basePools
|
|
12
|
-
_baseTokens
|
|
13
|
-
_secondBasePools
|
|
14
|
-
_secondBaseTokens
|
|
10
|
+
_pools?: string[];
|
|
11
|
+
_basePools?: string[];
|
|
12
|
+
_baseTokens?: string[];
|
|
13
|
+
_secondBasePools?: string[];
|
|
14
|
+
_secondBaseTokens?: string[];
|
|
15
15
|
};
|
|
16
16
|
export declare const swapExpected: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<string>;
|
|
17
17
|
export declare const swapRequired: (inputCoin: string, outputCoin: string, outAmount: number | string) => Promise<string>;
|
package/lib/router.js
CHANGED
|
@@ -66,6 +66,7 @@ var MAX_STEPS = 5;
|
|
|
66
66
|
var ROUTE_LENGTH = (MAX_STEPS * 2) + 1;
|
|
67
67
|
var GRAPH_MAX_EDGES = 3;
|
|
68
68
|
var MAX_ROUTES_FOR_ONE_COIN = 5;
|
|
69
|
+
var OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
|
|
69
70
|
var _removeDuplications = function (routes) {
|
|
70
71
|
return routes.filter(function (r, i, _routes) {
|
|
71
72
|
var routesByPoolIds = _routes.map(function (r) { return r.route.map(function (s) { return s.poolId; }).toString(); });
|
|
@@ -271,6 +272,8 @@ var _buildRouteGraph = memoize(function () { return __awaiter(void 0, void 0, vo
|
|
|
271
272
|
tokenAddress = poolData.token_address.toLowerCase();
|
|
272
273
|
isAaveLikeLending = poolData.is_lending && wrappedCoinAddresses.length === 3 && !poolData.deposit_address;
|
|
273
274
|
poolType = poolData.is_llamma ? 4 : poolData.is_crypto ? Math.min(poolData.wrapped_coins.length, 3) : 1;
|
|
275
|
+
if (poolData.is_ng)
|
|
276
|
+
poolType *= 10;
|
|
274
277
|
tvlMultiplier = poolData.is_crypto ? 1 : ((_j = amplificationCoefficientDict[poolData.swap_address]) !== null && _j !== void 0 ? _j : 1);
|
|
275
278
|
basePool = poolData.is_meta ? __assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA)[poolData.base_pool] : null;
|
|
276
279
|
basePoolAddress = basePool ? basePool.swap_address.toLowerCase() : curve.constants.ZERO_ADDRESS;
|
|
@@ -504,33 +507,49 @@ var _getRouteKey = function (route, inputCoinAddress, outputCoinAddress) {
|
|
|
504
507
|
return key;
|
|
505
508
|
};
|
|
506
509
|
var _getExchangeArgs = function (route) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
510
|
+
if (OLD_CHAINS.includes(curve.chainId)) {
|
|
511
|
+
var _route = [];
|
|
512
|
+
if (route.length > 0)
|
|
513
|
+
_route.push(route[0].inputCoinAddress);
|
|
514
|
+
var _swapParams = [];
|
|
515
|
+
var _pools = [];
|
|
516
|
+
var _basePools = [];
|
|
517
|
+
var _baseTokens = [];
|
|
518
|
+
var _secondBasePools = [];
|
|
519
|
+
var _secondBaseTokens = [];
|
|
520
|
+
for (var _i = 0, route_2 = route; _i < route_2.length; _i++) {
|
|
521
|
+
var routeStep = route_2[_i];
|
|
522
|
+
_route.push(routeStep.swapAddress, routeStep.outputCoinAddress);
|
|
523
|
+
_swapParams.push(routeStep.swapParams);
|
|
524
|
+
_pools.push(routeStep.poolAddress);
|
|
525
|
+
_basePools.push(routeStep.basePool);
|
|
526
|
+
_baseTokens.push(routeStep.baseToken);
|
|
527
|
+
_secondBasePools.push(routeStep.secondBasePool);
|
|
528
|
+
_secondBaseTokens.push(routeStep.secondBaseToken);
|
|
529
|
+
}
|
|
530
|
+
_route = _route.concat(Array(ROUTE_LENGTH - _route.length).fill(curve.constants.ZERO_ADDRESS));
|
|
531
|
+
_swapParams = _swapParams.concat(Array(MAX_STEPS - _swapParams.length).fill([0, 0, 0, 0, 0]));
|
|
532
|
+
_pools = _pools.concat(Array(MAX_STEPS - _pools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
533
|
+
_basePools = _basePools.concat(Array(MAX_STEPS - _basePools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
534
|
+
_baseTokens = _baseTokens.concat(Array(MAX_STEPS - _baseTokens.length).fill(curve.constants.ZERO_ADDRESS));
|
|
535
|
+
_secondBasePools = _secondBasePools.concat(Array(MAX_STEPS - _secondBasePools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
536
|
+
_secondBaseTokens = _secondBaseTokens.concat(Array(MAX_STEPS - _secondBaseTokens.length).fill(curve.constants.ZERO_ADDRESS));
|
|
537
|
+
return { _route: _route, _swapParams: _swapParams, _pools: _pools, _basePools: _basePools, _baseTokens: _baseTokens, _secondBasePools: _secondBasePools, _secondBaseTokens: _secondBaseTokens };
|
|
538
|
+
}
|
|
539
|
+
else { // RouterNgPoolsOnly
|
|
540
|
+
var _route = [];
|
|
541
|
+
if (route.length > 0)
|
|
542
|
+
_route.push(route[0].inputCoinAddress);
|
|
543
|
+
var _swapParams = [];
|
|
544
|
+
for (var _a = 0, route_3 = route; _a < route_3.length; _a++) {
|
|
545
|
+
var routeStep = route_3[_a];
|
|
546
|
+
_route.push(routeStep.swapAddress, routeStep.outputCoinAddress);
|
|
547
|
+
_swapParams.push(routeStep.swapParams.slice(0, 4));
|
|
548
|
+
}
|
|
549
|
+
_route = _route.concat(Array(ROUTE_LENGTH - _route.length).fill(curve.constants.ZERO_ADDRESS));
|
|
550
|
+
_swapParams = _swapParams.concat(Array(MAX_STEPS - _swapParams.length).fill([0, 0, 0, 0]));
|
|
551
|
+
return { _route: _route, _swapParams: _swapParams };
|
|
525
552
|
}
|
|
526
|
-
_route = _route.concat(Array(ROUTE_LENGTH - _route.length).fill(curve.constants.ZERO_ADDRESS));
|
|
527
|
-
_swapParams = _swapParams.concat(Array(MAX_STEPS - _swapParams.length).fill([0, 0, 0, 0, 0]));
|
|
528
|
-
_pools = _pools.concat(Array(MAX_STEPS - _pools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
529
|
-
_basePools = _basePools.concat(Array(MAX_STEPS - _basePools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
530
|
-
_baseTokens = _baseTokens.concat(Array(MAX_STEPS - _baseTokens.length).fill(curve.constants.ZERO_ADDRESS));
|
|
531
|
-
_secondBasePools = _secondBasePools.concat(Array(MAX_STEPS - _secondBasePools.length).fill(curve.constants.ZERO_ADDRESS));
|
|
532
|
-
_secondBaseTokens = _secondBaseTokens.concat(Array(MAX_STEPS - _secondBaseTokens.length).fill(curve.constants.ZERO_ADDRESS));
|
|
533
|
-
return { _route: _route, _swapParams: _swapParams, _pools: _pools, _basePools: _basePools, _baseTokens: _baseTokens, _secondBasePools: _secondBasePools, _secondBaseTokens: _secondBaseTokens };
|
|
534
553
|
};
|
|
535
554
|
var _estimatedGasForDifferentRoutesCache = {};
|
|
536
555
|
var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -550,7 +569,12 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
|
|
|
550
569
|
gasPromise = void 0;
|
|
551
570
|
_a = _getExchangeArgs(route), _route = _a._route, _swapParams = _a._swapParams, _pools = _a._pools;
|
|
552
571
|
if ((((_b = _estimatedGasForDifferentRoutesCache[routeKey]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 3600000 < Date.now()) {
|
|
553
|
-
|
|
572
|
+
if (_pools) {
|
|
573
|
+
gasPromise = contract.exchange.estimateGas(_route, _swapParams, _amount, 0, _pools, __assign(__assign({}, curve.constantOptions), { value: value }));
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
gasPromise = contract.exchange.estimateGas(_route, _swapParams, _amount, 0, __assign(__assign({}, curve.constantOptions), { value: value }));
|
|
577
|
+
}
|
|
554
578
|
}
|
|
555
579
|
else {
|
|
556
580
|
gasPromise = Promise.resolve(_estimatedGasForDifferentRoutesCache[routeKey].gas);
|
|
@@ -576,9 +600,9 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
|
|
|
576
600
|
});
|
|
577
601
|
}); };
|
|
578
602
|
var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
579
|
-
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _pools, _outputAmounts, i, err_2, contract, _outputs, _c, routesRaw_2, r, _d, _route, _swapParams, _pools, _e, _f, e_1, i,
|
|
580
|
-
return __generator(this, function (
|
|
581
|
-
switch (
|
|
603
|
+
var _a, inputCoinDecimals, outputCoinDecimals, _amount, routesRaw, routes, calls, multicallContract, _i, routesRaw_1, r, _b, _route, _swapParams, _pools, _outputAmounts, i, err_2, contract, _outputs, _c, routesRaw_2, r, _d, _route, _swapParams, _pools, _e, _f, _h, _j, e_1, i, _k, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, L1GasPrice, _l, txCostsUsd;
|
|
604
|
+
return __generator(this, function (_m) {
|
|
605
|
+
switch (_m.label) {
|
|
582
606
|
case 0:
|
|
583
607
|
_a = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
584
608
|
_amount = parseUnits(amount, inputCoinDecimals);
|
|
@@ -586,52 +610,65 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
586
610
|
return [2 /*return*/, []];
|
|
587
611
|
return [4 /*yield*/, _findRoutes(inputCoinAddress, outputCoinAddress)];
|
|
588
612
|
case 1:
|
|
589
|
-
routesRaw = (
|
|
613
|
+
routesRaw = (_m.sent()).map(function (route) { return ({ route: route, _output: curve.parseUnits("0"), outputUsd: 0, txCostUsd: 0 }); });
|
|
590
614
|
routes = [];
|
|
591
|
-
|
|
615
|
+
_m.label = 2;
|
|
592
616
|
case 2:
|
|
593
|
-
|
|
617
|
+
_m.trys.push([2, 4, , 14]);
|
|
594
618
|
calls = [];
|
|
595
619
|
multicallContract = curve.contracts[curve.constants.ALIASES.router].multicallContract;
|
|
596
620
|
for (_i = 0, routesRaw_1 = routesRaw; _i < routesRaw_1.length; _i++) {
|
|
597
621
|
r = routesRaw_1[_i];
|
|
598
622
|
_b = _getExchangeArgs(r.route), _route = _b._route, _swapParams = _b._swapParams, _pools = _b._pools;
|
|
599
|
-
|
|
623
|
+
if (_pools) {
|
|
624
|
+
calls.push(multicallContract.get_dy(_route, _swapParams, _amount, _pools));
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
calls.push(multicallContract.get_dy(_route, _swapParams, _amount));
|
|
628
|
+
}
|
|
600
629
|
}
|
|
601
630
|
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
602
631
|
case 3:
|
|
603
|
-
_outputAmounts =
|
|
632
|
+
_outputAmounts = _m.sent();
|
|
604
633
|
for (i = 0; i < _outputAmounts.length; i++) {
|
|
605
634
|
routesRaw[i]._output = _outputAmounts[i];
|
|
606
635
|
routes.push(routesRaw[i]);
|
|
607
636
|
}
|
|
608
|
-
return [3 /*break*/,
|
|
637
|
+
return [3 /*break*/, 14];
|
|
609
638
|
case 4:
|
|
610
|
-
err_2 =
|
|
639
|
+
err_2 = _m.sent();
|
|
611
640
|
contract = curve.contracts[curve.constants.ALIASES.router].contract;
|
|
612
641
|
_outputs = [];
|
|
613
642
|
_c = 0, routesRaw_2 = routesRaw;
|
|
614
|
-
|
|
643
|
+
_m.label = 5;
|
|
615
644
|
case 5:
|
|
616
|
-
if (!(_c < routesRaw_2.length)) return [3 /*break*/,
|
|
645
|
+
if (!(_c < routesRaw_2.length)) return [3 /*break*/, 13];
|
|
617
646
|
r = routesRaw_2[_c];
|
|
618
647
|
_d = _getExchangeArgs(r.route), _route = _d._route, _swapParams = _d._swapParams, _pools = _d._pools;
|
|
619
|
-
|
|
648
|
+
_m.label = 6;
|
|
620
649
|
case 6:
|
|
621
|
-
|
|
650
|
+
_m.trys.push([6, 11, , 12]);
|
|
651
|
+
if (!_pools) return [3 /*break*/, 8];
|
|
622
652
|
_f = (_e = _outputs).push;
|
|
623
653
|
return [4 /*yield*/, contract.get_dy(_route, _swapParams, _amount, _pools, curve.constantOptions)];
|
|
624
654
|
case 7:
|
|
625
|
-
_f.apply(_e, [
|
|
626
|
-
return [3 /*break*/,
|
|
655
|
+
_f.apply(_e, [_m.sent()]);
|
|
656
|
+
return [3 /*break*/, 10];
|
|
627
657
|
case 8:
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
return [3 /*break*/, 9];
|
|
658
|
+
_j = (_h = _outputs).push;
|
|
659
|
+
return [4 /*yield*/, contract.get_dy(_route, _swapParams, _amount, curve.constantOptions)];
|
|
631
660
|
case 9:
|
|
661
|
+
_j.apply(_h, [_m.sent()]);
|
|
662
|
+
_m.label = 10;
|
|
663
|
+
case 10: return [3 /*break*/, 12];
|
|
664
|
+
case 11:
|
|
665
|
+
e_1 = _m.sent();
|
|
666
|
+
_outputs.push(curve.parseUnits('-1', 0));
|
|
667
|
+
return [3 /*break*/, 12];
|
|
668
|
+
case 12:
|
|
632
669
|
_c++;
|
|
633
670
|
return [3 /*break*/, 5];
|
|
634
|
-
case
|
|
671
|
+
case 13:
|
|
635
672
|
for (i = 0; i < _outputs.length; i++) {
|
|
636
673
|
if (_outputs[i] < 0) {
|
|
637
674
|
console.log("Route ".concat((routesRaw[i].route.map(function (s) { return s.poolId; })).join(" --> "), " is unavailable"));
|
|
@@ -640,8 +677,8 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
640
677
|
routesRaw[i]._output = _outputs[i];
|
|
641
678
|
routes.push(routesRaw[i]);
|
|
642
679
|
}
|
|
643
|
-
return [3 /*break*/,
|
|
644
|
-
case
|
|
680
|
+
return [3 /*break*/, 14];
|
|
681
|
+
case 14:
|
|
645
682
|
if (routes.length === 0)
|
|
646
683
|
return [2 /*return*/, []];
|
|
647
684
|
if (routes.length === 1)
|
|
@@ -652,21 +689,21 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
652
689
|
axios.get("https://api.curve.fi/api/getGas"),
|
|
653
690
|
_getUsdRate(ETH_ADDRESS),
|
|
654
691
|
])];
|
|
655
|
-
case
|
|
656
|
-
|
|
692
|
+
case 15:
|
|
693
|
+
_k = _m.sent(), gasAmounts = _k[0], outputCoinUsdRate = _k[1], gasData = _k[2], ethUsdRate = _k[3];
|
|
657
694
|
gasPrice = gasData.data.data.gas.standard;
|
|
658
695
|
expectedAmounts = (routes).map(function (route) { return Number(curve.formatUnits(route._output, outputCoinDecimals)); });
|
|
659
696
|
expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
|
|
660
|
-
if (!L2Networks.includes(curve.chainId)) return [3 /*break*/,
|
|
697
|
+
if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 17];
|
|
661
698
|
return [4 /*yield*/, getGasPriceFromL1()];
|
|
662
|
-
case
|
|
663
|
-
|
|
664
|
-
return [3 /*break*/,
|
|
665
|
-
case
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
case
|
|
669
|
-
L1GasPrice =
|
|
699
|
+
case 16:
|
|
700
|
+
_l = _m.sent();
|
|
701
|
+
return [3 /*break*/, 18];
|
|
702
|
+
case 17:
|
|
703
|
+
_l = 0;
|
|
704
|
+
_m.label = 18;
|
|
705
|
+
case 18:
|
|
706
|
+
L1GasPrice = _l;
|
|
670
707
|
txCostsUsd = gasAmounts.map(function (a) { return getTxCostsUsd(ethUsdRate, gasPrice, a, L1GasPrice); });
|
|
671
708
|
routes.forEach(function (route, i) {
|
|
672
709
|
route.outputUsd = expectedAmountsUsd[i];
|
|
@@ -693,8 +730,11 @@ var _getOutputForRoute = memoize(function (route, _amount) { return __awaiter(vo
|
|
|
693
730
|
case 0:
|
|
694
731
|
contract = curve.contracts[curve.constants.ALIASES.router].contract;
|
|
695
732
|
_a = _getExchangeArgs(route), _route = _a._route, _swapParams = _a._swapParams, _pools = _a._pools;
|
|
733
|
+
if (!_pools) return [3 /*break*/, 2];
|
|
696
734
|
return [4 /*yield*/, contract.get_dy(_route, _swapParams, _amount, _pools, curve.constantOptions)];
|
|
697
735
|
case 1: return [2 /*return*/, _b.sent()];
|
|
736
|
+
case 2: return [4 /*yield*/, contract.get_dy(_route, _swapParams, _amount, curve.constantOptions)];
|
|
737
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
698
738
|
}
|
|
699
739
|
});
|
|
700
740
|
}); }, {
|
|
@@ -769,12 +809,18 @@ export var swapRequired = function (inputCoin, outputCoin, outAmount) { return _
|
|
|
769
809
|
return [4 /*yield*/, contract.get_dx(_route, _swapParams, _outAmount, _pools, _basePools, _baseTokens, _secondBasePools, _secondBaseTokens, curve.constantOptions)];
|
|
770
810
|
case 4:
|
|
771
811
|
_required = _d.sent();
|
|
772
|
-
return [3 /*break*/,
|
|
773
|
-
case 5:
|
|
812
|
+
return [3 /*break*/, 9];
|
|
813
|
+
case 5:
|
|
814
|
+
if (!_pools) return [3 /*break*/, 7];
|
|
815
|
+
return [4 /*yield*/, contract.get_dx(_route, _swapParams, _outAmount, _pools, _basePools, _baseTokens, curve.constantOptions)];
|
|
774
816
|
case 6:
|
|
775
817
|
_required = _d.sent();
|
|
776
|
-
|
|
777
|
-
case 7: return [
|
|
818
|
+
return [3 /*break*/, 9];
|
|
819
|
+
case 7: return [4 /*yield*/, contract.get_dx(_route, _swapParams, _outAmount, curve.constantOptions)];
|
|
820
|
+
case 8:
|
|
821
|
+
_required = _d.sent();
|
|
822
|
+
_d.label = 9;
|
|
823
|
+
case 9: return [2 /*return*/, curve.formatUnits(_required, inputCoinDecimals)];
|
|
778
824
|
}
|
|
779
825
|
});
|
|
780
826
|
}); };
|
|
@@ -797,19 +843,31 @@ export var swapPriceImpact = function (inputCoin, outputCoin, amount) { return _
|
|
|
797
843
|
_d = _getExchangeArgs(route), _route = _d._route, _swapParams = _d._swapParams, _pools = _d._pools;
|
|
798
844
|
_e.label = 1;
|
|
799
845
|
case 1:
|
|
800
|
-
_e.trys.push([1,
|
|
846
|
+
_e.trys.push([1, 6, , 11]);
|
|
847
|
+
if (!_pools) return [3 /*break*/, 3];
|
|
801
848
|
return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, _pools, curve.constantOptions)];
|
|
802
849
|
case 2:
|
|
803
850
|
_smallOutput = _e.sent();
|
|
804
851
|
return [3 /*break*/, 5];
|
|
805
|
-
case 3:
|
|
852
|
+
case 3: return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, curve.constantOptions)];
|
|
853
|
+
case 4:
|
|
854
|
+
_smallOutput = _e.sent();
|
|
855
|
+
_e.label = 5;
|
|
856
|
+
case 5: return [3 /*break*/, 11];
|
|
857
|
+
case 6:
|
|
806
858
|
e_2 = _e.sent();
|
|
807
859
|
_smallAmount = curve.parseUnits("1", inputCoinDecimals); // Dirty hack
|
|
860
|
+
if (!_pools) return [3 /*break*/, 8];
|
|
808
861
|
return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, _pools, curve.constantOptions)];
|
|
809
|
-
case
|
|
862
|
+
case 7:
|
|
810
863
|
_smallOutput = _e.sent();
|
|
811
|
-
return [3 /*break*/,
|
|
812
|
-
case
|
|
864
|
+
return [3 /*break*/, 10];
|
|
865
|
+
case 8: return [4 /*yield*/, contract.get_dy(_route, _swapParams, _smallAmount, curve.constantOptions)];
|
|
866
|
+
case 9:
|
|
867
|
+
_smallOutput = _e.sent();
|
|
868
|
+
_e.label = 10;
|
|
869
|
+
case 10: return [3 /*break*/, 11];
|
|
870
|
+
case 11:
|
|
813
871
|
priceImpactBN = _get_price_impact(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
814
872
|
return [2 /*return*/, Number(_cutZeros(priceImpactBN.toFixed(4)))];
|
|
815
873
|
}
|
|
@@ -860,15 +918,15 @@ export var swapEstimateGas = function (inputCoin, outputCoin, amount) { return _
|
|
|
860
918
|
export var swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
861
919
|
if (slippage === void 0) { slippage = 0.5; }
|
|
862
920
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
863
|
-
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _d, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit, _e;
|
|
864
|
-
return __generator(this, function (
|
|
865
|
-
switch (
|
|
921
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _d, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit, _e, gasLimit, _f;
|
|
922
|
+
return __generator(this, function (_h) {
|
|
923
|
+
switch (_h.label) {
|
|
866
924
|
case 0:
|
|
867
925
|
_a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
868
926
|
_b = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
|
|
869
927
|
return [4 /*yield*/, swapApprove(inputCoin, amount)];
|
|
870
928
|
case 1:
|
|
871
|
-
|
|
929
|
+
_h.sent();
|
|
872
930
|
_c = _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount), route = _c.route, output = _c.output;
|
|
873
931
|
if (route.length === 0) {
|
|
874
932
|
throw new Error("This pair can't be exchanged");
|
|
@@ -881,13 +939,21 @@ export var swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
|
881
939
|
value = isEth(inputCoinAddress) ? _amount : curve.parseUnits("0");
|
|
882
940
|
return [4 /*yield*/, curve.updateFeeData()];
|
|
883
941
|
case 2:
|
|
884
|
-
|
|
942
|
+
_h.sent();
|
|
943
|
+
if (!_pools) return [3 /*break*/, 5];
|
|
885
944
|
_e = DIGas;
|
|
886
945
|
return [4 /*yield*/, contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
887
946
|
case 3:
|
|
888
|
-
gasLimit = (_e.apply(void 0, [
|
|
947
|
+
gasLimit = (_e.apply(void 0, [_h.sent()])) * (curve.chainId === 1 ? curve.parseUnits("130", 0) : curve.parseUnits("160", 0)) / curve.parseUnits("100", 0);
|
|
889
948
|
return [4 /*yield*/, contract.exchange(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
890
|
-
case 4: return [2 /*return*/,
|
|
949
|
+
case 4: return [2 /*return*/, _h.sent()];
|
|
950
|
+
case 5:
|
|
951
|
+
_f = DIGas;
|
|
952
|
+
return [4 /*yield*/, contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
953
|
+
case 6:
|
|
954
|
+
gasLimit = (_f.apply(void 0, [_h.sent()])) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0);
|
|
955
|
+
return [4 /*yield*/, contract.exchange(_route, _swapParams, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
956
|
+
case 7: return [2 /*return*/, _h.sent()];
|
|
891
957
|
}
|
|
892
958
|
});
|
|
893
959
|
});
|
package/lib/utils.js
CHANGED
|
@@ -1008,7 +1008,7 @@ export var getBasePools = function () { return __awaiter(void 0, void 0, void 0,
|
|
|
1008
1008
|
factoryMulticallContract = curve.contracts[curve.constants.ALIASES['stable_ng_factory']].multicallContract;
|
|
1009
1009
|
_a = Number;
|
|
1010
1010
|
_c = (_b = curve).formatUnits;
|
|
1011
|
-
return [4 /*yield*/, factoryContract.base_pool_count(
|
|
1011
|
+
return [4 /*yield*/, factoryContract.base_pool_count()];
|
|
1012
1012
|
case 1:
|
|
1013
1013
|
basePoolCount = _a.apply(void 0, [_c.apply(_b, [_d.sent(), 0])]);
|
|
1014
1014
|
calls = [];
|