@curvefi/api 2.17.0 → 2.18.1
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 +8 -0
- package/lib/index.js +3 -0
- package/lib/pools/utils.d.ts +9 -3
- package/lib/pools/utils.js +258 -13
- package/lib/utils.js +6 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -34,8 +34,16 @@ declare const curve: {
|
|
|
34
34
|
getPoolList: () => string[];
|
|
35
35
|
getFactoryPoolList: () => string[];
|
|
36
36
|
getCryptoFactoryPoolList: () => string[];
|
|
37
|
+
getUserPoolListByLiquidity: (address?: string) => Promise<string[]>;
|
|
38
|
+
getUserPoolListByClaimable: (address?: string) => Promise<string[]>;
|
|
37
39
|
getUserPoolList: (address?: string) => Promise<string[]>;
|
|
38
40
|
getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
|
41
|
+
getUserClaimable: (pools: string[], address?: string) => Promise<{
|
|
42
|
+
token: string;
|
|
43
|
+
symbol: string;
|
|
44
|
+
amount: string;
|
|
45
|
+
price: number;
|
|
46
|
+
}[][]>;
|
|
39
47
|
PoolTemplate: typeof PoolTemplate;
|
|
40
48
|
getPool: (poolId: string) => PoolTemplate;
|
|
41
49
|
getUsdRate: (coin: string) => Promise<number>;
|
package/lib/index.js
CHANGED
|
@@ -119,8 +119,11 @@ var curve = {
|
|
|
119
119
|
getPoolList: utils_1.getPoolList,
|
|
120
120
|
getFactoryPoolList: utils_1.getFactoryPoolList,
|
|
121
121
|
getCryptoFactoryPoolList: utils_1.getCryptoFactoryPoolList,
|
|
122
|
+
getUserPoolListByLiquidity: utils_1.getUserPoolListByLiquidity,
|
|
123
|
+
getUserPoolListByClaimable: utils_1.getUserPoolListByClaimable,
|
|
122
124
|
getUserPoolList: utils_1.getUserPoolList,
|
|
123
125
|
getUserLiquidityUSD: utils_1.getUserLiquidityUSD,
|
|
126
|
+
getUserClaimable: utils_1.getUserClaimable,
|
|
124
127
|
PoolTemplate: pools_1.PoolTemplate,
|
|
125
128
|
getPool: pools_1.getPool,
|
|
126
129
|
getUsdRate: utils_2.getUsdRate,
|
package/lib/pools/utils.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
1
|
export declare const getPoolList: () => string[];
|
|
3
2
|
export declare const getFactoryPoolList: () => string[];
|
|
4
3
|
export declare const getCryptoFactoryPoolList: () => string[];
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
|
4
|
+
export declare const getUserPoolListByLiquidity: (address?: string) => Promise<string[]>;
|
|
7
5
|
export declare const getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
|
|
6
|
+
export declare const getUserPoolListByClaimable: (address?: string) => Promise<string[]>;
|
|
7
|
+
export declare const getUserClaimable: (pools: string[], address?: string) => Promise<{
|
|
8
|
+
token: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
price: number;
|
|
12
|
+
}[][]>;
|
|
13
|
+
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
package/lib/pools/utils.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,27 +55,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
55
|
}
|
|
45
56
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
57
|
};
|
|
58
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
+
};
|
|
47
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.
|
|
62
|
+
exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
|
|
49
63
|
var ethers_1 = require("ethers");
|
|
50
64
|
var poolConstructor_1 = require("./poolConstructor");
|
|
51
65
|
var curve_1 = require("../curve");
|
|
52
66
|
var utils_1 = require("../utils");
|
|
67
|
+
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
53
68
|
var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
|
|
54
69
|
exports.getPoolList = getPoolList;
|
|
55
70
|
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
56
71
|
exports.getFactoryPoolList = getFactoryPoolList;
|
|
57
72
|
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
58
73
|
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
59
|
-
|
|
60
|
-
var
|
|
74
|
+
// _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
|
|
75
|
+
var _userLpBalanceCache = {};
|
|
76
|
+
var _isUserLpBalanceCacheExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userLpBalanceCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
|
|
61
77
|
var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
78
|
var poolsToFetch, calls, _i, poolsToFetch_1, poolId, pool, _rawBalances, _a, poolsToFetch_2, poolId, pool, _balance, _lpBalances, _b, pools_1, poolId;
|
|
63
79
|
var _c;
|
|
64
80
|
return __generator(this, function (_d) {
|
|
65
81
|
switch (_d.label) {
|
|
66
82
|
case 0:
|
|
67
|
-
poolsToFetch = useCache ? pools.filter(function (poolId) { return
|
|
83
|
+
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserLpBalanceCacheExpired(address, poolId); }) : pools;
|
|
68
84
|
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 2];
|
|
69
85
|
calls = [];
|
|
70
86
|
for (_i = 0, poolsToFetch_1 = poolsToFetch; _i < poolsToFetch_1.length; _i++) {
|
|
@@ -83,23 +99,22 @@ var _getUserLpBalances = function (pools, address, useCache) { return __awaiter(
|
|
|
83
99
|
_balance = _rawBalances.shift();
|
|
84
100
|
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
85
101
|
_balance = _balance.add(_rawBalances.shift());
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
if (!_userLpBalanceCache[address])
|
|
103
|
+
_userLpBalanceCache[address] = {};
|
|
104
|
+
_userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
89
105
|
}
|
|
90
106
|
_d.label = 2;
|
|
91
107
|
case 2:
|
|
92
108
|
_lpBalances = [];
|
|
93
109
|
for (_b = 0, pools_1 = pools; _b < pools_1.length; _b++) {
|
|
94
110
|
poolId = pools_1[_b];
|
|
95
|
-
_lpBalances.push((_c =
|
|
111
|
+
_lpBalances.push((_c = _userLpBalanceCache[address]) === null || _c === void 0 ? void 0 : _c[poolId]._lpBalance);
|
|
96
112
|
}
|
|
97
113
|
return [2 /*return*/, _lpBalances];
|
|
98
114
|
}
|
|
99
115
|
});
|
|
100
116
|
}); };
|
|
101
|
-
|
|
102
|
-
var getUserPoolList = function (address) {
|
|
117
|
+
var getUserPoolListByLiquidity = function (address) {
|
|
103
118
|
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
104
119
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
105
120
|
var pools, _lpBalances, userPoolList, i;
|
|
@@ -107,7 +122,7 @@ var getUserPoolList = function (address) {
|
|
|
107
122
|
switch (_a.label) {
|
|
108
123
|
case 0:
|
|
109
124
|
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
110
|
-
return [4 /*yield*/,
|
|
125
|
+
return [4 /*yield*/, _getUserLpBalances(pools, address, false)];
|
|
111
126
|
case 1:
|
|
112
127
|
_lpBalances = _a.sent();
|
|
113
128
|
userPoolList = [];
|
|
@@ -121,14 +136,14 @@ var getUserPoolList = function (address) {
|
|
|
121
136
|
});
|
|
122
137
|
});
|
|
123
138
|
};
|
|
124
|
-
exports.
|
|
139
|
+
exports.getUserPoolListByLiquidity = getUserPoolListByLiquidity;
|
|
125
140
|
var getUserLiquidityUSD = function (pools, address) {
|
|
126
141
|
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
127
142
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
128
143
|
var _lpBalances, userLiquidityUSD, i, pool, price;
|
|
129
144
|
return __generator(this, function (_a) {
|
|
130
145
|
switch (_a.label) {
|
|
131
|
-
case 0: return [4 /*yield*/,
|
|
146
|
+
case 0: return [4 /*yield*/, _getUserLpBalances(pools, address, true)];
|
|
132
147
|
case 1:
|
|
133
148
|
_lpBalances = _a.sent();
|
|
134
149
|
userLiquidityUSD = [];
|
|
@@ -151,3 +166,233 @@ var getUserLiquidityUSD = function (pools, address) {
|
|
|
151
166
|
});
|
|
152
167
|
};
|
|
153
168
|
exports.getUserLiquidityUSD = getUserLiquidityUSD;
|
|
169
|
+
// _userClaimable: { address: { poolId: { rewards: [ { token: '0x111...', 'symbol': 'TST', '', 'amount': 0 } ], time: 0 } }
|
|
170
|
+
var _userClaimableCache = {};
|
|
171
|
+
var _isUserClaimableCacheExpired = function (address, poolId) { var _a, _b; return (((_b = (_a = _userClaimableCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
|
|
172
|
+
var _getUserClaimable = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
173
|
+
var poolsToFetch, hasCrvReward, _i, poolsToFetch_3, poolId, pool, gaugeContract, rewardCount, _a, poolsToFetch_4, poolId, pool, gaugeContract, rewardTokenCalls, i, pool, count, gaugeContract, rewardContract, rewardMulticallContract, method, rawRewardTokens, rewardTokens, i, j, rewardAddress, rewardInfoCalls, i, poolId, pool, gaugeContract, gaugeMulticallContract, _b, _c, token, tokenMulticallContract, rawRewardInfo, i, poolId, pool, gaugeContract, token, symbol, decimals, _amount, amount, _d, _e, token, symbol, decimals, _amount, _claimedAmount, amount, _claimable, _f, pools_2, poolId;
|
|
174
|
+
var _g;
|
|
175
|
+
var _h;
|
|
176
|
+
return __generator(this, function (_j) {
|
|
177
|
+
switch (_j.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserClaimableCacheExpired(address, poolId); }) : pools;
|
|
180
|
+
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 3];
|
|
181
|
+
hasCrvReward = [];
|
|
182
|
+
for (_i = 0, poolsToFetch_3 = poolsToFetch; _i < poolsToFetch_3.length; _i++) {
|
|
183
|
+
poolId = poolsToFetch_3[_i];
|
|
184
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
185
|
+
if (curve_1.curve.chainId === 2222 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava
|
|
186
|
+
hasCrvReward.push(false);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
190
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
191
|
+
}
|
|
192
|
+
rewardCount = [];
|
|
193
|
+
for (_a = 0, poolsToFetch_4 = poolsToFetch; _a < poolsToFetch_4.length; _a++) {
|
|
194
|
+
poolId = poolsToFetch_4[_a];
|
|
195
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
196
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
197
|
+
rewardCount.push(0);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
201
|
+
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
202
|
+
rewardCount.push(8);
|
|
203
|
+
}
|
|
204
|
+
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
205
|
+
rewardCount.push(-1);
|
|
206
|
+
}
|
|
207
|
+
else { // gauge
|
|
208
|
+
rewardCount.push(0);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
rewardTokenCalls = [];
|
|
212
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
213
|
+
pool = (0, poolConstructor_1.getPool)(poolsToFetch[i]);
|
|
214
|
+
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
215
|
+
for (count = 0; count < rewardCount[i]; count++) {
|
|
216
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
217
|
+
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else { // gauge_synthetix
|
|
221
|
+
rewardCount[i] = 1;
|
|
222
|
+
rewardContract = curve_1.curve.contracts[pool.sRewardContract].contract;
|
|
223
|
+
rewardMulticallContract = curve_1.curve.contracts[pool.sRewardContract].multicallContract;
|
|
224
|
+
method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
|
|
225
|
+
;
|
|
226
|
+
rewardTokenCalls.push(rewardMulticallContract[method]());
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardTokenCalls)];
|
|
230
|
+
case 1:
|
|
231
|
+
rawRewardTokens = (_j.sent()).map(function (t) { return t.toLowerCase(); });
|
|
232
|
+
rewardTokens = {};
|
|
233
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
234
|
+
rewardTokens[poolsToFetch[i]] = [];
|
|
235
|
+
for (j = 0; j < rewardCount[i]; j++) {
|
|
236
|
+
rewardAddress = rawRewardTokens.shift();
|
|
237
|
+
if (rewardAddress === ethers_1.ethers.constants.AddressZero)
|
|
238
|
+
continue;
|
|
239
|
+
rewardTokens[poolsToFetch[i]].push(rewardAddress);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
rewardInfoCalls = [];
|
|
243
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
244
|
+
poolId = poolsToFetch[i];
|
|
245
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
246
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
247
|
+
continue;
|
|
248
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
249
|
+
gaugeMulticallContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
250
|
+
if (hasCrvReward[i]) {
|
|
251
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
252
|
+
}
|
|
253
|
+
for (_b = 0, _c = rewardTokens[poolId]; _b < _c.length; _b++) {
|
|
254
|
+
token = _c[_b];
|
|
255
|
+
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
256
|
+
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
257
|
+
rewardInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
258
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
259
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
|
|
260
|
+
}
|
|
261
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
262
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardInfoCalls)];
|
|
267
|
+
case 2:
|
|
268
|
+
rawRewardInfo = _j.sent();
|
|
269
|
+
for (i = 0; i < poolsToFetch.length; i++) {
|
|
270
|
+
poolId = poolsToFetch[i];
|
|
271
|
+
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
272
|
+
if (!_userClaimableCache[address])
|
|
273
|
+
_userClaimableCache[address] = (_g = {}, _g[poolId] = { rewards: [], time: Date.now() }, _g);
|
|
274
|
+
if (!_userClaimableCache[address][poolId])
|
|
275
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
276
|
+
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
277
|
+
continue;
|
|
278
|
+
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
279
|
+
if (hasCrvReward[i]) {
|
|
280
|
+
token = curve_1.curve.constants.ALIASES.crv;
|
|
281
|
+
symbol = 'CRV';
|
|
282
|
+
decimals = 18;
|
|
283
|
+
_amount = rawRewardInfo.shift();
|
|
284
|
+
amount = ethers_1.ethers.utils.formatUnits(_amount, decimals);
|
|
285
|
+
if (Number(amount) > 0)
|
|
286
|
+
_userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
|
|
287
|
+
}
|
|
288
|
+
for (_d = 0, _e = rewardTokens[poolId]; _d < _e.length; _d++) {
|
|
289
|
+
token = _e[_d];
|
|
290
|
+
symbol = rawRewardInfo.shift();
|
|
291
|
+
decimals = rawRewardInfo.shift();
|
|
292
|
+
_amount = rawRewardInfo.shift();
|
|
293
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
294
|
+
_claimedAmount = rawRewardInfo.shift();
|
|
295
|
+
_amount = _amount.sub(_claimedAmount);
|
|
296
|
+
}
|
|
297
|
+
amount = ethers_1.ethers.utils.formatUnits(_amount, decimals);
|
|
298
|
+
if (Number(amount) > 0)
|
|
299
|
+
_userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
_j.label = 3;
|
|
303
|
+
case 3:
|
|
304
|
+
_claimable = [];
|
|
305
|
+
for (_f = 0, pools_2 = pools; _f < pools_2.length; _f++) {
|
|
306
|
+
poolId = pools_2[_f];
|
|
307
|
+
_claimable.push((_h = _userClaimableCache[address]) === null || _h === void 0 ? void 0 : _h[poolId].rewards);
|
|
308
|
+
}
|
|
309
|
+
return [2 /*return*/, _claimable];
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}); };
|
|
313
|
+
var getUserPoolListByClaimable = function (address) {
|
|
314
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
315
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
316
|
+
var pools, _claimable, userPoolList, i;
|
|
317
|
+
return __generator(this, function (_a) {
|
|
318
|
+
switch (_a.label) {
|
|
319
|
+
case 0:
|
|
320
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
321
|
+
return [4 /*yield*/, _getUserClaimable(pools, address, false)];
|
|
322
|
+
case 1:
|
|
323
|
+
_claimable = _a.sent();
|
|
324
|
+
userPoolList = [];
|
|
325
|
+
for (i = 0; i < pools.length; i++) {
|
|
326
|
+
if (_claimable[i].length > 0) {
|
|
327
|
+
userPoolList.push(pools[i]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return [2 /*return*/, userPoolList];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
exports.getUserPoolListByClaimable = getUserPoolListByClaimable;
|
|
336
|
+
var getUserClaimable = function (pools, address) {
|
|
337
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
338
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
339
|
+
var _claimable, claimableWithPrice, i, _i, _a, c, price;
|
|
340
|
+
return __generator(this, function (_b) {
|
|
341
|
+
switch (_b.label) {
|
|
342
|
+
case 0: return [4 /*yield*/, _getUserClaimable(pools, address, true)];
|
|
343
|
+
case 1:
|
|
344
|
+
_claimable = _b.sent();
|
|
345
|
+
claimableWithPrice = [];
|
|
346
|
+
i = 0;
|
|
347
|
+
_b.label = 2;
|
|
348
|
+
case 2:
|
|
349
|
+
if (!(i < pools.length)) return [3 /*break*/, 7];
|
|
350
|
+
claimableWithPrice.push([]);
|
|
351
|
+
_i = 0, _a = _claimable[i];
|
|
352
|
+
_b.label = 3;
|
|
353
|
+
case 3:
|
|
354
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
355
|
+
c = _a[_i];
|
|
356
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(c.token)];
|
|
357
|
+
case 4:
|
|
358
|
+
price = _b.sent();
|
|
359
|
+
claimableWithPrice[claimableWithPrice.length - 1].push(__assign(__assign({}, c), { price: price }));
|
|
360
|
+
_b.label = 5;
|
|
361
|
+
case 5:
|
|
362
|
+
_i++;
|
|
363
|
+
return [3 /*break*/, 3];
|
|
364
|
+
case 6:
|
|
365
|
+
i++;
|
|
366
|
+
return [3 /*break*/, 2];
|
|
367
|
+
case 7: return [2 /*return*/, claimableWithPrice];
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
exports.getUserClaimable = getUserClaimable;
|
|
373
|
+
var getUserPoolList = function (address) {
|
|
374
|
+
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
375
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
376
|
+
var pools, _a, _lpBalances, _claimable, userPoolList, i;
|
|
377
|
+
return __generator(this, function (_b) {
|
|
378
|
+
switch (_b.label) {
|
|
379
|
+
case 0:
|
|
380
|
+
pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
381
|
+
return [4 /*yield*/, Promise.all([
|
|
382
|
+
_getUserLpBalances(pools, address, false),
|
|
383
|
+
_getUserClaimable(pools, address, false),
|
|
384
|
+
])];
|
|
385
|
+
case 1:
|
|
386
|
+
_a = _b.sent(), _lpBalances = _a[0], _claimable = _a[1];
|
|
387
|
+
userPoolList = [];
|
|
388
|
+
for (i = 0; i < pools.length; i++) {
|
|
389
|
+
if (_lpBalances[i].gt(0) || _claimable[i].length > 0) {
|
|
390
|
+
userPoolList.push(pools[i]);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return [2 /*return*/, userPoolList];
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
exports.getUserPoolList = getUserPoolList;
|
package/lib/utils.js
CHANGED
|
@@ -454,7 +454,10 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
454
454
|
var _a, _b;
|
|
455
455
|
return __generator(this, function (_c) {
|
|
456
456
|
switch (_c.label) {
|
|
457
|
-
case 0:
|
|
457
|
+
case 0:
|
|
458
|
+
if (curve_1.curve.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
|
|
459
|
+
return [2 /*return*/, 0]; // RSR
|
|
460
|
+
return [4 /*yield*/, (0, exports._getUsdPricesFromApi)()];
|
|
458
461
|
case 1:
|
|
459
462
|
pricesFromApi = _c.sent();
|
|
460
463
|
if (assetId.toLowerCase() in pricesFromApi)
|
|
@@ -513,10 +516,10 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
513
516
|
case 2:
|
|
514
517
|
response = _c.sent();
|
|
515
518
|
try {
|
|
516
|
-
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b :
|
|
519
|
+
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b : 0, 'time': Date.now() };
|
|
517
520
|
}
|
|
518
521
|
catch (err) { // TODO pay attention!
|
|
519
|
-
_usdRatesCache[assetId] = { 'rate':
|
|
522
|
+
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
520
523
|
}
|
|
521
524
|
_c.label = 3;
|
|
522
525
|
case 3: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
|