@curvefi/api 1.25.1 → 1.25.2

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.
@@ -43,7 +43,7 @@ exports.POOLS_DATA_POLYGON = {
43
43
  swap_abi: swap_json_1.default,
44
44
  sCurveRewards_abi: rewards_json_1.default,
45
45
  sCurveRewards_address: '0xBdFF0C27dd073C119ebcb1299a68A6A92aE607F0',
46
- reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af", "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"],
46
+ reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af"],
47
47
  reward_contract: "0xC48f4653dd6a9509De44c92beb0604BEA3AEe714",
48
48
  gauge_abi: gauge_rewards_only_json_1.default,
49
49
  },
@@ -74,7 +74,7 @@ exports.POOLS_DATA_POLYGON = {
74
74
  ],
75
75
  swap_abi: swap_json_2.default,
76
76
  reward_contract: "0x488E6ef919C2bB9de535C634a80afb0114DA8F62",
77
- reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af", "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"],
77
+ reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af"],
78
78
  gauge_abi: gauge_rewards_only_json_1.default,
79
79
  },
80
80
  atricrypto3: {
@@ -118,7 +118,7 @@ exports.POOLS_DATA_POLYGON = {
118
118
  '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', // USDT
119
119
  ],
120
120
  reward_contract: "0x060e386eCfBacf42Aa72171Af9EFe17b3993fC4F",
121
- reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af", "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"],
121
+ reward_tokens: ["0x172370d5cd63279efa6d502dab29171933a610af"],
122
122
  gauge_abi: gauge_rewards_only_json_1.default,
123
123
  },
124
124
  eurtusd: {
@@ -1,3 +1,4 @@
1
- import { IExtendedPoolDataFromApi } from "./interfaces";
1
+ import { IExtendedPoolDataFromApi, IReward, DictInterface } from "./interfaces";
2
2
  import memoize from "memoizee";
3
3
  export declare const _getPoolsFromApi: ((network: "ethereum" | "polygon", poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: "ethereum" | "polygon", poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>>;
4
+ export declare const _getMainPoolsGaugeRewards: (() => Promise<DictInterface<IReward[]>>) & memoize.Memoized<() => Promise<DictInterface<IReward[]>>>;
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports._getPoolsFromApi = void 0;
42
+ exports._getMainPoolsGaugeRewards = exports._getPoolsFromApi = void 0;
43
43
  var axios_1 = __importDefault(require("axios"));
44
44
  var memoizee_1 = __importDefault(require("memoizee"));
45
45
  exports._getPoolsFromApi = (0, memoizee_1.default)(function (network, poolType) { return __awaiter(void 0, void 0, void 0, function () {
@@ -59,3 +59,19 @@ exports._getPoolsFromApi = (0, memoizee_1.default)(function (network, poolType)
59
59
  promise: true,
60
60
  maxAge: 5 * 60 * 1000, // 5m
61
61
  });
62
+ exports._getMainPoolsGaugeRewards = (0, memoizee_1.default)(function () { return __awaiter(void 0, void 0, void 0, function () {
63
+ var url, response;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ url = "https://api.curve.fi/api/getMainPoolsGaugeRewards";
68
+ return [4 /*yield*/, axios_1.default.get(url, { validateStatus: function () { return true; } })];
69
+ case 1:
70
+ response = _a.sent();
71
+ return [2 /*return*/, response.data.data.mainPoolsGaugeRewards];
72
+ }
73
+ });
74
+ }); }, {
75
+ promise: true,
76
+ maxAge: 5 * 60 * 1000, // 5m
77
+ });
@@ -122,6 +122,23 @@ function setFactoryCoinsContracts(rawPoolList) {
122
122
  }
123
123
  }
124
124
  }
125
+ function setFactoryRewardCoinsContracts(rawPoolList) {
126
+ var _a;
127
+ for (var _i = 0, rawPoolList_2 = rawPoolList; _i < rawPoolList_2.length; _i++) {
128
+ var pool = rawPoolList_2[_i];
129
+ for (var _b = 0, _c = (_a = pool.gaugeRewards) !== null && _a !== void 0 ? _a : []; _b < _c.length; _b++) {
130
+ var rewardCoin = _c[_b];
131
+ var addr = rewardCoin.tokenAddress.toLowerCase();
132
+ if (addr in this.contracts)
133
+ continue;
134
+ this.contracts[addr] = {
135
+ contract: new ethers_1.Contract(addr, ERC20_json_1.default, this.signer || this.provider),
136
+ multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
137
+ };
138
+ this.constants.DECIMALS_LOWER_CASE[addr] = Number(rewardCoin.decimals);
139
+ }
140
+ }
141
+ }
125
142
  function setFactoryZapContracts() {
126
143
  if (this.chainId === 137) {
127
144
  var metaUsdZapAddress = "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase();
@@ -164,10 +181,12 @@ function getFactoryPoolsDataFromApi(isCrypto) {
164
181
  setCryptoFactoryTokenContracts.call(this, rawPoolList);
165
182
  setFactoryGaugeContracts.call(this, rawPoolList);
166
183
  setFactoryCoinsContracts.call(this, rawPoolList);
184
+ setFactoryRewardCoinsContracts.call(this, rawPoolList);
167
185
  if (!isCrypto)
168
186
  setFactoryZapContracts.call(this);
169
187
  FACTORY_POOLS_DATA = {};
170
188
  rawPoolList.forEach(function (pool) {
189
+ var _a, _b, _c;
171
190
  var coinAddresses = pool.coins.map(function (c) { return c.address.toLowerCase(); });
172
191
  var coinNames = pool.coins.map(function (c) { return c.symbol; });
173
192
  var coinDecimals = pool.coins.map(function (c) { return Number(c.decimals); });
@@ -193,6 +212,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
193
212
  gauge_address: pool.gaugeAddress ? pool.gaugeAddress.toLowerCase() : ethers_1.ethers.constants.AddressZero,
194
213
  underlying_coin_addresses: underlyingCoinAddresses,
195
214
  coin_addresses: coinAddresses,
215
+ reward_tokens: ((_a = pool.gaugeRewards) !== null && _a !== void 0 ? _a : []).map(function (r) { return r.tokenAddress; }),
196
216
  swap_abi: factory_crypto_pool_2_json_1.default,
197
217
  gauge_abi: gauge_factory_json_1.default,
198
218
  is_factory: true,
@@ -229,6 +249,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
229
249
  coins: coinNames,
230
250
  underlying_coin_addresses: coinAddresses,
231
251
  coin_addresses: coinAddresses,
252
+ reward_tokens: ((_b = pool.gaugeRewards) !== null && _b !== void 0 ? _b : []).map(function (r) { return r.tokenAddress; }),
232
253
  swap_abi: implementationABIDict[pool.implementationAddress],
233
254
  gauge_abi: gauge_factory_json_1.default,
234
255
  is_factory: true,
@@ -260,6 +281,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
260
281
  coins: coinNames,
261
282
  underlying_coin_addresses: coinAddresses,
262
283
  coin_addresses: coinAddresses,
284
+ reward_tokens: ((_c = pool.gaugeRewards) !== null && _c !== void 0 ? _c : []).map(function (r) { return r.tokenAddress; }),
263
285
  swap_abi: implementationABIDict[pool.implementationAddress],
264
286
  gauge_abi: gauge_factory_json_1.default,
265
287
  is_factory: true,
@@ -94,6 +94,15 @@ export interface ICoinFromPoolDataApi {
94
94
  decimals: string;
95
95
  usdPrice: number | string;
96
96
  }
97
+ export interface IReward {
98
+ gaugeAddress: string;
99
+ tokenAddress: string;
100
+ tokenPrice?: number;
101
+ name?: string;
102
+ symbol: string;
103
+ decimals?: number;
104
+ apy: number;
105
+ }
97
106
  export interface IPoolDataFromApi {
98
107
  id: string;
99
108
  name: string;
@@ -105,6 +114,7 @@ export interface IPoolDataFromApi {
105
114
  implementation: string;
106
115
  implementationAddress: string;
107
116
  coins: ICoinFromPoolDataApi[];
117
+ gaugeRewards?: IReward[];
108
118
  usdTotal: number;
109
119
  }
110
120
  export interface IExtendedPoolDataFromApi {
@@ -112,11 +122,6 @@ export interface IExtendedPoolDataFromApi {
112
122
  tvl?: number;
113
123
  tvlAll: number;
114
124
  }
115
- export interface RewardsApyInterface {
116
- token: string;
117
- symbol: string;
118
- apy: string;
119
- }
120
125
  export interface IPoolStats {
121
126
  volume: number;
122
127
  apy: {
package/lib/pools.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ethers } from "ethers";
2
2
  import BigNumber from 'bignumber.js';
3
- import { DictInterface, IRouteStep, RewardsApyInterface } from './interfaces';
3
+ import { DictInterface, IRouteStep, IReward } from './interfaces';
4
4
  export declare class Pool {
5
5
  id: string;
6
6
  name: string;
@@ -73,7 +73,7 @@ export declare class Pool {
73
73
  total: string;
74
74
  }>;
75
75
  getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>;
76
- getRewardsApy: () => Promise<RewardsApyInterface[]>;
76
+ getRewardsApy: () => Promise<IReward[]>;
77
77
  };
78
78
  constructor(id: string);
79
79
  calcLpTokenAmount: (amounts: string[], isDeposit?: boolean) => Promise<string>;
package/lib/pools.js CHANGED
@@ -365,58 +365,68 @@ var Pool = /** @class */ (function () {
365
365
  });
366
366
  }); };
367
367
  this.getRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
368
- var apy_1, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, mainPoolsGaugeRewards, mainPoolsGaugeRewardsLowerCase, apyData, apy, _d, apyData_1, data;
369
- return __generator(this, function (_e) {
370
- switch (_e.label) {
368
+ var apy, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, network, promises, _d, mainPoolsRewards, allTypesExtendedPoolData, rewards, _e, _f, extendedPoolData, _h, _j, pool;
369
+ var _k;
370
+ return __generator(this, function (_l) {
371
+ switch (_l.label) {
371
372
  case 0:
372
373
  if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
373
- apy_1 = [];
374
+ apy = [];
374
375
  _i = 0, _a = this.rewardTokens;
375
- _e.label = 1;
376
+ _l.label = 1;
376
377
  case 1:
377
378
  if (!(_i < _a.length)) return [3 /*break*/, 7];
378
379
  rewardToken = _a[_i];
379
380
  rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
380
381
  return [4 /*yield*/, this.getTotalLiquidity()];
381
382
  case 2:
382
- totalLiquidityUSD = _e.sent();
383
+ totalLiquidityUSD = _l.sent();
383
384
  return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
384
385
  case 3:
385
- crvRate = _e.sent();
386
+ crvRate = _l.sent();
386
387
  _c = utils_1.toBN;
387
388
  return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
388
389
  case 4:
389
- inflation = _c.apply(void 0, [(_e.sent()).rate]);
390
+ inflation = _c.apply(void 0, [(_l.sent()).rate]);
390
391
  baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
391
392
  rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
392
393
  return [4 /*yield*/, rewardTokenContract.symbol()];
393
394
  case 5:
394
- symbol = _e.sent();
395
- apy_1.push({
396
- token: rewardToken,
395
+ symbol = _l.sent();
396
+ apy.push({
397
+ gaugeAddress: this.gauge.toLowerCase(),
398
+ tokenAddress: rewardToken,
397
399
  symbol: symbol,
398
- apy: baseApy.times(100).toFixed(4),
400
+ apy: Number(baseApy.times(100).toFixed(4)),
399
401
  });
400
- _e.label = 6;
402
+ _l.label = 6;
401
403
  case 6:
402
404
  _i++;
403
405
  return [3 /*break*/, 1];
404
- case 7: return [2 /*return*/, apy_1];
405
- case 8: return [4 /*yield*/, axios_1.default.get("https://api.curve.fi/api/getMainPoolsGaugeRewards")];
406
+ case 7: return [2 /*return*/, apy];
407
+ case 8:
408
+ network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
409
+ promises = [
410
+ (0, external_api_1._getMainPoolsGaugeRewards)(),
411
+ (0, external_api_1._getPoolsFromApi)(network, "main"),
412
+ (0, external_api_1._getPoolsFromApi)(network, "crypto"),
413
+ (0, external_api_1._getPoolsFromApi)(network, "factory"),
414
+ (0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
415
+ ];
416
+ return [4 /*yield*/, Promise.all(promises)];
406
417
  case 9:
407
- mainPoolsGaugeRewards = (_e.sent()).data.data.mainPoolsGaugeRewards;
408
- mainPoolsGaugeRewardsLowerCase = Object.fromEntries(Object.entries(mainPoolsGaugeRewards).map(function (entry) { return [entry[0].toLowerCase(), entry[1]]; }));
409
- apyData = mainPoolsGaugeRewardsLowerCase[this.gauge.toLowerCase()] || [];
410
- apy = [];
411
- for (_d = 0, apyData_1 = apyData; _d < apyData_1.length; _d++) {
412
- data = apyData_1[_d];
413
- apy.push({
414
- token: data.tokenAddress,
415
- symbol: data.symbol,
416
- apy: String(data.apy),
417
- });
418
+ _d = _l.sent(), mainPoolsRewards = _d[0], allTypesExtendedPoolData = _d.slice(1);
419
+ rewards = mainPoolsRewards;
420
+ for (_e = 0, _f = allTypesExtendedPoolData; _e < _f.length; _e++) {
421
+ extendedPoolData = _f[_e];
422
+ for (_h = 0, _j = extendedPoolData.poolData; _h < _j.length; _h++) {
423
+ pool = _j[_h];
424
+ if (pool.gaugeAddress && pool.gaugeRewards) {
425
+ rewards[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
426
+ }
427
+ }
418
428
  }
419
- return [2 /*return*/, apy];
429
+ return [2 /*return*/, (_k = rewards[this.gauge.toLowerCase()]) !== null && _k !== void 0 ? _k : []];
420
430
  }
421
431
  });
422
432
  }); };
package/lib/utils.js CHANGED
@@ -376,9 +376,10 @@ var getPoolNameBySwapAddress = function (swapAddress) {
376
376
  };
377
377
  exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
378
378
  var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
379
- var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, _c, _d, coin;
380
- return __generator(this, function (_e) {
381
- switch (_e.label) {
379
+ var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, _c, _d, coin, _e, _f, coin;
380
+ var _g;
381
+ return __generator(this, function (_h) {
382
+ switch (_h.label) {
382
383
  case 0:
383
384
  network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
384
385
  promises = [
@@ -389,7 +390,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
389
390
  ];
390
391
  return [4 /*yield*/, Promise.all(promises)];
391
392
  case 1:
392
- allTypesExtendedPoolData = _e.sent();
393
+ allTypesExtendedPoolData = _h.sent();
393
394
  priceDict = {};
394
395
  for (_i = 0, allTypesExtendedPoolData_1 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_1.length; _i++) {
395
396
  extendedPoolData = allTypesExtendedPoolData_1[_i];
@@ -400,6 +401,11 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
400
401
  if (typeof coin.usdPrice === "number")
401
402
  priceDict[coin.address.toLowerCase()] = coin.usdPrice;
402
403
  }
404
+ for (_e = 0, _f = (_g = pool.gaugeRewards) !== null && _g !== void 0 ? _g : []; _e < _f.length; _e++) {
405
+ coin = _f[_e];
406
+ if (typeof coin.tokenPrice === "number")
407
+ priceDict[coin.tokenAddress.toLowerCase()] = coin.tokenPrice;
408
+ }
403
409
  }
404
410
  }
405
411
  return [2 /*return*/, priceDict];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.25.1",
3
+ "version": "1.25.2",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",