@curvefi/api 1.20.0 → 1.21.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 +46 -39
- package/lib/constants/abis/abis-ethereum.js +138 -0
- package/lib/constants/abis/abis-polygon.js +12 -0
- package/lib/curve.d.ts +5 -5
- package/lib/curve.js +42 -18
- package/lib/factory/constants.d.ts +18 -0
- package/lib/factory/constants.js +149 -0
- package/lib/factory/factory-api.d.ts +2 -0
- package/lib/factory/factory-api.js +273 -0
- package/lib/factory/factory-crypto.d.ts +2 -0
- package/lib/{factory-crypto.js → factory/factory-crypto.js} +44 -54
- package/lib/factory/factory.d.ts +2 -0
- package/lib/{factory.js → factory/factory.js} +73 -64
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -4
- package/lib/interfaces.d.ts +51 -2
- package/lib/pools.d.ts +5 -1
- package/lib/pools.js +122 -90
- package/package.json +1 -1
- package/lib/factory-crypto.d.ts +0 -32
- package/lib/factory.d.ts +0 -32
package/lib/pools.js
CHANGED
|
@@ -59,13 +59,13 @@ 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.Pool = void 0;
|
|
62
|
+
exports.getUserPoolList = 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
65
|
var curve_1 = require("./curve");
|
|
66
66
|
var axios_1 = __importDefault(require("axios"));
|
|
67
67
|
var Pool = /** @class */ (function () {
|
|
68
|
-
function Pool(
|
|
68
|
+
function Pool(id) {
|
|
69
69
|
var _this = this;
|
|
70
70
|
this.calcLpTokenAmount = function (amounts, isDeposit) {
|
|
71
71
|
if (isDeposit === void 0) { isDeposit = true; }
|
|
@@ -81,9 +81,9 @@ var Pool = /** @class */ (function () {
|
|
|
81
81
|
_amounts = amounts.map(function (amount, i) {
|
|
82
82
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
83
83
|
});
|
|
84
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
84
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
85
85
|
this.isCryptoFactory ||
|
|
86
|
-
(curve_1.curve.chainId === 137 && this.
|
|
86
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 2];
|
|
87
87
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
|
|
88
88
|
case 1:
|
|
89
89
|
_expected = _a.sent(); // Lending pools
|
|
@@ -156,7 +156,7 @@ var Pool = /** @class */ (function () {
|
|
|
156
156
|
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
157
157
|
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
158
158
|
], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
|
|
159
|
-
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.
|
|
159
|
+
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
|
|
160
160
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
|
|
161
161
|
case 2:
|
|
162
162
|
_d = _f.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
|
|
@@ -183,7 +183,7 @@ var Pool = /** @class */ (function () {
|
|
|
183
183
|
_poolWrappedBalances = _a.sent();
|
|
184
184
|
_poolUnderlyingBalances = [];
|
|
185
185
|
if (!this.isMeta) return [3 /*break*/, 3];
|
|
186
|
-
if (this.
|
|
186
|
+
if (this.id !== 'atricrypto3') {
|
|
187
187
|
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
188
188
|
}
|
|
189
189
|
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolUnderlyingBalance = _poolWrappedBalances.slice(1);
|
|
@@ -191,12 +191,12 @@ var Pool = /** @class */ (function () {
|
|
|
191
191
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_poolMetaCoinBalance)];
|
|
192
192
|
case 2:
|
|
193
193
|
_basePoolExpectedAmounts = _a.sent();
|
|
194
|
-
_poolUnderlyingBalances = this.
|
|
194
|
+
_poolUnderlyingBalances = this.id !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
|
|
195
195
|
return [3 /*break*/, 6];
|
|
196
196
|
case 3:
|
|
197
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
197
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
198
198
|
this.isCryptoFactory ||
|
|
199
|
-
(curve_1.curve.chainId === 137 && this.
|
|
199
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 5];
|
|
200
200
|
return [4 /*yield*/, this._getRates()];
|
|
201
201
|
case 4:
|
|
202
202
|
_rates_1 = _a.sent();
|
|
@@ -250,7 +250,7 @@ var Pool = /** @class */ (function () {
|
|
|
250
250
|
switch (_a.label) {
|
|
251
251
|
case 0:
|
|
252
252
|
statsUrl = this.isFactory ? (0, utils_1._getFactoryStatsUrl)() : (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
253
|
-
name = (this.
|
|
253
|
+
name = (this.id === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.id === 'sbtc' ? 'rens' : this.id;
|
|
254
254
|
key = this.isFactory ? this.swap.toLowerCase() : name;
|
|
255
255
|
if (!this.isFactory) return [3 /*break*/, 4];
|
|
256
256
|
if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 2];
|
|
@@ -482,13 +482,13 @@ var Pool = /** @class */ (function () {
|
|
|
482
482
|
_amounts = amounts.map(function (amount, i) {
|
|
483
483
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
484
484
|
});
|
|
485
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
485
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id)) return [3 /*break*/, 4];
|
|
486
486
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
487
487
|
case 3: return [2 /*return*/, _d.sent()];
|
|
488
488
|
case 4:
|
|
489
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
489
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
490
490
|
this.isCryptoFactory ||
|
|
491
|
-
(curve_1.curve.chainId === 137 && this.
|
|
491
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 6];
|
|
492
492
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
493
493
|
case 5: return [2 /*return*/, _d.sent()];
|
|
494
494
|
case 6:
|
|
@@ -540,13 +540,13 @@ var Pool = /** @class */ (function () {
|
|
|
540
540
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
541
541
|
case 1:
|
|
542
542
|
_a.sent();
|
|
543
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.
|
|
543
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id)) return [3 /*break*/, 3];
|
|
544
544
|
return [4 /*yield*/, this._addLiquidityZap(_amounts)];
|
|
545
545
|
case 2: return [2 /*return*/, _a.sent()];
|
|
546
546
|
case 3:
|
|
547
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
547
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
548
548
|
this.isCryptoFactory ||
|
|
549
|
-
(curve_1.curve.chainId === 137 && this.
|
|
549
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 5];
|
|
550
550
|
return [4 /*yield*/, this._addLiquidity(_amounts, true)];
|
|
551
551
|
case 4: return [2 /*return*/, _a.sent()];
|
|
552
552
|
case 5:
|
|
@@ -725,9 +725,9 @@ var Pool = /** @class */ (function () {
|
|
|
725
725
|
return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
|
|
726
726
|
});
|
|
727
727
|
contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
|
|
728
|
-
useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
728
|
+
useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
729
729
|
this.isCryptoFactory ||
|
|
730
|
-
(curve_1.curve.chainId === 137 && this.
|
|
730
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'));
|
|
731
731
|
if (!isUnderlying) return [3 /*break*/, 14];
|
|
732
732
|
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
733
733
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
@@ -898,9 +898,9 @@ var Pool = /** @class */ (function () {
|
|
|
898
898
|
_amounts = amounts.map(function (amount, i) {
|
|
899
899
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
900
900
|
});
|
|
901
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
901
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
902
902
|
this.isCryptoFactory ||
|
|
903
|
-
(curve_1.curve.chainId === 137 && this.
|
|
903
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 4];
|
|
904
904
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
905
905
|
case 3: return [2 /*return*/, _d.sent()];
|
|
906
906
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
@@ -928,9 +928,9 @@ var Pool = /** @class */ (function () {
|
|
|
928
928
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
929
929
|
case 1:
|
|
930
930
|
_a.sent();
|
|
931
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
931
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
932
932
|
this.isCryptoFactory ||
|
|
933
|
-
(curve_1.curve.chainId === 137 && this.
|
|
933
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
934
934
|
return [4 /*yield*/, this._addLiquidity(_amounts, false)];
|
|
935
935
|
case 2: return [2 /*return*/, _a.sent()];
|
|
936
936
|
case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
|
|
@@ -1072,9 +1072,9 @@ var Pool = /** @class */ (function () {
|
|
|
1072
1072
|
switch (_a.label) {
|
|
1073
1073
|
case 0:
|
|
1074
1074
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1075
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1075
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1076
1076
|
this.isCryptoFactory ||
|
|
1077
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1077
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 2];
|
|
1078
1078
|
return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
|
|
1079
1079
|
case 1:
|
|
1080
1080
|
_expected = _a.sent(); // Lending pools
|
|
@@ -1147,13 +1147,13 @@ var Pool = /** @class */ (function () {
|
|
|
1147
1147
|
throw Error("Token allowance is needed to estimate gas");
|
|
1148
1148
|
}
|
|
1149
1149
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1150
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.
|
|
1150
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id)) return [3 /*break*/, 5];
|
|
1151
1151
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
1152
1152
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1153
1153
|
case 5:
|
|
1154
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1154
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1155
1155
|
this.isCryptoFactory ||
|
|
1156
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1156
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 7];
|
|
1157
1157
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
1158
1158
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1159
1159
|
case 7:
|
|
@@ -1174,13 +1174,13 @@ var Pool = /** @class */ (function () {
|
|
|
1174
1174
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1175
1175
|
case 1:
|
|
1176
1176
|
_a.sent();
|
|
1177
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.
|
|
1177
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id)) return [3 /*break*/, 3];
|
|
1178
1178
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
|
|
1179
1179
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1180
1180
|
case 3:
|
|
1181
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1181
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1182
1182
|
this.isCryptoFactory ||
|
|
1183
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1183
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 5];
|
|
1184
1184
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
|
|
1185
1185
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1186
1186
|
case 5:
|
|
@@ -1224,9 +1224,9 @@ var Pool = /** @class */ (function () {
|
|
|
1224
1224
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
1225
1225
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
1226
1226
|
}
|
|
1227
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1227
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1228
1228
|
this.isCryptoFactory ||
|
|
1229
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1229
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
1230
1230
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
1231
1231
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1232
1232
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
@@ -1246,9 +1246,9 @@ var Pool = /** @class */ (function () {
|
|
|
1246
1246
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1247
1247
|
case 1:
|
|
1248
1248
|
_a.sent();
|
|
1249
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1249
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1250
1250
|
this.isCryptoFactory ||
|
|
1251
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1251
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
1252
1252
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
|
|
1253
1253
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1254
1254
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
@@ -1298,7 +1298,7 @@ var Pool = /** @class */ (function () {
|
|
|
1298
1298
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
1299
1299
|
}
|
|
1300
1300
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
1301
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1301
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 3];
|
|
1302
1302
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
1303
1303
|
case 1:
|
|
1304
1304
|
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
@@ -1325,7 +1325,7 @@ var Pool = /** @class */ (function () {
|
|
|
1325
1325
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
1326
1326
|
}
|
|
1327
1327
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
1328
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1328
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 3];
|
|
1329
1329
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
1330
1330
|
case 1:
|
|
1331
1331
|
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
@@ -1352,7 +1352,7 @@ var Pool = /** @class */ (function () {
|
|
|
1352
1352
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
|
|
1353
1353
|
}
|
|
1354
1354
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
1355
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1355
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 3];
|
|
1356
1356
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
|
|
1357
1357
|
case 1:
|
|
1358
1358
|
_maxBurnAmount = (_a.sent()).mul(101).div(100);
|
|
@@ -1398,11 +1398,11 @@ var Pool = /** @class */ (function () {
|
|
|
1398
1398
|
throw Error("Token allowance is needed to estimate gas");
|
|
1399
1399
|
}
|
|
1400
1400
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
1401
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1401
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 6];
|
|
1402
1402
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
|
|
1403
1403
|
case 5: return [2 /*return*/, _c.sent()];
|
|
1404
1404
|
case 6:
|
|
1405
|
-
if (!(['aave', 'saave', 'ib'].includes(this.
|
|
1405
|
+
if (!(['aave', 'saave', 'ib'].includes(this.id) || (curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 8];
|
|
1406
1406
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
|
|
1407
1407
|
case 7: return [2 /*return*/, _c.sent()];
|
|
1408
1408
|
case 8:
|
|
@@ -1427,11 +1427,11 @@ var Pool = /** @class */ (function () {
|
|
|
1427
1427
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1428
1428
|
case 1:
|
|
1429
1429
|
_a.sent();
|
|
1430
|
-
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1430
|
+
if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 3];
|
|
1431
1431
|
return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts)];
|
|
1432
1432
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1433
1433
|
case 3:
|
|
1434
|
-
if (!(['aave', 'saave', 'ib'].includes(this.
|
|
1434
|
+
if (!(['aave', 'saave', 'ib'].includes(this.id) || (curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 5];
|
|
1435
1435
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true)];
|
|
1436
1436
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1437
1437
|
case 5:
|
|
@@ -1494,7 +1494,7 @@ var Pool = /** @class */ (function () {
|
|
|
1494
1494
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
1495
1495
|
}
|
|
1496
1496
|
_amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
|
|
1497
|
-
if (!(['aave', 'saave', 'ib'].includes(this.
|
|
1497
|
+
if (!(['aave', 'saave', 'ib'].includes(this.id) || (curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 4];
|
|
1498
1498
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, true)];
|
|
1499
1499
|
case 3: return [2 /*return*/, _a.sent()];
|
|
1500
1500
|
case 4: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
|
|
@@ -1517,7 +1517,7 @@ var Pool = /** @class */ (function () {
|
|
|
1517
1517
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1518
1518
|
case 1:
|
|
1519
1519
|
_a.sent();
|
|
1520
|
-
if (!(['aave', 'saave', 'ib'].includes(this.
|
|
1520
|
+
if (!(['aave', 'saave', 'ib'].includes(this.id) || (curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
1521
1521
|
return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, estimateGas)];
|
|
1522
1522
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1523
1523
|
case 3: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
|
|
@@ -1533,13 +1533,13 @@ var Pool = /** @class */ (function () {
|
|
|
1533
1533
|
case 0:
|
|
1534
1534
|
i = this._getCoinIdx(coin);
|
|
1535
1535
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1536
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1536
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id) || this.id === 'susd' || this.isMeta)) return [3 /*break*/, 2];
|
|
1537
1537
|
return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
|
|
1538
1538
|
case 1:
|
|
1539
1539
|
_expected = _a.sent(); // Lending pools with zap, susd and metapools
|
|
1540
1540
|
return [3 /*break*/, 6];
|
|
1541
1541
|
case 2:
|
|
1542
|
-
if (!(this.
|
|
1542
|
+
if (!(this.id === 'ib')) return [3 /*break*/, 4];
|
|
1543
1543
|
return [4 /*yield*/, this._calcWithdrawOneCoin(_lpTokenAmount, i, true)];
|
|
1544
1544
|
case 3:
|
|
1545
1545
|
_expected = _a.sent(); // ib
|
|
@@ -1627,13 +1627,13 @@ var Pool = /** @class */ (function () {
|
|
|
1627
1627
|
}
|
|
1628
1628
|
i = this._getCoinIdx(coin);
|
|
1629
1629
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1630
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.
|
|
1630
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id) || this.id === 'susd' || this.isMeta)) return [3 /*break*/, 5];
|
|
1631
1631
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
1632
1632
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1633
1633
|
case 5:
|
|
1634
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1634
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1635
1635
|
this.isCryptoFactory ||
|
|
1636
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1636
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 7];
|
|
1637
1637
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
1638
1638
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1639
1639
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1653,13 +1653,13 @@ var Pool = /** @class */ (function () {
|
|
|
1653
1653
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1654
1654
|
case 1:
|
|
1655
1655
|
_a.sent();
|
|
1656
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.
|
|
1656
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.id) || this.id === 'susd' || this.isMeta)) return [3 /*break*/, 3];
|
|
1657
1657
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
|
|
1658
1658
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1659
1659
|
case 3:
|
|
1660
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1660
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1661
1661
|
this.isCryptoFactory ||
|
|
1662
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1662
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 5];
|
|
1663
1663
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
|
|
1664
1664
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1665
1665
|
case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1677,12 +1677,12 @@ var Pool = /** @class */ (function () {
|
|
|
1677
1677
|
if (this.isFake) {
|
|
1678
1678
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1679
1679
|
}
|
|
1680
|
-
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1680
|
+
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) {
|
|
1681
1681
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1682
1682
|
}
|
|
1683
1683
|
i = this._getCoinIdx(coin, false);
|
|
1684
1684
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1685
|
-
if (!(this.
|
|
1685
|
+
if (!(this.id === 'ib')) return [3 /*break*/, 2];
|
|
1686
1686
|
return [4 /*yield*/, this._calcWithdrawOneCoin(_lpTokenAmount, i, false)];
|
|
1687
1687
|
case 1:
|
|
1688
1688
|
_expected = _a.sent(); // ib
|
|
@@ -1733,13 +1733,13 @@ var Pool = /** @class */ (function () {
|
|
|
1733
1733
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
1734
1734
|
}
|
|
1735
1735
|
i = this._getCoinIdx(coin, false);
|
|
1736
|
-
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1736
|
+
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) {
|
|
1737
1737
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1738
1738
|
}
|
|
1739
1739
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1740
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1740
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1741
1741
|
this.isCryptoFactory ||
|
|
1742
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1742
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
1743
1743
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
|
|
1744
1744
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1745
1745
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1756,16 +1756,16 @@ var Pool = /** @class */ (function () {
|
|
|
1756
1756
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1757
1757
|
}
|
|
1758
1758
|
i = this._getCoinIdx(coin, false);
|
|
1759
|
-
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.
|
|
1759
|
+
if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.id)) {
|
|
1760
1760
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1761
1761
|
}
|
|
1762
1762
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1763
1763
|
case 1:
|
|
1764
1764
|
_a.sent();
|
|
1765
1765
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1766
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.
|
|
1766
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.id) ||
|
|
1767
1767
|
this.isCryptoFactory ||
|
|
1768
|
-
(curve_1.curve.chainId === 137 && this.
|
|
1768
|
+
(curve_1.curve.chainId === 137 && this.id === 'ren'))) return [3 /*break*/, 3];
|
|
1769
1769
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
|
|
1770
1770
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1771
1771
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -2090,8 +2090,8 @@ var Pool = /** @class */ (function () {
|
|
|
2090
2090
|
return __generator(this, function (_a) {
|
|
2091
2091
|
switch (_a.label) {
|
|
2092
2092
|
case 0:
|
|
2093
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
2094
|
-
(curve_1.curve.chainId === 137 && this.
|
|
2093
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ||
|
|
2094
|
+
(curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.swap;
|
|
2095
2095
|
i = this._getCoinIdx(inputCoin);
|
|
2096
2096
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
2097
2097
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2103,8 +2103,8 @@ var Pool = /** @class */ (function () {
|
|
|
2103
2103
|
return __generator(this, function (_a) {
|
|
2104
2104
|
switch (_a.label) {
|
|
2105
2105
|
case 0:
|
|
2106
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
2107
|
-
(curve_1.curve.chainId === 137 && this.
|
|
2106
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ||
|
|
2107
|
+
(curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.swap;
|
|
2108
2108
|
i = this._getCoinIdx(inputCoin);
|
|
2109
2109
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2110
2110
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2116,8 +2116,8 @@ var Pool = /** @class */ (function () {
|
|
|
2116
2116
|
return __generator(this, function (_a) {
|
|
2117
2117
|
switch (_a.label) {
|
|
2118
2118
|
case 0:
|
|
2119
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
2120
|
-
(curve_1.curve.chainId === 137 && this.
|
|
2119
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ||
|
|
2120
|
+
(curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.swap;
|
|
2121
2121
|
i = this._getCoinIdx(inputCoin);
|
|
2122
2122
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2123
2123
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2131,8 +2131,8 @@ var Pool = /** @class */ (function () {
|
|
|
2131
2131
|
return __generator(this, function (_d) {
|
|
2132
2132
|
switch (_d.label) {
|
|
2133
2133
|
case 0:
|
|
2134
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
2135
|
-
(curve_1.curve.chainId === 137 && this.
|
|
2134
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ||
|
|
2135
|
+
(curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.swap;
|
|
2136
2136
|
i = this._getCoinIdx(inputCoin);
|
|
2137
2137
|
j = this._getCoinIdx(outputCoin);
|
|
2138
2138
|
_c = (_a = Object).values;
|
|
@@ -2157,11 +2157,11 @@ var Pool = /** @class */ (function () {
|
|
|
2157
2157
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2158
2158
|
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
2159
2159
|
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
2160
|
-
if (!(this.
|
|
2160
|
+
if (!(this.id === "tricrypto2")) return [3 /*break*/, 5];
|
|
2161
2161
|
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2162
2162
|
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2163
2163
|
case 5:
|
|
2164
|
-
if (!(curve_1.curve.chainId === 137 && this.
|
|
2164
|
+
if (!(curve_1.curve.chainId === 137 && this.isMetaFactory)) return [3 /*break*/, 7];
|
|
2165
2165
|
return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2166
2166
|
case 6: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2167
2167
|
case 7: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
@@ -2177,8 +2177,8 @@ var Pool = /** @class */ (function () {
|
|
|
2177
2177
|
return __generator(this, function (_a) {
|
|
2178
2178
|
switch (_a.label) {
|
|
2179
2179
|
case 0:
|
|
2180
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
2181
|
-
(curve_1.curve.chainId === 137 && this.
|
|
2180
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ||
|
|
2181
|
+
(curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.swap;
|
|
2182
2182
|
i = this._getCoinIdx(inputCoin);
|
|
2183
2183
|
j = this._getCoinIdx(outputCoin);
|
|
2184
2184
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
@@ -2197,14 +2197,14 @@ var Pool = /** @class */ (function () {
|
|
|
2197
2197
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2198
2198
|
case 3:
|
|
2199
2199
|
_a.sent();
|
|
2200
|
-
if (!(this.
|
|
2200
|
+
if (!(this.id === 'tricrypto2')) return [3 /*break*/, 6];
|
|
2201
2201
|
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2202
2202
|
case 4:
|
|
2203
2203
|
gasLimit_1 = (_a.sent()).mul(130).div(100);
|
|
2204
2204
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
|
|
2205
2205
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2206
2206
|
case 6:
|
|
2207
|
-
if (!(curve_1.curve.chainId === 137 && this.
|
|
2207
|
+
if (!(curve_1.curve.chainId === 137 && this.isMetaFactory)) return [3 /*break*/, 9];
|
|
2208
2208
|
return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2209
2209
|
case 7:
|
|
2210
2210
|
gasLimit_2 = (_a.sent()).mul(140).div(100);
|
|
@@ -2213,7 +2213,7 @@ var Pool = /** @class */ (function () {
|
|
|
2213
2213
|
case 9: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2214
2214
|
case 10:
|
|
2215
2215
|
estimatedGas = _a.sent();
|
|
2216
|
-
gasLimit = curve_1.curve.chainId === 137 && this.
|
|
2216
|
+
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ?
|
|
2217
2217
|
estimatedGas.mul(160).div(100) :
|
|
2218
2218
|
estimatedGas.mul(130).div(100);
|
|
2219
2219
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
@@ -2315,7 +2315,7 @@ var Pool = /** @class */ (function () {
|
|
|
2315
2315
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
2316
2316
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
2317
2317
|
value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
2318
|
-
if (!(this.
|
|
2318
|
+
if (!(this.id === 'tricrypto2')) return [3 /*break*/, 5];
|
|
2319
2319
|
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2320
2320
|
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2321
2321
|
case 5: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
@@ -2351,7 +2351,7 @@ var Pool = /** @class */ (function () {
|
|
|
2351
2351
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2352
2352
|
case 3:
|
|
2353
2353
|
_a.sent();
|
|
2354
|
-
if (!(this.
|
|
2354
|
+
if (!(this.id === 'tricrypto2')) return [3 /*break*/, 6];
|
|
2355
2355
|
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2356
2356
|
case 4:
|
|
2357
2357
|
gasLimit_3 = (_a.sent()).mul(130).div(100);
|
|
@@ -2360,7 +2360,7 @@ var Pool = /** @class */ (function () {
|
|
|
2360
2360
|
case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2361
2361
|
case 7:
|
|
2362
2362
|
estimatedGas = _a.sent();
|
|
2363
|
-
gasLimit = curve_1.curve.chainId === 137 && this.
|
|
2363
|
+
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ?
|
|
2364
2364
|
estimatedGas.mul(140).div(100) :
|
|
2365
2365
|
estimatedGas.mul(130).div(100);
|
|
2366
2366
|
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
@@ -2532,14 +2532,14 @@ var Pool = /** @class */ (function () {
|
|
|
2532
2532
|
if (!(i < this.coinAddresses.length)) return [3 /*break*/, 9];
|
|
2533
2533
|
addr = this.coinAddresses[i];
|
|
2534
2534
|
if (!this.useLending[i]) return [3 /*break*/, 7];
|
|
2535
|
-
if (!['compound', 'usdt', 'ib'].includes(this.
|
|
2535
|
+
if (!['compound', 'usdt', 'ib'].includes(this.id)) return [3 /*break*/, 3];
|
|
2536
2536
|
_c = (_a = _rates).push;
|
|
2537
2537
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.exchangeRateStored()];
|
|
2538
2538
|
case 2:
|
|
2539
2539
|
_c.apply(_a, [_f.sent()]);
|
|
2540
2540
|
return [3 /*break*/, 6];
|
|
2541
2541
|
case 3:
|
|
2542
|
-
if (!['y', 'busd', 'pax'].includes(this.
|
|
2542
|
+
if (!['y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 5];
|
|
2543
2543
|
_e = (_d = _rates).push;
|
|
2544
2544
|
return [4 /*yield*/, curve_1.curve.contracts[addr].contract.getPricePerFullShare()];
|
|
2545
2545
|
case 4:
|
|
@@ -2816,7 +2816,7 @@ var Pool = /** @class */ (function () {
|
|
|
2816
2816
|
switch (_a.label) {
|
|
2817
2817
|
case 0:
|
|
2818
2818
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
2819
|
-
if (!(["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.
|
|
2819
|
+
if (!(["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.id) || this.isCryptoFactory)) return [3 /*break*/, 2];
|
|
2820
2820
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
2821
2821
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2822
2822
|
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -2837,7 +2837,7 @@ var Pool = /** @class */ (function () {
|
|
|
2837
2837
|
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
2838
2838
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2839
2839
|
case 2:
|
|
2840
|
-
if (!["eurtusd", "xautusd"].includes(this.
|
|
2840
|
+
if (!["eurtusd", "xautusd"].includes(this.id)) return [3 /*break*/, 4];
|
|
2841
2841
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
2842
2842
|
case 3: return [2 /*return*/, _a.sent()];
|
|
2843
2843
|
case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -3080,7 +3080,7 @@ var Pool = /** @class */ (function () {
|
|
|
3080
3080
|
case 0: return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
|
|
3081
3081
|
case 1:
|
|
3082
3082
|
_expectedWrappedAmounts = _a.sent();
|
|
3083
|
-
if (this.
|
|
3083
|
+
if (this.id !== 'atricrypto3') {
|
|
3084
3084
|
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
3085
3085
|
}
|
|
3086
3086
|
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
@@ -3088,7 +3088,7 @@ var Pool = /** @class */ (function () {
|
|
|
3088
3088
|
return [4 /*yield*/, basePool._calcExpectedAmounts(_expectedMetaCoinAmount)];
|
|
3089
3089
|
case 2:
|
|
3090
3090
|
_basePoolExpectedAmounts = _a.sent();
|
|
3091
|
-
return [2 /*return*/, this.
|
|
3091
|
+
return [2 /*return*/, this.id !== 'atricrypto3' ? __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
|
|
3092
3092
|
}
|
|
3093
3093
|
});
|
|
3094
3094
|
}); };
|
|
@@ -3342,7 +3342,7 @@ var Pool = /** @class */ (function () {
|
|
|
3342
3342
|
if (estimateGas) {
|
|
3343
3343
|
return [2 /*return*/, gas.toNumber()];
|
|
3344
3344
|
}
|
|
3345
|
-
gasLimit = curve_1.curve.chainId === 137 && this.
|
|
3345
|
+
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ?
|
|
3346
3346
|
gas.mul(140).div(100) :
|
|
3347
3347
|
gas.mul(130).div(100);
|
|
3348
3348
|
return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
@@ -3420,7 +3420,7 @@ var Pool = /** @class */ (function () {
|
|
|
3420
3420
|
_c.sent();
|
|
3421
3421
|
_c.label = 2;
|
|
3422
3422
|
case 2:
|
|
3423
|
-
if (!(this.
|
|
3423
|
+
if (!(this.id === 'tricrypto2')) return [3 /*break*/, 4];
|
|
3424
3424
|
return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
|
|
3425
3425
|
case 3:
|
|
3426
3426
|
_a = _c.sent();
|
|
@@ -3464,7 +3464,7 @@ var Pool = /** @class */ (function () {
|
|
|
3464
3464
|
return __generator(this, function (_c) {
|
|
3465
3465
|
switch (_c.label) {
|
|
3466
3466
|
case 0:
|
|
3467
|
-
if (!(this.
|
|
3467
|
+
if (!(this.id === 'ib')) return [3 /*break*/, 2];
|
|
3468
3468
|
return [4 /*yield*/, this._calcWithdrawOneCoin(_lpTokenAmount, i, useUnderlying)];
|
|
3469
3469
|
case 1:
|
|
3470
3470
|
_a = _c.sent();
|
|
@@ -3483,7 +3483,7 @@ var Pool = /** @class */ (function () {
|
|
|
3483
3483
|
if (estimateGas) {
|
|
3484
3484
|
return [2 /*return*/, gas.toNumber()];
|
|
3485
3485
|
}
|
|
3486
|
-
gasLimit = curve_1.curve.chainId === 137 && this.
|
|
3486
|
+
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ?
|
|
3487
3487
|
gas.mul(160).div(100) :
|
|
3488
3488
|
gas.mul(130).div(100);
|
|
3489
3489
|
return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
@@ -3497,7 +3497,7 @@ var Pool = /** @class */ (function () {
|
|
|
3497
3497
|
return __generator(this, function (_a) {
|
|
3498
3498
|
switch (_a.label) {
|
|
3499
3499
|
case 0:
|
|
3500
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.
|
|
3500
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.id) ? this.zap : this.swap;
|
|
3501
3501
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
3502
3502
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
3503
3503
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
@@ -3515,8 +3515,11 @@ var Pool = /** @class */ (function () {
|
|
|
3515
3515
|
}
|
|
3516
3516
|
});
|
|
3517
3517
|
}); };
|
|
3518
|
-
var poolData = __assign(__assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {})), (curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA || {}))[
|
|
3519
|
-
this.
|
|
3518
|
+
var poolData = __assign(__assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {})), (curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA || {}))[id];
|
|
3519
|
+
this.id = id;
|
|
3520
|
+
this.name = poolData.name;
|
|
3521
|
+
this.fullName = poolData.full_name;
|
|
3522
|
+
this.symbol = poolData.symbol;
|
|
3520
3523
|
this.referenceAsset = poolData.reference_asset;
|
|
3521
3524
|
this.swap = poolData.swap_address;
|
|
3522
3525
|
this.zap = poolData.deposit_address || null;
|
|
@@ -4125,3 +4128,32 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
4125
4128
|
});
|
|
4126
4129
|
};
|
|
4127
4130
|
exports.crossAssetExchange = crossAssetExchange;
|
|
4131
|
+
var getUserPoolList = function (address) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4132
|
+
var poolNames, promises, _i, poolNames_1, poolName, pool, userPoolList, balances, i;
|
|
4133
|
+
return __generator(this, function (_a) {
|
|
4134
|
+
switch (_a.label) {
|
|
4135
|
+
case 0:
|
|
4136
|
+
if (!address)
|
|
4137
|
+
address = curve_1.curve.signerAddress;
|
|
4138
|
+
address = address;
|
|
4139
|
+
poolNames = __spreadArray(__spreadArray(__spreadArray([], (0, utils_1.getPoolList)(), true), (0, utils_1.getFactoryPoolList)(), true), (0, utils_1.getCryptoFactoryPoolList)(), true);
|
|
4140
|
+
promises = [];
|
|
4141
|
+
for (_i = 0, poolNames_1 = poolNames; _i < poolNames_1.length; _i++) {
|
|
4142
|
+
poolName = poolNames_1[_i];
|
|
4143
|
+
pool = new Pool(poolName);
|
|
4144
|
+
promises.push(pool.lpTokenBalances(address)); // TODO optimization
|
|
4145
|
+
}
|
|
4146
|
+
userPoolList = [];
|
|
4147
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
4148
|
+
case 1:
|
|
4149
|
+
balances = (_a.sent()).map(function (lpBalance) { return Object.values(lpBalance).map(Number).reduce(function (a, b) { return a + b; }); });
|
|
4150
|
+
for (i = 0; i < poolNames.length; i++) {
|
|
4151
|
+
if (balances[i] > 0) {
|
|
4152
|
+
userPoolList.push(poolNames[i]);
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
return [2 /*return*/, userPoolList];
|
|
4156
|
+
}
|
|
4157
|
+
});
|
|
4158
|
+
}); };
|
|
4159
|
+
exports.getUserPoolList = getUserPoolList;
|