@curvefi/api 2.5.0 → 2.7.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.
@@ -262,7 +262,7 @@ var PoolTemplate = /** @class */ (function () {
262
262
  case 0:
263
263
  if (this.gauge === ethers_1.ethers.constants.AddressZero)
264
264
  return [2 /*return*/, []];
265
- if (![137, 250, 43114].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
265
+ if (![10, 137, 250, 43114, 42161].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
266
266
  apy = [];
267
267
  return [4 /*yield*/, this.rewardTokens()];
268
268
  case 1:
@@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.getPool = void 0;
19
+ var curve_1 = require("../curve");
19
20
  var PoolTemplate_1 = require("./PoolTemplate");
20
21
  var poolBalancesMixin_1 = require("./mixins/poolBalancesMixin");
21
22
  var depositBalancedAmountsMixins_1 = require("./mixins/depositBalancedAmountsMixins");
@@ -226,7 +227,7 @@ var getPool = function (poolId) {
226
227
  }
227
228
  }
228
229
  // swap and swapEstimateGas
229
- if (poolId === 'tricrypto2') {
230
+ if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract) { // tricrypto2 (eth), tricrypto (arbitrum)
230
231
  Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
231
232
  }
232
233
  else if (poolDummy.isMetaFactory && (0, exports.getPool)(poolDummy.basePool).isLending) {
@@ -238,7 +239,7 @@ var getPool = function (poolId) {
238
239
  // swapWrapped and swapWrappedEstimateGas
239
240
  if (!poolDummy.isPlain && !poolDummy.isFake) {
240
241
  Object.assign(Pool.prototype, swapWrappedMixins_1.swapWrappedExpectedAndApproveMixin);
241
- if (poolId === 'tricrypto2') {
242
+ if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract) { // tricrypto2 (eth), tricrypto (arbitrum)
242
243
  Object.assign(Pool.prototype, swapWrappedMixins_1.swapWrappedTricrypto2Mixin);
243
244
  }
244
245
  else {
@@ -46,6 +46,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.getUserPoolList = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
49
+ var ethers_1 = require("ethers");
49
50
  var curve_1 = require("../curve");
50
51
  var poolConstructor_1 = require("./poolConstructor");
51
52
  var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
@@ -55,27 +56,34 @@ exports.getFactoryPoolList = getFactoryPoolList;
55
56
  var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
56
57
  exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
57
58
  var getUserPoolList = function (address) { return __awaiter(void 0, void 0, void 0, function () {
58
- var poolNames, promises, _i, poolNames_1, poolName, pool, userPoolList, balances, i;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
59
+ var poolIds, calls, _i, poolIds_1, poolId, pool, userPoolList, _rawBalances, _a, poolIds_2, poolId, pool, _balance;
60
+ return __generator(this, function (_b) {
61
+ switch (_b.label) {
61
62
  case 0:
62
63
  if (!address)
63
64
  address = curve_1.curve.signerAddress;
64
65
  address = address;
65
- poolNames = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
66
- promises = [];
67
- for (_i = 0, poolNames_1 = poolNames; _i < poolNames_1.length; _i++) {
68
- poolName = poolNames_1[_i];
69
- pool = (0, poolConstructor_1.getPool)(poolName);
70
- promises.push(pool.wallet.lpTokenBalances(address)); // TODO optimization
66
+ poolIds = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
67
+ calls = [];
68
+ for (_i = 0, poolIds_1 = poolIds; _i < poolIds_1.length; _i++) {
69
+ poolId = poolIds_1[_i];
70
+ pool = (0, poolConstructor_1.getPool)(poolId);
71
+ calls.push(curve_1.curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
72
+ if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
73
+ calls.push(curve_1.curve.contracts[pool.gauge].multicallContract.balanceOf(address));
71
74
  }
72
75
  userPoolList = [];
73
- return [4 /*yield*/, Promise.all(promises)];
76
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
74
77
  case 1:
75
- balances = (_a.sent()).map(function (lpBalance) { return Object.values(lpBalance).map(Number).reduce(function (a, b) { return a + b; }); });
76
- for (i = 0; i < poolNames.length; i++) {
77
- if (balances[i] > 0) {
78
- userPoolList.push(poolNames[i]);
78
+ _rawBalances = _b.sent();
79
+ for (_a = 0, poolIds_2 = poolIds; _a < poolIds_2.length; _a++) {
80
+ poolId = poolIds_2[_a];
81
+ pool = (0, poolConstructor_1.getPool)(poolId);
82
+ _balance = _rawBalances.shift();
83
+ if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
84
+ _balance = _balance.add(_rawBalances.shift());
85
+ if (_balance.gt(0)) {
86
+ userPoolList.push(poolId);
79
87
  }
80
88
  }
81
89
  return [2 /*return*/, userPoolList];
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,15 +452,19 @@ 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',
455
456
  137: 'polygon-pos',
456
457
  250: 'fantom',
457
458
  43114: 'avalanche',
459
+ 42161: 'arbitrum-one',
458
460
  }[curve_1.curve.chainId];
459
461
  nativeTokenName = {
460
462
  1: 'ethereum',
463
+ 10: 'optimism',
461
464
  137: 'matic-network',
462
465
  250: 'fantom',
463
466
  43114: 'avalanche-2',
467
+ 42161: 'ethereum',
464
468
  }[curve_1.curve.chainId];
465
469
  if (chainName === undefined) {
466
470
  throw Error('curve object is not initialized');
@@ -523,9 +527,11 @@ var getTVL = function (chainId) {
523
527
  case 0:
524
528
  network = (_a = {
525
529
  1: "ethereum",
530
+ 10: 'optimism',
526
531
  137: "polygon",
527
532
  250: "fantom",
528
533
  43114: "avalanche",
534
+ 42161: "arbitrum",
529
535
  }[chainId]) !== null && _a !== void 0 ? _a : "ethereum";
530
536
  promises = [
531
537
  (0, external_api_1._getPoolsFromApi)(network, "main"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",