@curvefi/api 1.8.2 → 1.10.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/utils.d.ts CHANGED
@@ -21,3 +21,4 @@ export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: stri
21
21
  export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
22
22
  export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
23
23
  export declare const getCrvRate: () => Promise<number>;
24
+ export declare const _getUsdRate: (assetId: string) => Promise<number>;
package/lib/utils.js CHANGED
@@ -59,7 +59,7 @@ 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.getCrvRate = 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.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
62
+ exports._getUsdRate = exports.getCrvRate = 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.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = 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"));
@@ -107,7 +107,7 @@ var _getCoinAddresses = function () {
107
107
  for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
108
108
  var coinAddr = coinAddresses_1[_a];
109
109
  if (!availableAddresses.includes(coinAddr.toLowerCase()))
110
- throw Error("Coin with address '" + coinAddr + "' is not available");
110
+ throw Error("Coin with address '".concat(coinAddr, "' is not available"));
111
111
  }
112
112
  return coinAddresses;
113
113
  };
@@ -388,7 +388,7 @@ var getCrvRate = function () { return __awaiter(void 0, void 0, void 0, function
388
388
  crvAddress = "0xd533a949740bb3306d119cc777fa900ba034cd52";
389
389
  crvAddress = crvAddress.toLowerCase();
390
390
  if (!(_crvRateCache.time + 60000 < Date.now())) return [3 /*break*/, 2];
391
- return [4 /*yield*/, axios_1.default.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=" + crvAddress + "&vs_currencies=usd")];
391
+ return [4 /*yield*/, axios_1.default.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=".concat(crvAddress, "&vs_currencies=usd"))];
392
392
  case 1:
393
393
  response = _a.sent();
394
394
  _crvRateCache['rate'] = response.data[crvAddress]['usd'];
@@ -399,3 +399,25 @@ var getCrvRate = function () { return __awaiter(void 0, void 0, void 0, function
399
399
  });
400
400
  }); };
401
401
  exports.getCrvRate = getCrvRate;
402
+ var _usdRatesCache = {};
403
+ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
404
+ var url, response;
405
+ var _a;
406
+ return __generator(this, function (_b) {
407
+ switch (_b.label) {
408
+ case 0:
409
+ assetId = (0, exports.isEth)(assetId) ? "ethereum" : assetId.toLowerCase();
410
+ if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 2];
411
+ url = assetId.toLowerCase() === "ethereum" ?
412
+ "https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
413
+ "https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=".concat(assetId, "&vs_currencies=usd");
414
+ return [4 /*yield*/, axios_1.default.get(url)];
415
+ case 1:
416
+ response = _b.sent();
417
+ _usdRatesCache[assetId] = { 'rate': response.data[assetId]['usd'], 'time': Date.now() };
418
+ _b.label = 2;
419
+ case 2: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
420
+ }
421
+ });
422
+ }); };
423
+ exports._getUsdRate = _getUsdRate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.8.2",
3
+ "version": "1.10.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {