@curvefi/api 2.8.2 → 2.8.5
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/atricrypto3/base_pool_zap.json +216 -0
- package/lib/constants/abis/gauge_v5.json +1 -1
- package/lib/factory/common.d.ts +1 -0
- package/lib/factory/common.js +12 -1
- package/lib/factory/constants.js +5 -0
- package/lib/factory/factory-api.js +101 -30
- package/lib/factory/factory-crypto.js +75 -22
- package/lib/factory/factory.js +31 -12
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +101 -61
- package/lib/pools/mixins/common.d.ts +1 -0
- package/lib/pools/mixins/common.js +30 -1
- package/lib/pools/mixins/poolBalancesMixin.js +14 -6
- package/lib/pools/mixins/withdrawExpectedMixins.js +17 -15
- package/lib/pools/poolConstructor.js +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +15 -7
- package/package.json +1 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"stateMutability": "nonpayable",
|
|
4
|
+
"type": "constructor",
|
|
5
|
+
"inputs": [
|
|
6
|
+
{
|
|
7
|
+
"name": "_base_pool",
|
|
8
|
+
"type": "address"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "_base_lp_token",
|
|
12
|
+
"type": "address"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "_weth",
|
|
16
|
+
"type": "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "_base_coins",
|
|
20
|
+
"type": "address[5]"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"outputs": []
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"stateMutability": "payable",
|
|
27
|
+
"type": "fallback"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"stateMutability": "payable",
|
|
31
|
+
"type": "function",
|
|
32
|
+
"name": "exchange",
|
|
33
|
+
"inputs": [
|
|
34
|
+
{
|
|
35
|
+
"name": "_pool",
|
|
36
|
+
"type": "address"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "i",
|
|
40
|
+
"type": "uint256"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "j",
|
|
44
|
+
"type": "uint256"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "_dx",
|
|
48
|
+
"type": "uint256"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "_min_dy",
|
|
52
|
+
"type": "uint256"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"outputs": [
|
|
56
|
+
{
|
|
57
|
+
"name": "",
|
|
58
|
+
"type": "uint256"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"stateMutability": "view",
|
|
64
|
+
"type": "function",
|
|
65
|
+
"name": "get_dy",
|
|
66
|
+
"inputs": [
|
|
67
|
+
{
|
|
68
|
+
"name": "_pool",
|
|
69
|
+
"type": "address"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "i",
|
|
73
|
+
"type": "uint256"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "j",
|
|
77
|
+
"type": "uint256"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "_dx",
|
|
81
|
+
"type": "uint256"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"outputs": [
|
|
85
|
+
{
|
|
86
|
+
"name": "",
|
|
87
|
+
"type": "uint256"
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"stateMutability": "payable",
|
|
93
|
+
"type": "function",
|
|
94
|
+
"name": "add_liquidity",
|
|
95
|
+
"inputs": [
|
|
96
|
+
{
|
|
97
|
+
"name": "_pool",
|
|
98
|
+
"type": "address"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "_deposit_amounts",
|
|
102
|
+
"type": "uint256[6]"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "_min_mint_amount",
|
|
106
|
+
"type": "uint256"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"outputs": [
|
|
110
|
+
{
|
|
111
|
+
"name": "",
|
|
112
|
+
"type": "uint256"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"stateMutability": "view",
|
|
118
|
+
"type": "function",
|
|
119
|
+
"name": "calc_token_amount",
|
|
120
|
+
"inputs": [
|
|
121
|
+
{
|
|
122
|
+
"name": "_pool",
|
|
123
|
+
"type": "address"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"name": "_amounts",
|
|
127
|
+
"type": "uint256[6]"
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"outputs": [
|
|
131
|
+
{
|
|
132
|
+
"name": "",
|
|
133
|
+
"type": "uint256"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"stateMutability": "nonpayable",
|
|
139
|
+
"type": "function",
|
|
140
|
+
"name": "remove_liquidity",
|
|
141
|
+
"inputs": [
|
|
142
|
+
{
|
|
143
|
+
"name": "_pool",
|
|
144
|
+
"type": "address"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "_burn_amount",
|
|
148
|
+
"type": "uint256"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "_min_amounts",
|
|
152
|
+
"type": "uint256[6]"
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
"outputs": [
|
|
156
|
+
{
|
|
157
|
+
"name": "",
|
|
158
|
+
"type": "uint256[6]"
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"stateMutability": "nonpayable",
|
|
164
|
+
"type": "function",
|
|
165
|
+
"name": "remove_liquidity_one_coin",
|
|
166
|
+
"inputs": [
|
|
167
|
+
{
|
|
168
|
+
"name": "_pool",
|
|
169
|
+
"type": "address"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "_burn_amount",
|
|
173
|
+
"type": "uint256"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"name": "i",
|
|
177
|
+
"type": "uint256"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"name": "_min_amount",
|
|
181
|
+
"type": "uint256"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"outputs": [
|
|
185
|
+
{
|
|
186
|
+
"name": "",
|
|
187
|
+
"type": "uint256"
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"stateMutability": "view",
|
|
193
|
+
"type": "function",
|
|
194
|
+
"name": "calc_withdraw_one_coin",
|
|
195
|
+
"inputs": [
|
|
196
|
+
{
|
|
197
|
+
"name": "_pool",
|
|
198
|
+
"type": "address"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "_token_amount",
|
|
202
|
+
"type": "uint256"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "i",
|
|
206
|
+
"type": "uint256"
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
"outputs": [
|
|
210
|
+
{
|
|
211
|
+
"name": "",
|
|
212
|
+
"type": "uint256"
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
]
|
package/lib/factory/common.d.ts
CHANGED
package/lib/factory/common.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setFactoryZapContracts = void 0;
|
|
6
|
+
exports.setCryptoFactoryZapContracts = exports.setFactoryZapContracts = void 0;
|
|
7
7
|
var ethers_1 = require("ethers");
|
|
8
8
|
var ethcall_1 = require("ethcall");
|
|
9
9
|
var deposit_json_1 = __importDefault(require("../constants/abis/factoryPools/deposit.json"));
|
|
@@ -12,6 +12,7 @@ var DepositZapMetaUsdPolygon_json_1 = __importDefault(require("../constants/abis
|
|
|
12
12
|
var DepositZapMetaBtcPolygon_json_1 = __importDefault(require("../constants/abis/factory-v2/DepositZapMetaBtcPolygon.json"));
|
|
13
13
|
var DepositZapFantom_json_1 = __importDefault(require("../constants/abis/factory-v2/DepositZapFantom.json"));
|
|
14
14
|
var DepositZapMetaUsd2Fantom_json_1 = __importDefault(require("../constants/abis/factory-v2/DepositZapMetaUsd2Fantom.json"));
|
|
15
|
+
var base_pool_zap_json_1 = __importDefault(require("../constants/abis/atricrypto3/base_pool_zap.json"));
|
|
15
16
|
function setFactoryZapContracts() {
|
|
16
17
|
if (this.chainId === 1) {
|
|
17
18
|
var fraxusdcMetaZapAddress = "0x08780fb7E580e492c1935bEe4fA5920b94AA95Da".toLowerCase();
|
|
@@ -94,3 +95,13 @@ function setFactoryZapContracts() {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
exports.setFactoryZapContracts = setFactoryZapContracts;
|
|
98
|
+
function setCryptoFactoryZapContracts() {
|
|
99
|
+
if (this.chainId === 137) {
|
|
100
|
+
var atricrypto3ZapAddress = "0x3d8EADb739D1Ef95dd53D718e4810721837c69c1".toLowerCase();
|
|
101
|
+
this.contracts[atricrypto3ZapAddress] = {
|
|
102
|
+
contract: new ethers_1.Contract(atricrypto3ZapAddress, base_pool_zap_json_1.default, this.signer || this.provider),
|
|
103
|
+
multicallContract: new ethcall_1.Contract(atricrypto3ZapAddress, base_pool_zap_json_1.default),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.setCryptoFactoryZapContracts = setCryptoFactoryZapContracts;
|
package/lib/factory/constants.js
CHANGED
|
@@ -126,6 +126,8 @@ exports.implementationABIDictArbitrum = {
|
|
|
126
126
|
exports.implementationABIDictOptimism = {
|
|
127
127
|
"0x78CF256256C8089d68Cde634Cf7cDEFb39286470": MetaUSD_json_1.default,
|
|
128
128
|
"0xADf698e4d8Df08b3E2c79682891636eF00F6e205": MetaUSDBalances_json_1.default,
|
|
129
|
+
"0xe8269B33E47761f552E1a3070119560d5fa8bBD6": MetaFraxUSD_json_1.default,
|
|
130
|
+
"0x114C4042B11a2b16F58Fe1BFe847589a122F678a": MetaFraxUSDBalances_json_1.default,
|
|
129
131
|
"0xC2b1DF84112619D190193E48148000e3990Bf627": Plain2Basic_json_1.default,
|
|
130
132
|
"0x16a7DA911A4DD1d83F3fF066fE28F3C792C50d90": Plain2Balances_json_1.default,
|
|
131
133
|
"0x4f3E8F405CF5aFC05D68142F3783bDfE13811522": Plain2ETH_json_1.default,
|
|
@@ -195,6 +197,8 @@ exports.implementationBasePoolIdDictArbitrum = {
|
|
|
195
197
|
exports.implementationBasePoolIdDictOptimism = {
|
|
196
198
|
"0x78CF256256C8089d68Cde634Cf7cDEFb39286470": "3pool",
|
|
197
199
|
"0xADf698e4d8Df08b3E2c79682891636eF00F6e205": "3pool",
|
|
200
|
+
"0xe8269B33E47761f552E1a3070119560d5fa8bBD6": "factory-v2-16",
|
|
201
|
+
"0x114C4042B11a2b16F58Fe1BFe847589a122F678a": "factory-v2-16", // fraxusdc
|
|
198
202
|
};
|
|
199
203
|
exports.implementationBasePoolIdDictXDai = {
|
|
200
204
|
"0x4A5bF7Ab9A8202692051c19B102d3eDD62aaBAE6": "3pool",
|
|
@@ -225,6 +229,7 @@ exports.basePoolIdZapDictArbitrum = {
|
|
|
225
229
|
};
|
|
226
230
|
exports.basePoolIdZapDictOptimism = {
|
|
227
231
|
"3pool": "0x167e42a1c7ab4be03764a2222aac57f5f6754411".toLowerCase(),
|
|
232
|
+
"factory-v2-16": "'0x4244eB811D6e0Ef302326675207A95113dB4E1F8'".toLowerCase(),
|
|
228
233
|
};
|
|
229
234
|
exports.basePoolIdZapDictXDai = {
|
|
230
235
|
"3pool": "0x87C067fAc25f123554a0E76596BF28cFa37fD5E9".toLowerCase(),
|
|
@@ -1,4 +1,15 @@
|
|
|
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,9 +64,11 @@ var axios_1 = __importDefault(require("axios"));
|
|
|
53
64
|
var ethers_1 = require("ethers");
|
|
54
65
|
var ethcall_1 = require("ethcall");
|
|
55
66
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
67
|
+
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
56
68
|
var deposit_json_1 = __importDefault(require("../constants/abis/factoryPools/deposit.json"));
|
|
57
69
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
58
70
|
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
|
|
71
|
+
var base_pool_zap_json_1 = __importDefault(require("../constants/abis/atricrypto3/base_pool_zap.json"));
|
|
59
72
|
var constants_1 = require("./constants");
|
|
60
73
|
var common_1 = require("./common");
|
|
61
74
|
function setFactorySwapContracts(rawPoolList, isCrypto) {
|
|
@@ -96,8 +109,8 @@ function setFactoryGaugeContracts(rawPoolList) {
|
|
|
96
109
|
if (pool.gaugeAddress) {
|
|
97
110
|
var addr = pool.gaugeAddress.toLowerCase();
|
|
98
111
|
_this.contracts[addr] = {
|
|
99
|
-
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
100
|
-
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
112
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
113
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
101
114
|
};
|
|
102
115
|
}
|
|
103
116
|
});
|
|
@@ -133,22 +146,38 @@ function setFactoryRewardCoinsContracts(rawPoolList) {
|
|
|
133
146
|
}
|
|
134
147
|
}
|
|
135
148
|
}
|
|
149
|
+
var atricrypto3Lp = "0xdAD97F7713Ae9437fa9249920eC8507e5FbB23d3".toLowerCase();
|
|
136
150
|
function getFactoryPoolsDataFromApi(isCrypto) {
|
|
137
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
-
var network, factoryType, url, response, rawPoolList, mainAddresses, FACTORY_POOLS_DATA;
|
|
152
|
+
var network, factoryType, url, response, rawPoolList, mainAddresses, url_1, response_1, poolGaugeDict, _i, _a, gaugeData, i, FACTORY_POOLS_DATA;
|
|
139
153
|
var _this = this;
|
|
140
|
-
return __generator(this, function (
|
|
141
|
-
switch (
|
|
154
|
+
return __generator(this, function (_b) {
|
|
155
|
+
switch (_b.label) {
|
|
142
156
|
case 0:
|
|
143
157
|
network = this.constants.NETWORK_NAME;
|
|
144
158
|
factoryType = isCrypto ? "factory-crypto" : "factory";
|
|
145
159
|
url = "https://api.curve.fi/api/getPools/".concat(network, "/").concat(factoryType);
|
|
146
160
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
147
161
|
case 1:
|
|
148
|
-
response =
|
|
162
|
+
response = _b.sent();
|
|
149
163
|
rawPoolList = response.data.data.poolData;
|
|
150
164
|
mainAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
151
165
|
rawPoolList = rawPoolList.filter(function (p) { return !mainAddresses.includes(p.address.toLowerCase()); });
|
|
166
|
+
if (!(this.chainId !== 1)) return [3 /*break*/, 3];
|
|
167
|
+
url_1 = "https://api.curve.fi/api/getFactoGauges/".concat(network);
|
|
168
|
+
return [4 /*yield*/, axios_1.default.get(url_1)];
|
|
169
|
+
case 2:
|
|
170
|
+
response_1 = _b.sent();
|
|
171
|
+
poolGaugeDict = {};
|
|
172
|
+
for (_i = 0, _a = response_1.data.data.gauges; _i < _a.length; _i++) {
|
|
173
|
+
gaugeData = _a[_i];
|
|
174
|
+
poolGaugeDict[gaugeData.swap] = gaugeData.gauge;
|
|
175
|
+
}
|
|
176
|
+
for (i = 0; i < rawPoolList.length; i++) {
|
|
177
|
+
rawPoolList[i].gaugeAddress = poolGaugeDict[rawPoolList[i].address];
|
|
178
|
+
}
|
|
179
|
+
_b.label = 3;
|
|
180
|
+
case 3:
|
|
152
181
|
setFactorySwapContracts.call(this, rawPoolList, isCrypto);
|
|
153
182
|
if (isCrypto)
|
|
154
183
|
setCryptoFactoryTokenContracts.call(this, rawPoolList);
|
|
@@ -157,6 +186,8 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
157
186
|
setFactoryRewardCoinsContracts.call(this, rawPoolList);
|
|
158
187
|
if (!isCrypto)
|
|
159
188
|
common_1.setFactoryZapContracts.call(this);
|
|
189
|
+
if (isCrypto)
|
|
190
|
+
common_1.setCryptoFactoryZapContracts.call(this);
|
|
160
191
|
FACTORY_POOLS_DATA = {};
|
|
161
192
|
rawPoolList.forEach(function (pool) {
|
|
162
193
|
var coinAddresses = pool.coins.map(function (c) { return c.address.toLowerCase(); });
|
|
@@ -167,36 +198,76 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
167
198
|
var cryptoCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol; });
|
|
168
199
|
var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol; });
|
|
169
200
|
var underlyingCoinAddresses = coinAddresses.map(function (addr) { return addr === nativeToken.wrappedAddress ? constants_1.NATIVE_TOKEN_ADDRESS : addr; });
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
var isMeta = _this.chainId === 137 && coinAddresses[1].toLowerCase() === atricrypto3Lp;
|
|
202
|
+
if (isMeta) {
|
|
203
|
+
var basePoolId = "atricrypto3";
|
|
204
|
+
var basePoolCoinNames = ['DAI', 'USDC', 'USDT', 'WBTC', 'WETH'];
|
|
205
|
+
var basePoolCoinAddresses = [
|
|
206
|
+
'0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
|
|
207
|
+
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
|
|
208
|
+
'0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
209
|
+
'0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6',
|
|
210
|
+
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', // WETH
|
|
211
|
+
];
|
|
212
|
+
var basePoolDecimals = [18, 6, 6, 8, 18];
|
|
213
|
+
var basePoolZap = "0x3d8EADb739D1Ef95dd53D718e4810721837c69c1";
|
|
214
|
+
FACTORY_POOLS_DATA[pool.id] = {
|
|
215
|
+
name: pool.name.split(": ")[1].trim(),
|
|
216
|
+
full_name: pool.name,
|
|
217
|
+
symbol: pool.symbol,
|
|
218
|
+
reference_asset: "CRYPTO",
|
|
219
|
+
swap_address: pool.address.toLowerCase(),
|
|
220
|
+
token_address: pool.lpTokenAddress.toLowerCase(),
|
|
221
|
+
gauge_address: pool.gaugeAddress ? pool.gaugeAddress.toLowerCase() : ethers_1.ethers.constants.AddressZero,
|
|
222
|
+
deposit_address: basePoolZap,
|
|
223
|
+
is_meta: true,
|
|
224
|
+
is_crypto: true,
|
|
225
|
+
is_factory: true,
|
|
226
|
+
base_pool: basePoolId,
|
|
227
|
+
underlying_coins: __spreadArray([coinNames[0]], basePoolCoinNames, true),
|
|
228
|
+
wrapped_coins: coinNames,
|
|
229
|
+
underlying_coin_addresses: __spreadArray([coinAddresses[0]], basePoolCoinAddresses, true),
|
|
230
|
+
wrapped_coin_addresses: coinAddresses,
|
|
231
|
+
underlying_decimals: __spreadArray([coinDecimals[0]], basePoolDecimals, true),
|
|
232
|
+
wrapped_decimals: coinDecimals,
|
|
233
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
234
|
+
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
235
|
+
deposit_abi: base_pool_zap_json_1.default,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
FACTORY_POOLS_DATA[pool.id] = {
|
|
240
|
+
name: pool.name.split(": ")[1].trim(),
|
|
241
|
+
full_name: pool.name,
|
|
242
|
+
symbol: pool.symbol,
|
|
243
|
+
reference_asset: "CRYPTO",
|
|
244
|
+
swap_address: pool.address.toLowerCase(),
|
|
245
|
+
token_address: pool.lpTokenAddress.toLowerCase(),
|
|
246
|
+
gauge_address: pool.gaugeAddress ? pool.gaugeAddress.toLowerCase() : ethers_1.ethers.constants.AddressZero,
|
|
247
|
+
is_crypto: true,
|
|
248
|
+
is_factory: true,
|
|
249
|
+
underlying_coins: underlyingCoinNames,
|
|
250
|
+
wrapped_coins: cryptoCoinNames,
|
|
251
|
+
underlying_coin_addresses: underlyingCoinAddresses,
|
|
252
|
+
wrapped_coin_addresses: coinAddresses,
|
|
253
|
+
underlying_decimals: coinDecimals,
|
|
254
|
+
wrapped_decimals: coinDecimals,
|
|
255
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
256
|
+
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
189
259
|
}
|
|
190
260
|
else if (pool.implementation.startsWith("meta")) {
|
|
191
261
|
var implementationABIDict = constants_1.FACTORY_CONSTANTS[_this.chainId].implementationABIDict;
|
|
192
262
|
var implementationBasePoolIdDict = constants_1.FACTORY_CONSTANTS[_this.chainId].implementationBasePoolIdDict;
|
|
193
263
|
var basePoolIds = Object.values(implementationBasePoolIdDict).filter(function (poolId, i, arr) { return arr.indexOf(poolId) === i; });
|
|
264
|
+
var allPoolsData_1 = __assign(__assign({}, _this.constants.POOLS_DATA), FACTORY_POOLS_DATA);
|
|
194
265
|
// @ts-ignore
|
|
195
|
-
var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId,
|
|
266
|
+
var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coins]; }));
|
|
196
267
|
// @ts-ignore
|
|
197
|
-
var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId,
|
|
268
|
+
var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coin_addresses]; }));
|
|
198
269
|
// @ts-ignore
|
|
199
|
-
var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId,
|
|
270
|
+
var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_decimals]; }));
|
|
200
271
|
var basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[_this.chainId].basePoolIdZapDict;
|
|
201
272
|
var basePoolId = implementationBasePoolIdDict[pool.implementationAddress];
|
|
202
273
|
var basePoolCoinNames = basePoolIdCoinsDict[basePoolId];
|
|
@@ -222,7 +293,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
222
293
|
underlying_decimals: __spreadArray([coinDecimals[0]], basePoolDecimals, true),
|
|
223
294
|
wrapped_decimals: coinDecimals,
|
|
224
295
|
swap_abi: implementationABIDict[pool.implementationAddress],
|
|
225
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
296
|
+
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
226
297
|
deposit_abi: deposit_json_1.default,
|
|
227
298
|
};
|
|
228
299
|
}
|
|
@@ -245,7 +316,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
245
316
|
underlying_decimals: coinDecimals,
|
|
246
317
|
wrapped_decimals: coinDecimals,
|
|
247
318
|
swap_abi: implementationABIDict[pool.implementationAddress],
|
|
248
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
319
|
+
gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
249
320
|
};
|
|
250
321
|
}
|
|
251
322
|
});
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
@@ -45,7 +54,10 @@ var ethcall_1 = require("ethcall");
|
|
|
45
54
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
46
55
|
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
|
|
47
56
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
57
|
+
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
58
|
+
var base_pool_zap_json_1 = __importDefault(require("../constants/abis/atricrypto3/base_pool_zap.json"));
|
|
48
59
|
var constants_1 = require("./constants");
|
|
60
|
+
var common_1 = require("./common");
|
|
49
61
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
50
62
|
function getCryptoFactoryIdsAndSwapAddresses() {
|
|
51
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -134,8 +146,8 @@ function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
134
146
|
var _this = this;
|
|
135
147
|
factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
|
|
136
148
|
_this.contracts[addr] = {
|
|
137
|
-
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
138
|
-
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
149
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
150
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
139
151
|
};
|
|
140
152
|
});
|
|
141
153
|
}
|
|
@@ -308,9 +320,10 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
308
320
|
});
|
|
309
321
|
});
|
|
310
322
|
}
|
|
323
|
+
var atricrypto3Lp = "0xdAD97F7713Ae9437fa9249920eC8507e5FbB23d3".toLowerCase();
|
|
311
324
|
function getCryptoFactoryPoolData() {
|
|
312
325
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
326
|
+
var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i, isMeta, basePoolId, basePoolCoinNames, basePoolCoinAddresses, basePoolDecimals, basePoolZap;
|
|
314
327
|
return __generator(this, function (_c) {
|
|
315
328
|
switch (_c.label) {
|
|
316
329
|
case 0: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this)];
|
|
@@ -342,27 +355,67 @@ function getCryptoFactoryPoolData() {
|
|
|
342
355
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS)];
|
|
343
356
|
case 8:
|
|
344
357
|
coinAddressDecimalsDict = _c.sent();
|
|
358
|
+
common_1.setCryptoFactoryZapContracts.call(this);
|
|
345
359
|
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
346
360
|
for (i = 0; i < poolIds.length; i++) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
361
|
+
isMeta = this.chainId === 137 && coinAddresses[i][1].toLowerCase() === atricrypto3Lp;
|
|
362
|
+
if (isMeta) {
|
|
363
|
+
basePoolId = "atricrypto3";
|
|
364
|
+
basePoolCoinNames = ['DAI', 'USDC', 'USDT', 'WBTC', 'WETH'];
|
|
365
|
+
basePoolCoinAddresses = [
|
|
366
|
+
'0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
|
|
367
|
+
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
|
|
368
|
+
'0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
369
|
+
'0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6',
|
|
370
|
+
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', // WETH
|
|
371
|
+
];
|
|
372
|
+
basePoolDecimals = [18, 6, 6, 8, 18];
|
|
373
|
+
basePoolZap = "0x3d8EADb739D1Ef95dd53D718e4810721837c69c1";
|
|
374
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
375
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
376
|
+
full_name: poolNames[i],
|
|
377
|
+
symbol: poolSymbols[i],
|
|
378
|
+
reference_asset: "CRYPTO",
|
|
379
|
+
swap_address: swapAddresses[i],
|
|
380
|
+
token_address: tokenAddresses[i],
|
|
381
|
+
gauge_address: gaugeAddresses[i],
|
|
382
|
+
deposit_address: basePoolZap,
|
|
383
|
+
is_meta: true,
|
|
384
|
+
is_crypto: true,
|
|
385
|
+
is_factory: true,
|
|
386
|
+
base_pool: basePoolId,
|
|
387
|
+
underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolCoinNames, true),
|
|
388
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
389
|
+
underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolCoinAddresses, true),
|
|
390
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
391
|
+
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolDecimals, true),
|
|
392
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
393
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
394
|
+
gauge_abi: this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
395
|
+
deposit_abi: base_pool_zap_json_1.default,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
400
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
401
|
+
full_name: poolNames[i],
|
|
402
|
+
symbol: poolSymbols[i],
|
|
403
|
+
reference_asset: "CRYPTO",
|
|
404
|
+
swap_address: swapAddresses[i],
|
|
405
|
+
token_address: tokenAddresses[i],
|
|
406
|
+
gauge_address: gaugeAddresses[i],
|
|
407
|
+
is_crypto: true,
|
|
408
|
+
is_factory: true,
|
|
409
|
+
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
410
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
411
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
412
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
413
|
+
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
414
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
415
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
416
|
+
gauge_abi: this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
366
419
|
}
|
|
367
420
|
return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
|
|
368
421
|
}
|
package/lib/factory/factory.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -54,6 +65,7 @@ var ethcall_1 = require("ethcall");
|
|
|
54
65
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
55
66
|
var deposit_json_1 = __importDefault(require("../constants/abis/factoryPools/deposit.json"));
|
|
56
67
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
68
|
+
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
57
69
|
var common_1 = require("./common");
|
|
58
70
|
var constants_1 = require("./constants");
|
|
59
71
|
var BLACK_LIST = {
|
|
@@ -149,8 +161,8 @@ function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
149
161
|
var _this = this;
|
|
150
162
|
factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
|
|
151
163
|
_this.contracts[addr] = {
|
|
152
|
-
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
153
|
-
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
164
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
165
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
154
166
|
};
|
|
155
167
|
});
|
|
156
168
|
}
|
|
@@ -311,7 +323,7 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
311
323
|
return __generator(this, function (_a) {
|
|
312
324
|
switch (_a.label) {
|
|
313
325
|
case 0:
|
|
314
|
-
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
326
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses))).filter(function (addr) { return addr !== constants_1.NATIVE_TOKEN_ADDRESS; });
|
|
315
327
|
newCoinAddresses = [];
|
|
316
328
|
coinAddrNamesDict = {};
|
|
317
329
|
for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
|
|
@@ -359,8 +371,7 @@ function getFactoryIsMeta(factorySwapAddresses) {
|
|
|
359
371
|
}
|
|
360
372
|
function getFactoryPoolData() {
|
|
361
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
-
var _a, poolIds, swapAddresses, implementations, implementationABIDict, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds,
|
|
363
|
-
var _this = this;
|
|
374
|
+
var _a, poolIds, swapAddresses, implementations, implementationABIDict, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
|
|
364
375
|
return __generator(this, function (_c) {
|
|
365
376
|
switch (_c.label) {
|
|
366
377
|
case 0: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this)];
|
|
@@ -399,12 +410,8 @@ function getFactoryPoolData() {
|
|
|
399
410
|
implementationBasePoolIdDict = constants_1.FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
|
|
400
411
|
basePoolIds = implementations.map(function (addr) { return implementationBasePoolIdDict[addr]; });
|
|
401
412
|
common_1.setFactoryZapContracts.call(this);
|
|
402
|
-
basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_coins]; }));
|
|
403
|
-
basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_coin_addresses]; }));
|
|
404
|
-
basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_decimals]; }));
|
|
405
|
-
basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
|
|
406
413
|
FACTORY_POOLS_DATA = {};
|
|
407
|
-
|
|
414
|
+
_loop_2 = function (i) {
|
|
408
415
|
if (!isMeta[i]) {
|
|
409
416
|
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
410
417
|
name: poolNames[i].split(": ")[1].trim(),
|
|
@@ -423,10 +430,18 @@ function getFactoryPoolData() {
|
|
|
423
430
|
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
424
431
|
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
425
432
|
swap_abi: swapABIs[i],
|
|
426
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
433
|
+
gauge_abi: this_1.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
427
434
|
};
|
|
428
435
|
}
|
|
429
436
|
else {
|
|
437
|
+
var allPoolsData_1 = __assign(__assign({}, this_1.constants.POOLS_DATA), FACTORY_POOLS_DATA);
|
|
438
|
+
// @ts-ignore
|
|
439
|
+
var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coins]; }));
|
|
440
|
+
// @ts-ignore
|
|
441
|
+
var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coin_addresses]; }));
|
|
442
|
+
// @ts-ignore
|
|
443
|
+
var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_decimals]; }));
|
|
444
|
+
var basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[this_1.chainId].basePoolIdZapDict;
|
|
430
445
|
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
431
446
|
name: poolNames[i].split(": ")[1].trim(),
|
|
432
447
|
full_name: poolNames[i],
|
|
@@ -446,10 +461,14 @@ function getFactoryPoolData() {
|
|
|
446
461
|
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
|
|
447
462
|
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
448
463
|
swap_abi: swapABIs[i],
|
|
449
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
464
|
+
gauge_abi: this_1.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
450
465
|
deposit_abi: deposit_json_1.default,
|
|
451
466
|
};
|
|
452
467
|
}
|
|
468
|
+
};
|
|
469
|
+
this_1 = this;
|
|
470
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
471
|
+
_loop_2(i);
|
|
453
472
|
}
|
|
454
473
|
return [2 /*return*/, FACTORY_POOLS_DATA];
|
|
455
474
|
}
|
|
@@ -322,6 +322,76 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
324
|
}); };
|
|
325
|
+
this._calcLpTokenAmount = (0, memoizee_1.default)(function (_amounts, isDeposit, useUnderlying) {
|
|
326
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
327
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
328
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
329
|
+
var _rates_1, N_coins, decimals, calcContractAddress, calcContract, poolContract, lpContract, calls, res, _c, _totalSupply, _fee, _lpTokenAmount, balances, _d, totalSupplyBN, feeBN, lpTokenAmountBN, balancesBN, amountsBN, feesBN, i, _fees, _lpTokenFee;
|
|
330
|
+
return __generator(this, function (_e) {
|
|
331
|
+
switch (_e.label) {
|
|
332
|
+
case 0:
|
|
333
|
+
if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
|
|
334
|
+
return [4 /*yield*/, this._getRates()];
|
|
335
|
+
case 1:
|
|
336
|
+
_rates_1 = _e.sent();
|
|
337
|
+
_amounts = _amounts.map(function (_amount, i) {
|
|
338
|
+
return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
|
|
339
|
+
});
|
|
340
|
+
_e.label = 2;
|
|
341
|
+
case 2:
|
|
342
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
343
|
+
return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
|
|
344
|
+
case 3: return [2 /*return*/, _e.sent()];
|
|
345
|
+
case 4:
|
|
346
|
+
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
347
|
+
decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
348
|
+
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
349
|
+
calcContract = curve_1.curve.contracts[calcContractAddress].multicallContract;
|
|
350
|
+
poolContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
351
|
+
lpContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
352
|
+
calls = [lpContract.totalSupply(), poolContract.fee()];
|
|
353
|
+
// lpAmount before fees
|
|
354
|
+
if (this.isMetaFactory && useUnderlying) {
|
|
355
|
+
calls.push(calcContract.calc_token_amount(this.address, _amounts, isDeposit));
|
|
356
|
+
}
|
|
357
|
+
else if (calcContract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) {
|
|
358
|
+
calls.push(calcContract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions));
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
calls.push(calcContract.calc_token_amount(_amounts, curve_1.curve.constantOptions));
|
|
362
|
+
}
|
|
363
|
+
return [4 /*yield*/, Promise.all([
|
|
364
|
+
curve_1.curve.multicallProvider.all(calls),
|
|
365
|
+
useUnderlying ? this.stats.underlyingBalances() : this.stats.wrappedBalances(),
|
|
366
|
+
])];
|
|
367
|
+
case 5:
|
|
368
|
+
res = _e.sent();
|
|
369
|
+
_c = res[0], _totalSupply = _c[0], _fee = _c[1], _lpTokenAmount = _c[2];
|
|
370
|
+
balances = res[1];
|
|
371
|
+
_d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_lpTokenAmount)], totalSupplyBN = _d[0], feeBN = _d[1], lpTokenAmountBN = _d[2];
|
|
372
|
+
balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
|
|
373
|
+
amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
|
|
374
|
+
feesBN = [];
|
|
375
|
+
for (i = 0; i < N_coins; i++) {
|
|
376
|
+
feesBN[i] = balancesBN[i].times(lpTokenAmountBN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
|
|
377
|
+
if (feesBN[i].lt(0))
|
|
378
|
+
feesBN[i] = feesBN[i].times(-1);
|
|
379
|
+
}
|
|
380
|
+
_fees = feesBN.map(function (fBN, i) { return (0, utils_1.fromBN)(fBN, decimals[i]); });
|
|
381
|
+
return [4 /*yield*/, this._pureCalcLpTokenAmount(_fees, !isDeposit, useUnderlying)];
|
|
382
|
+
case 6:
|
|
383
|
+
_lpTokenFee = _e.sent();
|
|
384
|
+
if (isDeposit)
|
|
385
|
+
_lpTokenFee = _lpTokenFee.mul(-1);
|
|
386
|
+
return [2 /*return*/, _lpTokenAmount.add(_lpTokenFee)];
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}, {
|
|
391
|
+
primitive: true,
|
|
392
|
+
promise: true,
|
|
393
|
+
maxAge: 60 * 1000, // 1m
|
|
394
|
+
});
|
|
325
395
|
// ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
|
|
326
396
|
this.crvProfit = function (address) {
|
|
327
397
|
if (address === void 0) { address = ""; }
|
|
@@ -984,68 +1054,29 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
984
1054
|
});
|
|
985
1055
|
});
|
|
986
1056
|
};
|
|
987
|
-
PoolTemplate.prototype.
|
|
1057
|
+
PoolTemplate.prototype._pureCalcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
|
|
988
1058
|
if (isDeposit === void 0) { isDeposit = true; }
|
|
989
1059
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
990
1060
|
return __awaiter(this, void 0, void 0, function () {
|
|
991
|
-
var
|
|
992
|
-
return __generator(this, function (
|
|
993
|
-
switch (
|
|
1061
|
+
var calcContractAddress, N_coins, contract;
|
|
1062
|
+
return __generator(this, function (_c) {
|
|
1063
|
+
switch (_c.label) {
|
|
994
1064
|
case 0:
|
|
995
|
-
if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
|
|
996
|
-
return [4 /*yield*/, this._getRates()];
|
|
997
|
-
case 1:
|
|
998
|
-
_rates_1 = _e.sent();
|
|
999
|
-
_amounts = _amounts.map(function (_amount, i) {
|
|
1000
|
-
return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
|
|
1001
|
-
});
|
|
1002
|
-
_e.label = 2;
|
|
1003
|
-
case 2:
|
|
1004
|
-
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
1005
|
-
decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
1006
1065
|
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
1007
|
-
|
|
1008
|
-
poolContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
1009
|
-
lpContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
1010
|
-
calls = [lpContract.totalSupply(), poolContract.fee()];
|
|
1011
|
-
// lpAmount before fees
|
|
1012
|
-
if (this.isMetaFactory && useUnderlying) {
|
|
1013
|
-
calls.push(calcContract.calc_token_amount(this.address, _amounts, isDeposit));
|
|
1014
|
-
}
|
|
1015
|
-
else if (calcContract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) {
|
|
1016
|
-
calls.push(calcContract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions));
|
|
1017
|
-
}
|
|
1018
|
-
else {
|
|
1019
|
-
calls.push(calcContract.calc_token_amount(_amounts, curve_1.curve.constantOptions));
|
|
1020
|
-
}
|
|
1021
|
-
return [4 /*yield*/, Promise.all([
|
|
1022
|
-
curve_1.curve.multicallProvider.all(calls),
|
|
1023
|
-
useUnderlying ? this.stats.underlyingBalances() : this.stats.wrappedBalances(),
|
|
1024
|
-
])];
|
|
1025
|
-
case 3:
|
|
1026
|
-
res = _e.sent();
|
|
1027
|
-
_c = res[0], _totalSupply = _c[0], _fee = _c[1], _expected1 = _c[2];
|
|
1028
|
-
balances = res[1];
|
|
1029
|
-
_d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_expected1)], totalSupplyBN = _d[0], feeBN = _d[1], expected1BN = _d[2];
|
|
1030
|
-
balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
|
|
1031
|
-
amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
|
|
1032
|
-
feesBN = [];
|
|
1033
|
-
for (i = 0; i < N_coins; i++) {
|
|
1034
|
-
feesBN[i] = balancesBN[i].times(expected1BN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
|
|
1035
|
-
if (feesBN[i].lt(0))
|
|
1036
|
-
feesBN[i] = feesBN[i].times(-1);
|
|
1037
|
-
}
|
|
1038
|
-
_newAmounts = amountsBN.map(function (aBN, i) { return (0, utils_1.fromBN)(isDeposit ? aBN.minus(feesBN[i]) : aBN.plus(feesBN[i]), decimals[i]); });
|
|
1066
|
+
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
1039
1067
|
contract = curve_1.curve.contracts[calcContractAddress].contract;
|
|
1040
|
-
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/,
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
case
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
case
|
|
1047
|
-
|
|
1048
|
-
|
|
1068
|
+
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
|
|
1069
|
+
if (!contract["calc_token_amount(address,uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 2];
|
|
1070
|
+
return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1071
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1072
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, curve_1.curve.constantOptions)];
|
|
1073
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1074
|
+
case 4:
|
|
1075
|
+
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 6];
|
|
1076
|
+
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1077
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1078
|
+
case 6: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1079
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
1049
1080
|
}
|
|
1050
1081
|
});
|
|
1051
1082
|
});
|
|
@@ -2363,7 +2394,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2363
2394
|
lpTotalBalanceBN = (0, utils_1.BN)(lpBalances.lpToken);
|
|
2364
2395
|
if ('gauge' in lpBalances)
|
|
2365
2396
|
lpTotalBalanceBN = lpTotalBalanceBN.plus((0, utils_1.BN)(lpBalances.gauge));
|
|
2366
|
-
return [2 /*return*/, lpTotalBalanceBN
|
|
2397
|
+
return [2 /*return*/, lpTotalBalanceBN];
|
|
2367
2398
|
}
|
|
2368
2399
|
});
|
|
2369
2400
|
});
|
|
@@ -2381,7 +2412,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2381
2412
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2382
2413
|
case 1:
|
|
2383
2414
|
lpTotalBalanceBN = _c.sent();
|
|
2384
|
-
|
|
2415
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2416
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2417
|
+
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2385
2418
|
case 2: return [2 /*return*/, _c.sent()];
|
|
2386
2419
|
}
|
|
2387
2420
|
});
|
|
@@ -2400,7 +2433,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2400
2433
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2401
2434
|
case 1:
|
|
2402
2435
|
lpTotalBalanceBN = _c.sent();
|
|
2403
|
-
|
|
2436
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2437
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2438
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2404
2439
|
case 2: return [2 /*return*/, _c.sent()];
|
|
2405
2440
|
}
|
|
2406
2441
|
});
|
|
@@ -2515,8 +2550,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2515
2550
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2516
2551
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2517
2552
|
case 1: return [2 /*return*/, _c.sent()];
|
|
2518
|
-
case 2:
|
|
2519
|
-
|
|
2553
|
+
case 2:
|
|
2554
|
+
if (!('get_dy(address,uint256,uint256,uint256)' in contract)) return [3 /*break*/, 4];
|
|
2555
|
+
return [4 /*yield*/, contract.get_dy(this.address, i, j, _amount, curve_1.curve.constantOptions)];
|
|
2556
|
+
case 3: // atricrypto3 based metapools
|
|
2557
|
+
return [2 /*return*/, _c.sent()];
|
|
2558
|
+
case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2559
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
2520
2560
|
}
|
|
2521
2561
|
});
|
|
2522
2562
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { PoolTemplate } from "../PoolTemplate";
|
|
3
3
|
export declare function _calcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
|
|
4
|
+
export declare function _atricrypto3CalcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
|
|
@@ -35,8 +35,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports._calcExpectedAmounts = void 0;
|
|
48
|
+
exports._atricrypto3CalcExpectedAmounts = exports._calcExpectedAmounts = void 0;
|
|
49
|
+
var PoolTemplate_1 = require("../PoolTemplate");
|
|
40
50
|
var curve_1 = require("../../curve");
|
|
41
51
|
var utils_1 = require("../../utils");
|
|
42
52
|
function _calcExpectedAmounts(_lpTokenAmount) {
|
|
@@ -75,3 +85,22 @@ function _calcExpectedAmounts(_lpTokenAmount) {
|
|
|
75
85
|
});
|
|
76
86
|
}
|
|
77
87
|
exports._calcExpectedAmounts = _calcExpectedAmounts;
|
|
88
|
+
function _atricrypto3CalcExpectedAmounts(_lpTokenAmount) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
94
|
+
case 1:
|
|
95
|
+
_expectedWrappedAmounts = _a.sent();
|
|
96
|
+
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
97
|
+
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
98
|
+
return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
99
|
+
case 2:
|
|
100
|
+
_basePoolExpectedAmounts = _a.sent();
|
|
101
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports._atricrypto3CalcExpectedAmounts = _atricrypto3CalcExpectedAmounts;
|
|
@@ -80,22 +80,30 @@ exports.poolBalancesAtricrypto3Mixin = {
|
|
|
80
80
|
exports.poolBalancesMetaMixin = {
|
|
81
81
|
statsUnderlyingBalances: function () {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _poolUnderlyingBalances;
|
|
83
|
+
var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _a, _poolUnderlyingBalances;
|
|
84
84
|
var _this = this;
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
85
|
+
return __generator(this, function (_c) {
|
|
86
|
+
switch (_c.label) {
|
|
87
87
|
case 0:
|
|
88
88
|
swapContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
89
89
|
contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
|
|
90
90
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
91
91
|
case 1:
|
|
92
|
-
_poolWrappedBalances =
|
|
92
|
+
_poolWrappedBalances = _c.sent();
|
|
93
93
|
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
94
94
|
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalance = _poolWrappedBalances.slice(1);
|
|
95
95
|
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
96
|
-
return [
|
|
96
|
+
if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
|
|
97
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
|
|
97
98
|
case 2:
|
|
98
|
-
|
|
99
|
+
_a = _c.sent();
|
|
100
|
+
return [3 /*break*/, 5];
|
|
101
|
+
case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
|
|
102
|
+
case 4:
|
|
103
|
+
_a = _c.sent();
|
|
104
|
+
_c.label = 5;
|
|
105
|
+
case 5:
|
|
106
|
+
_basePoolExpectedAmounts = _a;
|
|
99
107
|
_poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolNonMetaBalance, true), _basePoolExpectedAmounts, true);
|
|
100
108
|
return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
|
|
101
109
|
}
|
|
@@ -96,21 +96,29 @@ exports.withdrawExpectedLendingOrCryptoMixin = {
|
|
|
96
96
|
exports.withdrawExpectedMetaMixin = {
|
|
97
97
|
withdrawExpected: function (lpTokenAmount) {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _expected;
|
|
99
|
+
var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a, _expected;
|
|
100
100
|
var _this = this;
|
|
101
|
-
return __generator(this, function (
|
|
102
|
-
switch (
|
|
101
|
+
return __generator(this, function (_b) {
|
|
102
|
+
switch (_b.label) {
|
|
103
103
|
case 0:
|
|
104
104
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
105
105
|
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
106
106
|
case 1:
|
|
107
|
-
_expectedWrappedAmounts =
|
|
107
|
+
_expectedWrappedAmounts = _b.sent();
|
|
108
108
|
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
109
109
|
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
110
110
|
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
111
|
-
return [
|
|
111
|
+
if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
|
|
112
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
112
113
|
case 2:
|
|
113
|
-
|
|
114
|
+
_a = _b.sent();
|
|
115
|
+
return [3 /*break*/, 5];
|
|
116
|
+
case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
117
|
+
case 4:
|
|
118
|
+
_a = _b.sent();
|
|
119
|
+
_b.label = 5;
|
|
120
|
+
case 5:
|
|
121
|
+
_basePoolExpectedAmounts = _a;
|
|
114
122
|
_expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
|
|
115
123
|
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
116
124
|
}
|
|
@@ -122,21 +130,15 @@ exports.withdrawExpectedMetaMixin = {
|
|
|
122
130
|
exports.withdrawExpectedAtricrypto3Mixin = {
|
|
123
131
|
withdrawExpected: function (lpTokenAmount) {
|
|
124
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var _lpTokenAmount,
|
|
133
|
+
var _lpTokenAmount, _expected;
|
|
126
134
|
var _this = this;
|
|
127
135
|
return __generator(this, function (_a) {
|
|
128
136
|
switch (_a.label) {
|
|
129
137
|
case 0:
|
|
130
138
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
131
|
-
return [4 /*yield*/, common_1.
|
|
139
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
132
140
|
case 1:
|
|
133
|
-
|
|
134
|
-
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
135
|
-
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
136
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
137
|
-
case 2:
|
|
138
|
-
_basePoolExpectedAmounts = _a.sent();
|
|
139
|
-
_expected = __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true);
|
|
141
|
+
_expected = _a.sent();
|
|
140
142
|
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
141
143
|
}
|
|
142
144
|
});
|
|
@@ -230,7 +230,7 @@ var getPool = function (poolId) {
|
|
|
230
230
|
if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract) { // tricrypto2 (eth), tricrypto (arbitrum)
|
|
231
231
|
Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
|
|
232
232
|
}
|
|
233
|
-
else if (poolDummy.isMetaFactory && (0, exports.getPool)(poolDummy.basePool).isLending) {
|
|
233
|
+
else if (poolDummy.isMetaFactory && ((0, exports.getPool)(poolDummy.basePool).isLending || (0, exports.getPool)(poolDummy.basePool).isFake)) {
|
|
234
234
|
Object.assign(Pool.prototype, swapMixins_1.swapMetaFactoryMixin);
|
|
235
235
|
}
|
|
236
236
|
else {
|
package/lib/utils.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const formatNumber: (n: number | string, decimals?: number) => st
|
|
|
13
13
|
export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
|
|
14
14
|
export declare const isEth: (address: string) => boolean;
|
|
15
15
|
export declare const getEthIndex: (addresses: string[]) => number;
|
|
16
|
+
export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
|
|
16
17
|
export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
|
|
17
18
|
export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
|
|
18
19
|
export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<IDict<string[]>>;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -116,7 +116,7 @@ exports.isEth = isEth;
|
|
|
116
116
|
var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(exports.ETH_ADDRESS.toLowerCase()); };
|
|
117
117
|
exports.getEthIndex = getEthIndex;
|
|
118
118
|
// coins can be either addresses or symbols
|
|
119
|
-
var
|
|
119
|
+
var _getCoinAddressesNoCheck = function () {
|
|
120
120
|
var coins = [];
|
|
121
121
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
122
|
coins[_i] = arguments[_i];
|
|
@@ -124,7 +124,15 @@ var _getCoinAddresses = function () {
|
|
|
124
124
|
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
125
125
|
coins = coins[0];
|
|
126
126
|
coins = coins;
|
|
127
|
-
|
|
127
|
+
return coins.map(function (c) { return c.toLowerCase(); }).map(function (c) { return curve_1.curve.constants.COINS[c] || c; });
|
|
128
|
+
};
|
|
129
|
+
exports._getCoinAddressesNoCheck = _getCoinAddressesNoCheck;
|
|
130
|
+
var _getCoinAddresses = function () {
|
|
131
|
+
var coins = [];
|
|
132
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
133
|
+
coins[_i] = arguments[_i];
|
|
134
|
+
}
|
|
135
|
+
var coinAddresses = exports._getCoinAddressesNoCheck.apply(void 0, coins);
|
|
128
136
|
var availableAddresses = __spreadArray(__spreadArray([], Object.keys(curve_1.curve.constants.DECIMALS), true), curve_1.curve.constants.GAUGES, true);
|
|
129
137
|
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
130
138
|
var coinAddr = coinAddresses_1[_a];
|
|
@@ -473,11 +481,11 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
473
481
|
}
|
|
474
482
|
assetId = {
|
|
475
483
|
'CRV': 'curve-dao-token',
|
|
476
|
-
'EUR':
|
|
484
|
+
'EUR': 'stasis-eurs',
|
|
477
485
|
'BTC': 'bitcoin',
|
|
478
486
|
'ETH': 'ethereum',
|
|
479
487
|
'LINK': 'link',
|
|
480
|
-
}[assetId] || assetId;
|
|
488
|
+
}[assetId.toUpperCase()] || assetId;
|
|
481
489
|
assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
482
490
|
// No EURT on Coingecko Polygon
|
|
483
491
|
if (curve_1.curve.chainId === 137 && assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt) {
|
|
@@ -489,7 +497,7 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
489
497
|
assetId = 'curve-dao-token';
|
|
490
498
|
}
|
|
491
499
|
if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
|
|
492
|
-
url = [nativeTokenName, 'bitcoin', 'link', 'curve-dao-token'].includes(assetId.toLowerCase()) ?
|
|
500
|
+
url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
493
501
|
"https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
|
|
494
502
|
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
495
503
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
@@ -512,7 +520,7 @@ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, func
|
|
|
512
520
|
return __generator(this, function (_a) {
|
|
513
521
|
switch (_a.label) {
|
|
514
522
|
case 0:
|
|
515
|
-
coinAddress = (0, exports.
|
|
523
|
+
coinAddress = (0, exports._getCoinAddressesNoCheck)(coin)[0];
|
|
516
524
|
return [4 /*yield*/, (0, exports._getUsdRate)(coinAddress)];
|
|
517
525
|
case 1: return [2 /*return*/, _a.sent()];
|
|
518
526
|
}
|