@curvefi/api 2.30.1 → 2.31.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.
@@ -35,20 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
38
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedAtricrypto3Mixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
39
+ exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
49
40
  var ethers_1 = require("ethers");
50
41
  var common_1 = require("./common");
51
- var PoolTemplate_1 = require("../PoolTemplate");
52
42
  var utils_1 = require("../../utils");
53
43
  // @ts-ignore
54
44
  exports.withdrawExpectedMixin = {
@@ -94,40 +84,6 @@ exports.withdrawExpectedLendingOrCryptoMixin = {
94
84
  };
95
85
  // @ts-ignore
96
86
  exports.withdrawExpectedMetaMixin = {
97
- withdrawExpected: function (lpTokenAmount) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a, _expected;
100
- var _this = this;
101
- return __generator(this, function (_b) {
102
- switch (_b.label) {
103
- case 0:
104
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
105
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
106
- case 1:
107
- _expectedWrappedAmounts = _b.sent();
108
- _expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
109
- _expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
110
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
111
- if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
112
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
113
- case 2:
114
- _a = _b.sent();
115
- return [3 /*break*/, 5];
116
- case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
117
- case 4:
118
- _a = _b.sent();
119
- _b.label = 5;
120
- case 5:
121
- _basePoolExpectedAmounts = _a;
122
- _expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
123
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
124
- }
125
- });
126
- });
127
- },
128
- };
129
- // @ts-ignore
130
- exports.withdrawExpectedAtricrypto3Mixin = {
131
87
  withdrawExpected: function (lpTokenAmount) {
132
88
  return __awaiter(this, void 0, void 0, function () {
133
89
  var _lpTokenAmount, _expected;
@@ -136,7 +92,7 @@ exports.withdrawExpectedAtricrypto3Mixin = {
136
92
  switch (_a.label) {
137
93
  case 0:
138
94
  _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
139
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
95
+ return [4 /*yield*/, common_1._calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount)];
140
96
  case 1:
141
97
  _expected = _a.sent();
142
98
  return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.withdrawPlainMixin = exports.withdrawLendingOrCryptoMixin = exports.withdrawZapMixin = exports.withdrawCryptoMetaFactoryMixin = exports.withdrawMetaFactoryMixin = void 0;
51
60
  var ethers_1 = require("ethers");
@@ -235,27 +244,31 @@ exports.withdrawZapMixin = {
235
244
  _withdraw: function (_lpTokenAmount, slippage, estimateGas) {
236
245
  if (estimateGas === void 0) { estimateGas = false; }
237
246
  return __awaiter(this, void 0, void 0, function () {
238
- var _minAmounts, contract, gas, gasLimit;
239
- return __generator(this, function (_b) {
240
- switch (_b.label) {
247
+ var _minAmounts, contract, args, gas, gasLimit;
248
+ var _b;
249
+ return __generator(this, function (_c) {
250
+ switch (_c.label) {
241
251
  case 0:
242
252
  if (!!estimateGas) return [3 /*break*/, 2];
243
253
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
244
254
  case 1:
245
- _b.sent();
246
- _b.label = 2;
255
+ _c.sent();
256
+ _c.label = 2;
247
257
  case 2: return [4 /*yield*/, _withdrawMinAmounts.call(this, _lpTokenAmount, slippage)];
248
258
  case 3:
249
- _minAmounts = _b.sent();
259
+ _minAmounts = _c.sent();
250
260
  contract = curve_1.curve.contracts[this.zap].contract;
251
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
261
+ args = [_lpTokenAmount, _minAmounts];
262
+ if ("remove_liquidity(uint256,uint256[".concat(this.underlyingCoinAddresses.length, "],bool)") in contract)
263
+ args.push(true);
264
+ return [4 /*yield*/, (_b = contract.estimateGas).remove_liquidity.apply(_b, __spreadArray(__spreadArray([], args, false), [curve_1.curve.constantOptions], false))];
252
265
  case 4:
253
- gas = _b.sent();
266
+ gas = _c.sent();
254
267
  if (estimateGas)
255
268
  return [2 /*return*/, gas.toNumber()];
256
269
  gasLimit = gas.mul(130).div(100);
257
- return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
258
- case 5: return [2 /*return*/, (_b.sent()).hash];
270
+ return [4 /*yield*/, contract.remove_liquidity.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit })], false))];
271
+ case 5: return [2 /*return*/, (_c.sent()).hash];
259
272
  }
260
273
  });
261
274
  });
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.withdrawOneCoinPlainMixin = exports.withdrawOneCoinLendingOrCryptoMixin = exports.withdrawOneCoinZapMixin = exports.withdrawOneCoinCryptoMetaFactoryMixin = exports.withdrawOneCoinMetaFactoryMixin = void 0;
51
60
  var curve_1 = require("../../curve");
@@ -235,27 +244,31 @@ exports.withdrawOneCoinZapMixin = {
235
244
  _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
236
245
  if (estimateGas === void 0) { estimateGas = false; }
237
246
  return __awaiter(this, void 0, void 0, function () {
238
- var _minAmount, contract, gas, gasLimit;
239
- return __generator(this, function (_a) {
240
- switch (_a.label) {
247
+ var _minAmount, contract, args, gas, gasLimit;
248
+ var _a;
249
+ return __generator(this, function (_b) {
250
+ switch (_b.label) {
241
251
  case 0:
242
252
  if (!!estimateGas) return [3 /*break*/, 2];
243
253
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
244
254
  case 1:
245
- _a.sent();
246
- _a.label = 2;
255
+ _b.sent();
256
+ _b.label = 2;
247
257
  case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
248
258
  case 3:
249
- _minAmount = _a.sent();
259
+ _minAmount = _b.sent();
250
260
  contract = curve_1.curve.contracts[this.zap].contract;
251
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
261
+ args = [_lpTokenAmount, i, _minAmount];
262
+ if ("remove_liquidity_one_coin(uint256,uint256,uint256,bool)" in contract)
263
+ args.push(true);
264
+ return [4 /*yield*/, (_a = contract.estimateGas).remove_liquidity_one_coin.apply(_a, __spreadArray(__spreadArray([], args, false), [curve_1.curve.constantOptions], false))];
252
265
  case 4:
253
- gas = _a.sent();
266
+ gas = _b.sent();
254
267
  if (estimateGas)
255
268
  return [2 /*return*/, gas.toNumber()];
256
269
  gasLimit = gas.mul(130).div(100);
257
- return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
258
- case 5: return [2 /*return*/, (_a.sent()).hash];
270
+ return [4 /*yield*/, contract.remove_liquidity_one_coin.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit })], false))];
271
+ case 5: return [2 /*return*/, (_b.sent()).hash];
259
272
  }
260
273
  });
261
274
  });
@@ -43,10 +43,7 @@ var getPool = function (poolId) {
43
43
  return Pool;
44
44
  }(PoolTemplate_1.PoolTemplate));
45
45
  // statsBalances
46
- if (poolDummy.isFake || (curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // 100 is xDAI
47
- Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesAtricrypto3Mixin);
48
- }
49
- else if (poolDummy.isMeta) {
46
+ if (poolDummy.isMeta) {
50
47
  Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesMetaMixin);
51
48
  }
52
49
  else if (poolDummy.useLending.reduce(function (x, y) { return x || y; })) {
@@ -96,10 +93,7 @@ var getPool = function (poolId) {
96
93
  }
97
94
  }
98
95
  // withdrawExpected
99
- if (poolDummy.isFake || (curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // 100 is xDAI
100
- Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedAtricrypto3Mixin);
101
- }
102
- else if (poolDummy.isMeta) {
96
+ if (poolDummy.isMeta) {
103
97
  Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedMetaMixin);
104
98
  }
105
99
  else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
@@ -212,7 +206,7 @@ var getPool = function (poolId) {
212
206
  }
213
207
  // swap and swapEstimateGas
214
208
  if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract &&
215
- !(curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum); 100 is xDAI
209
+ !(curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum), avaxcrypto (avalanche); 100 is xDAI
216
210
  Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
217
211
  }
218
212
  else if (poolDummy.isMetaFactory && ((0, exports.getPool)(poolDummy.basePool).isLending || (0, exports.getPool)(poolDummy.basePool).isFake || poolDummy.isCrypto)) {
package/lib/router.js CHANGED
@@ -81,8 +81,35 @@ var getNewRoute = function (routeTvl, poolId, poolAddress, inputCoinAddress, out
81
81
  totalTvl: routeTvl.totalTvl + tvl,
82
82
  };
83
83
  };
84
+ // TODO REMOVE IT!!!
85
+ var filterMaticFactory83Route = function (routes) {
86
+ return routes.filter(function (r) {
87
+ for (var _i = 0, _a = r.route; _i < _a.length; _i++) {
88
+ var step = _a[_i];
89
+ if (step.poolId === "factory-crypto-83" && step.inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address)
90
+ return false;
91
+ }
92
+ return true;
93
+ });
94
+ };
95
+ // TODO REMOVE IT!!!
96
+ var filterAvax = function (routes) {
97
+ return routes.filter(function (r) {
98
+ for (var _i = 0, _a = r.route; _i < _a.length; _i++) {
99
+ var step = _a[_i];
100
+ if (step.poolId == 'avaxcrypto' && step.swapType == 4 && (step.i === 3 || step.j === 3))
101
+ return false;
102
+ }
103
+ return true;
104
+ });
105
+ };
84
106
  var MAX_ROUTES_FOR_ONE_COIN = 3;
85
107
  var filterRoutes = function (routes, inputCoinAddress, sortFn) {
108
+ // TODO REMOVE IT!!!
109
+ if (curve_1.curve.chainId === 137)
110
+ routes = filterMaticFactory83Route(routes);
111
+ if (curve_1.curve.chainId === 43114)
112
+ routes = filterAvax(routes);
86
113
  return routes
87
114
  .filter(function (r) { return r.route.length > 0; })
88
115
  .filter(function (r) { return r.route[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
@@ -94,13 +121,6 @@ var filterRoutes = function (routes, inputCoinAddress, sortFn) {
94
121
  };
95
122
  var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.route.length - b.route.length; };
96
123
  var sortByLength = function (a, b) { return a.route.length - b.route.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
97
- // TODO REMOVE IT!!!
98
- var filterMaticFactory83Route = function (routes) {
99
- return routes
100
- .filter(function (r) {
101
- return !(r.route.length === 1 && r.route[0].poolId === "factory-crypto-83" && r.route[0].inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address);
102
- });
103
- };
104
124
  // Inspired by Dijkstra's algorithm
105
125
  var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
106
126
  var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_1, inCoin, routes;
@@ -217,8 +237,8 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
217
237
  if (j === inCoinIndexes.wrapped_coin)
218
238
  return "continue";
219
239
  // Native swaps spend less gas
220
- if (wrapped_coin_addresses[j] !== outputCoinAddress && wrapped_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress)
221
- return "continue";
240
+ // TODO uncomment
241
+ // if (wrapped_coin_addresses[j] !== outputCoinAddress && wrapped_coin_addresses[j] === curve.constants.NATIVE_TOKEN.wrappedAddress) continue;
222
242
  // Looking for outputCoinAddress only on the final step
223
243
  if (step === 3 && wrapped_coin_addresses[j] !== outputCoinAddress)
224
244
  return "continue";
@@ -268,7 +288,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
268
288
  hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
269
289
  swapType = (poolData.is_crypto && poolData.is_meta && poolData.is_factory) ? 6
270
290
  : ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ? 5
271
- : hasEth ? 3
291
+ : hasEth && poolId !== 'avaxcrypto' ? 3
272
292
  : poolData.is_crypto ? 4
273
293
  : 2;
274
294
  newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
@@ -334,9 +354,6 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
334
354
  return [3 /*break*/, 2];
335
355
  case 8:
336
356
  routes = __spreadArray(__spreadArray([], ((_q = routesByTvl[outputCoinAddress]) !== null && _q !== void 0 ? _q : []), true), ((_r = routesByLength[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true);
337
- // TODO REMOVE IT!!!
338
- if (curve_1.curve.chainId === 137)
339
- routes = filterMaticFactory83Route(routes);
340
357
  return [2 /*return*/, routes.map(function (r) { return r.route; })];
341
358
  }
342
359
  });
@@ -523,6 +540,8 @@ var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { return __
523
540
  return [4 /*yield*/, _getBestRoute(inputCoinAddress, outputCoinAddress, amount)];
524
541
  case 1:
525
542
  route = _c.sent();
543
+ if (route.length === 0)
544
+ return [2 /*return*/, { route: route, output: '0.0' }];
526
545
  return [4 /*yield*/, _getOutputForRoute(route, (0, utils_1.parseUnits)(amount, inputCoinDecimals))];
527
546
  case 2:
528
547
  _output = _c.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.30.1",
3
+ "version": "2.31.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",