@curvefi/api 1.13.0 → 1.14.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/curve.js CHANGED
@@ -71,6 +71,7 @@ var address_provider_json_1 = __importDefault(require("./constants/abis/json/add
71
71
  var gaugecontroller_json_1 = __importDefault(require("./constants/abis/json/gaugecontroller.json"));
72
72
  var router_json_1 = __importDefault(require("./constants/abis/json/router.json"));
73
73
  var registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
74
+ var streamer_json_1 = __importDefault(require("./constants/abis/json/streamer.json"));
74
75
  var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
75
76
  var abis_polygon_1 = require("./constants/abis/abis-polygon");
76
77
  var coins_ethereum_1 = require("./constants/coins-ethereum");
@@ -314,6 +315,16 @@ var Curve = /** @class */ (function () {
314
315
  };
315
316
  }
316
317
  }
318
+ if (pool.crv_reward_contract) {
319
+ this.contracts[pool.crv_reward_contract] = {
320
+ contract: new ethers_1.Contract(pool.crv_reward_contract, streamer_json_1.default, this.signer || this.provider),
321
+ multicallContract: new ethcall_1.Contract(pool.crv_reward_contract, streamer_json_1.default),
322
+ };
323
+ this.contracts[pool.crv_reward_contract.toLowerCase()] = {
324
+ contract: new ethers_1.Contract(pool.crv_reward_contract, streamer_json_1.default, this.signer || this.provider),
325
+ multicallContract: new ethcall_1.Contract(pool.crv_reward_contract, streamer_json_1.default),
326
+ };
327
+ }
317
328
  }
318
329
  this.contracts[exports.ALIASES.crv] = {
319
330
  contract: new ethers_1.Contract(exports.ALIASES.crv, ERC20_json_1.default, this.signer || this.provider),
@@ -2,6 +2,7 @@ export interface DictInterface<T> {
2
2
  [index: string]: T;
3
3
  }
4
4
  export interface PoolDataInterface {
5
+ reference_asset: 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO';
5
6
  N_COINS: number;
6
7
  underlying_decimals: number[];
7
8
  decimals: number[];
@@ -48,4 +49,5 @@ export interface PoolDataInterface {
48
49
  reward_token?: string;
49
50
  reward_tokens?: string[];
50
51
  pool_type?: string;
52
+ crv_reward_contract?: string;
51
53
  }
package/lib/pools.d.ts CHANGED
@@ -3,10 +3,12 @@ import BigNumber from 'bignumber.js';
3
3
  import { DictInterface } from './interfaces';
4
4
  export declare class Pool {
5
5
  name: string;
6
+ referenceAsset: string;
6
7
  swap: string;
7
8
  zap: string | null;
8
9
  lpToken: string;
9
10
  gauge: string;
11
+ crvRewardContract: string | null;
10
12
  underlyingCoins: string[];
11
13
  coins: string[];
12
14
  underlyingCoinAddresses: string[];
@@ -41,12 +43,31 @@ export declare class Pool {
41
43
  exchangeWrappedApprove: (inputCoin: string | number, amount: string) => Promise<number>;
42
44
  exchangeWrapped: (inputCoin: string | number, outputCoin: string | number, amount: string, maxSlippage: number) => Promise<number>;
43
45
  };
46
+ stats: {
47
+ getParameters: () => Promise<{
48
+ virtualPrice: string;
49
+ fee: string;
50
+ adminFee: string;
51
+ A: string;
52
+ gamma?: string;
53
+ }>;
54
+ getPoolBalances: () => Promise<string[]>;
55
+ getPoolWrappedBalances: () => Promise<string[]>;
56
+ getTotalLiquidity: () => Promise<string>;
57
+ getVolume: () => Promise<string>;
58
+ getBaseApy: () => Promise<[daily: string, weekly: string, monthly: string, total: string]>;
59
+ getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>;
60
+ };
44
61
  constructor(name: string);
45
62
  calcLpTokenAmount: (amounts: string[], isDeposit?: boolean) => Promise<string>;
46
63
  calcLpTokenAmountWrapped: (amounts: string[], isDeposit?: boolean) => Promise<string>;
47
- getVirtualPrice: () => Promise<string>;
48
- getPoolBalances: () => Promise<string[]>;
49
- getPoolWrappedBalances: () => Promise<string[]>;
64
+ private getParameters;
65
+ private getPoolBalances;
66
+ private getPoolWrappedBalances;
67
+ private getTotalLiquidity;
68
+ private getVolume;
69
+ private getBaseApy;
70
+ private getTokenApy;
50
71
  addLiquidityExpected: (amounts: string[]) => Promise<string>;
51
72
  addLiquiditySlippage: (amounts: string[]) => Promise<string>;
52
73
  addLiquidityIsApproved: (amounts: string[]) => Promise<boolean>;
@@ -121,7 +142,6 @@ export declare class Pool {
121
142
  gaugeMaxBoostedDeposit: (...addresses: string[]) => Promise<DictInterface<string>>;
122
143
  gaugeOptimalDeposits: (...accounts: string[]) => Promise<DictInterface<string>>;
123
144
  boost: (address: string) => Promise<string>;
124
- getApy: () => Promise<string[]>;
125
145
  private _getCoinIdx;
126
146
  private _getRates;
127
147
  private _balances;
package/lib/pools.js CHANGED
@@ -126,14 +126,30 @@ var Pool = /** @class */ (function () {
126
126
  });
127
127
  });
128
128
  };
129
- this.getVirtualPrice = function () { return __awaiter(_this, void 0, void 0, function () {
130
- var _virtualPrice;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_virtual_price(curve_1.curve.constantOptions)];
129
+ this.getParameters = function () { return __awaiter(_this, void 0, void 0, function () {
130
+ var calls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma;
131
+ return __generator(this, function (_d) {
132
+ switch (_d.label) {
133
+ case 0:
134
+ calls = [
135
+ curve_1.curve.contracts[this.swap].multicallContract.get_virtual_price(),
136
+ curve_1.curve.contracts[this.swap].multicallContract.fee(),
137
+ curve_1.curve.contracts[this.swap].multicallContract.admin_fee(),
138
+ curve_1.curve.contracts[this.swap].multicallContract.A(),
139
+ ];
140
+ if (this.isCrypto)
141
+ calls.push(curve_1.curve.contracts[this.swap].multicallContract.gamma());
142
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
134
143
  case 1:
135
- _virtualPrice = _a.sent();
136
- return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_virtualPrice)];
144
+ _a = _d.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
145
+ _c = [
146
+ ethers_1.ethers.utils.formatUnits(_virtualPrice),
147
+ ethers_1.ethers.utils.formatUnits(_fee, 8),
148
+ ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
149
+ ethers_1.ethers.utils.formatUnits(_A, 0),
150
+ _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
151
+ ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
152
+ return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, gamma: gamma }];
137
153
  }
138
154
  });
139
155
  }); };
@@ -180,9 +196,6 @@ var Pool = /** @class */ (function () {
180
196
  return __generator(this, function (_a) {
181
197
  switch (_a.label) {
182
198
  case 0:
183
- if (this.isFake) {
184
- throw Error("".concat(this.name, " pool doesn't have this method"));
185
- }
186
199
  swapContract = curve_1.curve.contracts[this.swap].multicallContract;
187
200
  contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
188
201
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
@@ -192,6 +205,107 @@ var Pool = /** @class */ (function () {
192
205
  }
193
206
  });
194
207
  }); };
208
+ this.getTotalLiquidity = function () { return __awaiter(_this, void 0, void 0, function () {
209
+ var balances, promises, _i, _a, addr, prices, totalLiquidity;
210
+ return __generator(this, function (_c) {
211
+ switch (_c.label) {
212
+ case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
213
+ case 1:
214
+ balances = _c.sent();
215
+ promises = [];
216
+ for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
217
+ addr = _a[_i];
218
+ promises.push((0, utils_1._getUsdRate)(addr));
219
+ }
220
+ return [4 /*yield*/, Promise.all(promises)];
221
+ case 2:
222
+ prices = _c.sent();
223
+ totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
224
+ return [2 /*return*/, String(totalLiquidity)];
225
+ }
226
+ });
227
+ }); };
228
+ this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
229
+ var name, statsUrl, volume, usdRate, _a;
230
+ return __generator(this, function (_c) {
231
+ switch (_c.label) {
232
+ case 0:
233
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
234
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
235
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
236
+ case 1:
237
+ volume = (_c.sent()).data.volume[name] || 0;
238
+ if (!this.isCrypto) return [3 /*break*/, 2];
239
+ _a = 1;
240
+ return [3 /*break*/, 4];
241
+ case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
242
+ case 3:
243
+ _a = _c.sent();
244
+ _c.label = 4;
245
+ case 4:
246
+ usdRate = _a;
247
+ return [2 /*return*/, String(volume * usdRate)];
248
+ }
249
+ });
250
+ }); };
251
+ this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
252
+ var name, statsUrl, apy;
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0:
256
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
257
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
258
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
259
+ case 1:
260
+ apy = (_a.sent()).data.apy;
261
+ return [2 /*return*/, [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); })];
262
+ }
263
+ });
264
+ }); };
265
+ this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
266
+ var rewardContract, totalLiquidityUSD, crvRate, inflation, _a, baseApy, gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _c, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
267
+ return __generator(this, function (_d) {
268
+ switch (_d.label) {
269
+ case 0:
270
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 4];
271
+ rewardContract = curve_1.curve.contracts[this.crvRewardContract].contract;
272
+ return [4 /*yield*/, this.getTotalLiquidity()];
273
+ case 1:
274
+ totalLiquidityUSD = _d.sent();
275
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
276
+ case 2:
277
+ crvRate = _d.sent();
278
+ _a = utils_1.toBN;
279
+ return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
280
+ case 3:
281
+ inflation = _a.apply(void 0, [(_d.sent()).rate]);
282
+ baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
283
+ return [2 /*return*/, [baseApy.times(100).toFixed(4), ""]];
284
+ case 4:
285
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
286
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
287
+ gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
288
+ return [4 /*yield*/, this.getTotalLiquidity()];
289
+ case 5:
290
+ totalLiquidityUSD = _d.sent();
291
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
292
+ gaugeContract.inflation_rate(),
293
+ gaugeControllerContract.gauge_relative_weight(this.gauge),
294
+ gaugeContract.working_supply(),
295
+ lpTokenContract.totalSupply(),
296
+ ])];
297
+ case 6:
298
+ _c = (_d.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _c[0], weight = _c[1], workingSupply = _c[2], totalSupply = _c[3];
299
+ rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
300
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
301
+ case 7:
302
+ crvRate = _d.sent();
303
+ baseApy = rate.times(crvRate);
304
+ boostedApy = baseApy.times(2.5);
305
+ return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
306
+ }
307
+ });
308
+ }); };
195
309
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
196
310
  var _this = this;
197
311
  return __generator(this, function (_a) {
@@ -1718,32 +1832,6 @@ var Pool = /** @class */ (function () {
1718
1832
  }
1719
1833
  });
1720
1834
  }); };
1721
- this.getApy = function () { return __awaiter(_this, void 0, void 0, function () {
1722
- var swapContract, gaugeContract, gaugeControllerContract, _a, inflation, weight, workingSupply, virtualPrice, rate, crvRate, baseApy, boostedApy;
1723
- return __generator(this, function (_c) {
1724
- switch (_c.label) {
1725
- case 0:
1726
- swapContract = curve_1.curve.contracts[this.swap].multicallContract;
1727
- gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
1728
- gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
1729
- return [4 /*yield*/, curve_1.curve.multicallProvider.all([
1730
- gaugeContract.inflation_rate(),
1731
- gaugeControllerContract.gauge_relative_weight(this.gauge),
1732
- gaugeContract.working_supply(),
1733
- swapContract.get_virtual_price(),
1734
- ])];
1735
- case 1:
1736
- _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
1737
- rate = inflation.times(weight).times(31536000).div(workingSupply).times(0.4).div(virtualPrice);
1738
- return [4 /*yield*/, (0, utils_1.getCrvRate)()];
1739
- case 2:
1740
- crvRate = _c.sent();
1741
- baseApy = rate.times(crvRate);
1742
- boostedApy = baseApy.times(2.5);
1743
- return [2 /*return*/, [baseApy.toFixed(4), boostedApy.toFixed(4)]];
1744
- }
1745
- });
1746
- }); };
1747
1835
  this._getCoinIdx = function (coin, useUnderlying) {
1748
1836
  if (useUnderlying === void 0) { useUnderlying = true; }
1749
1837
  if (typeof coin === 'number') {
@@ -2647,10 +2735,12 @@ var Pool = /** @class */ (function () {
2647
2735
  }); };
2648
2736
  var poolData = curve_1.POOLS_DATA[name];
2649
2737
  this.name = name;
2738
+ this.referenceAsset = poolData.reference_asset;
2650
2739
  this.swap = poolData.swap_address;
2651
2740
  this.zap = poolData.deposit_address || null;
2652
2741
  this.lpToken = poolData.token_address;
2653
2742
  this.gauge = poolData.gauge_address;
2743
+ this.crvRewardContract = poolData.crv_reward_contract || null;
2654
2744
  this.underlyingCoins = poolData.underlying_coins;
2655
2745
  this.coins = poolData.coins;
2656
2746
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -2685,6 +2775,15 @@ var Pool = /** @class */ (function () {
2685
2775
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2686
2776
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2687
2777
  };
2778
+ this.stats = {
2779
+ getParameters: this.getParameters,
2780
+ getPoolBalances: this.getPoolBalances,
2781
+ getPoolWrappedBalances: this.getPoolWrappedBalances,
2782
+ getTotalLiquidity: this.getTotalLiquidity,
2783
+ getVolume: this.getVolume,
2784
+ getBaseApy: this.getBaseApy,
2785
+ getTokenApy: this.getTokenApy,
2786
+ };
2688
2787
  if (this.isMeta && !this.isFake) {
2689
2788
  var metaCoins = poolData.meta_coin_addresses;
2690
2789
  var metaCoinDecimals = poolData.meta_coin_decimals;
package/lib/utils.d.ts CHANGED
@@ -20,5 +20,5 @@ export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumb
20
20
  export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: string[], spender: string) => Promise<number>;
21
21
  export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
22
22
  export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
23
- export declare const getCrvRate: () => Promise<number>;
24
23
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
24
+ export declare const _getStatsUrl: (isCrypto?: boolean) => string;
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._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;
62
+ exports._getStatsUrl = exports._getUsdRate = 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"));
@@ -72,12 +72,12 @@ var BN = function (val) { return new bignumber_js_1.default(val); };
72
72
  exports.BN = BN;
73
73
  var toBN = function (n, decimals) {
74
74
  if (decimals === void 0) { decimals = 18; }
75
- return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals)).times(decimals);
75
+ return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
76
76
  };
77
77
  exports.toBN = toBN;
78
78
  var toStringFromBN = function (bn, decimals) {
79
79
  if (decimals === void 0) { decimals = 18; }
80
- return bn.div(decimals).toFixed(decimals);
80
+ return bn.toFixed(decimals);
81
81
  };
82
82
  exports.toStringFromBN = toStringFromBN;
83
83
  var fromBN = function (bn, decimals) {
@@ -373,41 +373,39 @@ var getPoolNameBySwapAddress = function (swapAddress) {
373
373
  })[0][0];
374
374
  };
375
375
  exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
376
- var _crvRateCache = {
377
- 'rate': 0,
378
- 'time': 0,
379
- };
380
- var getCrvRate = function () { return __awaiter(void 0, void 0, void 0, function () {
381
- var crvAddress, response;
382
- return __generator(this, function (_a) {
383
- switch (_a.label) {
384
- case 0:
385
- crvAddress = "0xd533a949740bb3306d119cc777fa900ba034cd52";
386
- crvAddress = crvAddress.toLowerCase();
387
- if (!(_crvRateCache.time + 60000 < Date.now())) return [3 /*break*/, 2];
388
- return [4 /*yield*/, axios_1.default.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=".concat(crvAddress, "&vs_currencies=usd"))];
389
- case 1:
390
- response = _a.sent();
391
- _crvRateCache['rate'] = response.data[crvAddress]['usd'];
392
- _crvRateCache['time'] = Date.now();
393
- _a.label = 2;
394
- case 2: return [2 /*return*/, _crvRateCache['rate']];
395
- }
396
- });
397
- }); };
398
- exports.getCrvRate = getCrvRate;
399
376
  var _usdRatesCache = {};
400
377
  var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
401
- var url, response;
378
+ var chainName, url, response;
402
379
  var _a;
403
380
  return __generator(this, function (_b) {
404
381
  switch (_b.label) {
405
382
  case 0:
383
+ if (assetId === 'USD' || (curve_1.curve.chainId === 137 && (assetId.toLowerCase() === curve_2.COINS.am3crv.toLowerCase())))
384
+ return [2 /*return*/, 1];
385
+ chainName = {
386
+ 1: 'ethereum',
387
+ 137: 'polygon-pos',
388
+ 1337: 'ethereum',
389
+ }[curve_1.curve.chainId];
390
+ if (chainName === undefined) {
391
+ throw Error('curve object is not initialized');
392
+ }
393
+ assetId = {
394
+ 'EUR': curve_2.COINS.eurt,
395
+ 'BTC': 'bitcoin',
396
+ 'ETH': 'ethereum',
397
+ 'LINK': 'link',
398
+ }[assetId] || assetId;
406
399
  assetId = (0, exports.isEth)(assetId) ? "ethereum" : assetId.toLowerCase();
400
+ // No EURT on Coingecko Polygon
401
+ if (assetId.toLowerCase() === curve_2.COINS.eurt.toLowerCase()) {
402
+ chainName = 'ethereum';
403
+ assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
404
+ }
407
405
  if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 2];
408
- url = assetId.toLowerCase() === "ethereum" ?
406
+ url = ['bitcoin', 'ethereum', 'link'].includes(assetId.toLowerCase()) ?
409
407
  "https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
410
- "https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=".concat(assetId, "&vs_currencies=usd");
408
+ "https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
411
409
  return [4 /*yield*/, axios_1.default.get(url)];
412
410
  case 1:
413
411
  response = _b.sent();
@@ -418,3 +416,16 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
418
416
  });
419
417
  }); };
420
418
  exports._getUsdRate = _getUsdRate;
419
+ var _getStatsUrl = function (isCrypto) {
420
+ if (isCrypto === void 0) { isCrypto = false; }
421
+ if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
422
+ return isCrypto ? "http://stats.curve.fi/raw-stats-crypto/apys.json" : "http://stats.curve.fi/raw-stats/apys.json";
423
+ }
424
+ else if (curve_1.curve.chainId === 137) {
425
+ return "http://stats.curve.fi/raw-stats-polygon/apys.json";
426
+ }
427
+ else {
428
+ throw Error("Unsupported network id".concat(curve_1.curve.chainId));
429
+ }
430
+ };
431
+ exports._getStatsUrl = _getStatsUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {