@curvefi/api 2.21.4 → 2.21.6
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.
|
@@ -70,6 +70,7 @@ var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/fa
|
|
|
70
70
|
var constants_1 = require("./constants");
|
|
71
71
|
var constants_crypto_1 = require("./constants-crypto");
|
|
72
72
|
var common_1 = require("./common");
|
|
73
|
+
var external_api_1 = require("../external-api");
|
|
73
74
|
function setFactorySwapContracts(rawPoolList, isCrypto) {
|
|
74
75
|
var _this = this;
|
|
75
76
|
if (isCrypto) {
|
|
@@ -131,27 +132,25 @@ function setFactoryCoinsContracts(rawPoolList) {
|
|
|
131
132
|
}
|
|
132
133
|
function getFactoryPoolsDataFromApi(isCrypto) {
|
|
133
134
|
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
-
var network, factoryType,
|
|
135
|
+
var network, factoryType, rawPoolList, mainAddresses, url, response, poolGaugeDict, _i, _a, gaugeData, i, FACTORY_POOLS_DATA;
|
|
135
136
|
var _this = this;
|
|
136
137
|
return __generator(this, function (_b) {
|
|
137
138
|
switch (_b.label) {
|
|
138
139
|
case 0:
|
|
139
140
|
network = this.constants.NETWORK_NAME;
|
|
140
141
|
factoryType = isCrypto ? "factory-crypto" : "factory";
|
|
141
|
-
|
|
142
|
-
return [4 /*yield*/, axios_1.default.get(url)];
|
|
142
|
+
return [4 /*yield*/, (0, external_api_1._getPoolsFromApi)(network, factoryType)];
|
|
143
143
|
case 1:
|
|
144
|
-
|
|
145
|
-
rawPoolList = response.data.data.poolData;
|
|
144
|
+
rawPoolList = (_b.sent()).poolData;
|
|
146
145
|
mainAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
147
146
|
rawPoolList = rawPoolList.filter(function (p) { return !mainAddresses.includes(p.address.toLowerCase()); });
|
|
148
147
|
if (!(this.chainId !== 1)) return [3 /*break*/, 3];
|
|
149
|
-
|
|
150
|
-
return [4 /*yield*/, axios_1.default.get(
|
|
148
|
+
url = "https://api.curve.fi/api/getFactoGauges/".concat(network);
|
|
149
|
+
return [4 /*yield*/, axios_1.default.get(url)];
|
|
151
150
|
case 2:
|
|
152
|
-
|
|
151
|
+
response = _b.sent();
|
|
153
152
|
poolGaugeDict = {};
|
|
154
|
-
for (_i = 0, _a =
|
|
153
|
+
for (_i = 0, _a = response.data.data.gauges; _i < _a.length; _i++) {
|
|
155
154
|
gaugeData = _a[_i];
|
|
156
155
|
poolGaugeDict[gaugeData.swap] = gaugeData.gauge;
|
|
157
156
|
}
|
|
@@ -157,14 +157,14 @@ export declare class PoolTemplate {
|
|
|
157
157
|
private depositAndStakeApproveEstimateGas;
|
|
158
158
|
depositAndStakeApprove(amounts: (number | string)[]): Promise<string[]>;
|
|
159
159
|
private depositAndStakeEstimateGas;
|
|
160
|
-
depositAndStake(amounts: (number | string)[]): Promise<string>;
|
|
160
|
+
depositAndStake(amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
161
161
|
depositAndStakeWrappedExpected(amounts: (number | string)[]): Promise<string>;
|
|
162
162
|
depositAndStakeWrappedBonus(amounts: (number | string)[]): Promise<string>;
|
|
163
163
|
depositAndStakeWrappedIsApproved(amounts: (number | string)[]): Promise<boolean>;
|
|
164
164
|
private depositAndStakeWrappedApproveEstimateGas;
|
|
165
165
|
depositAndStakeWrappedApprove(amounts: (number | string)[]): Promise<string[]>;
|
|
166
166
|
private depositAndStakeWrappedEstimateGas;
|
|
167
|
-
depositAndStakeWrapped(amounts: (number | string)[]): Promise<string>;
|
|
167
|
+
depositAndStakeWrapped(amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
168
168
|
private _depositAndStake;
|
|
169
169
|
withdrawExpected(lpTokenAmount: number | string): Promise<string[]>;
|
|
170
170
|
withdrawIsApproved(lpTokenAmount: number | string): Promise<boolean>;
|
|
@@ -1046,7 +1046,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1046
1046
|
});
|
|
1047
1047
|
});
|
|
1048
1048
|
};
|
|
1049
|
-
// Used by mixin. Don't delete it!!!
|
|
1050
1049
|
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1051
1050
|
var promises, _i, _c, addr;
|
|
1052
1051
|
return __generator(this, function (_d) {
|
|
@@ -1062,7 +1061,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1062
1061
|
}
|
|
1063
1062
|
});
|
|
1064
1063
|
}); };
|
|
1065
|
-
// Used by mixin. Don't delete it!!!
|
|
1066
1064
|
// NOTE! It may crash!
|
|
1067
1065
|
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1068
1066
|
var promises, _i, _c, addr;
|
|
@@ -1328,26 +1326,34 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1328
1326
|
};
|
|
1329
1327
|
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1330
1328
|
return __awaiter(this, void 0, void 0, function () {
|
|
1331
|
-
var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN,
|
|
1332
|
-
return __generator(this, function (
|
|
1333
|
-
switch (
|
|
1329
|
+
var amountsBN, prices, _c, pricesBN, balancesBN, balancedAmounts, expectedBN, _d, balancedExpectedBN, _e;
|
|
1330
|
+
return __generator(this, function (_f) {
|
|
1331
|
+
switch (_f.label) {
|
|
1334
1332
|
case 0:
|
|
1335
1333
|
amountsBN = amounts.map(utils_1.BN);
|
|
1334
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
1336
1335
|
return [4 /*yield*/, this._underlyingPrices()];
|
|
1337
1336
|
case 1:
|
|
1338
|
-
|
|
1339
|
-
return [
|
|
1337
|
+
_c = _f.sent();
|
|
1338
|
+
return [3 /*break*/, 3];
|
|
1340
1339
|
case 2:
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
_c = utils_1.BN;
|
|
1344
|
-
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1340
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
1341
|
+
_f.label = 3;
|
|
1345
1342
|
case 3:
|
|
1346
|
-
|
|
1343
|
+
prices = _c;
|
|
1344
|
+
pricesBN = prices.map(utils_1.BN);
|
|
1345
|
+
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
1346
|
+
case 4:
|
|
1347
|
+
balancesBN = (_f.sent()).map(utils_1.BN);
|
|
1348
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1347
1349
|
_d = utils_1.BN;
|
|
1350
|
+
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1351
|
+
case 5:
|
|
1352
|
+
expectedBN = _d.apply(void 0, [_f.sent()]);
|
|
1353
|
+
_e = utils_1.BN;
|
|
1348
1354
|
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
1349
|
-
case
|
|
1350
|
-
balancedExpectedBN =
|
|
1355
|
+
case 6:
|
|
1356
|
+
balancedExpectedBN = _e.apply(void 0, [_f.sent()]);
|
|
1351
1357
|
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1352
1358
|
}
|
|
1353
1359
|
});
|
|
@@ -1888,13 +1894,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1888
1894
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1889
1895
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1890
1896
|
}
|
|
1891
|
-
return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
|
|
1897
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, true, true)];
|
|
1892
1898
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1893
1899
|
}
|
|
1894
1900
|
});
|
|
1895
1901
|
});
|
|
1896
1902
|
};
|
|
1897
|
-
PoolTemplate.prototype.depositAndStake = function (amounts) {
|
|
1903
|
+
PoolTemplate.prototype.depositAndStake = function (amounts, slippage) {
|
|
1904
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
1898
1905
|
return __awaiter(this, void 0, void 0, function () {
|
|
1899
1906
|
return __generator(this, function (_c) {
|
|
1900
1907
|
switch (_c.label) {
|
|
@@ -1902,7 +1909,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1902
1909
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1903
1910
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1904
1911
|
}
|
|
1905
|
-
return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
|
|
1912
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, true, false)];
|
|
1906
1913
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1907
1914
|
}
|
|
1908
1915
|
});
|
|
@@ -2037,13 +2044,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2037
2044
|
}
|
|
2038
2045
|
if (this.isPlain || this.isFake)
|
|
2039
2046
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2040
|
-
return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
|
|
2047
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, false, true)];
|
|
2041
2048
|
case 1: return [2 /*return*/, _c.sent()];
|
|
2042
2049
|
}
|
|
2043
2050
|
});
|
|
2044
2051
|
});
|
|
2045
2052
|
};
|
|
2046
|
-
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts) {
|
|
2053
|
+
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts, slippage) {
|
|
2054
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
2047
2055
|
return __awaiter(this, void 0, void 0, function () {
|
|
2048
2056
|
return __generator(this, function (_c) {
|
|
2049
2057
|
switch (_c.label) {
|
|
@@ -2053,15 +2061,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2053
2061
|
}
|
|
2054
2062
|
if (this.isPlain || this.isFake)
|
|
2055
2063
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2056
|
-
return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
|
|
2064
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, false, false)];
|
|
2057
2065
|
case 1: return [2 /*return*/, _c.sent()];
|
|
2058
2066
|
}
|
|
2059
2067
|
});
|
|
2060
2068
|
});
|
|
2061
2069
|
};
|
|
2062
|
-
PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
|
|
2070
|
+
PoolTemplate.prototype._depositAndStake = function (amounts, slippage, isUnderlying, estimateGas) {
|
|
2063
2071
|
return __awaiter(this, void 0, void 0, function () {
|
|
2064
|
-
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying,
|
|
2072
|
+
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _expectedLpTokenAmount, _j, _k, _l, _m, _o, minAmountBN, _minMintAmount, ethIndex, value, i, _gas, gasLimit;
|
|
2065
2073
|
return __generator(this, function (_q) {
|
|
2066
2074
|
switch (_q.label) {
|
|
2067
2075
|
case 0:
|
|
@@ -2123,16 +2131,18 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2123
2131
|
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
2124
2132
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
2125
2133
|
case 13:
|
|
2126
|
-
_j = _l.apply(_k, [_q.sent()])
|
|
2134
|
+
_j = _l.apply(_k, [_q.sent()]);
|
|
2127
2135
|
return [3 /*break*/, 16];
|
|
2128
2136
|
case 14:
|
|
2129
2137
|
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
2130
2138
|
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
2131
2139
|
case 15:
|
|
2132
|
-
_j = _o.apply(_m, [_q.sent()])
|
|
2140
|
+
_j = _o.apply(_m, [_q.sent()]);
|
|
2133
2141
|
_q.label = 16;
|
|
2134
2142
|
case 16:
|
|
2135
|
-
|
|
2143
|
+
_expectedLpTokenAmount = _j;
|
|
2144
|
+
minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
2145
|
+
_minMintAmount = (0, utils_1.fromBN)(minAmountBN);
|
|
2136
2146
|
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
2137
2147
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
2138
2148
|
for (i = 0; i < 5; i++) {
|
|
@@ -2261,19 +2271,27 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2261
2271
|
};
|
|
2262
2272
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
2263
2273
|
return __awaiter(this, void 0, void 0, function () {
|
|
2264
|
-
var prices, value, lpTokenAmount, balancedAmounts, balancedValue;
|
|
2265
|
-
return __generator(this, function (
|
|
2266
|
-
switch (
|
|
2267
|
-
case 0:
|
|
2274
|
+
var prices, _c, value, lpTokenAmount, balancedAmounts, balancedValue;
|
|
2275
|
+
return __generator(this, function (_d) {
|
|
2276
|
+
switch (_d.label) {
|
|
2277
|
+
case 0:
|
|
2278
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2279
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2268
2280
|
case 1:
|
|
2269
|
-
|
|
2281
|
+
_c = _d.sent();
|
|
2282
|
+
return [3 /*break*/, 3];
|
|
2283
|
+
case 2:
|
|
2284
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2285
|
+
_d.label = 3;
|
|
2286
|
+
case 3:
|
|
2287
|
+
prices = _c;
|
|
2270
2288
|
value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2271
2289
|
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
2272
|
-
case
|
|
2273
|
-
lpTokenAmount =
|
|
2290
|
+
case 4:
|
|
2291
|
+
lpTokenAmount = _d.sent();
|
|
2274
2292
|
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2275
|
-
case
|
|
2276
|
-
balancedAmounts =
|
|
2293
|
+
case 5:
|
|
2294
|
+
balancedAmounts = _d.sent();
|
|
2277
2295
|
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2278
2296
|
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2279
2297
|
}
|
|
@@ -2440,21 +2458,29 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2440
2458
|
};
|
|
2441
2459
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2442
2460
|
return __awaiter(this, void 0, void 0, function () {
|
|
2443
|
-
var prices, coinPrice, amount,
|
|
2444
|
-
return __generator(this, function (
|
|
2445
|
-
switch (
|
|
2446
|
-
case 0:
|
|
2461
|
+
var prices, _c, coinPrice, amount, _d, value, balancedAmounts, balancedValue;
|
|
2462
|
+
return __generator(this, function (_e) {
|
|
2463
|
+
switch (_e.label) {
|
|
2464
|
+
case 0:
|
|
2465
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2466
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2447
2467
|
case 1:
|
|
2448
|
-
|
|
2468
|
+
_c = _e.sent();
|
|
2469
|
+
return [3 /*break*/, 3];
|
|
2470
|
+
case 2:
|
|
2471
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2472
|
+
_e.label = 3;
|
|
2473
|
+
case 3:
|
|
2474
|
+
prices = _c;
|
|
2449
2475
|
coinPrice = prices[this._getCoinIdx(coin)];
|
|
2450
|
-
|
|
2476
|
+
_d = Number;
|
|
2451
2477
|
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
2452
|
-
case
|
|
2453
|
-
amount =
|
|
2478
|
+
case 4:
|
|
2479
|
+
amount = _d.apply(void 0, [_e.sent()]);
|
|
2454
2480
|
value = amount * coinPrice;
|
|
2455
2481
|
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2456
|
-
case
|
|
2457
|
-
balancedAmounts =
|
|
2482
|
+
case 5:
|
|
2483
|
+
balancedAmounts = _e.sent();
|
|
2458
2484
|
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2459
2485
|
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2460
2486
|
}
|