@curvefi/api 2.16.1 → 2.16.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.
package/lib/index.d.ts CHANGED
@@ -32,8 +32,8 @@ declare const curve: {
32
32
  getPoolList: () => string[];
33
33
  getFactoryPoolList: () => string[];
34
34
  getCryptoFactoryPoolList: () => string[];
35
- getUserPoolList: (address?: string | undefined) => Promise<string[]>;
36
- getUserLiquidityUSD: (pools: string[], address?: string | undefined) => Promise<string[]>;
35
+ getUserPoolList: (address?: string) => Promise<string[]>;
36
+ getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
37
37
  PoolTemplate: typeof PoolTemplate;
38
38
  getPool: (poolId: string) => PoolTemplate;
39
39
  getUsdRate: (coin: string) => Promise<number>;
@@ -2,6 +2,6 @@ import { ethers } from "ethers";
2
2
  export declare const getPoolList: () => string[];
3
3
  export declare const getFactoryPoolList: () => string[];
4
4
  export declare const getCryptoFactoryPoolList: () => string[];
5
- export declare const _getUserLpBalances: (pools: string[], address?: string) => Promise<ethers.BigNumber[]>;
5
+ export declare const _getUserLpBalances: (pools: string[], address: string, useCache: boolean) => Promise<ethers.BigNumber[]>;
6
6
  export declare const getUserPoolList: (address?: string) => Promise<string[]>;
7
7
  export declare const getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
@@ -57,29 +57,18 @@ exports.getFactoryPoolList = getFactoryPoolList;
57
57
  var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
58
58
  exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
59
59
  var _userLpBalance = {};
60
- var _isUserLpBalanceExpired = function (address, poolId) {
61
- var _a, _b;
62
- return (((_b = (_a = _userLpBalance[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now();
63
- };
64
- var _getUserLpBalances = function (pools, address) { return __awaiter(void 0, void 0, void 0, function () {
65
- var poolsToFetch, _i, pools_1, poolId, calls, _a, poolsToFetch_1, poolId, pool, _rawBalances, _b, poolsToFetch_2, poolId, pool, _balance, _lpBalances, _c, pools_2, poolId;
66
- var _d;
67
- return __generator(this, function (_e) {
68
- switch (_e.label) {
60
+ var _isUserLpBalanceExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userLpBalance[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
61
+ var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
62
+ var poolsToFetch, calls, _i, poolsToFetch_1, poolId, pool, _rawBalances, _a, poolsToFetch_2, poolId, pool, _balance, _lpBalances, _b, pools_1, poolId;
63
+ var _c;
64
+ return __generator(this, function (_d) {
65
+ switch (_d.label) {
69
66
  case 0:
70
- if (!address)
71
- address = curve_1.curve.signerAddress;
72
- address = address;
73
- poolsToFetch = [];
74
- for (_i = 0, pools_1 = pools; _i < pools_1.length; _i++) {
75
- poolId = pools_1[_i];
76
- if (_isUserLpBalanceExpired(address, poolId))
77
- poolsToFetch.push(poolId);
78
- }
67
+ poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserLpBalanceExpired(address, poolId); }) : pools;
79
68
  if (!(poolsToFetch.length > 0)) return [3 /*break*/, 2];
80
69
  calls = [];
81
- for (_a = 0, poolsToFetch_1 = poolsToFetch; _a < poolsToFetch_1.length; _a++) {
82
- poolId = poolsToFetch_1[_a];
70
+ for (_i = 0, poolsToFetch_1 = poolsToFetch; _i < poolsToFetch_1.length; _i++) {
71
+ poolId = poolsToFetch_1[_i];
83
72
  pool = (0, poolConstructor_1.getPool)(poolId);
84
73
  calls.push(curve_1.curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
85
74
  if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
@@ -87,9 +76,9 @@ var _getUserLpBalances = function (pools, address) { return __awaiter(void 0, vo
87
76
  }
88
77
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
89
78
  case 1:
90
- _rawBalances = _e.sent();
91
- for (_b = 0, poolsToFetch_2 = poolsToFetch; _b < poolsToFetch_2.length; _b++) {
92
- poolId = poolsToFetch_2[_b];
79
+ _rawBalances = _d.sent();
80
+ for (_a = 0, poolsToFetch_2 = poolsToFetch; _a < poolsToFetch_2.length; _a++) {
81
+ poolId = poolsToFetch_2[_a];
93
82
  pool = (0, poolConstructor_1.getPool)(poolId);
94
83
  _balance = _rawBalances.shift();
95
84
  if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
@@ -98,61 +87,67 @@ var _getUserLpBalances = function (pools, address) { return __awaiter(void 0, vo
98
87
  _userLpBalance[address] = {};
99
88
  _userLpBalance[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
100
89
  }
101
- _e.label = 2;
90
+ _d.label = 2;
102
91
  case 2:
103
92
  _lpBalances = [];
104
- for (_c = 0, pools_2 = pools; _c < pools_2.length; _c++) {
105
- poolId = pools_2[_c];
106
- _lpBalances.push((_d = _userLpBalance[address]) === null || _d === void 0 ? void 0 : _d[poolId]._lpBalance);
93
+ for (_b = 0, pools_1 = pools; _b < pools_1.length; _b++) {
94
+ poolId = pools_1[_b];
95
+ _lpBalances.push((_c = _userLpBalance[address]) === null || _c === void 0 ? void 0 : _c[poolId]._lpBalance);
107
96
  }
108
97
  return [2 /*return*/, _lpBalances];
109
98
  }
110
99
  });
111
100
  }); };
112
101
  exports._getUserLpBalances = _getUserLpBalances;
113
- var getUserPoolList = function (address) { return __awaiter(void 0, void 0, void 0, function () {
114
- var pools, _lpBalances, userPoolList, i;
115
- return __generator(this, function (_a) {
116
- switch (_a.label) {
117
- case 0:
118
- pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
119
- return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address)];
120
- case 1:
121
- _lpBalances = _a.sent();
122
- userPoolList = [];
123
- for (i = 0; i < pools.length; i++) {
124
- if (_lpBalances[i].gt(0)) {
125
- userPoolList.push(pools[i]);
102
+ var getUserPoolList = function (address) {
103
+ if (address === void 0) { address = curve_1.curve.signerAddress; }
104
+ return __awaiter(void 0, void 0, void 0, function () {
105
+ var pools, _lpBalances, userPoolList, i;
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0:
109
+ pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
110
+ return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address, false)];
111
+ case 1:
112
+ _lpBalances = _a.sent();
113
+ userPoolList = [];
114
+ for (i = 0; i < pools.length; i++) {
115
+ if (_lpBalances[i].gt(0)) {
116
+ userPoolList.push(pools[i]);
117
+ }
126
118
  }
127
- }
128
- return [2 /*return*/, userPoolList];
129
- }
119
+ return [2 /*return*/, userPoolList];
120
+ }
121
+ });
130
122
  });
131
- }); };
123
+ };
132
124
  exports.getUserPoolList = getUserPoolList;
133
- var getUserLiquidityUSD = function (pools, address) { return __awaiter(void 0, void 0, void 0, function () {
134
- var _lpBalances, userLiquidityUSD, i, pool, price;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0: return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address)];
138
- case 1:
139
- _lpBalances = _a.sent();
140
- userLiquidityUSD = [];
141
- i = 0;
142
- _a.label = 2;
143
- case 2:
144
- if (!(i < pools.length)) return [3 /*break*/, 5];
145
- pool = (0, poolConstructor_1.getPool)(pools[i]);
146
- return [4 /*yield*/, (0, utils_1._getUsdRate)(pool.lpToken)];
147
- case 3:
148
- price = _a.sent();
149
- userLiquidityUSD.push((0, utils_1.toBN)(_lpBalances[i]).times(price).toFixed(8));
150
- _a.label = 4;
151
- case 4:
152
- i++;
153
- return [3 /*break*/, 2];
154
- case 5: return [2 /*return*/, userLiquidityUSD];
155
- }
125
+ var getUserLiquidityUSD = function (pools, address) {
126
+ if (address === void 0) { address = curve_1.curve.signerAddress; }
127
+ return __awaiter(void 0, void 0, void 0, function () {
128
+ var _lpBalances, userLiquidityUSD, i, pool, price;
129
+ return __generator(this, function (_a) {
130
+ switch (_a.label) {
131
+ case 0: return [4 /*yield*/, (0, exports._getUserLpBalances)(pools, address, true)];
132
+ case 1:
133
+ _lpBalances = _a.sent();
134
+ userLiquidityUSD = [];
135
+ i = 0;
136
+ _a.label = 2;
137
+ case 2:
138
+ if (!(i < pools.length)) return [3 /*break*/, 5];
139
+ pool = (0, poolConstructor_1.getPool)(pools[i]);
140
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(pool.lpToken)];
141
+ case 3:
142
+ price = _a.sent();
143
+ userLiquidityUSD.push((0, utils_1.toBN)(_lpBalances[i]).times(price).toFixed(8));
144
+ _a.label = 4;
145
+ case 4:
146
+ i++;
147
+ return [3 /*break*/, 2];
148
+ case 5: return [2 /*return*/, userLiquidityUSD];
149
+ }
150
+ });
156
151
  });
157
- }); };
152
+ };
158
153
  exports.getUserLiquidityUSD = getUserLiquidityUSD;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",