@curvefi/api 1.10.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/lib/constants/abis/abis-ethereum.d.ts +1 -1
- package/lib/constants/abis/abis-ethereum.js +68 -2
- package/lib/constants/abis/abis-polygon.d.ts +4 -0
- package/lib/constants/abis/abis-polygon.js +154 -0
- package/lib/constants/abis/json/atricrypto3/swap.json +1269 -0
- package/lib/constants/abis/json/atricrypto3/zap.json +239 -0
- package/lib/constants/abis/json/busd/deposit.json +5 -10
- package/lib/constants/abis/json/busd/swap.json +18 -36
- package/lib/constants/abis/json/compound/deposit.json +5 -10
- package/lib/constants/abis/json/compound/migration.json +1 -2
- package/lib/constants/abis/json/compound/oldSwap.json +16 -32
- package/lib/constants/abis/json/compound/swap.json +18 -36
- package/lib/constants/abis/json/iearn/deposit.json +5 -10
- package/lib/constants/abis/json/iearn/swap.json +18 -36
- package/lib/constants/abis/json/paave/rewards.json +657 -0
- package/lib/constants/abis/json/pax/deposit.json +5 -10
- package/lib/constants/abis/json/pax/swap.json +19 -38
- package/lib/constants/abis/json/ren/swap.json +19 -38
- package/lib/constants/abis/json/ren-polygon/swap.json +1112 -0
- package/lib/constants/abis/json/sbtc/swap.json +19 -38
- package/lib/constants/abis/json/streamer.json +257 -0
- package/lib/constants/abis/json/susdv2/deposit.json +5 -10
- package/lib/constants/abis/json/susdv2/swap.json +16 -32
- package/lib/constants/abis/json/usdt/deposit.json +5 -10
- package/lib/constants/abis/json/usdt/swap.json +19 -37
- package/lib/constants/aliases.d.ts +16 -0
- package/lib/constants/aliases.js +19 -0
- package/lib/constants/coins-ethereum.d.ts +31 -0
- package/lib/constants/{coins.js → coins-ethereum.js} +48 -14
- package/lib/constants/coins-polygon.d.ts +31 -0
- package/lib/constants/coins-polygon.js +74 -0
- package/lib/curve.d.ts +23 -7
- package/lib/curve.js +133 -91
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -0
- package/lib/interfaces.d.ts +3 -0
- package/lib/pools.d.ts +25 -4
- package/lib/pools.js +323 -101
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +49 -41
- package/package.json +6 -5
- package/lib/constants/coins.d.ts +0 -25
package/lib/pools.js
CHANGED
|
@@ -62,9 +62,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
62
62
|
exports.crossAssetExchange = exports.crossAssetExchangeEstimateGas = exports.crossAssetExchangeApprove = exports.crossAssetExchangeApproveEstimateGas = exports.crossAssetExchangeIsApproved = exports.crossAssetExchangeExpected = exports.crossAssetExchangeOutputAndSlippage = exports._crossAssetExchangeInfo = exports._getSmallAmountForCoin = exports.crossAssetExchangeAvailable = exports.exchange = exports.exchangeEstimateGas = exports.exchangeApprove = exports.exchangeApproveEstimateGas = exports.exchangeIsApproved = exports.exchangeExpected = exports.getBestPoolAndOutput = exports.Pool = void 0;
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var utils_1 = require("./utils");
|
|
65
|
-
var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
|
|
66
65
|
var curve_1 = require("./curve");
|
|
67
|
-
var coins_1 = require("./constants/coins");
|
|
68
66
|
var axios_1 = __importDefault(require("axios"));
|
|
69
67
|
var Pool = /** @class */ (function () {
|
|
70
68
|
function Pool(name) {
|
|
@@ -83,7 +81,7 @@ var Pool = /** @class */ (function () {
|
|
|
83
81
|
_amounts = amounts.map(function (amount, i) {
|
|
84
82
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
85
83
|
});
|
|
86
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
|
|
84
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
87
85
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
|
|
88
86
|
case 1:
|
|
89
87
|
_expected = _a.sent(); // Lending pools
|
|
@@ -111,6 +109,9 @@ var Pool = /** @class */ (function () {
|
|
|
111
109
|
return __generator(this, function (_a) {
|
|
112
110
|
switch (_a.label) {
|
|
113
111
|
case 0:
|
|
112
|
+
if (this.isFake) {
|
|
113
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
114
|
+
}
|
|
114
115
|
if (amounts.length !== this.coinAddresses.length) {
|
|
115
116
|
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
116
117
|
}
|
|
@@ -125,14 +126,30 @@ var Pool = /** @class */ (function () {
|
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
};
|
|
128
|
-
this.
|
|
129
|
-
var _virtualPrice;
|
|
130
|
-
return __generator(this, function (
|
|
131
|
-
switch (
|
|
132
|
-
case 0:
|
|
129
|
+
this.getParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
+
var calls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma;
|
|
131
|
+
return __generator(this, function (_d) {
|
|
132
|
+
switch (_d.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
calls = [
|
|
135
|
+
curve_1.curve.contracts[this.swap].multicallContract.get_virtual_price(),
|
|
136
|
+
curve_1.curve.contracts[this.swap].multicallContract.fee(),
|
|
137
|
+
curve_1.curve.contracts[this.swap].multicallContract.admin_fee(),
|
|
138
|
+
curve_1.curve.contracts[this.swap].multicallContract.A(),
|
|
139
|
+
];
|
|
140
|
+
if (this.isCrypto)
|
|
141
|
+
calls.push(curve_1.curve.contracts[this.swap].multicallContract.gamma());
|
|
142
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
133
143
|
case 1:
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
_a = _d.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
|
|
145
|
+
_c = [
|
|
146
|
+
ethers_1.ethers.utils.formatUnits(_virtualPrice),
|
|
147
|
+
ethers_1.ethers.utils.formatUnits(_fee, 8),
|
|
148
|
+
ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
|
|
149
|
+
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
150
|
+
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
151
|
+
], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
|
|
152
|
+
return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, gamma: gamma }];
|
|
136
153
|
}
|
|
137
154
|
});
|
|
138
155
|
}); };
|
|
@@ -146,19 +163,21 @@ var Pool = /** @class */ (function () {
|
|
|
146
163
|
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
147
164
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
148
165
|
case 1:
|
|
149
|
-
_poolWrappedBalances =
|
|
166
|
+
_poolWrappedBalances = _a.sent();
|
|
150
167
|
_poolUnderlyingBalances = [];
|
|
151
168
|
if (!this.isMeta) return [3 /*break*/, 3];
|
|
152
|
-
|
|
169
|
+
if (this.name !== 'atricrypto3') {
|
|
170
|
+
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
171
|
+
}
|
|
153
172
|
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolUnderlyingBalance = _poolWrappedBalances.slice(1);
|
|
154
173
|
basePool = new Pool(this.basePool);
|
|
155
174
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_poolMetaCoinBalance)];
|
|
156
175
|
case 2:
|
|
157
176
|
_basePoolExpectedAmounts = _a.sent();
|
|
158
|
-
_poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
|
|
177
|
+
_poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
|
|
159
178
|
return [3 /*break*/, 6];
|
|
160
179
|
case 3:
|
|
161
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
|
|
180
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
162
181
|
return [4 /*yield*/, this._getRates()];
|
|
163
182
|
case 4:
|
|
164
183
|
_rates_1 = _a.sent();
|
|
@@ -172,7 +191,7 @@ var Pool = /** @class */ (function () {
|
|
|
172
191
|
});
|
|
173
192
|
}); };
|
|
174
193
|
this.getPoolWrappedBalances = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
-
var swapContract, contractCalls;
|
|
194
|
+
var swapContract, contractCalls, _wrappedBalances;
|
|
176
195
|
var _this = this;
|
|
177
196
|
return __generator(this, function (_a) {
|
|
178
197
|
switch (_a.label) {
|
|
@@ -180,7 +199,110 @@ var Pool = /** @class */ (function () {
|
|
|
180
199
|
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
181
200
|
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
182
201
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
183
|
-
case 1:
|
|
202
|
+
case 1:
|
|
203
|
+
_wrappedBalances = _a.sent();
|
|
204
|
+
return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.decimals[i]); })];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}); };
|
|
208
|
+
this.getTotalLiquidity = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
209
|
+
var balances, promises, _i, _a, addr, prices, totalLiquidity;
|
|
210
|
+
return __generator(this, function (_c) {
|
|
211
|
+
switch (_c.label) {
|
|
212
|
+
case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
|
|
213
|
+
case 1:
|
|
214
|
+
balances = _c.sent();
|
|
215
|
+
promises = [];
|
|
216
|
+
for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
|
|
217
|
+
addr = _a[_i];
|
|
218
|
+
promises.push((0, utils_1._getUsdRate)(addr));
|
|
219
|
+
}
|
|
220
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
221
|
+
case 2:
|
|
222
|
+
prices = _c.sent();
|
|
223
|
+
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
224
|
+
return [2 /*return*/, String(totalLiquidity)];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); };
|
|
228
|
+
this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
229
|
+
var name, statsUrl, volume, usdRate, _a;
|
|
230
|
+
return __generator(this, function (_c) {
|
|
231
|
+
switch (_c.label) {
|
|
232
|
+
case 0:
|
|
233
|
+
name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
|
|
234
|
+
statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
235
|
+
return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
236
|
+
case 1:
|
|
237
|
+
volume = (_c.sent()).data.volume[name] || 0;
|
|
238
|
+
if (!this.isCrypto) return [3 /*break*/, 2];
|
|
239
|
+
_a = 1;
|
|
240
|
+
return [3 /*break*/, 4];
|
|
241
|
+
case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
|
|
242
|
+
case 3:
|
|
243
|
+
_a = _c.sent();
|
|
244
|
+
_c.label = 4;
|
|
245
|
+
case 4:
|
|
246
|
+
usdRate = _a;
|
|
247
|
+
return [2 /*return*/, String(volume * usdRate)];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}); };
|
|
251
|
+
this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
252
|
+
var name, statsUrl, apy;
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0:
|
|
256
|
+
name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
|
|
257
|
+
statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
258
|
+
return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
259
|
+
case 1:
|
|
260
|
+
apy = (_a.sent()).data.apy;
|
|
261
|
+
return [2 /*return*/, [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); })];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}); };
|
|
265
|
+
this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
266
|
+
var rewardContract, totalLiquidityUSD, crvRate, inflation, _a, baseApy, gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _c, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
|
|
267
|
+
return __generator(this, function (_d) {
|
|
268
|
+
switch (_d.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 4];
|
|
271
|
+
rewardContract = curve_1.curve.contracts[this.crvRewardContract].contract;
|
|
272
|
+
return [4 /*yield*/, this.getTotalLiquidity()];
|
|
273
|
+
case 1:
|
|
274
|
+
totalLiquidityUSD = _d.sent();
|
|
275
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
|
|
276
|
+
case 2:
|
|
277
|
+
crvRate = _d.sent();
|
|
278
|
+
_a = utils_1.toBN;
|
|
279
|
+
return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
|
|
280
|
+
case 3:
|
|
281
|
+
inflation = _a.apply(void 0, [(_d.sent()).rate]);
|
|
282
|
+
baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
|
|
283
|
+
return [2 /*return*/, [baseApy.times(100).toFixed(4), ""]];
|
|
284
|
+
case 4:
|
|
285
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
286
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
287
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
|
|
288
|
+
return [4 /*yield*/, this.getTotalLiquidity()];
|
|
289
|
+
case 5:
|
|
290
|
+
totalLiquidityUSD = _d.sent();
|
|
291
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
292
|
+
gaugeContract.inflation_rate(),
|
|
293
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
294
|
+
gaugeContract.working_supply(),
|
|
295
|
+
lpTokenContract.totalSupply(),
|
|
296
|
+
])];
|
|
297
|
+
case 6:
|
|
298
|
+
_c = (_d.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _c[0], weight = _c[1], workingSupply = _c[2], totalSupply = _c[3];
|
|
299
|
+
rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
|
|
300
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
|
|
301
|
+
case 7:
|
|
302
|
+
crvRate = _d.sent();
|
|
303
|
+
baseApy = rate.times(crvRate);
|
|
304
|
+
boostedApy = baseApy.times(2.5);
|
|
305
|
+
return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
|
|
184
306
|
}
|
|
185
307
|
});
|
|
186
308
|
}); };
|
|
@@ -273,7 +395,7 @@ var Pool = /** @class */ (function () {
|
|
|
273
395
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
274
396
|
case 3: return [2 /*return*/, _d.sent()];
|
|
275
397
|
case 4:
|
|
276
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 6];
|
|
398
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
|
|
277
399
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
278
400
|
case 5: return [2 /*return*/, _d.sent()];
|
|
279
401
|
case 6:
|
|
@@ -321,7 +443,7 @@ var Pool = /** @class */ (function () {
|
|
|
321
443
|
return [4 /*yield*/, this._addLiquidityZap(_amounts)];
|
|
322
444
|
case 2: return [2 /*return*/, _a.sent()];
|
|
323
445
|
case 3:
|
|
324
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
|
|
446
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
325
447
|
return [4 /*yield*/, this._addLiquidity(_amounts, true)];
|
|
326
448
|
case 4: return [2 /*return*/, _a.sent()];
|
|
327
449
|
case 5:
|
|
@@ -339,7 +461,11 @@ var Pool = /** @class */ (function () {
|
|
|
339
461
|
var poolBalances, walletBalances, _a, _c;
|
|
340
462
|
return __generator(this, function (_d) {
|
|
341
463
|
switch (_d.label) {
|
|
342
|
-
case 0:
|
|
464
|
+
case 0:
|
|
465
|
+
if (this.isFake) {
|
|
466
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
467
|
+
}
|
|
468
|
+
return [4 /*yield*/, this.getPoolWrappedBalances()];
|
|
343
469
|
case 1:
|
|
344
470
|
poolBalances = (_d.sent()).map(Number);
|
|
345
471
|
_c = (_a = Object).values;
|
|
@@ -355,6 +481,9 @@ var Pool = /** @class */ (function () {
|
|
|
355
481
|
return __generator(this, function (_a) {
|
|
356
482
|
switch (_a.label) {
|
|
357
483
|
case 0:
|
|
484
|
+
if (this.isFake) {
|
|
485
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
486
|
+
}
|
|
358
487
|
amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.decimals[i]); });
|
|
359
488
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
|
|
360
489
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -366,6 +495,9 @@ var Pool = /** @class */ (function () {
|
|
|
366
495
|
return __generator(this, function (_c) {
|
|
367
496
|
switch (_c.label) {
|
|
368
497
|
case 0:
|
|
498
|
+
if (this.isFake) {
|
|
499
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
500
|
+
}
|
|
369
501
|
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
370
502
|
_a = Number;
|
|
371
503
|
return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
|
|
@@ -379,7 +511,11 @@ var Pool = /** @class */ (function () {
|
|
|
379
511
|
this.addLiquidityWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
380
512
|
return __generator(this, function (_a) {
|
|
381
513
|
switch (_a.label) {
|
|
382
|
-
case 0:
|
|
514
|
+
case 0:
|
|
515
|
+
if (this.isFake) {
|
|
516
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
517
|
+
}
|
|
518
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
|
|
383
519
|
case 1: return [2 /*return*/, _a.sent()];
|
|
384
520
|
}
|
|
385
521
|
});
|
|
@@ -387,7 +523,11 @@ var Pool = /** @class */ (function () {
|
|
|
387
523
|
this.addLiquidityWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
388
524
|
return __generator(this, function (_a) {
|
|
389
525
|
switch (_a.label) {
|
|
390
|
-
case 0:
|
|
526
|
+
case 0:
|
|
527
|
+
if (this.isFake) {
|
|
528
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
529
|
+
}
|
|
530
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, this.swap)];
|
|
391
531
|
case 1: return [2 /*return*/, _a.sent()];
|
|
392
532
|
}
|
|
393
533
|
});
|
|
@@ -395,7 +535,11 @@ var Pool = /** @class */ (function () {
|
|
|
395
535
|
this.addLiquidityWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
396
536
|
return __generator(this, function (_a) {
|
|
397
537
|
switch (_a.label) {
|
|
398
|
-
case 0:
|
|
538
|
+
case 0:
|
|
539
|
+
if (this.isFake) {
|
|
540
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
541
|
+
}
|
|
542
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, this.swap)];
|
|
399
543
|
case 1: return [2 /*return*/, _a.sent()];
|
|
400
544
|
}
|
|
401
545
|
});
|
|
@@ -406,6 +550,9 @@ var Pool = /** @class */ (function () {
|
|
|
406
550
|
return __generator(this, function (_d) {
|
|
407
551
|
switch (_d.label) {
|
|
408
552
|
case 0:
|
|
553
|
+
if (this.isFake) {
|
|
554
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
555
|
+
}
|
|
409
556
|
if (amounts.length !== this.coinAddresses.length) {
|
|
410
557
|
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
411
558
|
}
|
|
@@ -426,7 +573,7 @@ var Pool = /** @class */ (function () {
|
|
|
426
573
|
_amounts = amounts.map(function (amount, i) {
|
|
427
574
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
428
575
|
});
|
|
429
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 4];
|
|
576
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
430
577
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
431
578
|
case 3: return [2 /*return*/, _d.sent()];
|
|
432
579
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
@@ -442,6 +589,9 @@ var Pool = /** @class */ (function () {
|
|
|
442
589
|
return __generator(this, function (_a) {
|
|
443
590
|
switch (_a.label) {
|
|
444
591
|
case 0:
|
|
592
|
+
if (this.isFake) {
|
|
593
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
594
|
+
}
|
|
445
595
|
if (amounts.length !== this.coinAddresses.length) {
|
|
446
596
|
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
447
597
|
}
|
|
@@ -451,7 +601,7 @@ var Pool = /** @class */ (function () {
|
|
|
451
601
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
452
602
|
case 1:
|
|
453
603
|
_a.sent();
|
|
454
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
|
|
604
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
455
605
|
return [4 /*yield*/, this._addLiquidity(_amounts, false)];
|
|
456
606
|
case 2: return [2 /*return*/, _a.sent()];
|
|
457
607
|
case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
|
|
@@ -468,7 +618,7 @@ var Pool = /** @class */ (function () {
|
|
|
468
618
|
switch (_a.label) {
|
|
469
619
|
case 0:
|
|
470
620
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
471
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
|
|
621
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
472
622
|
return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
|
|
473
623
|
case 1:
|
|
474
624
|
_expected = _a.sent(); // Lending pools
|
|
@@ -545,7 +695,7 @@ var Pool = /** @class */ (function () {
|
|
|
545
695
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
546
696
|
case 4: return [2 /*return*/, _c.sent()];
|
|
547
697
|
case 5:
|
|
548
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
|
|
698
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
549
699
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
550
700
|
case 6: return [2 /*return*/, _c.sent()];
|
|
551
701
|
case 7:
|
|
@@ -570,7 +720,7 @@ var Pool = /** @class */ (function () {
|
|
|
570
720
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
|
|
571
721
|
case 2: return [2 /*return*/, _a.sent()];
|
|
572
722
|
case 3:
|
|
573
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
|
|
723
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
574
724
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
|
|
575
725
|
case 4: return [2 /*return*/, _a.sent()];
|
|
576
726
|
case 5:
|
|
@@ -588,6 +738,9 @@ var Pool = /** @class */ (function () {
|
|
|
588
738
|
return __generator(this, function (_a) {
|
|
589
739
|
switch (_a.label) {
|
|
590
740
|
case 0:
|
|
741
|
+
if (this.isFake) {
|
|
742
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
743
|
+
}
|
|
591
744
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
592
745
|
return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
|
|
593
746
|
case 1:
|
|
@@ -601,6 +754,9 @@ var Pool = /** @class */ (function () {
|
|
|
601
754
|
return __generator(this, function (_a) {
|
|
602
755
|
switch (_a.label) {
|
|
603
756
|
case 0:
|
|
757
|
+
if (this.isFake) {
|
|
758
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
759
|
+
}
|
|
604
760
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
605
761
|
return [4 /*yield*/, this.lpTokenBalances()];
|
|
606
762
|
case 1:
|
|
@@ -608,7 +764,7 @@ var Pool = /** @class */ (function () {
|
|
|
608
764
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
609
765
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
610
766
|
}
|
|
611
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
|
|
767
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
612
768
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
613
769
|
case 2: return [2 /*return*/, _a.sent()];
|
|
614
770
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
@@ -621,11 +777,14 @@ var Pool = /** @class */ (function () {
|
|
|
621
777
|
return __generator(this, function (_a) {
|
|
622
778
|
switch (_a.label) {
|
|
623
779
|
case 0:
|
|
780
|
+
if (this.isFake) {
|
|
781
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
782
|
+
}
|
|
624
783
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
625
784
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
626
785
|
case 1:
|
|
627
786
|
_a.sent();
|
|
628
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
|
|
787
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
629
788
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
|
|
630
789
|
case 2: return [2 /*return*/, _a.sent()];
|
|
631
790
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
@@ -779,7 +938,7 @@ var Pool = /** @class */ (function () {
|
|
|
779
938
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
|
|
780
939
|
case 5: return [2 /*return*/, _c.sent()];
|
|
781
940
|
case 6:
|
|
782
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 8];
|
|
941
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 8];
|
|
783
942
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
|
|
784
943
|
case 7: return [2 /*return*/, _c.sent()];
|
|
785
944
|
case 8:
|
|
@@ -808,7 +967,7 @@ var Pool = /** @class */ (function () {
|
|
|
808
967
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts)];
|
|
809
968
|
case 2: return [2 /*return*/, _a.sent()];
|
|
810
969
|
case 3:
|
|
811
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
970
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
812
971
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true)];
|
|
813
972
|
case 4: return [2 /*return*/, _a.sent()];
|
|
814
973
|
case 5:
|
|
@@ -871,7 +1030,7 @@ var Pool = /** @class */ (function () {
|
|
|
871
1030
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
872
1031
|
}
|
|
873
1032
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
|
|
874
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
|
|
1033
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
875
1034
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, true)];
|
|
876
1035
|
case 3: return [2 /*return*/, _a.sent()];
|
|
877
1036
|
case 4: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
|
|
@@ -894,7 +1053,7 @@ var Pool = /** @class */ (function () {
|
|
|
894
1053
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
895
1054
|
case 1:
|
|
896
1055
|
_a.sent();
|
|
897
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
1056
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
898
1057
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, estimateGas)];
|
|
899
1058
|
case 2: return [2 /*return*/, _a.sent()];
|
|
900
1059
|
case 3: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
|
|
@@ -1002,7 +1161,7 @@ var Pool = /** @class */ (function () {
|
|
|
1002
1161
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
1003
1162
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1004
1163
|
case 5:
|
|
1005
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
|
|
1164
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1006
1165
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
1007
1166
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1008
1167
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1026,7 +1185,7 @@ var Pool = /** @class */ (function () {
|
|
|
1026
1185
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
|
|
1027
1186
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1028
1187
|
case 3:
|
|
1029
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
|
|
1188
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1030
1189
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
|
|
1031
1190
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1032
1191
|
case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1041,6 +1200,9 @@ var Pool = /** @class */ (function () {
|
|
|
1041
1200
|
return __generator(this, function (_a) {
|
|
1042
1201
|
switch (_a.label) {
|
|
1043
1202
|
case 0:
|
|
1203
|
+
if (this.isFake) {
|
|
1204
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1205
|
+
}
|
|
1044
1206
|
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
1045
1207
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1046
1208
|
}
|
|
@@ -1064,6 +1226,9 @@ var Pool = /** @class */ (function () {
|
|
|
1064
1226
|
return __generator(this, function (_c) {
|
|
1065
1227
|
switch (_c.label) {
|
|
1066
1228
|
case 0:
|
|
1229
|
+
if (this.isFake) {
|
|
1230
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1231
|
+
}
|
|
1067
1232
|
_a = Number;
|
|
1068
1233
|
return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
1069
1234
|
case 1:
|
|
@@ -1077,7 +1242,11 @@ var Pool = /** @class */ (function () {
|
|
|
1077
1242
|
var lpTokenBalance, i, _lpTokenAmount;
|
|
1078
1243
|
return __generator(this, function (_a) {
|
|
1079
1244
|
switch (_a.label) {
|
|
1080
|
-
case 0:
|
|
1245
|
+
case 0:
|
|
1246
|
+
if (this.isFake) {
|
|
1247
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1248
|
+
}
|
|
1249
|
+
return [4 /*yield*/, this.lpTokenBalances()];
|
|
1081
1250
|
case 1:
|
|
1082
1251
|
lpTokenBalance = (_a.sent())['lpToken'];
|
|
1083
1252
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
@@ -1088,7 +1257,7 @@ var Pool = /** @class */ (function () {
|
|
|
1088
1257
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1089
1258
|
}
|
|
1090
1259
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1091
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
|
|
1260
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1092
1261
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
|
|
1093
1262
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1094
1263
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1101,6 +1270,9 @@ var Pool = /** @class */ (function () {
|
|
|
1101
1270
|
return __generator(this, function (_a) {
|
|
1102
1271
|
switch (_a.label) {
|
|
1103
1272
|
case 0:
|
|
1273
|
+
if (this.isFake) {
|
|
1274
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1275
|
+
}
|
|
1104
1276
|
i = this._getCoinIdx(coin, false);
|
|
1105
1277
|
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
1106
1278
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
@@ -1109,7 +1281,7 @@ var Pool = /** @class */ (function () {
|
|
|
1109
1281
|
case 1:
|
|
1110
1282
|
_a.sent();
|
|
1111
1283
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1112
|
-
if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
|
|
1284
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1113
1285
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
|
|
1114
1286
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1115
1287
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1278,7 +1450,7 @@ var Pool = /** @class */ (function () {
|
|
|
1278
1450
|
return __generator(this, function (_a) {
|
|
1279
1451
|
switch (_a.label) {
|
|
1280
1452
|
case 0:
|
|
1281
|
-
contractAddress = this.name
|
|
1453
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1282
1454
|
i = this._getCoinIdx(inputCoin);
|
|
1283
1455
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1284
1456
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1290,7 +1462,7 @@ var Pool = /** @class */ (function () {
|
|
|
1290
1462
|
return __generator(this, function (_a) {
|
|
1291
1463
|
switch (_a.label) {
|
|
1292
1464
|
case 0:
|
|
1293
|
-
contractAddress = this.name
|
|
1465
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1294
1466
|
i = this._getCoinIdx(inputCoin);
|
|
1295
1467
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1296
1468
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1302,7 +1474,7 @@ var Pool = /** @class */ (function () {
|
|
|
1302
1474
|
return __generator(this, function (_a) {
|
|
1303
1475
|
switch (_a.label) {
|
|
1304
1476
|
case 0:
|
|
1305
|
-
contractAddress = this.name
|
|
1477
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1306
1478
|
i = this._getCoinIdx(inputCoin);
|
|
1307
1479
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1308
1480
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1312,10 +1484,11 @@ var Pool = /** @class */ (function () {
|
|
|
1312
1484
|
this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1313
1485
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1314
1486
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1315
|
-
var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount,
|
|
1487
|
+
var contractAddress, i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value;
|
|
1316
1488
|
return __generator(this, function (_d) {
|
|
1317
1489
|
switch (_d.label) {
|
|
1318
1490
|
case 0:
|
|
1491
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1319
1492
|
i = this._getCoinIdx(inputCoin);
|
|
1320
1493
|
j = this._getCoinIdx(outputCoin);
|
|
1321
1494
|
_c = (_a = Object).values;
|
|
@@ -1325,7 +1498,7 @@ var Pool = /** @class */ (function () {
|
|
|
1325
1498
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
1326
1499
|
throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
|
|
1327
1500
|
}
|
|
1328
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress,
|
|
1501
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1329
1502
|
case 2:
|
|
1330
1503
|
if (!(_d.sent())) {
|
|
1331
1504
|
throw Error("Token allowance is needed to estimate gas");
|
|
@@ -1337,7 +1510,6 @@ var Pool = /** @class */ (function () {
|
|
|
1337
1510
|
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
|
|
1338
1511
|
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1339
1512
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1340
|
-
contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
|
|
1341
1513
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
1342
1514
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
1343
1515
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
@@ -1353,10 +1525,11 @@ var Pool = /** @class */ (function () {
|
|
|
1353
1525
|
this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1354
1526
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1355
1527
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1356
|
-
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount,
|
|
1528
|
+
var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, estimatedGas, gasLimit;
|
|
1357
1529
|
return __generator(this, function (_a) {
|
|
1358
1530
|
switch (_a.label) {
|
|
1359
1531
|
case 0:
|
|
1532
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1360
1533
|
i = this._getCoinIdx(inputCoin);
|
|
1361
1534
|
j = this._getCoinIdx(outputCoin);
|
|
1362
1535
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
@@ -1366,10 +1539,9 @@ var Pool = /** @class */ (function () {
|
|
|
1366
1539
|
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
|
|
1367
1540
|
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1368
1541
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1369
|
-
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount],
|
|
1542
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
|
|
1370
1543
|
case 2:
|
|
1371
1544
|
_a.sent();
|
|
1372
|
-
contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
|
|
1373
1545
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
1374
1546
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
1375
1547
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
@@ -1384,7 +1556,10 @@ var Pool = /** @class */ (function () {
|
|
|
1384
1556
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1385
1557
|
case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1386
1558
|
case 7:
|
|
1387
|
-
|
|
1559
|
+
estimatedGas = _a.sent();
|
|
1560
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
1561
|
+
estimatedGas.mul(160).div(100) :
|
|
1562
|
+
estimatedGas.mul(130).div(100);
|
|
1388
1563
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
1389
1564
|
case 8: return [2 /*return*/, (_a.sent()).hash];
|
|
1390
1565
|
}
|
|
@@ -1396,6 +1571,9 @@ var Pool = /** @class */ (function () {
|
|
|
1396
1571
|
return __generator(this, function (_a) {
|
|
1397
1572
|
switch (_a.label) {
|
|
1398
1573
|
case 0:
|
|
1574
|
+
if (this.isFake) {
|
|
1575
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1576
|
+
}
|
|
1399
1577
|
i = this._getCoinIdx(inputCoin, false);
|
|
1400
1578
|
j = this._getCoinIdx(outputCoin, false);
|
|
1401
1579
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
|
|
@@ -1411,6 +1589,9 @@ var Pool = /** @class */ (function () {
|
|
|
1411
1589
|
return __generator(this, function (_a) {
|
|
1412
1590
|
switch (_a.label) {
|
|
1413
1591
|
case 0:
|
|
1592
|
+
if (this.isFake) {
|
|
1593
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1594
|
+
}
|
|
1414
1595
|
i = this._getCoinIdx(inputCoin, false);
|
|
1415
1596
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1416
1597
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1422,6 +1603,9 @@ var Pool = /** @class */ (function () {
|
|
|
1422
1603
|
return __generator(this, function (_a) {
|
|
1423
1604
|
switch (_a.label) {
|
|
1424
1605
|
case 0:
|
|
1606
|
+
if (this.isFake) {
|
|
1607
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1608
|
+
}
|
|
1425
1609
|
i = this._getCoinIdx(inputCoin, false);
|
|
1426
1610
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1427
1611
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1433,6 +1617,9 @@ var Pool = /** @class */ (function () {
|
|
|
1433
1617
|
return __generator(this, function (_a) {
|
|
1434
1618
|
switch (_a.label) {
|
|
1435
1619
|
case 0:
|
|
1620
|
+
if (this.isFake) {
|
|
1621
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1622
|
+
}
|
|
1436
1623
|
i = this._getCoinIdx(inputCoin, false);
|
|
1437
1624
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1438
1625
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1446,6 +1633,9 @@ var Pool = /** @class */ (function () {
|
|
|
1446
1633
|
return __generator(this, function (_d) {
|
|
1447
1634
|
switch (_d.label) {
|
|
1448
1635
|
case 0:
|
|
1636
|
+
if (this.isFake) {
|
|
1637
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1638
|
+
}
|
|
1449
1639
|
i = this._getCoinIdx(inputCoin, false);
|
|
1450
1640
|
j = this._getCoinIdx(outputCoin, false);
|
|
1451
1641
|
_c = (_a = Object).values;
|
|
@@ -1481,10 +1671,13 @@ var Pool = /** @class */ (function () {
|
|
|
1481
1671
|
this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1482
1672
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1483
1673
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1484
|
-
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
|
|
1674
|
+
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, estimatedGas, gasLimit;
|
|
1485
1675
|
return __generator(this, function (_a) {
|
|
1486
1676
|
switch (_a.label) {
|
|
1487
1677
|
case 0:
|
|
1678
|
+
if (this.isFake) {
|
|
1679
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1680
|
+
}
|
|
1488
1681
|
i = this._getCoinIdx(inputCoin, false);
|
|
1489
1682
|
j = this._getCoinIdx(outputCoin, false);
|
|
1490
1683
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
|
|
@@ -1510,7 +1703,10 @@ var Pool = /** @class */ (function () {
|
|
|
1510
1703
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1511
1704
|
case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1512
1705
|
case 7:
|
|
1513
|
-
|
|
1706
|
+
estimatedGas = _a.sent();
|
|
1707
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
1708
|
+
estimatedGas.mul(140).div(100) :
|
|
1709
|
+
estimatedGas.mul(130).div(100);
|
|
1514
1710
|
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
1515
1711
|
case 8: return [2 /*return*/, (_a.sent()).hash];
|
|
1516
1712
|
}
|
|
@@ -1523,7 +1719,7 @@ var Pool = /** @class */ (function () {
|
|
|
1523
1719
|
addresses[_i] = arguments[_i];
|
|
1524
1720
|
}
|
|
1525
1721
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1526
|
-
var votingEscrowContract, gaugeContract, contractCalls,
|
|
1722
|
+
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _a, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _c, _d, entry;
|
|
1527
1723
|
return __generator(this, function (_e) {
|
|
1528
1724
|
switch (_e.label) {
|
|
1529
1725
|
case 0:
|
|
@@ -1537,11 +1733,12 @@ var Pool = /** @class */ (function () {
|
|
|
1537
1733
|
});
|
|
1538
1734
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1539
1735
|
case 1:
|
|
1540
|
-
|
|
1541
|
-
|
|
1736
|
+
_response = _e.sent();
|
|
1737
|
+
responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1738
|
+
_a = responseBN.splice(0, 2), veTotalSupplyBN = _a[0], gaugeTotalSupplyBN = _a[1];
|
|
1542
1739
|
resultBN = {};
|
|
1543
1740
|
addresses.forEach(function (acct, i) {
|
|
1544
|
-
resultBN[acct] =
|
|
1741
|
+
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
1545
1742
|
});
|
|
1546
1743
|
result = {};
|
|
1547
1744
|
for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
|
|
@@ -1559,7 +1756,7 @@ var Pool = /** @class */ (function () {
|
|
|
1559
1756
|
accounts[_i] = arguments[_i];
|
|
1560
1757
|
}
|
|
1561
1758
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1562
|
-
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response, _a, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _c, accounts_1, acct, totalPower, optimalBN, _d, accounts_2, acct, amount, _e, accounts_3, acct, optimal, _f, _h, entry;
|
|
1759
|
+
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, response, _a, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _c, accounts_1, acct, totalPower, optimalBN, _d, accounts_2, acct, amount, _e, accounts_3, acct, optimal, _f, _h, entry;
|
|
1563
1760
|
return __generator(this, function (_j) {
|
|
1564
1761
|
switch (_j.label) {
|
|
1565
1762
|
case 0:
|
|
@@ -1574,7 +1771,8 @@ var Pool = /** @class */ (function () {
|
|
|
1574
1771
|
});
|
|
1575
1772
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1576
1773
|
case 1:
|
|
1577
|
-
|
|
1774
|
+
_response = _j.sent();
|
|
1775
|
+
response = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1578
1776
|
_a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
|
|
1579
1777
|
votingPower = {};
|
|
1580
1778
|
totalBalance = (0, utils_1.BN)(0);
|
|
@@ -1634,32 +1832,6 @@ var Pool = /** @class */ (function () {
|
|
|
1634
1832
|
}
|
|
1635
1833
|
});
|
|
1636
1834
|
}); };
|
|
1637
|
-
this.getApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1638
|
-
var swapContract, gaugeContract, gaugeControllerContract, _a, inflation, weight, workingSupply, virtualPrice, rate, crvRate, baseApy, boostedApy;
|
|
1639
|
-
return __generator(this, function (_c) {
|
|
1640
|
-
switch (_c.label) {
|
|
1641
|
-
case 0:
|
|
1642
|
-
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
1643
|
-
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
1644
|
-
gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
|
|
1645
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
1646
|
-
gaugeContract.inflation_rate(),
|
|
1647
|
-
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
1648
|
-
gaugeContract.working_supply(),
|
|
1649
|
-
swapContract.get_virtual_price(),
|
|
1650
|
-
])];
|
|
1651
|
-
case 1:
|
|
1652
|
-
_a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
|
|
1653
|
-
rate = inflation.times(weight).times(31536000).div(workingSupply).times(0.4).div(virtualPrice);
|
|
1654
|
-
return [4 /*yield*/, (0, utils_1.getCrvRate)()];
|
|
1655
|
-
case 2:
|
|
1656
|
-
crvRate = _c.sent();
|
|
1657
|
-
baseApy = rate.times(crvRate);
|
|
1658
|
-
boostedApy = baseApy.times(2.5);
|
|
1659
|
-
return [2 /*return*/, [baseApy.toFixed(4), boostedApy.toFixed(4)]];
|
|
1660
|
-
}
|
|
1661
|
-
});
|
|
1662
|
-
}); };
|
|
1663
1835
|
this._getCoinIdx = function (coin, useUnderlying) {
|
|
1664
1836
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
1665
1837
|
if (typeof coin === 'number') {
|
|
@@ -1862,7 +2034,7 @@ var Pool = /** @class */ (function () {
|
|
|
1862
2034
|
switch (_a.label) {
|
|
1863
2035
|
case 0:
|
|
1864
2036
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1865
|
-
if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
|
|
2037
|
+
if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
|
|
1866
2038
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1867
2039
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1868
2040
|
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -2126,13 +2298,15 @@ var Pool = /** @class */ (function () {
|
|
|
2126
2298
|
case 0: return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
|
|
2127
2299
|
case 1:
|
|
2128
2300
|
_expectedWrappedAmounts = _a.sent();
|
|
2129
|
-
|
|
2301
|
+
if (this.name !== 'atricrypto3') {
|
|
2302
|
+
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
2303
|
+
}
|
|
2130
2304
|
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
2131
2305
|
basePool = new Pool(this.basePool);
|
|
2132
2306
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_expectedMetaCoinAmount)];
|
|
2133
2307
|
case 2:
|
|
2134
2308
|
_basePoolExpectedAmounts = _a.sent();
|
|
2135
|
-
return [2 /*return*/, __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true)];
|
|
2309
|
+
return [2 /*return*/, this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
|
|
2136
2310
|
}
|
|
2137
2311
|
});
|
|
2138
2312
|
}); };
|
|
@@ -2386,7 +2560,9 @@ var Pool = /** @class */ (function () {
|
|
|
2386
2560
|
if (estimateGas) {
|
|
2387
2561
|
return [2 /*return*/, gas.toNumber()];
|
|
2388
2562
|
}
|
|
2389
|
-
gasLimit =
|
|
2563
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
2564
|
+
gas.mul(140).div(100) :
|
|
2565
|
+
gas.mul(130).div(100);
|
|
2390
2566
|
return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
2391
2567
|
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
2392
2568
|
}
|
|
@@ -2525,7 +2701,9 @@ var Pool = /** @class */ (function () {
|
|
|
2525
2701
|
if (estimateGas) {
|
|
2526
2702
|
return [2 /*return*/, gas.toNumber()];
|
|
2527
2703
|
}
|
|
2528
|
-
gasLimit =
|
|
2704
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
2705
|
+
gas.mul(160).div(100) :
|
|
2706
|
+
gas.mul(130).div(100);
|
|
2529
2707
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
2530
2708
|
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
2531
2709
|
}
|
|
@@ -2537,7 +2715,7 @@ var Pool = /** @class */ (function () {
|
|
|
2537
2715
|
return __generator(this, function (_a) {
|
|
2538
2716
|
switch (_a.label) {
|
|
2539
2717
|
case 0:
|
|
2540
|
-
contractAddress = this.name
|
|
2718
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2541
2719
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2542
2720
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2543
2721
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
@@ -2555,12 +2733,14 @@ var Pool = /** @class */ (function () {
|
|
|
2555
2733
|
}
|
|
2556
2734
|
});
|
|
2557
2735
|
}); };
|
|
2558
|
-
var poolData =
|
|
2736
|
+
var poolData = curve_1.POOLS_DATA[name];
|
|
2559
2737
|
this.name = name;
|
|
2738
|
+
this.referenceAsset = poolData.reference_asset;
|
|
2560
2739
|
this.swap = poolData.swap_address;
|
|
2561
2740
|
this.zap = poolData.deposit_address || null;
|
|
2562
2741
|
this.lpToken = poolData.token_address;
|
|
2563
2742
|
this.gauge = poolData.gauge_address;
|
|
2743
|
+
this.crvRewardContract = poolData.crv_reward_contract || null;
|
|
2564
2744
|
this.underlyingCoins = poolData.underlying_coins;
|
|
2565
2745
|
this.coins = poolData.coins;
|
|
2566
2746
|
this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
|
|
@@ -2569,6 +2749,7 @@ var Pool = /** @class */ (function () {
|
|
|
2569
2749
|
this.decimals = poolData.decimals;
|
|
2570
2750
|
this.useLending = poolData.use_lending;
|
|
2571
2751
|
this.isMeta = poolData.is_meta || false;
|
|
2752
|
+
this.isFake = poolData.is_fake || false;
|
|
2572
2753
|
this.isCrypto = poolData.is_crypto || false;
|
|
2573
2754
|
this.isFactory = poolData.is_factory || false;
|
|
2574
2755
|
this.basePool = poolData.base_pool || '';
|
|
@@ -2594,7 +2775,16 @@ var Pool = /** @class */ (function () {
|
|
|
2594
2775
|
exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
|
|
2595
2776
|
exchangeWrapped: this.exchangeWrappedEstimateGas,
|
|
2596
2777
|
};
|
|
2597
|
-
|
|
2778
|
+
this.stats = {
|
|
2779
|
+
getParameters: this.getParameters,
|
|
2780
|
+
getPoolBalances: this.getPoolBalances,
|
|
2781
|
+
getPoolWrappedBalances: this.getPoolWrappedBalances,
|
|
2782
|
+
getTotalLiquidity: this.getTotalLiquidity,
|
|
2783
|
+
getVolume: this.getVolume,
|
|
2784
|
+
getBaseApy: this.getBaseApy,
|
|
2785
|
+
getTokenApy: this.getTokenApy,
|
|
2786
|
+
};
|
|
2787
|
+
if (this.isMeta && !this.isFake) {
|
|
2598
2788
|
var metaCoins = poolData.meta_coin_addresses;
|
|
2599
2789
|
var metaCoinDecimals = poolData.meta_coin_decimals;
|
|
2600
2790
|
this.underlyingCoinAddresses = __spreadArray([this.underlyingCoinAddresses[0]], metaCoins, true);
|
|
@@ -2650,7 +2840,7 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
2650
2840
|
return __generator(this, function (_d) {
|
|
2651
2841
|
switch (_d.label) {
|
|
2652
2842
|
case 0:
|
|
2653
|
-
availablePools = Object.entries(
|
|
2843
|
+
availablePools = Object.entries(curve_1.POOLS_DATA).map(function (pool) {
|
|
2654
2844
|
var _a;
|
|
2655
2845
|
var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
2656
2846
|
var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
@@ -2665,6 +2855,9 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
2665
2855
|
underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
2666
2856
|
meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
|
|
2667
2857
|
];
|
|
2858
|
+
if (pool[0] === 'atricrypto3') {
|
|
2859
|
+
return null;
|
|
2860
|
+
}
|
|
2668
2861
|
if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
|
|
2669
2862
|
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
2670
2863
|
}
|
|
@@ -2705,7 +2898,7 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
2705
2898
|
_estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
|
|
2706
2899
|
(0, utils_1._getUsdRate)(outputCoinAddress),
|
|
2707
2900
|
axios_1.default.get("https://api.curve.fi/api/getGas"),
|
|
2708
|
-
(0, utils_1._getUsdRate)(
|
|
2901
|
+
(0, utils_1._getUsdRate)(curve_1.COINS.eth),
|
|
2709
2902
|
])];
|
|
2710
2903
|
case 3:
|
|
2711
2904
|
_c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
|
|
@@ -2846,9 +3039,12 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
|
|
|
2846
3039
|
return __generator(this, function (_c) {
|
|
2847
3040
|
switch (_c.label) {
|
|
2848
3041
|
case 0:
|
|
3042
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3043
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3044
|
+
}
|
|
2849
3045
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2850
3046
|
// TODO remove it when fixed
|
|
2851
|
-
if (inputCoinAddress.toLowerCase() ===
|
|
3047
|
+
if (inputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase())
|
|
2852
3048
|
return [2 /*return*/, false];
|
|
2853
3049
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2854
3050
|
case 1:
|
|
@@ -2860,11 +3056,11 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
|
|
|
2860
3056
|
exports.crossAssetExchangeAvailable = crossAssetExchangeAvailable;
|
|
2861
3057
|
var _getSmallAmountForCoin = function (coinAddress) {
|
|
2862
3058
|
var smallAmount = '10'; // $10 or €10
|
|
2863
|
-
if (Object.values(
|
|
3059
|
+
if (Object.values(curve_1.BTC_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2864
3060
|
smallAmount = '0.00025'; // =10$ when BTC = $40k
|
|
2865
|
-
else if (Object.values(
|
|
3061
|
+
else if (Object.values(curve_1.ETH_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2866
3062
|
smallAmount = '0.004'; // =10$ when ETH = $2.5k
|
|
2867
|
-
else if (Object.values(
|
|
3063
|
+
else if (Object.values(curve_1.LINK_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2868
3064
|
smallAmount = '0.5'; // =10$ when LINK = $20
|
|
2869
3065
|
return smallAmount;
|
|
2870
3066
|
};
|
|
@@ -2901,6 +3097,9 @@ var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amoun
|
|
|
2901
3097
|
return __generator(this, function (_e) {
|
|
2902
3098
|
switch (_e.label) {
|
|
2903
3099
|
case 0:
|
|
3100
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3101
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3102
|
+
}
|
|
2904
3103
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2905
3104
|
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2906
3105
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
@@ -2917,6 +3116,9 @@ var crossAssetExchangeExpected = function (inputCoin, outputCoin, amount) { retu
|
|
|
2917
3116
|
return __generator(this, function (_e) {
|
|
2918
3117
|
switch (_e.label) {
|
|
2919
3118
|
case 0:
|
|
3119
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3120
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3121
|
+
}
|
|
2920
3122
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2921
3123
|
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2922
3124
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
@@ -2934,7 +3136,11 @@ exports.crossAssetExchangeExpected = crossAssetExchangeExpected;
|
|
|
2934
3136
|
var crossAssetExchangeIsApproved = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2935
3137
|
return __generator(this, function (_a) {
|
|
2936
3138
|
switch (_a.label) {
|
|
2937
|
-
case 0:
|
|
3139
|
+
case 0:
|
|
3140
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3141
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3142
|
+
}
|
|
3143
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
|
|
2938
3144
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2939
3145
|
}
|
|
2940
3146
|
});
|
|
@@ -2943,7 +3149,11 @@ exports.crossAssetExchangeIsApproved = crossAssetExchangeIsApproved;
|
|
|
2943
3149
|
var crossAssetExchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2944
3150
|
return __generator(this, function (_a) {
|
|
2945
3151
|
switch (_a.label) {
|
|
2946
|
-
case 0:
|
|
3152
|
+
case 0:
|
|
3153
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3154
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3155
|
+
}
|
|
3156
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.router)];
|
|
2947
3157
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2948
3158
|
}
|
|
2949
3159
|
});
|
|
@@ -2952,7 +3162,11 @@ exports.crossAssetExchangeApproveEstimateGas = crossAssetExchangeApproveEstimate
|
|
|
2952
3162
|
var crossAssetExchangeApprove = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2953
3163
|
return __generator(this, function (_a) {
|
|
2954
3164
|
switch (_a.label) {
|
|
2955
|
-
case 0:
|
|
3165
|
+
case 0:
|
|
3166
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3167
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3168
|
+
}
|
|
3169
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.router)];
|
|
2956
3170
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2957
3171
|
}
|
|
2958
3172
|
});
|
|
@@ -2964,7 +3178,11 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
|
|
|
2964
3178
|
var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
|
|
2965
3179
|
return __generator(this, function (_e) {
|
|
2966
3180
|
switch (_e.label) {
|
|
2967
|
-
case 0:
|
|
3181
|
+
case 0:
|
|
3182
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3183
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3184
|
+
}
|
|
3185
|
+
return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
2968
3186
|
case 1:
|
|
2969
3187
|
if (!(_e.sent()))
|
|
2970
3188
|
throw Error("Such exchange is not available");
|
|
@@ -3004,7 +3222,11 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
3004
3222
|
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
|
|
3005
3223
|
return __generator(this, function (_e) {
|
|
3006
3224
|
switch (_e.label) {
|
|
3007
|
-
case 0:
|
|
3225
|
+
case 0:
|
|
3226
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3227
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3228
|
+
}
|
|
3229
|
+
return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
3008
3230
|
case 1:
|
|
3009
3231
|
if (!(_e.sent()))
|
|
3010
3232
|
throw Error("Such exchange is not available");
|