@curvefi/api 2.1.0 → 2.2.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/lib/router.js CHANGED
@@ -173,7 +173,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
173
173
  // No input coin in this pool --> skip
174
174
  if (inCoinIndexes.wrapped_coin === -1 && inCoinIndexes.underlying_coin === -1 && inCoinIndexes.meta_coin === -1)
175
175
  return [3 /*break*/, 17];
176
- if (!(inCoinIndexes.wrapped_coin >= 0 && poolId !== "atricrypto3")) return [3 /*break*/, 7];
176
+ if (!(inCoinIndexes.wrapped_coin >= 0 && !poolData.is_fake)) return [3 /*break*/, 7];
177
177
  j = 0;
178
178
  _5.label = 4;
179
179
  case 4:
@@ -214,14 +214,14 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
214
214
  j++;
215
215
  return [3 /*break*/, 4];
216
216
  case 7:
217
- poolAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(poolId) ||
218
- (curve_1.curve.chainId === 137 && poolData.is_factory) ? poolData.deposit_address : poolData.swap_address;
217
+ poolAddress = (poolData.is_crypto && poolData.is_meta) || ([137, 43114].includes(curve_1.curve.chainId) && poolData.is_factory) ?
218
+ poolData.deposit_address : poolData.swap_address;
219
219
  if (!(wrapped_coin_addresses.join("|") !== underlying_coin_addresses.join("|") && 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 (poolId === "atricrypto3" && inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
224
+ if (poolData.is_fake && inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
225
225
  return [3 /*break*/, 10];
226
226
  // If this coin already marked or will be marked on the current step, no need to consider it on the next step
227
227
  if (markedCoins.includes(underlying_coin_addresses[j]) || curCoins.includes(underlying_coin_addresses[j]))
@@ -259,7 +259,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
259
259
  j++;
260
260
  return [3 /*break*/, 8];
261
261
  case 11:
262
- if (!(inCoinIndexes.wrapped_coin === 0 && meta_coin_addresses.length > 0 && poolId !== "atricrypto3")) return [3 /*break*/, 15];
262
+ if (!(inCoinIndexes.wrapped_coin === 0 && meta_coin_addresses.length > 0 && !poolData.is_fake)) return [3 /*break*/, 15];
263
263
  j = 0;
264
264
  _5.label = 12;
265
265
  case 12:
@@ -279,7 +279,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
279
279
  // Skip imbalanced pools
280
280
  if (IMBALANCED_POOLS.includes(poolId))
281
281
  return [3 /*break*/, 14];
282
- swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
282
+ swapType = ([137, 43114].includes(curve_1.curve.chainId) && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
283
283
  for (_r = 0, _s = routes[inCoin]; _r < _s.length; _r++) {
284
284
  inCoinRoute = _s[_r];
285
285
  routes[meta_coin_addresses[j]] = ((_2 = routes[meta_coin_addresses[j]]) !== null && _2 !== void 0 ? _2 : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
@@ -300,7 +300,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
300
300
  j++;
301
301
  return [3 /*break*/, 12];
302
302
  case 15:
303
- if (!(inCoinIndexes.meta_coin >= 0 && poolId !== "atricrypto3")) return [3 /*break*/, 17];
303
+ if (!(inCoinIndexes.meta_coin >= 0 && !poolData.is_fake)) return [3 /*break*/, 17];
304
304
  // If this coin already marked or will be marked on the current step, no need to consider it on the next step
305
305
  if (markedCoins.includes(wrapped_coin_addresses[0]) || curCoins.includes(wrapped_coin_addresses[0]))
306
306
  return [3 /*break*/, 17];
@@ -316,7 +316,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
316
316
  // Skip imbalanced pools
317
317
  if (IMBALANCED_POOLS.includes(poolId))
318
318
  return [3 /*break*/, 17];
319
- swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
319
+ swapType = ([137, 43114].includes(curve_1.curve.chainId) && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
320
320
  for (_u = 0, _v = routes[inCoin]; _u < _v.length; _u++) {
321
321
  inCoinRoute = _v[_u];
322
322
  routes[wrapped_coin_addresses[0]] = ((_3 = routes[wrapped_coin_addresses[0]]) !== null && _3 !== void 0 ? _3 : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
@@ -488,7 +488,7 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
488
488
  _estimateGasForDifferentRoutes(routes, inputCoinAddress, outputCoinAddress, _amount),
489
489
  (0, utils_1._getUsdRate)(outputCoinAddress),
490
490
  axios_1.default.get("https://api.curve.fi/api/getGas"),
491
- (0, utils_1._getUsdRate)(curve_1.curve.chainId === 137 ? curve_1.curve.constants.COINS.matic : curve_1.curve.constants.COINS.eth),
491
+ (0, utils_1._getUsdRate)(utils_1.ETH_ADDRESS),
492
492
  ])];
493
493
  case 7:
494
494
  _e = _f.sent(), gasAmounts = _e[0], outputCoinUsdRate = _e[1], gasData = _e[2], ethUsdRate = _e[3];
@@ -541,7 +541,7 @@ var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaite
541
541
  return [4 /*yield*/, _getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
542
542
  case 1:
543
543
  route = _d.sent();
544
- target = (0, utils_1.BN)(Math.pow(10, 12));
544
+ target = (0, utils_1.BN)(Math.pow(10, 15));
545
545
  amountIntBN = (0, utils_1.BN)(amount).times(Math.pow(10, inputCoinDecimals));
546
546
  outputIntBN = (0, utils_1.toBN)(route._output, 0);
547
547
  k = bignumber_js_1.default.min(bignumber_js_1.default.max(target.div(amountIntBN), target.div(outputIntBN)), 0.2);
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ethers } from 'ethers';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { IDict } from './interfaces';
4
+ export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
4
5
  export declare const MAX_ALLOWANCE: ethers.BigNumber;
5
6
  export declare const BN: (val: number | string) => BigNumber;
6
7
  export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
package/lib/utils.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.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
62
+ exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var ethers_1 = require("ethers");
65
65
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
66
66
  var curve_1 = require("./curve");
67
67
  var external_api_1 = require("./external-api");
68
- var ETH_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
68
+ exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
69
69
  exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
70
70
  // bignumber.js
71
71
  var BN = function (val) { return new bignumber_js_1.default(val); };
@@ -110,9 +110,9 @@ var parseUnits = function (n, decimals) {
110
110
  };
111
111
  exports.parseUnits = parseUnits;
112
112
  // -------------------
113
- var isEth = function (address) { return address.toLowerCase() === ETH_ADDRESS.toLowerCase(); };
113
+ var isEth = function (address) { return address.toLowerCase() === exports.ETH_ADDRESS.toLowerCase(); };
114
114
  exports.isEth = isEth;
115
- var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(ETH_ADDRESS.toLowerCase()); };
115
+ var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(exports.ETH_ADDRESS.toLowerCase()); };
116
116
  exports.getEthIndex = getEthIndex;
117
117
  // coins can be either addresses or symbols
118
118
  var _getCoinAddresses = function () {
@@ -404,7 +404,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
404
404
  return __generator(this, function (_h) {
405
405
  switch (_h.label) {
406
406
  case 0:
407
- network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
407
+ network = curve_1.curve.constants.NETWORK_NAME;
408
408
  promises = [
409
409
  (0, external_api_1._getPoolsFromApi)(network, "main"),
410
410
  (0, external_api_1._getPoolsFromApi)(network, "crypto"),
@@ -438,7 +438,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
438
438
  exports._getUsdPricesFromApi = _getUsdPricesFromApi;
439
439
  var _usdRatesCache = {};
440
440
  var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
441
- var pricesFromApi, chainName, url, response;
441
+ var pricesFromApi, chainName, nativeTokenName, url, response;
442
442
  var _a, _b;
443
443
  return __generator(this, function (_c) {
444
444
  switch (_c.label) {
@@ -452,7 +452,12 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
452
452
  chainName = {
453
453
  1: 'ethereum',
454
454
  137: 'polygon-pos',
455
- 1337: 'ethereum',
455
+ 43114: 'avalanche',
456
+ }[curve_1.curve.chainId];
457
+ nativeTokenName = {
458
+ 1: 'ethereum',
459
+ 137: 'matic-network',
460
+ 43114: 'avalanche-2',
456
461
  }[curve_1.curve.chainId];
457
462
  if (chainName === undefined) {
458
463
  throw Error('curve object is not initialized');
@@ -463,14 +468,14 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
463
468
  'ETH': 'ethereum',
464
469
  'LINK': 'link',
465
470
  }[assetId] || assetId;
466
- assetId = (0, exports.isEth)(assetId) ? "ethereum" : assetId.toLowerCase();
471
+ assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
467
472
  // No EURT on Coingecko Polygon
468
473
  if (assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt.toLowerCase()) {
469
474
  chainName = 'ethereum';
470
475
  assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
471
476
  }
472
477
  if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
473
- url = ['bitcoin', 'ethereum', 'link'].includes(assetId.toLowerCase()) ?
478
+ url = [nativeTokenName, 'bitcoin', 'link'].includes(assetId.toLowerCase()) ?
474
479
  "https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
475
480
  "https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
476
481
  return [4 /*yield*/, axios_1.default.get(url)];
@@ -504,10 +509,15 @@ var getTVL = function (chainId) {
504
509
  if (chainId === void 0) { chainId = curve_1.curve.chainId; }
505
510
  return __awaiter(void 0, void 0, void 0, function () {
506
511
  var network, promises, allTypesExtendedPoolData;
507
- return __generator(this, function (_a) {
508
- switch (_a.label) {
512
+ var _a;
513
+ return __generator(this, function (_b) {
514
+ switch (_b.label) {
509
515
  case 0:
510
- network = chainId === 137 ? "polygon" : "ethereum";
516
+ network = (_a = {
517
+ 1: "ethereum",
518
+ 137: "polygon",
519
+ 43114: "avalanche",
520
+ }[chainId]) !== null && _a !== void 0 ? _a : "ethereum";
511
521
  promises = [
512
522
  (0, external_api_1._getPoolsFromApi)(network, "main"),
513
523
  (0, external_api_1._getPoolsFromApi)(network, "crypto"),
@@ -516,7 +526,7 @@ var getTVL = function (chainId) {
516
526
  ];
517
527
  return [4 /*yield*/, Promise.all(promises)];
518
528
  case 1:
519
- allTypesExtendedPoolData = _a.sent();
529
+ allTypesExtendedPoolData = _b.sent();
520
530
  return [2 /*return*/, allTypesExtendedPoolData.reduce(function (sum, data) { var _a; return sum + ((_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll); }, 0)];
521
531
  }
522
532
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",