@curvefi/api 2.6.0 → 2.8.1

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/lib/router.js CHANGED
@@ -216,12 +216,13 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
216
216
  case 7:
217
217
  poolAddress = (poolData.is_crypto && poolData.is_meta) || (base_pool && base_pool.is_meta && poolData.is_factory) ?
218
218
  poolData.deposit_address : poolData.swap_address;
219
- if (!(wrapped_coin_addresses.join("|") !== underlying_coin_addresses.join("|") && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 11];
219
+ if (!(!poolData.is_plain && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 11];
220
220
  j = 0;
221
221
  _5.label = 8;
222
222
  case 8:
223
223
  if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 11];
224
- if (poolData.is_fake && inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
224
+ // Don't swap metacoins since they can be swapped directly in base pool
225
+ if (inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
225
226
  return [3 /*break*/, 10];
226
227
  // If this coin already marked or will be marked on the current step, no need to consider it on the next step
227
228
  if (markedCoins.includes(underlying_coin_addresses[j]) || curCoins.includes(underlying_coin_addresses[j]))
@@ -430,6 +431,13 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
430
431
  case 0:
431
432
  _a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
432
433
  _amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
434
+ if (_amount.eq(0))
435
+ return [2 /*return*/, {
436
+ steps: [],
437
+ _output: ethers_1.ethers.BigNumber.from(0),
438
+ outputUsd: 0,
439
+ txCostUsd: 0,
440
+ }];
433
441
  return [4 /*yield*/, (0, exports._findAllRoutes)(inputCoinAddress, outputCoinAddress)];
434
442
  case 1:
435
443
  routesRaw = (_f.sent()).map(function (steps) { return ({ steps: steps, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 }); });
@@ -466,7 +474,7 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
466
474
  res = _f.sent();
467
475
  for (i = 0; i < res.length; i++) {
468
476
  if (res[i].status === 'rejected') {
469
- console.log("Route ".concat((routesRaw[i].steps.map(function (s) { return s.poolId; })).join(" --> "), " is anavailable"));
477
+ console.log("Route ".concat((routesRaw[i].steps.map(function (s) { return s.poolId; })).join(" --> "), " is unavailable"));
470
478
  continue;
471
479
  }
472
480
  routesRaw[i]._output = res[i].value;
@@ -603,6 +611,8 @@ var swapEstimateGas = function (inputCoin, outputCoin, amount) { return __awaite
603
611
  return [4 /*yield*/, _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
604
612
  case 1:
605
613
  route = _b.sent();
614
+ if (route.steps.length === 0)
615
+ return [2 /*return*/, 0];
606
616
  _amount = (0, utils_1.parseUnits)(amount, inputCoinDecimals);
607
617
  return [4 /*yield*/, _estimateGasForDifferentRoutes([route], inputCoinAddress, outputCoinAddress, _amount)];
608
618
  case 2:
package/lib/utils.js CHANGED
@@ -240,7 +240,7 @@ var _getAllowance = function (coins, address, spender) { return __awaiter(void 0
240
240
  _coins.splice(ethIndex, 1);
241
241
  }
242
242
  if (!(_coins.length === 1)) return [3 /*break*/, 2];
243
- return [4 /*yield*/, curve_1.curve.contracts[_coins[0]].contract.allowance(address, spender)];
243
+ return [4 /*yield*/, curve_1.curve.contracts[_coins[0]].contract.allowance(address, spender, curve_1.curve.constantOptions)];
244
244
  case 1:
245
245
  allowance = [_a.sent()];
246
246
  return [3 /*break*/, 4];
@@ -452,6 +452,8 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
452
452
  return [2 /*return*/, 1];
453
453
  chainName = {
454
454
  1: 'ethereum',
455
+ 10: 'optimistic-ethereum',
456
+ 100: 'xdai',
455
457
  137: 'polygon-pos',
456
458
  250: 'fantom',
457
459
  43114: 'avalanche',
@@ -459,6 +461,8 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
459
461
  }[curve_1.curve.chainId];
460
462
  nativeTokenName = {
461
463
  1: 'ethereum',
464
+ 10: 'ethereum',
465
+ 100: 'xdai',
462
466
  137: 'matic-network',
463
467
  250: 'fantom',
464
468
  43114: 'avalanche-2',
@@ -525,6 +529,8 @@ var getTVL = function (chainId) {
525
529
  case 0:
526
530
  network = (_a = {
527
531
  1: "ethereum",
532
+ 10: 'optimism',
533
+ 100: 'xdai',
528
534
  137: "polygon",
529
535
  250: "fantom",
530
536
  43114: "avalanche",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.6.0",
3
+ "version": "2.8.1",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",