@curvefi/api 1.8.3 → 1.11.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 +0 -6
- package/lib/boosting.js +2 -2
- package/lib/constants/abis/abis-ethereum.d.ts +1 -1
- package/lib/constants/abis/abis-ethereum.js +97 -5
- package/lib/constants/abis/abis-polygon.d.ts +4 -0
- package/lib/constants/abis/abis-polygon.js +146 -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/crveth/swap.json +1258 -0
- package/lib/constants/abis/json/{registry.json → eurt/swap.json} +402 -497
- package/lib/constants/abis/json/eurtusd/deposit.json +257 -0
- package/lib/constants/abis/json/eurtusd/swap.json +1199 -0
- package/lib/constants/abis/json/paave/rewards.json +657 -0
- package/lib/constants/abis/json/registry_exchange.json +0 -37
- package/lib/constants/abis/json/ren-polygon/swap.json +1112 -0
- package/lib/constants/abis/json/tricrypto2/deposit.json +0 -79
- 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} +47 -13
- package/lib/constants/coins-polygon.d.ts +31 -0
- package/lib/constants/coins-polygon.js +74 -0
- package/lib/curve.d.ts +23 -6
- package/lib/curve.js +137 -80
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/interfaces.d.ts +2 -0
- package/lib/pools.d.ts +2 -11
- package/lib/pools.js +584 -440
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +34 -15
- package/package.json +6 -5
- package/lib/constants/coins.d.ts +0 -25
package/lib/pools.js
CHANGED
|
@@ -59,14 +59,11 @@ 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.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.
|
|
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 registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
|
|
66
|
-
var registry_json_1 = __importDefault(require("./constants/abis/json/registry.json"));
|
|
67
|
-
var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
|
|
68
65
|
var curve_1 = require("./curve");
|
|
69
|
-
var
|
|
66
|
+
var axios_1 = __importDefault(require("axios"));
|
|
70
67
|
var Pool = /** @class */ (function () {
|
|
71
68
|
function Pool(name) {
|
|
72
69
|
var _this = this;
|
|
@@ -79,12 +76,12 @@ var Pool = /** @class */ (function () {
|
|
|
79
76
|
switch (_a.label) {
|
|
80
77
|
case 0:
|
|
81
78
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
82
|
-
throw Error(this.name
|
|
79
|
+
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
83
80
|
}
|
|
84
81
|
_amounts = amounts.map(function (amount, i) {
|
|
85
82
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
86
83
|
});
|
|
87
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
|
|
84
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
88
85
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
|
|
89
86
|
case 1:
|
|
90
87
|
_expected = _a.sent(); // Lending pools
|
|
@@ -112,8 +109,11 @@ var Pool = /** @class */ (function () {
|
|
|
112
109
|
return __generator(this, function (_a) {
|
|
113
110
|
switch (_a.label) {
|
|
114
111
|
case 0:
|
|
112
|
+
if (this.isFake) {
|
|
113
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
114
|
+
}
|
|
115
115
|
if (amounts.length !== this.coinAddresses.length) {
|
|
116
|
-
throw Error(this.name
|
|
116
|
+
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
117
117
|
}
|
|
118
118
|
_amounts = amounts.map(function (amount, i) {
|
|
119
119
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
@@ -147,19 +147,21 @@ var Pool = /** @class */ (function () {
|
|
|
147
147
|
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
148
148
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
149
149
|
case 1:
|
|
150
|
-
_poolWrappedBalances =
|
|
150
|
+
_poolWrappedBalances = _a.sent();
|
|
151
151
|
_poolUnderlyingBalances = [];
|
|
152
152
|
if (!this.isMeta) return [3 /*break*/, 3];
|
|
153
|
-
|
|
153
|
+
if (this.name !== 'atricrypto3') {
|
|
154
|
+
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
155
|
+
}
|
|
154
156
|
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolUnderlyingBalance = _poolWrappedBalances.slice(1);
|
|
155
157
|
basePool = new Pool(this.basePool);
|
|
156
158
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_poolMetaCoinBalance)];
|
|
157
159
|
case 2:
|
|
158
160
|
_basePoolExpectedAmounts = _a.sent();
|
|
159
|
-
_poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
|
|
161
|
+
_poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
|
|
160
162
|
return [3 /*break*/, 6];
|
|
161
163
|
case 3:
|
|
162
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
164
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
163
165
|
return [4 /*yield*/, this._getRates()];
|
|
164
166
|
case 4:
|
|
165
167
|
_rates_1 = _a.sent();
|
|
@@ -173,15 +175,20 @@ var Pool = /** @class */ (function () {
|
|
|
173
175
|
});
|
|
174
176
|
}); };
|
|
175
177
|
this.getPoolWrappedBalances = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
176
|
-
var swapContract, contractCalls;
|
|
178
|
+
var swapContract, contractCalls, _wrappedBalances;
|
|
177
179
|
var _this = this;
|
|
178
180
|
return __generator(this, function (_a) {
|
|
179
181
|
switch (_a.label) {
|
|
180
182
|
case 0:
|
|
183
|
+
if (this.isFake) {
|
|
184
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
185
|
+
}
|
|
181
186
|
swapContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
182
187
|
contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
|
|
183
188
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
184
|
-
case 1:
|
|
189
|
+
case 1:
|
|
190
|
+
_wrappedBalances = _a.sent();
|
|
191
|
+
return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.decimals[i]); })];
|
|
185
192
|
}
|
|
186
193
|
});
|
|
187
194
|
}); };
|
|
@@ -251,7 +258,7 @@ var Pool = /** @class */ (function () {
|
|
|
251
258
|
switch (_d.label) {
|
|
252
259
|
case 0:
|
|
253
260
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
254
|
-
throw Error(this.name
|
|
261
|
+
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
255
262
|
}
|
|
256
263
|
_c = (_a = Object).values;
|
|
257
264
|
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
@@ -259,7 +266,7 @@ var Pool = /** @class */ (function () {
|
|
|
259
266
|
balances = _c.apply(_a, [_d.sent()]);
|
|
260
267
|
for (i = 0; i < balances.length; i++) {
|
|
261
268
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
262
|
-
throw Error("Not enough "
|
|
269
|
+
throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
263
270
|
}
|
|
264
271
|
}
|
|
265
272
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
|
|
@@ -274,7 +281,7 @@ var Pool = /** @class */ (function () {
|
|
|
274
281
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
275
282
|
case 3: return [2 /*return*/, _d.sent()];
|
|
276
283
|
case 4:
|
|
277
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
|
|
284
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
|
|
278
285
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
279
286
|
case 5: return [2 /*return*/, _d.sent()];
|
|
280
287
|
case 6:
|
|
@@ -310,7 +317,7 @@ var Pool = /** @class */ (function () {
|
|
|
310
317
|
switch (_a.label) {
|
|
311
318
|
case 0:
|
|
312
319
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
313
|
-
throw Error(this.name
|
|
320
|
+
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
314
321
|
}
|
|
315
322
|
_amounts = amounts.map(function (amount, i) {
|
|
316
323
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
@@ -318,11 +325,11 @@ var Pool = /** @class */ (function () {
|
|
|
318
325
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
319
326
|
case 1:
|
|
320
327
|
_a.sent();
|
|
321
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
328
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 3];
|
|
322
329
|
return [4 /*yield*/, this._addLiquidityZap(_amounts)];
|
|
323
330
|
case 2: return [2 /*return*/, _a.sent()];
|
|
324
331
|
case 3:
|
|
325
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
332
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
326
333
|
return [4 /*yield*/, this._addLiquidity(_amounts, true)];
|
|
327
334
|
case 4: return [2 /*return*/, _a.sent()];
|
|
328
335
|
case 5:
|
|
@@ -340,7 +347,11 @@ var Pool = /** @class */ (function () {
|
|
|
340
347
|
var poolBalances, walletBalances, _a, _c;
|
|
341
348
|
return __generator(this, function (_d) {
|
|
342
349
|
switch (_d.label) {
|
|
343
|
-
case 0:
|
|
350
|
+
case 0:
|
|
351
|
+
if (this.isFake) {
|
|
352
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
353
|
+
}
|
|
354
|
+
return [4 /*yield*/, this.getPoolWrappedBalances()];
|
|
344
355
|
case 1:
|
|
345
356
|
poolBalances = (_d.sent()).map(Number);
|
|
346
357
|
_c = (_a = Object).values;
|
|
@@ -356,6 +367,9 @@ var Pool = /** @class */ (function () {
|
|
|
356
367
|
return __generator(this, function (_a) {
|
|
357
368
|
switch (_a.label) {
|
|
358
369
|
case 0:
|
|
370
|
+
if (this.isFake) {
|
|
371
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
372
|
+
}
|
|
359
373
|
amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.decimals[i]); });
|
|
360
374
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
|
|
361
375
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -367,6 +381,9 @@ var Pool = /** @class */ (function () {
|
|
|
367
381
|
return __generator(this, function (_c) {
|
|
368
382
|
switch (_c.label) {
|
|
369
383
|
case 0:
|
|
384
|
+
if (this.isFake) {
|
|
385
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
386
|
+
}
|
|
370
387
|
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
371
388
|
_a = Number;
|
|
372
389
|
return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
|
|
@@ -380,7 +397,11 @@ var Pool = /** @class */ (function () {
|
|
|
380
397
|
this.addLiquidityWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
381
398
|
return __generator(this, function (_a) {
|
|
382
399
|
switch (_a.label) {
|
|
383
|
-
case 0:
|
|
400
|
+
case 0:
|
|
401
|
+
if (this.isFake) {
|
|
402
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
403
|
+
}
|
|
404
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
|
|
384
405
|
case 1: return [2 /*return*/, _a.sent()];
|
|
385
406
|
}
|
|
386
407
|
});
|
|
@@ -388,7 +409,11 @@ var Pool = /** @class */ (function () {
|
|
|
388
409
|
this.addLiquidityWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
389
410
|
return __generator(this, function (_a) {
|
|
390
411
|
switch (_a.label) {
|
|
391
|
-
case 0:
|
|
412
|
+
case 0:
|
|
413
|
+
if (this.isFake) {
|
|
414
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
415
|
+
}
|
|
416
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, this.swap)];
|
|
392
417
|
case 1: return [2 /*return*/, _a.sent()];
|
|
393
418
|
}
|
|
394
419
|
});
|
|
@@ -396,7 +421,11 @@ var Pool = /** @class */ (function () {
|
|
|
396
421
|
this.addLiquidityWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
397
422
|
return __generator(this, function (_a) {
|
|
398
423
|
switch (_a.label) {
|
|
399
|
-
case 0:
|
|
424
|
+
case 0:
|
|
425
|
+
if (this.isFake) {
|
|
426
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
427
|
+
}
|
|
428
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, this.swap)];
|
|
400
429
|
case 1: return [2 /*return*/, _a.sent()];
|
|
401
430
|
}
|
|
402
431
|
});
|
|
@@ -407,8 +436,11 @@ var Pool = /** @class */ (function () {
|
|
|
407
436
|
return __generator(this, function (_d) {
|
|
408
437
|
switch (_d.label) {
|
|
409
438
|
case 0:
|
|
439
|
+
if (this.isFake) {
|
|
440
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
441
|
+
}
|
|
410
442
|
if (amounts.length !== this.coinAddresses.length) {
|
|
411
|
-
throw Error(this.name
|
|
443
|
+
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
412
444
|
}
|
|
413
445
|
_c = (_a = Object).values;
|
|
414
446
|
return [4 /*yield*/, this.coinBalances()];
|
|
@@ -416,7 +448,7 @@ var Pool = /** @class */ (function () {
|
|
|
416
448
|
balances = _c.apply(_a, [_d.sent()]);
|
|
417
449
|
for (i = 0; i < balances.length; i++) {
|
|
418
450
|
if (Number(balances[i]) < Number(amounts[i])) {
|
|
419
|
-
throw Error("Not enough "
|
|
451
|
+
throw Error("Not enough ".concat(this.coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
420
452
|
}
|
|
421
453
|
}
|
|
422
454
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
|
|
@@ -427,7 +459,7 @@ var Pool = /** @class */ (function () {
|
|
|
427
459
|
_amounts = amounts.map(function (amount, i) {
|
|
428
460
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
429
461
|
});
|
|
430
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
|
|
462
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
431
463
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
432
464
|
case 3: return [2 /*return*/, _d.sent()];
|
|
433
465
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
@@ -443,8 +475,11 @@ var Pool = /** @class */ (function () {
|
|
|
443
475
|
return __generator(this, function (_a) {
|
|
444
476
|
switch (_a.label) {
|
|
445
477
|
case 0:
|
|
478
|
+
if (this.isFake) {
|
|
479
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
480
|
+
}
|
|
446
481
|
if (amounts.length !== this.coinAddresses.length) {
|
|
447
|
-
throw Error(this.name
|
|
482
|
+
throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
448
483
|
}
|
|
449
484
|
_amounts = amounts.map(function (amount, i) {
|
|
450
485
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
@@ -452,7 +487,7 @@ var Pool = /** @class */ (function () {
|
|
|
452
487
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
453
488
|
case 1:
|
|
454
489
|
_a.sent();
|
|
455
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
490
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
456
491
|
return [4 /*yield*/, this._addLiquidity(_amounts, false)];
|
|
457
492
|
case 2: return [2 /*return*/, _a.sent()];
|
|
458
493
|
case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
|
|
@@ -469,7 +504,7 @@ var Pool = /** @class */ (function () {
|
|
|
469
504
|
switch (_a.label) {
|
|
470
505
|
case 0:
|
|
471
506
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
472
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
|
|
507
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
473
508
|
return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
|
|
474
509
|
case 1:
|
|
475
510
|
_expected = _a.sent(); // Lending pools
|
|
@@ -492,7 +527,7 @@ var Pool = /** @class */ (function () {
|
|
|
492
527
|
return __generator(this, function (_a) {
|
|
493
528
|
switch (_a.label) {
|
|
494
529
|
case 0:
|
|
495
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
530
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
|
|
496
531
|
return [2 /*return*/, true];
|
|
497
532
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
498
533
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -503,7 +538,7 @@ var Pool = /** @class */ (function () {
|
|
|
503
538
|
return __generator(this, function (_a) {
|
|
504
539
|
switch (_a.label) {
|
|
505
540
|
case 0:
|
|
506
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
541
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
|
|
507
542
|
return [2 /*return*/, 0];
|
|
508
543
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
509
544
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -514,7 +549,7 @@ var Pool = /** @class */ (function () {
|
|
|
514
549
|
return __generator(this, function (_a) {
|
|
515
550
|
switch (_a.label) {
|
|
516
551
|
case 0:
|
|
517
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
|
|
552
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
|
|
518
553
|
return [2 /*return*/, []];
|
|
519
554
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
520
555
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -529,7 +564,7 @@ var Pool = /** @class */ (function () {
|
|
|
529
564
|
case 1:
|
|
530
565
|
lpTokenBalance = (_c.sent())['lpToken'];
|
|
531
566
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
532
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
567
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
533
568
|
}
|
|
534
569
|
_a = this.zap;
|
|
535
570
|
if (!_a) return [3 /*break*/, 3];
|
|
@@ -542,11 +577,11 @@ var Pool = /** @class */ (function () {
|
|
|
542
577
|
throw Error("Token allowance is needed to estimate gas");
|
|
543
578
|
}
|
|
544
579
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
545
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
|
|
580
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 5];
|
|
546
581
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
547
582
|
case 4: return [2 /*return*/, _c.sent()];
|
|
548
583
|
case 5:
|
|
549
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
|
|
584
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
550
585
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
551
586
|
case 6: return [2 /*return*/, _c.sent()];
|
|
552
587
|
case 7:
|
|
@@ -567,11 +602,11 @@ var Pool = /** @class */ (function () {
|
|
|
567
602
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
568
603
|
case 1:
|
|
569
604
|
_a.sent();
|
|
570
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
605
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 3];
|
|
571
606
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
|
|
572
607
|
case 2: return [2 /*return*/, _a.sent()];
|
|
573
608
|
case 3:
|
|
574
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
609
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
575
610
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
|
|
576
611
|
case 4: return [2 /*return*/, _a.sent()];
|
|
577
612
|
case 5:
|
|
@@ -589,6 +624,9 @@ var Pool = /** @class */ (function () {
|
|
|
589
624
|
return __generator(this, function (_a) {
|
|
590
625
|
switch (_a.label) {
|
|
591
626
|
case 0:
|
|
627
|
+
if (this.isFake) {
|
|
628
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
629
|
+
}
|
|
592
630
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
593
631
|
return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
|
|
594
632
|
case 1:
|
|
@@ -602,14 +640,17 @@ var Pool = /** @class */ (function () {
|
|
|
602
640
|
return __generator(this, function (_a) {
|
|
603
641
|
switch (_a.label) {
|
|
604
642
|
case 0:
|
|
643
|
+
if (this.isFake) {
|
|
644
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
645
|
+
}
|
|
605
646
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
606
647
|
return [4 /*yield*/, this.lpTokenBalances()];
|
|
607
648
|
case 1:
|
|
608
649
|
lpTokenBalance = (_a.sent())['lpToken'];
|
|
609
650
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
610
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
651
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
611
652
|
}
|
|
612
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
653
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
613
654
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
614
655
|
case 2: return [2 /*return*/, _a.sent()];
|
|
615
656
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
@@ -622,11 +663,14 @@ var Pool = /** @class */ (function () {
|
|
|
622
663
|
return __generator(this, function (_a) {
|
|
623
664
|
switch (_a.label) {
|
|
624
665
|
case 0:
|
|
666
|
+
if (this.isFake) {
|
|
667
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
668
|
+
}
|
|
625
669
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
626
670
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
627
671
|
case 1:
|
|
628
672
|
_a.sent();
|
|
629
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
673
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
630
674
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
|
|
631
675
|
case 2: return [2 /*return*/, _a.sent()];
|
|
632
676
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
@@ -639,6 +683,9 @@ var Pool = /** @class */ (function () {
|
|
|
639
683
|
return __generator(this, function (_a) {
|
|
640
684
|
switch (_a.label) {
|
|
641
685
|
case 0:
|
|
686
|
+
if (this.isCrypto) {
|
|
687
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
688
|
+
}
|
|
642
689
|
amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
|
|
643
690
|
return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
|
|
644
691
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -650,6 +697,9 @@ var Pool = /** @class */ (function () {
|
|
|
650
697
|
return __generator(this, function (_c) {
|
|
651
698
|
switch (_c.label) {
|
|
652
699
|
case 0:
|
|
700
|
+
if (this.isCrypto) {
|
|
701
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
702
|
+
}
|
|
653
703
|
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
654
704
|
_a = Number;
|
|
655
705
|
return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
|
|
@@ -666,6 +716,9 @@ var Pool = /** @class */ (function () {
|
|
|
666
716
|
return __generator(this, function (_a) {
|
|
667
717
|
switch (_a.label) {
|
|
668
718
|
case 0:
|
|
719
|
+
if (this.isCrypto) {
|
|
720
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
721
|
+
}
|
|
669
722
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
670
723
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
671
724
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
@@ -690,6 +743,9 @@ var Pool = /** @class */ (function () {
|
|
|
690
743
|
return __generator(this, function (_a) {
|
|
691
744
|
switch (_a.label) {
|
|
692
745
|
case 0:
|
|
746
|
+
if (this.isCrypto) {
|
|
747
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
748
|
+
}
|
|
693
749
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
694
750
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
695
751
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
@@ -714,6 +770,9 @@ var Pool = /** @class */ (function () {
|
|
|
714
770
|
return __generator(this, function (_a) {
|
|
715
771
|
switch (_a.label) {
|
|
716
772
|
case 0:
|
|
773
|
+
if (this.isCrypto) {
|
|
774
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
775
|
+
}
|
|
717
776
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
718
777
|
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
|
|
719
778
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
@@ -737,14 +796,18 @@ var Pool = /** @class */ (function () {
|
|
|
737
796
|
var _this = this;
|
|
738
797
|
return __generator(this, function (_c) {
|
|
739
798
|
switch (_c.label) {
|
|
740
|
-
case 0:
|
|
799
|
+
case 0:
|
|
800
|
+
if (this.isCrypto) {
|
|
801
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
802
|
+
}
|
|
803
|
+
return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
|
|
741
804
|
case 1:
|
|
742
805
|
lpTokenAmount = _c.sent();
|
|
743
806
|
return [4 /*yield*/, this.lpTokenBalances()];
|
|
744
807
|
case 2:
|
|
745
808
|
lpTokenBalance = (_c.sent())['lpToken'];
|
|
746
809
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
747
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
810
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
748
811
|
}
|
|
749
812
|
_a = this.zap;
|
|
750
813
|
if (!_a) return [3 /*break*/, 4];
|
|
@@ -761,7 +824,7 @@ var Pool = /** @class */ (function () {
|
|
|
761
824
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
|
|
762
825
|
case 5: return [2 /*return*/, _c.sent()];
|
|
763
826
|
case 6:
|
|
764
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 8];
|
|
827
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 8];
|
|
765
828
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
|
|
766
829
|
case 7: return [2 /*return*/, _c.sent()];
|
|
767
830
|
case 8:
|
|
@@ -779,6 +842,9 @@ var Pool = /** @class */ (function () {
|
|
|
779
842
|
return __generator(this, function (_a) {
|
|
780
843
|
switch (_a.label) {
|
|
781
844
|
case 0:
|
|
845
|
+
if (this.isCrypto) {
|
|
846
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
847
|
+
}
|
|
782
848
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
783
849
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
784
850
|
case 1:
|
|
@@ -787,7 +853,7 @@ var Pool = /** @class */ (function () {
|
|
|
787
853
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts)];
|
|
788
854
|
case 2: return [2 /*return*/, _a.sent()];
|
|
789
855
|
case 3:
|
|
790
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
856
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
791
857
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true)];
|
|
792
858
|
case 4: return [2 /*return*/, _a.sent()];
|
|
793
859
|
case 5:
|
|
@@ -804,6 +870,9 @@ var Pool = /** @class */ (function () {
|
|
|
804
870
|
return __generator(this, function (_a) {
|
|
805
871
|
switch (_a.label) {
|
|
806
872
|
case 0:
|
|
873
|
+
if (this.isCrypto) {
|
|
874
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
875
|
+
}
|
|
807
876
|
amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
|
|
808
877
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
809
878
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -815,6 +884,9 @@ var Pool = /** @class */ (function () {
|
|
|
815
884
|
return __generator(this, function (_c) {
|
|
816
885
|
switch (_c.label) {
|
|
817
886
|
case 0:
|
|
887
|
+
if (this.isCrypto) {
|
|
888
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
889
|
+
}
|
|
818
890
|
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
819
891
|
_a = Number;
|
|
820
892
|
return [4 /*yield*/, this.removeLiquidityImbalanceWrappedExpected(amounts)];
|
|
@@ -830,17 +902,21 @@ var Pool = /** @class */ (function () {
|
|
|
830
902
|
var _this = this;
|
|
831
903
|
return __generator(this, function (_a) {
|
|
832
904
|
switch (_a.label) {
|
|
833
|
-
case 0:
|
|
905
|
+
case 0:
|
|
906
|
+
if (this.isCrypto) {
|
|
907
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
908
|
+
}
|
|
909
|
+
return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
|
|
834
910
|
case 1:
|
|
835
911
|
lpTokenAmount = _a.sent();
|
|
836
912
|
return [4 /*yield*/, this.lpTokenBalances()];
|
|
837
913
|
case 2:
|
|
838
914
|
lpTokenBalance = (_a.sent())['lpToken'];
|
|
839
915
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
840
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
916
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
841
917
|
}
|
|
842
918
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
|
|
843
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
|
|
919
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
844
920
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, true)];
|
|
845
921
|
case 3: return [2 /*return*/, _a.sent()];
|
|
846
922
|
case 4: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
|
|
@@ -856,11 +932,14 @@ var Pool = /** @class */ (function () {
|
|
|
856
932
|
return __generator(this, function (_a) {
|
|
857
933
|
switch (_a.label) {
|
|
858
934
|
case 0:
|
|
935
|
+
if (this.isCrypto) {
|
|
936
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
937
|
+
}
|
|
859
938
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
|
|
860
939
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
861
940
|
case 1:
|
|
862
941
|
_a.sent();
|
|
863
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
942
|
+
if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
864
943
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, estimateGas)];
|
|
865
944
|
case 2: return [2 /*return*/, _a.sent()];
|
|
866
945
|
case 3: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
|
|
@@ -913,7 +992,7 @@ var Pool = /** @class */ (function () {
|
|
|
913
992
|
return __generator(this, function (_a) {
|
|
914
993
|
switch (_a.label) {
|
|
915
994
|
case 0:
|
|
916
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
995
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
917
996
|
return [2 /*return*/, true];
|
|
918
997
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
919
998
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -924,7 +1003,7 @@ var Pool = /** @class */ (function () {
|
|
|
924
1003
|
return __generator(this, function (_a) {
|
|
925
1004
|
switch (_a.label) {
|
|
926
1005
|
case 0:
|
|
927
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
1006
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
928
1007
|
return [2 /*return*/, 0];
|
|
929
1008
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
930
1009
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -935,7 +1014,7 @@ var Pool = /** @class */ (function () {
|
|
|
935
1014
|
return __generator(this, function (_a) {
|
|
936
1015
|
switch (_a.label) {
|
|
937
1016
|
case 0:
|
|
938
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
1017
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
|
|
939
1018
|
return [2 /*return*/, []];
|
|
940
1019
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
941
1020
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -950,7 +1029,7 @@ var Pool = /** @class */ (function () {
|
|
|
950
1029
|
case 1:
|
|
951
1030
|
lpTokenBalance = (_c.sent())['lpToken'];
|
|
952
1031
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
953
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
1032
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
954
1033
|
}
|
|
955
1034
|
_a = this.zap;
|
|
956
1035
|
if (!_a) return [3 /*break*/, 3];
|
|
@@ -964,11 +1043,11 @@ var Pool = /** @class */ (function () {
|
|
|
964
1043
|
}
|
|
965
1044
|
i = this._getCoinIdx(coin);
|
|
966
1045
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
967
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
|
|
1046
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
|
|
968
1047
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
969
1048
|
case 4: return [2 /*return*/, _c.sent()];
|
|
970
1049
|
case 5:
|
|
971
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
|
|
1050
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
972
1051
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
973
1052
|
case 6: return [2 /*return*/, _c.sent()];
|
|
974
1053
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -988,11 +1067,11 @@ var Pool = /** @class */ (function () {
|
|
|
988
1067
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
989
1068
|
case 1:
|
|
990
1069
|
_a.sent();
|
|
991
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 3];
|
|
1070
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 3];
|
|
992
1071
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
|
|
993
1072
|
case 2: return [2 /*return*/, _a.sent()];
|
|
994
1073
|
case 3:
|
|
995
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
|
|
1074
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
996
1075
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
|
|
997
1076
|
case 4: return [2 /*return*/, _a.sent()];
|
|
998
1077
|
case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1007,8 +1086,11 @@ var Pool = /** @class */ (function () {
|
|
|
1007
1086
|
return __generator(this, function (_a) {
|
|
1008
1087
|
switch (_a.label) {
|
|
1009
1088
|
case 0:
|
|
1089
|
+
if (this.isFake) {
|
|
1090
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1091
|
+
}
|
|
1010
1092
|
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
1011
|
-
throw Error(this.name
|
|
1093
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1012
1094
|
}
|
|
1013
1095
|
i = this._getCoinIdx(coin, false);
|
|
1014
1096
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
@@ -1030,6 +1112,9 @@ var Pool = /** @class */ (function () {
|
|
|
1030
1112
|
return __generator(this, function (_c) {
|
|
1031
1113
|
switch (_c.label) {
|
|
1032
1114
|
case 0:
|
|
1115
|
+
if (this.isFake) {
|
|
1116
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1117
|
+
}
|
|
1033
1118
|
_a = Number;
|
|
1034
1119
|
return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
1035
1120
|
case 1:
|
|
@@ -1043,18 +1128,22 @@ var Pool = /** @class */ (function () {
|
|
|
1043
1128
|
var lpTokenBalance, i, _lpTokenAmount;
|
|
1044
1129
|
return __generator(this, function (_a) {
|
|
1045
1130
|
switch (_a.label) {
|
|
1046
|
-
case 0:
|
|
1131
|
+
case 0:
|
|
1132
|
+
if (this.isFake) {
|
|
1133
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1134
|
+
}
|
|
1135
|
+
return [4 /*yield*/, this.lpTokenBalances()];
|
|
1047
1136
|
case 1:
|
|
1048
1137
|
lpTokenBalance = (_a.sent())['lpToken'];
|
|
1049
1138
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
1050
|
-
throw Error("Not enough LP tokens. Actual: "
|
|
1139
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
1051
1140
|
}
|
|
1052
1141
|
i = this._getCoinIdx(coin, false);
|
|
1053
1142
|
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
1054
|
-
throw Error(this.name
|
|
1143
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1055
1144
|
}
|
|
1056
1145
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1057
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
1146
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1058
1147
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
|
|
1059
1148
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1060
1149
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1067,15 +1156,18 @@ var Pool = /** @class */ (function () {
|
|
|
1067
1156
|
return __generator(this, function (_a) {
|
|
1068
1157
|
switch (_a.label) {
|
|
1069
1158
|
case 0:
|
|
1159
|
+
if (this.isFake) {
|
|
1160
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1161
|
+
}
|
|
1070
1162
|
i = this._getCoinIdx(coin, false);
|
|
1071
1163
|
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
|
|
1072
|
-
throw Error(this.name
|
|
1164
|
+
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1073
1165
|
}
|
|
1074
1166
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1075
1167
|
case 1:
|
|
1076
1168
|
_a.sent();
|
|
1077
1169
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1078
|
-
if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
|
|
1170
|
+
if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1079
1171
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
|
|
1080
1172
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1081
1173
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1156,70 +1248,70 @@ var Pool = /** @class */ (function () {
|
|
|
1156
1248
|
}); };
|
|
1157
1249
|
this.balances = function () {
|
|
1158
1250
|
var addresses = [];
|
|
1159
|
-
for (var
|
|
1160
|
-
addresses[
|
|
1251
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1252
|
+
addresses[_i] = arguments[_i];
|
|
1161
1253
|
}
|
|
1162
1254
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1163
|
-
return __generator(this, function (
|
|
1164
|
-
switch (
|
|
1255
|
+
return __generator(this, function (_a) {
|
|
1256
|
+
switch (_a.label) {
|
|
1165
1257
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
1166
|
-
case 1: return [2 /*return*/,
|
|
1258
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1167
1259
|
}
|
|
1168
1260
|
});
|
|
1169
1261
|
});
|
|
1170
1262
|
};
|
|
1171
1263
|
this.lpTokenBalances = function () {
|
|
1172
1264
|
var addresses = [];
|
|
1173
|
-
for (var
|
|
1174
|
-
addresses[
|
|
1265
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1266
|
+
addresses[_i] = arguments[_i];
|
|
1175
1267
|
}
|
|
1176
1268
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1177
|
-
return __generator(this, function (
|
|
1178
|
-
switch (
|
|
1269
|
+
return __generator(this, function (_a) {
|
|
1270
|
+
switch (_a.label) {
|
|
1179
1271
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
1180
|
-
case 1: return [2 /*return*/,
|
|
1272
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1181
1273
|
}
|
|
1182
1274
|
});
|
|
1183
1275
|
});
|
|
1184
1276
|
};
|
|
1185
1277
|
this.underlyingCoinBalances = function () {
|
|
1186
1278
|
var addresses = [];
|
|
1187
|
-
for (var
|
|
1188
|
-
addresses[
|
|
1279
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1280
|
+
addresses[_i] = arguments[_i];
|
|
1189
1281
|
}
|
|
1190
1282
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1191
|
-
return __generator(this, function (
|
|
1192
|
-
switch (
|
|
1283
|
+
return __generator(this, function (_a) {
|
|
1284
|
+
switch (_a.label) {
|
|
1193
1285
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoins, this.underlyingCoinAddresses], addresses, false))];
|
|
1194
|
-
case 1: return [2 /*return*/,
|
|
1286
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1195
1287
|
}
|
|
1196
1288
|
});
|
|
1197
1289
|
});
|
|
1198
1290
|
};
|
|
1199
1291
|
this.coinBalances = function () {
|
|
1200
1292
|
var addresses = [];
|
|
1201
|
-
for (var
|
|
1202
|
-
addresses[
|
|
1293
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1294
|
+
addresses[_i] = arguments[_i];
|
|
1203
1295
|
}
|
|
1204
1296
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1205
|
-
return __generator(this, function (
|
|
1206
|
-
switch (
|
|
1297
|
+
return __generator(this, function (_a) {
|
|
1298
|
+
switch (_a.label) {
|
|
1207
1299
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.coins, this.coinAddresses], addresses, false))];
|
|
1208
|
-
case 1: return [2 /*return*/,
|
|
1300
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1209
1301
|
}
|
|
1210
1302
|
});
|
|
1211
1303
|
});
|
|
1212
1304
|
};
|
|
1213
1305
|
this.allCoinBalances = function () {
|
|
1214
1306
|
var addresses = [];
|
|
1215
|
-
for (var
|
|
1216
|
-
addresses[
|
|
1307
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1308
|
+
addresses[_i] = arguments[_i];
|
|
1217
1309
|
}
|
|
1218
1310
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1219
|
-
return __generator(this, function (
|
|
1220
|
-
switch (
|
|
1311
|
+
return __generator(this, function (_a) {
|
|
1312
|
+
switch (_a.label) {
|
|
1221
1313
|
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
1222
|
-
case 1: return [2 /*return*/,
|
|
1314
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1223
1315
|
}
|
|
1224
1316
|
});
|
|
1225
1317
|
});
|
|
@@ -1240,34 +1332,37 @@ var Pool = /** @class */ (function () {
|
|
|
1240
1332
|
});
|
|
1241
1333
|
}); };
|
|
1242
1334
|
this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1243
|
-
var i;
|
|
1335
|
+
var contractAddress, i;
|
|
1244
1336
|
return __generator(this, function (_a) {
|
|
1245
1337
|
switch (_a.label) {
|
|
1246
1338
|
case 0:
|
|
1339
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1247
1340
|
i = this._getCoinIdx(inputCoin);
|
|
1248
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress,
|
|
1341
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1249
1342
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1250
1343
|
}
|
|
1251
1344
|
});
|
|
1252
1345
|
}); };
|
|
1253
1346
|
this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1254
|
-
var i;
|
|
1347
|
+
var contractAddress, i;
|
|
1255
1348
|
return __generator(this, function (_a) {
|
|
1256
1349
|
switch (_a.label) {
|
|
1257
1350
|
case 0:
|
|
1351
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1258
1352
|
i = this._getCoinIdx(inputCoin);
|
|
1259
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount],
|
|
1353
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1260
1354
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1261
1355
|
}
|
|
1262
1356
|
});
|
|
1263
1357
|
}); };
|
|
1264
1358
|
this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1265
|
-
var i;
|
|
1359
|
+
var contractAddress, i;
|
|
1266
1360
|
return __generator(this, function (_a) {
|
|
1267
1361
|
switch (_a.label) {
|
|
1268
1362
|
case 0:
|
|
1363
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1269
1364
|
i = this._getCoinIdx(inputCoin);
|
|
1270
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount],
|
|
1365
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1271
1366
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1272
1367
|
}
|
|
1273
1368
|
});
|
|
@@ -1275,13 +1370,11 @@ var Pool = /** @class */ (function () {
|
|
|
1275
1370
|
this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1276
1371
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1277
1372
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1278
|
-
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
|
|
1373
|
+
var contractAddress, i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value;
|
|
1279
1374
|
return __generator(this, function (_d) {
|
|
1280
1375
|
switch (_d.label) {
|
|
1281
1376
|
case 0:
|
|
1282
|
-
|
|
1283
|
-
throw Error("Use exchangeTricryptoEstimateGas method for tricrypto2 pool instead");
|
|
1284
|
-
}
|
|
1377
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1285
1378
|
i = this._getCoinIdx(inputCoin);
|
|
1286
1379
|
j = this._getCoinIdx(outputCoin);
|
|
1287
1380
|
_c = (_a = Object).values;
|
|
@@ -1289,9 +1382,9 @@ var Pool = /** @class */ (function () {
|
|
|
1289
1382
|
case 1:
|
|
1290
1383
|
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
1291
1384
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
1292
|
-
throw Error("Not enough "
|
|
1385
|
+
throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
|
|
1293
1386
|
}
|
|
1294
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress,
|
|
1387
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1295
1388
|
case 2:
|
|
1296
1389
|
if (!(_d.sent())) {
|
|
1297
1390
|
throw Error("Token allowance is needed to estimate gas");
|
|
@@ -1300,12 +1393,17 @@ var Pool = /** @class */ (function () {
|
|
|
1300
1393
|
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
1301
1394
|
case 3:
|
|
1302
1395
|
_expected = _d.sent();
|
|
1303
|
-
|
|
1304
|
-
|
|
1396
|
+
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
|
|
1397
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1398
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1399
|
+
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
1305
1400
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
1306
1401
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1307
|
-
|
|
1402
|
+
if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
|
|
1403
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1308
1404
|
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1405
|
+
case 5: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1406
|
+
case 6: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1309
1407
|
}
|
|
1310
1408
|
});
|
|
1311
1409
|
});
|
|
@@ -1313,158 +1411,43 @@ var Pool = /** @class */ (function () {
|
|
|
1313
1411
|
this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1314
1412
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1315
1413
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1316
|
-
var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit;
|
|
1414
|
+
var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, estimatedGas, gasLimit;
|
|
1317
1415
|
return __generator(this, function (_a) {
|
|
1318
1416
|
switch (_a.label) {
|
|
1319
1417
|
case 0:
|
|
1320
|
-
|
|
1321
|
-
throw Error("Use exchangeTricrypto method for tricrypto2 pool instead");
|
|
1322
|
-
}
|
|
1418
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1323
1419
|
i = this._getCoinIdx(inputCoin);
|
|
1324
1420
|
j = this._getCoinIdx(outputCoin);
|
|
1325
1421
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
1326
1422
|
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
1327
1423
|
case 1:
|
|
1328
1424
|
_expected = _a.sent();
|
|
1329
|
-
|
|
1330
|
-
|
|
1425
|
+
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
|
|
1426
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1427
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1428
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
|
|
1331
1429
|
case 2:
|
|
1332
1430
|
_a.sent();
|
|
1333
|
-
contract = curve_1.curve.contracts[
|
|
1431
|
+
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
1334
1432
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
1335
1433
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1336
1434
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1337
1435
|
case 3:
|
|
1338
1436
|
_a.sent();
|
|
1339
|
-
|
|
1437
|
+
if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
|
|
1438
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1340
1439
|
case 4:
|
|
1341
|
-
|
|
1342
|
-
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit:
|
|
1440
|
+
gasLimit_1 = (_a.sent()).mul(130).div(100);
|
|
1441
|
+
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
|
|
1343
1442
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
return __generator(this, function (_a) {
|
|
1353
|
-
switch (_a.label) {
|
|
1354
|
-
case 0:
|
|
1355
|
-
i = this._getCoinIdx(inputCoin);
|
|
1356
|
-
if (i === 2 && useEth)
|
|
1357
|
-
return [2 /*return*/, true];
|
|
1358
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1359
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1360
|
-
}
|
|
1361
|
-
});
|
|
1362
|
-
});
|
|
1363
|
-
};
|
|
1364
|
-
this.exchangeTricryptoApproveEstimateGas = function (inputCoin, amount, useEth) {
|
|
1365
|
-
if (useEth === void 0) { useEth = false; }
|
|
1366
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1367
|
-
var i;
|
|
1368
|
-
return __generator(this, function (_a) {
|
|
1369
|
-
switch (_a.label) {
|
|
1370
|
-
case 0:
|
|
1371
|
-
i = this._getCoinIdx(inputCoin);
|
|
1372
|
-
if (i === 2 && useEth)
|
|
1373
|
-
return [2 /*return*/, 0];
|
|
1374
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1375
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
});
|
|
1379
|
-
};
|
|
1380
|
-
this.exchangeTricryptoApprove = function (inputCoin, amount, useEth) {
|
|
1381
|
-
if (useEth === void 0) { useEth = false; }
|
|
1382
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1383
|
-
var i;
|
|
1384
|
-
return __generator(this, function (_a) {
|
|
1385
|
-
switch (_a.label) {
|
|
1386
|
-
case 0:
|
|
1387
|
-
i = this._getCoinIdx(inputCoin);
|
|
1388
|
-
if (i === 2 && useEth)
|
|
1389
|
-
return [2 /*return*/, []];
|
|
1390
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
|
|
1391
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
});
|
|
1395
|
-
};
|
|
1396
|
-
this.exchangeTricryptoEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage, useEth) {
|
|
1397
|
-
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1398
|
-
if (useEth === void 0) { useEth = false; }
|
|
1399
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1400
|
-
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
|
|
1401
|
-
return __generator(this, function (_d) {
|
|
1402
|
-
switch (_d.label) {
|
|
1403
|
-
case 0:
|
|
1404
|
-
if (this.name !== 'tricrypto2') {
|
|
1405
|
-
throw Error("This method is for only tricrypto2 pool");
|
|
1406
|
-
}
|
|
1407
|
-
i = this._getCoinIdx(inputCoin);
|
|
1408
|
-
j = this._getCoinIdx(outputCoin);
|
|
1409
|
-
_c = (_a = Object).values;
|
|
1410
|
-
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
1411
|
-
case 1:
|
|
1412
|
-
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
1413
|
-
if (Number(inputCoinBalance) < Number(amount)) {
|
|
1414
|
-
throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
|
|
1415
|
-
}
|
|
1416
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1417
|
-
case 2:
|
|
1418
|
-
if (!(_d.sent())) {
|
|
1419
|
-
throw Error("Token allowance is needed to estimate gas");
|
|
1420
|
-
}
|
|
1421
|
-
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
1422
|
-
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
1423
|
-
case 3:
|
|
1424
|
-
_expected = _d.sent();
|
|
1425
|
-
_minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
|
|
1426
|
-
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1427
|
-
value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1428
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1429
|
-
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
});
|
|
1433
|
-
};
|
|
1434
|
-
this.exchangeTricrypto = function (inputCoin, outputCoin, amount, maxSlippage, useEth) {
|
|
1435
|
-
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1436
|
-
if (useEth === void 0) { useEth = false; }
|
|
1437
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1438
|
-
var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit;
|
|
1439
|
-
return __generator(this, function (_a) {
|
|
1440
|
-
switch (_a.label) {
|
|
1441
|
-
case 0:
|
|
1442
|
-
if (this.name !== 'tricrypto2') {
|
|
1443
|
-
throw Error("This method is for only tricrypto2 pool");
|
|
1444
|
-
}
|
|
1445
|
-
i = this._getCoinIdx(inputCoin);
|
|
1446
|
-
j = this._getCoinIdx(outputCoin);
|
|
1447
|
-
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
1448
|
-
return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
|
|
1449
|
-
case 1:
|
|
1450
|
-
_expected = _a.sent();
|
|
1451
|
-
_minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
|
|
1452
|
-
if (!(i !== 2 || !useEth)) return [3 /*break*/, 3];
|
|
1453
|
-
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
|
|
1454
|
-
case 2:
|
|
1455
|
-
_a.sent();
|
|
1456
|
-
_a.label = 3;
|
|
1457
|
-
case 3:
|
|
1458
|
-
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1459
|
-
value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1460
|
-
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1461
|
-
case 4:
|
|
1462
|
-
_a.sent();
|
|
1463
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1464
|
-
case 5:
|
|
1465
|
-
gasLimit = (_a.sent()).mul(130).div(100);
|
|
1466
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
1467
|
-
case 6: return [2 /*return*/, (_a.sent()).hash];
|
|
1443
|
+
case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1444
|
+
case 7:
|
|
1445
|
+
estimatedGas = _a.sent();
|
|
1446
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
1447
|
+
estimatedGas.mul(160).div(100) :
|
|
1448
|
+
estimatedGas.mul(130).div(100);
|
|
1449
|
+
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
1450
|
+
case 8: return [2 /*return*/, (_a.sent()).hash];
|
|
1468
1451
|
}
|
|
1469
1452
|
});
|
|
1470
1453
|
});
|
|
@@ -1474,6 +1457,9 @@ var Pool = /** @class */ (function () {
|
|
|
1474
1457
|
return __generator(this, function (_a) {
|
|
1475
1458
|
switch (_a.label) {
|
|
1476
1459
|
case 0:
|
|
1460
|
+
if (this.isFake) {
|
|
1461
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1462
|
+
}
|
|
1477
1463
|
i = this._getCoinIdx(inputCoin, false);
|
|
1478
1464
|
j = this._getCoinIdx(outputCoin, false);
|
|
1479
1465
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
|
|
@@ -1489,6 +1475,9 @@ var Pool = /** @class */ (function () {
|
|
|
1489
1475
|
return __generator(this, function (_a) {
|
|
1490
1476
|
switch (_a.label) {
|
|
1491
1477
|
case 0:
|
|
1478
|
+
if (this.isFake) {
|
|
1479
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1480
|
+
}
|
|
1492
1481
|
i = this._getCoinIdx(inputCoin, false);
|
|
1493
1482
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1494
1483
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1500,6 +1489,9 @@ var Pool = /** @class */ (function () {
|
|
|
1500
1489
|
return __generator(this, function (_a) {
|
|
1501
1490
|
switch (_a.label) {
|
|
1502
1491
|
case 0:
|
|
1492
|
+
if (this.isFake) {
|
|
1493
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1494
|
+
}
|
|
1503
1495
|
i = this._getCoinIdx(inputCoin, false);
|
|
1504
1496
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1505
1497
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1511,6 +1503,9 @@ var Pool = /** @class */ (function () {
|
|
|
1511
1503
|
return __generator(this, function (_a) {
|
|
1512
1504
|
switch (_a.label) {
|
|
1513
1505
|
case 0:
|
|
1506
|
+
if (this.isFake) {
|
|
1507
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1508
|
+
}
|
|
1514
1509
|
i = this._getCoinIdx(inputCoin, false);
|
|
1515
1510
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.coinAddresses[i]], [amount], this.swap)];
|
|
1516
1511
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1520,10 +1515,13 @@ var Pool = /** @class */ (function () {
|
|
|
1520
1515
|
this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1521
1516
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1522
1517
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1523
|
-
var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
|
|
1518
|
+
var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value;
|
|
1524
1519
|
return __generator(this, function (_d) {
|
|
1525
1520
|
switch (_d.label) {
|
|
1526
1521
|
case 0:
|
|
1522
|
+
if (this.isFake) {
|
|
1523
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1524
|
+
}
|
|
1527
1525
|
i = this._getCoinIdx(inputCoin, false);
|
|
1528
1526
|
j = this._getCoinIdx(outputCoin, false);
|
|
1529
1527
|
_c = (_a = Object).values;
|
|
@@ -1531,7 +1529,7 @@ var Pool = /** @class */ (function () {
|
|
|
1531
1529
|
case 1:
|
|
1532
1530
|
inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
|
|
1533
1531
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
1534
|
-
throw Error("Not enough "
|
|
1532
|
+
throw Error("Not enough ".concat(this.coins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
|
|
1535
1533
|
}
|
|
1536
1534
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
|
|
1537
1535
|
case 2:
|
|
@@ -1542,11 +1540,16 @@ var Pool = /** @class */ (function () {
|
|
|
1542
1540
|
return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
|
|
1543
1541
|
case 3:
|
|
1544
1542
|
_expected = _d.sent();
|
|
1545
|
-
|
|
1543
|
+
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
|
|
1544
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1545
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1546
1546
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1547
1547
|
value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
1548
|
-
|
|
1548
|
+
if (!(this.name === 'tricrypto2')) return [3 /*break*/, 5];
|
|
1549
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1549
1550
|
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1551
|
+
case 5: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1552
|
+
case 6: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
1550
1553
|
}
|
|
1551
1554
|
});
|
|
1552
1555
|
});
|
|
@@ -1554,17 +1557,22 @@ var Pool = /** @class */ (function () {
|
|
|
1554
1557
|
this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
1555
1558
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
1556
1559
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1557
|
-
var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit;
|
|
1560
|
+
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, estimatedGas, gasLimit;
|
|
1558
1561
|
return __generator(this, function (_a) {
|
|
1559
1562
|
switch (_a.label) {
|
|
1560
1563
|
case 0:
|
|
1564
|
+
if (this.isFake) {
|
|
1565
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1566
|
+
}
|
|
1561
1567
|
i = this._getCoinIdx(inputCoin, false);
|
|
1562
1568
|
j = this._getCoinIdx(outputCoin, false);
|
|
1563
1569
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
|
|
1564
1570
|
return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
|
|
1565
1571
|
case 1:
|
|
1566
1572
|
_expected = _a.sent();
|
|
1567
|
-
|
|
1573
|
+
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
|
|
1574
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
1575
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
1568
1576
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.coinAddresses[i]], [_amount], this.swap)];
|
|
1569
1577
|
case 2:
|
|
1570
1578
|
_a.sent();
|
|
@@ -1573,24 +1581,33 @@ var Pool = /** @class */ (function () {
|
|
|
1573
1581
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1574
1582
|
case 3:
|
|
1575
1583
|
_a.sent();
|
|
1576
|
-
|
|
1584
|
+
if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
|
|
1585
|
+
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1577
1586
|
case 4:
|
|
1578
|
-
|
|
1579
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit:
|
|
1587
|
+
gasLimit_2 = (_a.sent()).mul(130).div(100);
|
|
1588
|
+
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
|
|
1580
1589
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
1590
|
+
case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
1591
|
+
case 7:
|
|
1592
|
+
estimatedGas = _a.sent();
|
|
1593
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
1594
|
+
estimatedGas.mul(140).div(100) :
|
|
1595
|
+
estimatedGas.mul(130).div(100);
|
|
1596
|
+
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
1597
|
+
case 8: return [2 /*return*/, (_a.sent()).hash];
|
|
1581
1598
|
}
|
|
1582
1599
|
});
|
|
1583
1600
|
});
|
|
1584
1601
|
};
|
|
1585
1602
|
this.gaugeMaxBoostedDeposit = function () {
|
|
1586
1603
|
var addresses = [];
|
|
1587
|
-
for (var
|
|
1588
|
-
addresses[
|
|
1604
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1605
|
+
addresses[_i] = arguments[_i];
|
|
1589
1606
|
}
|
|
1590
1607
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1591
|
-
var votingEscrowContract, gaugeContract, contractCalls,
|
|
1592
|
-
return __generator(this, function (
|
|
1593
|
-
switch (
|
|
1608
|
+
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _a, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _c, _d, entry;
|
|
1609
|
+
return __generator(this, function (_e) {
|
|
1610
|
+
switch (_e.label) {
|
|
1594
1611
|
case 0:
|
|
1595
1612
|
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
1596
1613
|
addresses = addresses[0];
|
|
@@ -1602,15 +1619,16 @@ var Pool = /** @class */ (function () {
|
|
|
1602
1619
|
});
|
|
1603
1620
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1604
1621
|
case 1:
|
|
1605
|
-
|
|
1606
|
-
|
|
1622
|
+
_response = _e.sent();
|
|
1623
|
+
responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1624
|
+
_a = responseBN.splice(0, 2), veTotalSupplyBN = _a[0], gaugeTotalSupplyBN = _a[1];
|
|
1607
1625
|
resultBN = {};
|
|
1608
1626
|
addresses.forEach(function (acct, i) {
|
|
1609
|
-
resultBN[acct] =
|
|
1627
|
+
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
1610
1628
|
});
|
|
1611
1629
|
result = {};
|
|
1612
|
-
for (
|
|
1613
|
-
entry =
|
|
1630
|
+
for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
|
|
1631
|
+
entry = _d[_c];
|
|
1614
1632
|
result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
1615
1633
|
}
|
|
1616
1634
|
return [2 /*return*/, result];
|
|
@@ -1620,13 +1638,13 @@ var Pool = /** @class */ (function () {
|
|
|
1620
1638
|
};
|
|
1621
1639
|
this.gaugeOptimalDeposits = function () {
|
|
1622
1640
|
var accounts = [];
|
|
1623
|
-
for (var
|
|
1624
|
-
accounts[
|
|
1641
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1642
|
+
accounts[_i] = arguments[_i];
|
|
1625
1643
|
}
|
|
1626
1644
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1627
|
-
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response,
|
|
1628
|
-
return __generator(this, function (
|
|
1629
|
-
switch (
|
|
1645
|
+
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;
|
|
1646
|
+
return __generator(this, function (_j) {
|
|
1647
|
+
switch (_j.label) {
|
|
1630
1648
|
case 0:
|
|
1631
1649
|
if (accounts.length == 1 && Array.isArray(accounts[0]))
|
|
1632
1650
|
accounts = accounts[0];
|
|
@@ -1639,12 +1657,13 @@ var Pool = /** @class */ (function () {
|
|
|
1639
1657
|
});
|
|
1640
1658
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
1641
1659
|
case 1:
|
|
1642
|
-
|
|
1643
|
-
|
|
1660
|
+
_response = _j.sent();
|
|
1661
|
+
response = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
1662
|
+
_a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
|
|
1644
1663
|
votingPower = {};
|
|
1645
1664
|
totalBalance = (0, utils_1.BN)(0);
|
|
1646
|
-
for (
|
|
1647
|
-
acct = accounts_1[
|
|
1665
|
+
for (_c = 0, accounts_1 = accounts; _c < accounts_1.length; _c++) {
|
|
1666
|
+
acct = accounts_1[_c];
|
|
1648
1667
|
votingPower[acct] = response[0];
|
|
1649
1668
|
totalBalance = totalBalance.plus(response[1]).plus(response[2]);
|
|
1650
1669
|
response.splice(0, 3);
|
|
@@ -1652,8 +1671,8 @@ var Pool = /** @class */ (function () {
|
|
|
1652
1671
|
totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
|
|
1653
1672
|
optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
|
|
1654
1673
|
if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
|
|
1655
|
-
for (
|
|
1656
|
-
acct = accounts_2[
|
|
1674
|
+
for (_d = 0, accounts_2 = accounts; _d < accounts_2.length; _d++) {
|
|
1675
|
+
acct = accounts_2[_d];
|
|
1657
1676
|
amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
|
|
1658
1677
|
gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
|
|
1659
1678
|
optimalBN[acct] = amount;
|
|
@@ -1665,16 +1684,16 @@ var Pool = /** @class */ (function () {
|
|
|
1665
1684
|
}
|
|
1666
1685
|
else {
|
|
1667
1686
|
if (totalPower.lt(0)) {
|
|
1668
|
-
for (
|
|
1669
|
-
acct = accounts_3[
|
|
1687
|
+
for (_e = 0, accounts_3 = accounts; _e < accounts_3.length; _e++) {
|
|
1688
|
+
acct = accounts_3[_e];
|
|
1670
1689
|
optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
|
|
1671
1690
|
}
|
|
1672
1691
|
}
|
|
1673
1692
|
optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
|
|
1674
1693
|
}
|
|
1675
1694
|
optimal = {};
|
|
1676
|
-
for (
|
|
1677
|
-
entry = _h[
|
|
1695
|
+
for (_f = 0, _h = Object.entries(optimalBN); _f < _h.length; _f++) {
|
|
1696
|
+
entry = _h[_f];
|
|
1678
1697
|
optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
1679
1698
|
}
|
|
1680
1699
|
return [2 /*return*/, optimal];
|
|
@@ -1737,7 +1756,7 @@ var Pool = /** @class */ (function () {
|
|
|
1737
1756
|
throw Error('Index must be >= 0');
|
|
1738
1757
|
}
|
|
1739
1758
|
if (idx_1 > coins_N - 1) {
|
|
1740
|
-
throw Error("Index must be < "
|
|
1759
|
+
throw Error("Index must be < ".concat(coins_N));
|
|
1741
1760
|
}
|
|
1742
1761
|
return idx_1;
|
|
1743
1762
|
}
|
|
@@ -1747,7 +1766,7 @@ var Pool = /** @class */ (function () {
|
|
|
1747
1766
|
_this.coinAddresses.map(function (c) { return c.toLowerCase(); });
|
|
1748
1767
|
var idx = lowerCaseCoinAddresses.indexOf(coinAddress.toLowerCase());
|
|
1749
1768
|
if (idx === -1) {
|
|
1750
|
-
throw Error("There is no "
|
|
1769
|
+
throw Error("There is no ".concat(coin, " in ").concat(_this.name, " pool"));
|
|
1751
1770
|
}
|
|
1752
1771
|
return idx;
|
|
1753
1772
|
};
|
|
@@ -1792,13 +1811,13 @@ var Pool = /** @class */ (function () {
|
|
|
1792
1811
|
}); };
|
|
1793
1812
|
this._balances = function (rawCoinNames, rawCoinAddresses) {
|
|
1794
1813
|
var addresses = [];
|
|
1795
|
-
for (var
|
|
1796
|
-
addresses[
|
|
1814
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1815
|
+
addresses[_i - 2] = arguments[_i];
|
|
1797
1816
|
}
|
|
1798
1817
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1799
|
-
var coinNames, coinAddresses, i, rawBalances, balances,
|
|
1800
|
-
return __generator(this, function (
|
|
1801
|
-
switch (
|
|
1818
|
+
var coinNames, coinAddresses, i, rawBalances, balances, _a, addresses_1, address, _c, coinNames_1, coinName;
|
|
1819
|
+
return __generator(this, function (_d) {
|
|
1820
|
+
switch (_d.label) {
|
|
1802
1821
|
case 0:
|
|
1803
1822
|
coinNames = [];
|
|
1804
1823
|
coinAddresses = [];
|
|
@@ -1809,20 +1828,16 @@ var Pool = /** @class */ (function () {
|
|
|
1809
1828
|
coinAddresses.push(rawCoinAddresses[i]);
|
|
1810
1829
|
}
|
|
1811
1830
|
}
|
|
1812
|
-
if (this.name === 'tricrypto2') {
|
|
1813
|
-
coinNames.push('ETH');
|
|
1814
|
-
coinAddresses.push('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE');
|
|
1815
|
-
}
|
|
1816
1831
|
addresses = (0, utils_1._prepareAddresses)(addresses);
|
|
1817
1832
|
return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
|
|
1818
1833
|
case 1:
|
|
1819
|
-
rawBalances =
|
|
1834
|
+
rawBalances = _d.sent();
|
|
1820
1835
|
balances = {};
|
|
1821
|
-
for (
|
|
1822
|
-
address = addresses_1[
|
|
1836
|
+
for (_a = 0, addresses_1 = addresses; _a < addresses_1.length; _a++) {
|
|
1837
|
+
address = addresses_1[_a];
|
|
1823
1838
|
balances[address] = {};
|
|
1824
|
-
for (
|
|
1825
|
-
coinName = coinNames_1[
|
|
1839
|
+
for (_c = 0, coinNames_1 = coinNames; _c < coinNames_1.length; _c++) {
|
|
1840
|
+
coinName = coinNames_1[_c];
|
|
1826
1841
|
balances[address][coinName] = rawBalances[address].shift();
|
|
1827
1842
|
}
|
|
1828
1843
|
}
|
|
@@ -1926,10 +1941,16 @@ var Pool = /** @class */ (function () {
|
|
|
1926
1941
|
this._calcLpTokenAmount = function (_amounts, isDeposit) {
|
|
1927
1942
|
if (isDeposit === void 0) { isDeposit = true; }
|
|
1928
1943
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1944
|
+
var contract;
|
|
1929
1945
|
return __generator(this, function (_a) {
|
|
1930
1946
|
switch (_a.label) {
|
|
1931
|
-
case 0:
|
|
1947
|
+
case 0:
|
|
1948
|
+
contract = curve_1.curve.contracts[this.swap].contract;
|
|
1949
|
+
if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
|
|
1950
|
+
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1932
1951
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1952
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1953
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
1933
1954
|
}
|
|
1934
1955
|
});
|
|
1935
1956
|
});
|
|
@@ -1945,8 +1966,12 @@ var Pool = /** @class */ (function () {
|
|
|
1945
1966
|
if (!this.isFactory) return [3 /*break*/, 2];
|
|
1946
1967
|
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1947
1968
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1948
|
-
case 2:
|
|
1969
|
+
case 2:
|
|
1970
|
+
if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
|
|
1971
|
+
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1949
1972
|
case 3: return [2 /*return*/, _a.sent()];
|
|
1973
|
+
case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1974
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
1950
1975
|
}
|
|
1951
1976
|
});
|
|
1952
1977
|
});
|
|
@@ -1963,7 +1988,7 @@ var Pool = /** @class */ (function () {
|
|
|
1963
1988
|
_wrapped_amounts = _underlying_amounts.map(function (amount, i) {
|
|
1964
1989
|
return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
|
|
1965
1990
|
});
|
|
1966
|
-
return [4 /*yield*/,
|
|
1991
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_wrapped_amounts, isDeposit)];
|
|
1967
1992
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1968
1993
|
}
|
|
1969
1994
|
});
|
|
@@ -2034,7 +2059,7 @@ var Pool = /** @class */ (function () {
|
|
|
2034
2059
|
this._addLiquidityMetaZap = function (_amounts, estimateGas) {
|
|
2035
2060
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
2036
2061
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2037
|
-
var _minMintAmount, ethIndex, value, contract, gas_1,
|
|
2062
|
+
var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_3, gas, gasLimit;
|
|
2038
2063
|
return __generator(this, function (_a) {
|
|
2039
2064
|
switch (_a.label) {
|
|
2040
2065
|
case 0:
|
|
@@ -2056,8 +2081,8 @@ var Pool = /** @class */ (function () {
|
|
|
2056
2081
|
if (estimateGas) {
|
|
2057
2082
|
return [2 /*return*/, gas_1.toNumber()];
|
|
2058
2083
|
}
|
|
2059
|
-
|
|
2060
|
-
return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
2084
|
+
gasLimit_3 = gas_1.mul(130).div(100);
|
|
2085
|
+
return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3, value: value }))];
|
|
2061
2086
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2062
2087
|
case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2063
2088
|
case 7:
|
|
@@ -2100,7 +2125,7 @@ var Pool = /** @class */ (function () {
|
|
|
2100
2125
|
_minMintAmount = _a;
|
|
2101
2126
|
_minMintAmount = _minMintAmount.mul(99).div(100);
|
|
2102
2127
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
2103
|
-
ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
|
|
2128
|
+
ethIndex = (0, utils_1.getEthIndex)(useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses);
|
|
2104
2129
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
2105
2130
|
return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2106
2131
|
case 7:
|
|
@@ -2116,21 +2141,21 @@ var Pool = /** @class */ (function () {
|
|
|
2116
2141
|
});
|
|
2117
2142
|
};
|
|
2118
2143
|
this._calcExpectedAmounts = function (_lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
2119
|
-
var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN,
|
|
2144
|
+
var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _i, coinBalancesBN_1, coinBalance;
|
|
2120
2145
|
var _this = this;
|
|
2121
|
-
return __generator(this, function (
|
|
2122
|
-
switch (
|
|
2146
|
+
return __generator(this, function (_c) {
|
|
2147
|
+
switch (_c.label) {
|
|
2123
2148
|
case 0:
|
|
2124
2149
|
coinBalancesBN = [];
|
|
2125
2150
|
i = 0;
|
|
2126
|
-
|
|
2151
|
+
_c.label = 1;
|
|
2127
2152
|
case 1:
|
|
2128
2153
|
if (!(i < this.coinAddresses.length)) return [3 /*break*/, 4];
|
|
2129
2154
|
return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.constantOptions)];
|
|
2130
2155
|
case 2:
|
|
2131
|
-
_balance =
|
|
2156
|
+
_balance = _c.sent();
|
|
2132
2157
|
coinBalancesBN.push((0, utils_1.toBN)(_balance, this.decimals[i]));
|
|
2133
|
-
|
|
2158
|
+
_c.label = 3;
|
|
2134
2159
|
case 3:
|
|
2135
2160
|
i++;
|
|
2136
2161
|
return [3 /*break*/, 1];
|
|
@@ -2138,10 +2163,10 @@ var Pool = /** @class */ (function () {
|
|
|
2138
2163
|
_a = utils_1.toBN;
|
|
2139
2164
|
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
|
|
2140
2165
|
case 5:
|
|
2141
|
-
totalSupplyBN = _a.apply(void 0, [
|
|
2166
|
+
totalSupplyBN = _a.apply(void 0, [_c.sent()]);
|
|
2142
2167
|
expectedAmountsBN = [];
|
|
2143
|
-
for (
|
|
2144
|
-
coinBalance = coinBalancesBN_1[
|
|
2168
|
+
for (_i = 0, coinBalancesBN_1 = coinBalancesBN; _i < coinBalancesBN_1.length; _i++) {
|
|
2169
|
+
coinBalance = coinBalancesBN_1[_i];
|
|
2145
2170
|
expectedAmountsBN.push(coinBalance.times((0, utils_1.toBN)(_lpTokenAmount)).div(totalSupplyBN));
|
|
2146
2171
|
}
|
|
2147
2172
|
return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return (0, utils_1.fromBN)(amount, _this.decimals[i]); })];
|
|
@@ -2185,13 +2210,15 @@ var Pool = /** @class */ (function () {
|
|
|
2185
2210
|
case 0: return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
|
|
2186
2211
|
case 1:
|
|
2187
2212
|
_expectedWrappedAmounts = _a.sent();
|
|
2188
|
-
|
|
2213
|
+
if (this.name !== 'atricrypto3') {
|
|
2214
|
+
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
2215
|
+
}
|
|
2189
2216
|
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
2190
2217
|
basePool = new Pool(this.basePool);
|
|
2191
2218
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_expectedMetaCoinAmount)];
|
|
2192
2219
|
case 2:
|
|
2193
2220
|
_basePoolExpectedAmounts = _a.sent();
|
|
2194
|
-
return [2 /*return*/, __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true)];
|
|
2221
|
+
return [2 /*return*/, this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
|
|
2195
2222
|
}
|
|
2196
2223
|
});
|
|
2197
2224
|
}); };
|
|
@@ -2258,7 +2285,7 @@ var Pool = /** @class */ (function () {
|
|
|
2258
2285
|
this._removeLiquidityMetaZap = function (_lpTokenAmount, estimateGas) {
|
|
2259
2286
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
2260
2287
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2261
|
-
var _minAmounts, contract, gas_2,
|
|
2288
|
+
var _minAmounts, contract, gas_2, gasLimit_4, gas, gasLimit;
|
|
2262
2289
|
return __generator(this, function (_a) {
|
|
2263
2290
|
switch (_a.label) {
|
|
2264
2291
|
case 0:
|
|
@@ -2278,8 +2305,8 @@ var Pool = /** @class */ (function () {
|
|
|
2278
2305
|
if (estimateGas) {
|
|
2279
2306
|
return [2 /*return*/, gas_2.toNumber()];
|
|
2280
2307
|
}
|
|
2281
|
-
|
|
2282
|
-
return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
2308
|
+
gasLimit_4 = gas_2.mul(130).div(100);
|
|
2309
|
+
return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
|
|
2283
2310
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2284
2311
|
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
2285
2312
|
case 7:
|
|
@@ -2382,7 +2409,7 @@ var Pool = /** @class */ (function () {
|
|
|
2382
2409
|
this._removeLiquidityImbalanceMetaZap = function (_amounts, estimateGas) {
|
|
2383
2410
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
2384
2411
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2385
|
-
var _maxBurnAmount, contract, gas_3,
|
|
2412
|
+
var _maxBurnAmount, contract, gas_3, gasLimit_5, gas, gasLimit;
|
|
2386
2413
|
return __generator(this, function (_a) {
|
|
2387
2414
|
switch (_a.label) {
|
|
2388
2415
|
case 0: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
|
|
@@ -2402,8 +2429,8 @@ var Pool = /** @class */ (function () {
|
|
|
2402
2429
|
if (estimateGas) {
|
|
2403
2430
|
return [2 /*return*/, gas_3.toNumber()];
|
|
2404
2431
|
}
|
|
2405
|
-
|
|
2406
|
-
return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
2432
|
+
gasLimit_5 = gas_3.mul(130).div(100);
|
|
2433
|
+
return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
|
|
2407
2434
|
case 5: return [2 /*return*/, (_a.sent())];
|
|
2408
2435
|
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
2409
2436
|
case 7:
|
|
@@ -2445,7 +2472,9 @@ var Pool = /** @class */ (function () {
|
|
|
2445
2472
|
if (estimateGas) {
|
|
2446
2473
|
return [2 /*return*/, gas.toNumber()];
|
|
2447
2474
|
}
|
|
2448
|
-
gasLimit =
|
|
2475
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
2476
|
+
gas.mul(140).div(100) :
|
|
2477
|
+
gas.mul(130).div(100);
|
|
2449
2478
|
return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
2450
2479
|
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
2451
2480
|
}
|
|
@@ -2511,38 +2540,48 @@ var Pool = /** @class */ (function () {
|
|
|
2511
2540
|
this._removeLiquidityOneCoinZap = function (_lpTokenAmount, i, estimateGas) {
|
|
2512
2541
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
2513
2542
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2514
|
-
var _minAmount, contract, gas_4,
|
|
2515
|
-
return __generator(this, function (
|
|
2516
|
-
switch (
|
|
2543
|
+
var _minAmount, _a, contract, gas_4, gasLimit_6, gas, gasLimit;
|
|
2544
|
+
return __generator(this, function (_c) {
|
|
2545
|
+
switch (_c.label) {
|
|
2517
2546
|
case 0:
|
|
2518
2547
|
if (!!estimateGas) return [3 /*break*/, 2];
|
|
2519
2548
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
|
|
2520
2549
|
case 1:
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
case 2:
|
|
2550
|
+
_c.sent();
|
|
2551
|
+
_c.label = 2;
|
|
2552
|
+
case 2:
|
|
2553
|
+
if (!(this.name === 'tricrypto2')) return [3 /*break*/, 4];
|
|
2554
|
+
return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
|
|
2524
2555
|
case 3:
|
|
2525
|
-
|
|
2556
|
+
_a = _c.sent();
|
|
2557
|
+
return [3 /*break*/, 6];
|
|
2558
|
+
case 4: return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
|
|
2559
|
+
case 5:
|
|
2560
|
+
_a = _c.sent();
|
|
2561
|
+
_c.label = 6;
|
|
2562
|
+
case 6:
|
|
2563
|
+
_minAmount = _a;
|
|
2564
|
+
_minAmount = _minAmount.mul(99).div(100);
|
|
2526
2565
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
2527
|
-
if (!this.isFactory) return [3 /*break*/,
|
|
2566
|
+
if (!this.isFactory) return [3 /*break*/, 9];
|
|
2528
2567
|
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
2529
|
-
case
|
|
2530
|
-
gas_4 =
|
|
2568
|
+
case 7:
|
|
2569
|
+
gas_4 = _c.sent();
|
|
2531
2570
|
if (estimateGas) {
|
|
2532
2571
|
return [2 /*return*/, gas_4.toNumber()];
|
|
2533
2572
|
}
|
|
2534
|
-
|
|
2535
|
-
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
2536
|
-
case
|
|
2537
|
-
case
|
|
2538
|
-
case
|
|
2539
|
-
gas =
|
|
2573
|
+
gasLimit_6 = gas_4.mul(130).div(100);
|
|
2574
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
|
|
2575
|
+
case 8: return [2 /*return*/, (_c.sent()).hash];
|
|
2576
|
+
case 9: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
2577
|
+
case 10:
|
|
2578
|
+
gas = _c.sent();
|
|
2540
2579
|
if (estimateGas) {
|
|
2541
2580
|
return [2 /*return*/, gas.toNumber()];
|
|
2542
2581
|
}
|
|
2543
2582
|
gasLimit = gas.mul(130).div(100);
|
|
2544
2583
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
2545
|
-
case
|
|
2584
|
+
case 11: return [2 /*return*/, (_c.sent()).hash];
|
|
2546
2585
|
}
|
|
2547
2586
|
});
|
|
2548
2587
|
});
|
|
@@ -2574,7 +2613,9 @@ var Pool = /** @class */ (function () {
|
|
|
2574
2613
|
if (estimateGas) {
|
|
2575
2614
|
return [2 /*return*/, gas.toNumber()];
|
|
2576
2615
|
}
|
|
2577
|
-
gasLimit =
|
|
2616
|
+
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
2617
|
+
gas.mul(160).div(100) :
|
|
2618
|
+
gas.mul(130).div(100);
|
|
2578
2619
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
2579
2620
|
case 6: return [2 /*return*/, (_c.sent()).hash];
|
|
2580
2621
|
}
|
|
@@ -2582,11 +2623,12 @@ var Pool = /** @class */ (function () {
|
|
|
2582
2623
|
});
|
|
2583
2624
|
};
|
|
2584
2625
|
this._getExchangeOutput = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
|
|
2585
|
-
var contract;
|
|
2626
|
+
var contractAddress, contract;
|
|
2586
2627
|
return __generator(this, function (_a) {
|
|
2587
2628
|
switch (_a.label) {
|
|
2588
2629
|
case 0:
|
|
2589
|
-
|
|
2630
|
+
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2631
|
+
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2590
2632
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2591
2633
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2592
2634
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2603,7 +2645,7 @@ var Pool = /** @class */ (function () {
|
|
|
2603
2645
|
}
|
|
2604
2646
|
});
|
|
2605
2647
|
}); };
|
|
2606
|
-
var poolData =
|
|
2648
|
+
var poolData = curve_1.POOLS_DATA[name];
|
|
2607
2649
|
this.name = name;
|
|
2608
2650
|
this.swap = poolData.swap_address;
|
|
2609
2651
|
this.zap = poolData.deposit_address || null;
|
|
@@ -2617,8 +2659,10 @@ var Pool = /** @class */ (function () {
|
|
|
2617
2659
|
this.decimals = poolData.decimals;
|
|
2618
2660
|
this.useLending = poolData.use_lending;
|
|
2619
2661
|
this.isMeta = poolData.is_meta || false;
|
|
2620
|
-
this.
|
|
2662
|
+
this.isFake = poolData.is_fake || false;
|
|
2663
|
+
this.isCrypto = poolData.is_crypto || false;
|
|
2621
2664
|
this.isFactory = poolData.is_factory || false;
|
|
2665
|
+
this.basePool = poolData.base_pool || '';
|
|
2622
2666
|
this.estimateGas = {
|
|
2623
2667
|
addLiquidityApprove: this.addLiquidityApproveEstimateGas,
|
|
2624
2668
|
addLiquidity: this.addLiquidityEstimateGas,
|
|
@@ -2638,12 +2682,10 @@ var Pool = /** @class */ (function () {
|
|
|
2638
2682
|
removeLiquidityOneCoinWrapped: this.removeLiquidityOneCoinWrappedEstimateGas,
|
|
2639
2683
|
exchangeApprove: this.exchangeApproveEstimateGas,
|
|
2640
2684
|
exchange: this.exchangeEstimateGas,
|
|
2641
|
-
exchangeTricryptoApprove: this.exchangeTricryptoApproveEstimateGas,
|
|
2642
|
-
exchangeTricrypto: this.exchangeTricryptoEstimateGas,
|
|
2643
2685
|
exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
|
|
2644
2686
|
exchangeWrapped: this.exchangeWrappedEstimateGas,
|
|
2645
2687
|
};
|
|
2646
|
-
if (this.isMeta) {
|
|
2688
|
+
if (this.isMeta && !this.isFake) {
|
|
2647
2689
|
var metaCoins = poolData.meta_coin_addresses;
|
|
2648
2690
|
var metaCoinDecimals = poolData.meta_coin_decimals;
|
|
2649
2691
|
this.underlyingCoinAddresses = __spreadArray([this.underlyingCoinAddresses[0]], metaCoins, true);
|
|
@@ -2654,71 +2696,138 @@ var Pool = /** @class */ (function () {
|
|
|
2654
2696
|
}());
|
|
2655
2697
|
exports.Pool = Pool;
|
|
2656
2698
|
// --------- Exchange Using All Pools ---------
|
|
2657
|
-
var
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2699
|
+
var _estimatedGasForPoolsCache = {};
|
|
2700
|
+
var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2701
|
+
var registryExchangeContract, sortedCoins, gasPromises, _i, poolAddresses_1, poolAddress, key, gasPromise, _gasAmounts_1, err_1;
|
|
2702
|
+
var _a;
|
|
2703
|
+
return __generator(this, function (_c) {
|
|
2704
|
+
switch (_c.label) {
|
|
2661
2705
|
case 0:
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2706
|
+
registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
2707
|
+
sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
|
|
2708
|
+
gasPromises = [];
|
|
2709
|
+
for (_i = 0, poolAddresses_1 = poolAddresses; _i < poolAddresses_1.length; _i++) {
|
|
2710
|
+
poolAddress = poolAddresses_1[_i];
|
|
2711
|
+
key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
2712
|
+
gasPromise = void 0;
|
|
2713
|
+
if ((((_a = _estimatedGasForPoolsCache[key]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 3600000 < Date.now()) {
|
|
2714
|
+
gasPromise = registryExchangeContract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, 0, curve_1.curve.constantOptions);
|
|
2715
|
+
}
|
|
2716
|
+
else {
|
|
2717
|
+
gasPromise = Promise.resolve(_estimatedGasForPoolsCache[key].gas);
|
|
2718
|
+
}
|
|
2719
|
+
gasPromises.push(gasPromise);
|
|
2720
|
+
}
|
|
2721
|
+
_c.label = 1;
|
|
2666
2722
|
case 1:
|
|
2667
|
-
|
|
2668
|
-
return [
|
|
2723
|
+
_c.trys.push([1, 3, , 4]);
|
|
2724
|
+
return [4 /*yield*/, Promise.all(gasPromises)];
|
|
2669
2725
|
case 2:
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2726
|
+
_gasAmounts_1 = _c.sent();
|
|
2727
|
+
poolAddresses.forEach(function (poolAddress, i) {
|
|
2728
|
+
var key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
2729
|
+
_estimatedGasForPoolsCache[key] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
|
|
2730
|
+
});
|
|
2731
|
+
return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(ethers_1.ethers.utils.formatUnits(_g, 0)); })];
|
|
2673
2732
|
case 3:
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
2678
|
-
case 4:
|
|
2679
|
-
_c = _d.sent(), poolAddress = _c[0], _output = _c[1];
|
|
2680
|
-
return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
|
|
2733
|
+
err_1 = _c.sent();
|
|
2734
|
+
return [2 /*return*/, poolAddresses.map(function () { return 0; })];
|
|
2735
|
+
case 4: return [2 /*return*/];
|
|
2681
2736
|
}
|
|
2682
2737
|
});
|
|
2683
2738
|
}); };
|
|
2684
|
-
|
|
2685
|
-
var
|
|
2686
|
-
var _a, inputCoinAddress, outputCoinAddress, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, isUnderlying, i, j;
|
|
2739
|
+
var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2740
|
+
var availablePools, _a, inputCoinDecimals, outputCoinDecimals, _amount, poolAddress, registryExchangeContract, _output, registryExchangeMulticall, calls, _i, availablePools_1, pool, _c, _expectedAmounts, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd, bestPool;
|
|
2687
2741
|
return __generator(this, function (_d) {
|
|
2688
2742
|
switch (_d.label) {
|
|
2689
2743
|
case 0:
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2744
|
+
availablePools = Object.entries(curve_1.POOLS_DATA).map(function (pool) {
|
|
2745
|
+
var _a;
|
|
2746
|
+
var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
2747
|
+
var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
2748
|
+
var meta_coin_addresses = (_a = pool[1].meta_coin_addresses) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a.toLowerCase(); });
|
|
2749
|
+
var inputCoinIndexes = [
|
|
2750
|
+
coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
2751
|
+
underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
2752
|
+
meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
|
|
2753
|
+
];
|
|
2754
|
+
var outputCoinIndexes = [
|
|
2755
|
+
coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
2756
|
+
underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
2757
|
+
meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
|
|
2758
|
+
];
|
|
2759
|
+
if (pool[0] === 'atricrypto3') {
|
|
2760
|
+
return null;
|
|
2761
|
+
}
|
|
2762
|
+
if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
|
|
2763
|
+
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
2764
|
+
}
|
|
2765
|
+
else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
|
|
2766
|
+
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
2767
|
+
}
|
|
2768
|
+
else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
|
|
2769
|
+
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
2770
|
+
}
|
|
2771
|
+
else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
|
|
2772
|
+
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
2773
|
+
}
|
|
2774
|
+
else {
|
|
2775
|
+
return null;
|
|
2776
|
+
}
|
|
2777
|
+
}).filter(function (pool) { return pool !== null; });
|
|
2778
|
+
_a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
2779
|
+
_amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
|
|
2780
|
+
if (availablePools.length === 0) {
|
|
2781
|
+
return [2 /*return*/, { poolAddress: "0x0000000000000000000000000000000000000000", _output: ethers_1.ethers.BigNumber.from(0) }];
|
|
2782
|
+
}
|
|
2783
|
+
if (!(availablePools.length === 1)) return [3 /*break*/, 2];
|
|
2784
|
+
poolAddress = availablePools[0].poolAddress;
|
|
2785
|
+
registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
2786
|
+
return [4 /*yield*/, registryExchangeContract.get_exchange_amount(poolAddress, inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
2693
2787
|
case 1:
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
|
|
2788
|
+
_output = _d.sent();
|
|
2789
|
+
return [2 /*return*/, { poolAddress: poolAddress, _output: _output }];
|
|
2697
2790
|
case 2:
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2791
|
+
registryExchangeMulticall = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].multicallContract;
|
|
2792
|
+
calls = [];
|
|
2793
|
+
for (_i = 0, availablePools_1 = availablePools; _i < availablePools_1.length; _i++) {
|
|
2794
|
+
pool = availablePools_1[_i];
|
|
2795
|
+
calls.push(registryExchangeMulticall.get_exchange_amount(pool.poolAddress, inputCoinAddress, outputCoinAddress, _amount));
|
|
2796
|
+
}
|
|
2797
|
+
return [4 /*yield*/, Promise.all([
|
|
2798
|
+
curve_1.curve.multicallProvider.all(calls),
|
|
2799
|
+
_estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
|
|
2800
|
+
(0, utils_1._getUsdRate)(outputCoinAddress),
|
|
2801
|
+
axios_1.default.get("https://api.curve.fi/api/getGas"),
|
|
2802
|
+
(0, utils_1._getUsdRate)(curve_1.COINS.eth),
|
|
2803
|
+
])];
|
|
2704
2804
|
case 3:
|
|
2705
|
-
_c = _d.sent(),
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2805
|
+
_c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
|
|
2806
|
+
gasPrice = gasData.data.data.gas.standard;
|
|
2807
|
+
expectedAmounts = _expectedAmounts.map(function (_amount) { return Number(ethers_1.ethers.utils.formatUnits(_amount, outputCoinDecimals)); });
|
|
2808
|
+
expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
|
|
2809
|
+
txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
|
|
2810
|
+
availablePools.forEach(function (pool, i) {
|
|
2811
|
+
pool._output = _expectedAmounts[i];
|
|
2812
|
+
pool.outputUsd = expectedAmountsUsd[i];
|
|
2813
|
+
pool.txCostUsd = txCostsUsd[i];
|
|
2814
|
+
});
|
|
2815
|
+
bestPool = availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; });
|
|
2816
|
+
return [2 /*return*/, { poolAddress: bestPool.poolAddress, _output: bestPool._output }];
|
|
2709
2817
|
}
|
|
2710
2818
|
});
|
|
2711
2819
|
}); };
|
|
2712
2820
|
var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2713
|
-
var _a, inputCoinAddress, outputCoinAddress, _c, poolAddress,
|
|
2821
|
+
var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolAddress, _output;
|
|
2714
2822
|
return __generator(this, function (_d) {
|
|
2715
2823
|
switch (_d.label) {
|
|
2716
2824
|
case 0:
|
|
2717
2825
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2718
|
-
|
|
2826
|
+
outputCoinDecimals = (0, utils_1._getCoinDecimals)(outputCoinAddress)[0];
|
|
2827
|
+
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
2719
2828
|
case 1:
|
|
2720
|
-
_c = _d.sent(), poolAddress = _c.poolAddress,
|
|
2721
|
-
return [2 /*return*/, { poolAddress: poolAddress, output:
|
|
2829
|
+
_c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
|
|
2830
|
+
return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
|
|
2722
2831
|
}
|
|
2723
2832
|
});
|
|
2724
2833
|
}); };
|
|
@@ -2733,40 +2842,28 @@ var exchangeExpected = function (inputCoin, outputCoin, amount) { return __await
|
|
|
2733
2842
|
}); };
|
|
2734
2843
|
exports.exchangeExpected = exchangeExpected;
|
|
2735
2844
|
var exchangeIsApproved = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2736
|
-
var poolAddress;
|
|
2737
2845
|
return __generator(this, function (_a) {
|
|
2738
2846
|
switch (_a.label) {
|
|
2739
|
-
case 0: return [4 /*yield*/, (0,
|
|
2740
|
-
case 1:
|
|
2741
|
-
poolAddress = (_a.sent()).poolAddress;
|
|
2742
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, poolAddress)];
|
|
2743
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
2847
|
+
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.registry_exchange)];
|
|
2848
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2744
2849
|
}
|
|
2745
2850
|
});
|
|
2746
2851
|
}); };
|
|
2747
2852
|
exports.exchangeIsApproved = exchangeIsApproved;
|
|
2748
2853
|
var exchangeApproveEstimateGas = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2749
|
-
var poolAddress;
|
|
2750
2854
|
return __generator(this, function (_a) {
|
|
2751
2855
|
switch (_a.label) {
|
|
2752
|
-
case 0: return [4 /*yield*/, (0,
|
|
2753
|
-
case 1:
|
|
2754
|
-
poolAddress = (_a.sent()).poolAddress;
|
|
2755
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], poolAddress)];
|
|
2756
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
2856
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
|
|
2857
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2757
2858
|
}
|
|
2758
2859
|
});
|
|
2759
2860
|
}); };
|
|
2760
2861
|
exports.exchangeApproveEstimateGas = exchangeApproveEstimateGas;
|
|
2761
2862
|
var exchangeApprove = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2762
|
-
var poolAddress;
|
|
2763
2863
|
return __generator(this, function (_a) {
|
|
2764
2864
|
switch (_a.label) {
|
|
2765
|
-
case 0: return [4 /*yield*/, (0,
|
|
2766
|
-
case 1:
|
|
2767
|
-
poolAddress = (_a.sent()).poolAddress;
|
|
2768
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], poolAddress)];
|
|
2769
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
2865
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
|
|
2866
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2770
2867
|
}
|
|
2771
2868
|
});
|
|
2772
2869
|
}); };
|
|
@@ -2774,22 +2871,28 @@ exports.exchangeApprove = exchangeApprove;
|
|
|
2774
2871
|
var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2775
2872
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2776
2873
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2777
|
-
var _a,
|
|
2778
|
-
return __generator(this, function (
|
|
2779
|
-
switch (
|
|
2780
|
-
case 0:
|
|
2874
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
|
|
2875
|
+
return __generator(this, function (_e) {
|
|
2876
|
+
switch (_e.label) {
|
|
2877
|
+
case 0:
|
|
2878
|
+
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2879
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2880
|
+
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
2781
2881
|
case 1:
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
case
|
|
2882
|
+
_d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
|
|
2883
|
+
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
2884
|
+
throw new Error("This pair can't be exchanged");
|
|
2885
|
+
}
|
|
2886
|
+
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2887
|
+
minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
|
|
2888
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2889
|
+
contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
2890
|
+
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
2891
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2892
|
+
case 2:
|
|
2893
|
+
_e.sent();
|
|
2894
|
+
return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2895
|
+
case 3: return [2 /*return*/, (_e.sent()).toNumber()];
|
|
2793
2896
|
}
|
|
2794
2897
|
});
|
|
2795
2898
|
});
|
|
@@ -2798,22 +2901,34 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
|
|
|
2798
2901
|
var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2799
2902
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2800
2903
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2801
|
-
var _a,
|
|
2802
|
-
return __generator(this, function (
|
|
2803
|
-
switch (
|
|
2804
|
-
case 0:
|
|
2904
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
|
|
2905
|
+
return __generator(this, function (_e) {
|
|
2906
|
+
switch (_e.label) {
|
|
2907
|
+
case 0:
|
|
2908
|
+
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2909
|
+
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2910
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
|
|
2805
2911
|
case 1:
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2912
|
+
_e.sent();
|
|
2913
|
+
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
2914
|
+
case 2:
|
|
2915
|
+
_d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
|
|
2916
|
+
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
2917
|
+
throw new Error("This pair can't be exchanged");
|
|
2918
|
+
}
|
|
2919
|
+
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
2920
|
+
minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
|
|
2921
|
+
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2922
|
+
contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
2923
|
+
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
2924
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2811
2925
|
case 3:
|
|
2812
|
-
|
|
2813
|
-
return [4 /*yield*/,
|
|
2814
|
-
case 4:
|
|
2815
|
-
|
|
2816
|
-
|
|
2926
|
+
_e.sent();
|
|
2927
|
+
return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2928
|
+
case 4:
|
|
2929
|
+
gasLimit = (_e.sent()).mul(130).div(100);
|
|
2930
|
+
return [4 /*yield*/, contract.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
2931
|
+
case 5: return [2 /*return*/, (_e.sent()).hash];
|
|
2817
2932
|
}
|
|
2818
2933
|
});
|
|
2819
2934
|
});
|
|
@@ -2825,9 +2940,12 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
|
|
|
2825
2940
|
return __generator(this, function (_c) {
|
|
2826
2941
|
switch (_c.label) {
|
|
2827
2942
|
case 0:
|
|
2943
|
+
if (curve_1.curve.chainId !== 1) {
|
|
2944
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
2945
|
+
}
|
|
2828
2946
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2829
2947
|
// TODO remove it when fixed
|
|
2830
|
-
if (inputCoinAddress.toLowerCase() ===
|
|
2948
|
+
if (inputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase())
|
|
2831
2949
|
return [2 /*return*/, false];
|
|
2832
2950
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
2833
2951
|
case 1:
|
|
@@ -2839,11 +2957,11 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
|
|
|
2839
2957
|
exports.crossAssetExchangeAvailable = crossAssetExchangeAvailable;
|
|
2840
2958
|
var _getSmallAmountForCoin = function (coinAddress) {
|
|
2841
2959
|
var smallAmount = '10'; // $10 or €10
|
|
2842
|
-
if (Object.values(
|
|
2960
|
+
if (Object.values(curve_1.BTC_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2843
2961
|
smallAmount = '0.00025'; // =10$ when BTC = $40k
|
|
2844
|
-
else if (Object.values(
|
|
2962
|
+
else if (Object.values(curve_1.ETH_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2845
2963
|
smallAmount = '0.004'; // =10$ when ETH = $2.5k
|
|
2846
|
-
else if (Object.values(
|
|
2964
|
+
else if (Object.values(curve_1.LINK_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
|
|
2847
2965
|
smallAmount = '0.5'; // =10$ when LINK = $20
|
|
2848
2966
|
return smallAmount;
|
|
2849
2967
|
};
|
|
@@ -2880,6 +2998,9 @@ var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amoun
|
|
|
2880
2998
|
return __generator(this, function (_e) {
|
|
2881
2999
|
switch (_e.label) {
|
|
2882
3000
|
case 0:
|
|
3001
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3002
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3003
|
+
}
|
|
2883
3004
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2884
3005
|
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2885
3006
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
@@ -2896,6 +3017,9 @@ var crossAssetExchangeExpected = function (inputCoin, outputCoin, amount) { retu
|
|
|
2896
3017
|
return __generator(this, function (_e) {
|
|
2897
3018
|
switch (_e.label) {
|
|
2898
3019
|
case 0:
|
|
3020
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3021
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3022
|
+
}
|
|
2899
3023
|
_a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
|
|
2900
3024
|
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2901
3025
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
@@ -2913,7 +3037,11 @@ exports.crossAssetExchangeExpected = crossAssetExchangeExpected;
|
|
|
2913
3037
|
var crossAssetExchangeIsApproved = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2914
3038
|
return __generator(this, function (_a) {
|
|
2915
3039
|
switch (_a.label) {
|
|
2916
|
-
case 0:
|
|
3040
|
+
case 0:
|
|
3041
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3042
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3043
|
+
}
|
|
3044
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
|
|
2917
3045
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2918
3046
|
}
|
|
2919
3047
|
});
|
|
@@ -2922,7 +3050,11 @@ exports.crossAssetExchangeIsApproved = crossAssetExchangeIsApproved;
|
|
|
2922
3050
|
var crossAssetExchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2923
3051
|
return __generator(this, function (_a) {
|
|
2924
3052
|
switch (_a.label) {
|
|
2925
|
-
case 0:
|
|
3053
|
+
case 0:
|
|
3054
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3055
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3056
|
+
}
|
|
3057
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.router)];
|
|
2926
3058
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2927
3059
|
}
|
|
2928
3060
|
});
|
|
@@ -2931,7 +3063,11 @@ exports.crossAssetExchangeApproveEstimateGas = crossAssetExchangeApproveEstimate
|
|
|
2931
3063
|
var crossAssetExchangeApprove = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2932
3064
|
return __generator(this, function (_a) {
|
|
2933
3065
|
switch (_a.label) {
|
|
2934
|
-
case 0:
|
|
3066
|
+
case 0:
|
|
3067
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3068
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3069
|
+
}
|
|
3070
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.router)];
|
|
2935
3071
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2936
3072
|
}
|
|
2937
3073
|
});
|
|
@@ -2943,7 +3079,11 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
|
|
|
2943
3079
|
var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
|
|
2944
3080
|
return __generator(this, function (_e) {
|
|
2945
3081
|
switch (_e.label) {
|
|
2946
|
-
case 0:
|
|
3082
|
+
case 0:
|
|
3083
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3084
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3085
|
+
}
|
|
3086
|
+
return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
2947
3087
|
case 1:
|
|
2948
3088
|
if (!(_e.sent()))
|
|
2949
3089
|
throw Error("Such exchange is not available");
|
|
@@ -2952,7 +3092,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
|
|
|
2952
3092
|
case 2:
|
|
2953
3093
|
inputCoinBalance = (_e.sent())[curve_1.curve.signerAddress];
|
|
2954
3094
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
2955
|
-
throw Error("Not enough "
|
|
3095
|
+
throw Error("Not enough ".concat(inputCoin, ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
|
|
2956
3096
|
}
|
|
2957
3097
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
|
|
2958
3098
|
case 3:
|
|
@@ -2964,7 +3104,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
|
|
|
2964
3104
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
2965
3105
|
case 4:
|
|
2966
3106
|
_d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
|
|
2967
|
-
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(
|
|
3107
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
2968
3108
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2969
3109
|
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
|
|
2970
3110
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|
|
@@ -2983,7 +3123,11 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
2983
3123
|
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
|
|
2984
3124
|
return __generator(this, function (_e) {
|
|
2985
3125
|
switch (_e.label) {
|
|
2986
|
-
case 0:
|
|
3126
|
+
case 0:
|
|
3127
|
+
if (curve_1.curve.chainId !== 1) {
|
|
3128
|
+
throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
|
|
3129
|
+
}
|
|
3130
|
+
return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
|
|
2987
3131
|
case 1:
|
|
2988
3132
|
if (!(_e.sent()))
|
|
2989
3133
|
throw Error("Such exchange is not available");
|
|
@@ -2993,7 +3137,7 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
2993
3137
|
return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
|
|
2994
3138
|
case 2:
|
|
2995
3139
|
_d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
|
|
2996
|
-
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(
|
|
3140
|
+
minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
|
|
2997
3141
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2998
3142
|
value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
|
|
2999
3143
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
|