@curvefi/api 2.31.0 → 2.31.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/boosting.js +137 -402
- package/lib/constants/aliases.d.ts +11 -11
- package/lib/constants/aliases.js +12 -15
- package/lib/constants/coins/arbitrum.js +6 -9
- package/lib/constants/coins/aurora.js +6 -9
- package/lib/constants/coins/avalanche.js +7 -10
- package/lib/constants/coins/celo.js +6 -9
- package/lib/constants/coins/ethereum.js +10 -13
- package/lib/constants/coins/fantom.js +8 -11
- package/lib/constants/coins/kava.js +6 -9
- package/lib/constants/coins/moonbeam.js +6 -9
- package/lib/constants/coins/optimism.js +6 -9
- package/lib/constants/coins/polygon.js +7 -10
- package/lib/constants/coins/xdai.js +6 -9
- package/lib/constants/pools/arbitrum.d.ts +2 -4
- package/lib/constants/pools/arbitrum.js +22 -28
- package/lib/constants/pools/aurora.d.ts +2 -4
- package/lib/constants/pools/aurora.js +6 -12
- package/lib/constants/pools/avalanche.d.ts +2 -4
- package/lib/constants/pools/avalanche.js +21 -27
- package/lib/constants/pools/celo.d.ts +2 -4
- package/lib/constants/pools/celo.js +2 -5
- package/lib/constants/pools/ethereum.js +247 -253
- package/lib/constants/pools/fantom.d.ts +2 -4
- package/lib/constants/pools/fantom.js +28 -34
- package/lib/constants/pools/index.d.ts +11 -11
- package/lib/constants/pools/index.js +12 -25
- package/lib/constants/pools/kava.d.ts +2 -4
- package/lib/constants/pools/kava.js +2 -5
- package/lib/constants/pools/moonbeam.d.ts +2 -4
- package/lib/constants/pools/moonbeam.js +6 -12
- package/lib/constants/pools/optimism.d.ts +2 -4
- package/lib/constants/pools/optimism.js +9 -15
- package/lib/constants/pools/polygon.d.ts +2 -4
- package/lib/constants/pools/polygon.js +22 -28
- package/lib/constants/pools/xdai.d.ts +2 -4
- package/lib/constants/pools/xdai.js +24 -30
- package/lib/constants/utils.js +20 -29
- package/lib/curve.d.ts +9 -7
- package/lib/curve.js +397 -615
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +47 -140
- package/lib/factory/common.js +6 -10
- package/lib/factory/constants-crypto.js +48 -54
- package/lib/factory/constants.js +274 -280
- package/lib/factory/deploy.d.ts +8 -8
- package/lib/factory/deploy.js +177 -347
- package/lib/factory/factory-api.js +195 -278
- package/lib/factory/factory-crypto.js +170 -323
- package/lib/factory/factory.js +195 -350
- package/lib/index.d.ts +24 -25
- package/lib/index.js +87 -143
- package/lib/interfaces.d.ts +5 -5
- package/lib/interfaces.js +1 -2
- package/lib/pools/PoolTemplate.js +1516 -2929
- package/lib/pools/index.d.ts +2 -2
- package/lib/pools/index.js +3 -7
- package/lib/pools/mixins/common.d.ts +3 -4
- package/lib/pools/mixins/common.js +23 -112
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
- package/lib/pools/mixins/depositMixins.d.ts +1 -1
- package/lib/pools/mixins/depositMixins.js +144 -417
- package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/depositWrappedMixins.js +72 -227
- package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -1
- package/lib/pools/mixins/poolBalancesMixin.js +25 -105
- package/lib/pools/mixins/swapMixins.d.ts +1 -1
- package/lib/pools/mixins/swapMixins.js +127 -353
- package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/swapWrappedMixins.js +90 -276
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawExpectedMixins.js +26 -110
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
- package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawMixins.js +123 -390
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinMixins.js +124 -390
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
- package/lib/pools/poolConstructor.d.ts +1 -1
- package/lib/pools/poolConstructor.js +77 -101
- package/lib/pools/utils.js +298 -500
- package/lib/router.d.ts +2 -2
- package/lib/router.js +390 -653
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +377 -731
- package/package.json +8 -8
package/lib/pools/utils.js
CHANGED
|
@@ -1,523 +1,321 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { getPool } from "./poolConstructor.js";
|
|
2
|
+
import { curve } from "../curve.js";
|
|
3
|
+
import { _getRewardsFromApi, _getUsdRate, _setContracts, toBN } from "../utils.js";
|
|
4
|
+
import { _getPoolsFromApi } from "../external-api.js";
|
|
5
|
+
import ERC20Abi from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
6
|
+
// _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
|
|
7
|
+
const _userLpBalanceCache = {};
|
|
8
|
+
const _isUserLpBalanceCacheExpired = (address, poolId) => (_userLpBalanceCache[address]?.[poolId]?.time || 0) + 600000 < Date.now();
|
|
9
|
+
const _getUserLpBalances = async (pools, address, useCache) => {
|
|
10
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserLpBalanceCacheExpired(address, poolId)) : pools;
|
|
11
|
+
if (poolsToFetch.length > 0) {
|
|
12
|
+
const calls = [];
|
|
13
|
+
for (const poolId of poolsToFetch) {
|
|
14
|
+
const pool = getPool(poolId);
|
|
15
|
+
calls.push(curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
|
|
16
|
+
if (pool.gauge !== curve.constants.ZERO_ADDRESS)
|
|
17
|
+
calls.push(curve.contracts[pool.gauge].multicallContract.balanceOf(address));
|
|
8
18
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
19
|
+
const _rawBalances = await curve.multicallProvider.all(calls);
|
|
20
|
+
for (const poolId of poolsToFetch) {
|
|
21
|
+
const pool = getPool(poolId);
|
|
22
|
+
let _balance = _rawBalances.shift();
|
|
23
|
+
if (pool.gauge !== curve.constants.ZERO_ADDRESS)
|
|
24
|
+
_balance = _balance + _rawBalances.shift();
|
|
25
|
+
if (!_userLpBalanceCache[address])
|
|
26
|
+
_userLpBalanceCache[address] = {};
|
|
27
|
+
_userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const _lpBalances = [];
|
|
31
|
+
for (const poolId of pools) {
|
|
32
|
+
_lpBalances.push(_userLpBalanceCache[address]?.[poolId]._lpBalance);
|
|
47
33
|
}
|
|
34
|
+
return _lpBalances;
|
|
48
35
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
export const getUserPoolListByLiquidity = async (address = curve.signerAddress) => {
|
|
37
|
+
const pools = [...curve.getPoolList(), ...curve.getFactoryPoolList(), ...curve.getCryptoFactoryPoolList()];
|
|
38
|
+
const _lpBalances = await _getUserLpBalances(pools, address, false);
|
|
39
|
+
const userPoolList = [];
|
|
40
|
+
for (let i = 0; i < pools.length; i++) {
|
|
41
|
+
if (_lpBalances[i] > 0) {
|
|
42
|
+
userPoolList.push(pools[i]);
|
|
54
43
|
}
|
|
55
44
|
}
|
|
56
|
-
return
|
|
45
|
+
return userPoolList;
|
|
57
46
|
};
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
export const getUserLiquidityUSD = async (pools, address = curve.signerAddress) => {
|
|
48
|
+
const _lpBalances = await _getUserLpBalances(pools, address, true);
|
|
49
|
+
const userLiquidityUSD = [];
|
|
50
|
+
for (let i = 0; i < pools.length; i++) {
|
|
51
|
+
const pool = getPool(pools[i]);
|
|
52
|
+
const price = await _getUsdRate(pool.lpToken);
|
|
53
|
+
userLiquidityUSD.push(toBN(_lpBalances[i]).times(price).toFixed(8));
|
|
54
|
+
}
|
|
55
|
+
return userLiquidityUSD;
|
|
60
56
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
case 0:
|
|
78
|
-
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserLpBalanceCacheExpired(address, poolId); }) : pools;
|
|
79
|
-
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 2];
|
|
80
|
-
calls = [];
|
|
81
|
-
for (_i = 0, poolsToFetch_1 = poolsToFetch; _i < poolsToFetch_1.length; _i++) {
|
|
82
|
-
poolId = poolsToFetch_1[_i];
|
|
83
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
84
|
-
calls.push(curve_1.curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
|
|
85
|
-
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
86
|
-
calls.push(curve_1.curve.contracts[pool.gauge].multicallContract.balanceOf(address));
|
|
87
|
-
}
|
|
88
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
89
|
-
case 1:
|
|
90
|
-
_rawBalances = _d.sent();
|
|
91
|
-
for (_a = 0, poolsToFetch_2 = poolsToFetch; _a < poolsToFetch_2.length; _a++) {
|
|
92
|
-
poolId = poolsToFetch_2[_a];
|
|
93
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
94
|
-
_balance = _rawBalances.shift();
|
|
95
|
-
if (pool.gauge !== ethers_1.ethers.constants.AddressZero)
|
|
96
|
-
_balance = _balance.add(_rawBalances.shift());
|
|
97
|
-
if (!_userLpBalanceCache[address])
|
|
98
|
-
_userLpBalanceCache[address] = {};
|
|
99
|
-
_userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
100
|
-
}
|
|
101
|
-
_d.label = 2;
|
|
102
|
-
case 2:
|
|
103
|
-
_lpBalances = [];
|
|
104
|
-
for (_b = 0, pools_1 = pools; _b < pools_1.length; _b++) {
|
|
105
|
-
poolId = pools_1[_b];
|
|
106
|
-
_lpBalances.push((_c = _userLpBalanceCache[address]) === null || _c === void 0 ? void 0 : _c[poolId]._lpBalance);
|
|
107
|
-
}
|
|
108
|
-
return [2 /*return*/, _lpBalances];
|
|
57
|
+
// _userClaimable: { address: { poolId: { rewards: [ { token: '0x111...', 'symbol': 'TST', '', 'amount': 0 } ], time: 0 } }
|
|
58
|
+
const _userClaimableCache = {};
|
|
59
|
+
const _isUserClaimableCacheExpired = (address, poolId) => (_userClaimableCache[address]?.[poolId]?.time || 0) + 600000 < Date.now();
|
|
60
|
+
const _getUserClaimable = async (pools, address, useCache) => {
|
|
61
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
|
|
62
|
+
if (poolsToFetch.length > 0) {
|
|
63
|
+
// --- 1. CRV ---
|
|
64
|
+
const hasCrvReward = [];
|
|
65
|
+
for (const poolId of poolsToFetch) {
|
|
66
|
+
const pool = getPool(poolId);
|
|
67
|
+
if (curve.chainId === 2222 || pool.gauge === curve.constants.ZERO_ADDRESS) { // TODO remove this for Kava
|
|
68
|
+
hasCrvReward.push(false);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
72
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
109
73
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
switch (_a.label) {
|
|
118
|
-
case 0:
|
|
119
|
-
pools = __spreadArray(__spreadArray(__spreadArray([], curve_1.curve.getPoolList(), true), curve_1.curve.getFactoryPoolList(), true), curve_1.curve.getCryptoFactoryPoolList(), true);
|
|
120
|
-
return [4 /*yield*/, _getUserLpBalances(pools, address, false)];
|
|
121
|
-
case 1:
|
|
122
|
-
_lpBalances = _a.sent();
|
|
123
|
-
userPoolList = [];
|
|
124
|
-
for (i = 0; i < pools.length; i++) {
|
|
125
|
-
if (_lpBalances[i].gt(0)) {
|
|
126
|
-
userPoolList.push(pools[i]);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return [2 /*return*/, userPoolList];
|
|
74
|
+
// --- 2. The number of reward tokens ---
|
|
75
|
+
const rewardCount = [];
|
|
76
|
+
for (const poolId of poolsToFetch) {
|
|
77
|
+
const pool = getPool(poolId);
|
|
78
|
+
if (pool.gauge === curve.constants.ZERO_ADDRESS) {
|
|
79
|
+
rewardCount.push(0);
|
|
80
|
+
continue;
|
|
130
81
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
exports.getUserPoolListByLiquidity = getUserPoolListByLiquidity;
|
|
135
|
-
var getUserLiquidityUSD = function (pools, address) {
|
|
136
|
-
if (address === void 0) { address = curve_1.curve.signerAddress; }
|
|
137
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
138
|
-
var _lpBalances, userLiquidityUSD, i, pool, price;
|
|
139
|
-
return __generator(this, function (_a) {
|
|
140
|
-
switch (_a.label) {
|
|
141
|
-
case 0: return [4 /*yield*/, _getUserLpBalances(pools, address, true)];
|
|
142
|
-
case 1:
|
|
143
|
-
_lpBalances = _a.sent();
|
|
144
|
-
userLiquidityUSD = [];
|
|
145
|
-
i = 0;
|
|
146
|
-
_a.label = 2;
|
|
147
|
-
case 2:
|
|
148
|
-
if (!(i < pools.length)) return [3 /*break*/, 5];
|
|
149
|
-
pool = (0, poolConstructor_1.getPool)(pools[i]);
|
|
150
|
-
return [4 /*yield*/, (0, utils_1._getUsdRate)(pool.lpToken)];
|
|
151
|
-
case 3:
|
|
152
|
-
price = _a.sent();
|
|
153
|
-
userLiquidityUSD.push((0, utils_1.toBN)(_lpBalances[i]).times(price).toFixed(8));
|
|
154
|
-
_a.label = 4;
|
|
155
|
-
case 4:
|
|
156
|
-
i++;
|
|
157
|
-
return [3 /*break*/, 2];
|
|
158
|
-
case 5: return [2 /*return*/, userLiquidityUSD];
|
|
82
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
83
|
+
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
84
|
+
rewardCount.push(8);
|
|
159
85
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
hasCrvReward = [];
|
|
176
|
-
for (_i = 0, poolsToFetch_3 = poolsToFetch; _i < poolsToFetch_3.length; _i++) {
|
|
177
|
-
poolId = poolsToFetch_3[_i];
|
|
178
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
179
|
-
if (curve_1.curve.chainId === 2222 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava
|
|
180
|
-
hasCrvReward.push(false);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
184
|
-
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
185
|
-
}
|
|
186
|
-
rewardCount = [];
|
|
187
|
-
for (_a = 0, poolsToFetch_4 = poolsToFetch; _a < poolsToFetch_4.length; _a++) {
|
|
188
|
-
poolId = poolsToFetch_4[_a];
|
|
189
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
190
|
-
if (pool.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
191
|
-
rewardCount.push(0);
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
195
|
-
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
196
|
-
rewardCount.push(8);
|
|
197
|
-
}
|
|
198
|
-
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
199
|
-
rewardCount.push(-1);
|
|
200
|
-
}
|
|
201
|
-
else { // gauge
|
|
202
|
-
rewardCount.push(0);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
rewardTokenCalls = [];
|
|
206
|
-
for (i = 0; i < poolsToFetch.length; i++) {
|
|
207
|
-
pool = (0, poolConstructor_1.getPool)(poolsToFetch[i]);
|
|
208
|
-
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
209
|
-
for (count = 0; count < rewardCount[i]; count++) {
|
|
210
|
-
gaugeContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
211
|
-
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else { // gauge_synthetix
|
|
215
|
-
rewardCount[i] = 1;
|
|
216
|
-
rewardContract = curve_1.curve.contracts[pool.sRewardContract].contract;
|
|
217
|
-
rewardMulticallContract = curve_1.curve.contracts[pool.sRewardContract].multicallContract;
|
|
218
|
-
method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
|
|
219
|
-
;
|
|
220
|
-
rewardTokenCalls.push(rewardMulticallContract[method]());
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardTokenCalls)];
|
|
224
|
-
case 1:
|
|
225
|
-
rawRewardTokens = (_h.sent()).map(function (t) { return t.toLowerCase(); });
|
|
226
|
-
rewardTokens = {};
|
|
227
|
-
for (i = 0; i < poolsToFetch.length; i++) {
|
|
228
|
-
rewardTokens[poolsToFetch[i]] = [];
|
|
229
|
-
for (j = 0; j < rewardCount[i]; j++) {
|
|
230
|
-
rewardAddress = rawRewardTokens.shift();
|
|
231
|
-
if (rewardAddress === ethers_1.ethers.constants.AddressZero)
|
|
232
|
-
continue;
|
|
233
|
-
// REYIELD shitcoin which breaks things, because symbol() throws an error
|
|
234
|
-
if (rewardAddress === "0xf228ec3476318aCB4E719D2b290bb2ef8B34DFfA".toLowerCase())
|
|
235
|
-
continue;
|
|
236
|
-
rewardTokens[poolsToFetch[i]].push(rewardAddress);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
rewardInfoCalls = [];
|
|
240
|
-
for (i = 0; i < poolsToFetch.length; i++) {
|
|
241
|
-
poolId = poolsToFetch[i];
|
|
242
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
243
|
-
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
244
|
-
continue;
|
|
245
|
-
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
246
|
-
gaugeMulticallContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
247
|
-
if (hasCrvReward[i]) {
|
|
248
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
249
|
-
}
|
|
250
|
-
for (_b = 0, _c = rewardTokens[poolId]; _b < _c.length; _b++) {
|
|
251
|
-
token = _c[_b];
|
|
252
|
-
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
253
|
-
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
254
|
-
rewardInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
255
|
-
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
256
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
|
|
257
|
-
}
|
|
258
|
-
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
259
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
86
|
+
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
87
|
+
rewardCount.push(-1);
|
|
88
|
+
}
|
|
89
|
+
else { // gauge
|
|
90
|
+
rewardCount.push(0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// --- 3. Reward tokens ---
|
|
94
|
+
const rewardTokenCalls = [];
|
|
95
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
96
|
+
const pool = getPool(poolsToFetch[i]);
|
|
97
|
+
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
98
|
+
for (let count = 0; count < rewardCount[i]; count++) {
|
|
99
|
+
const gaugeContract = curve.contracts[pool.gauge].multicallContract;
|
|
100
|
+
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
262
101
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
102
|
+
}
|
|
103
|
+
else { // gauge_synthetix
|
|
104
|
+
rewardCount[i] = 1;
|
|
105
|
+
const rewardContract = curve.contracts[pool.sRewardContract].contract;
|
|
106
|
+
const rewardMulticallContract = curve.contracts[pool.sRewardContract].multicallContract;
|
|
107
|
+
const method = "snx()" in rewardContract ? "snx" : "rewardsToken"; // susd, tbtc : dusd, musd, rsv, sbtc
|
|
108
|
+
rewardTokenCalls.push(rewardMulticallContract[method]());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const rawRewardTokens = (await curve.multicallProvider.all(rewardTokenCalls)).map((t) => t.toLowerCase());
|
|
112
|
+
const rewardTokens = {};
|
|
113
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
114
|
+
rewardTokens[poolsToFetch[i]] = [];
|
|
115
|
+
for (let j = 0; j < rewardCount[i]; j++) {
|
|
116
|
+
const rewardAddress = rawRewardTokens.shift();
|
|
117
|
+
if (rewardAddress === curve.constants.ZERO_ADDRESS)
|
|
118
|
+
continue;
|
|
119
|
+
// REYIELD shitcoin which breaks things, because symbol() throws an error
|
|
120
|
+
if (rewardAddress === "0xf228ec3476318aCB4E719D2b290bb2ef8B34DFfA".toLowerCase())
|
|
121
|
+
continue;
|
|
122
|
+
rewardTokens[poolsToFetch[i]].push(rewardAddress);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// --- 4. Reward info ---
|
|
126
|
+
const rewardInfoCalls = [];
|
|
127
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
128
|
+
const poolId = poolsToFetch[i];
|
|
129
|
+
const pool = getPool(poolId);
|
|
130
|
+
if (pool.gauge === curve.constants.ZERO_ADDRESS)
|
|
131
|
+
continue;
|
|
132
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
133
|
+
const gaugeMulticallContract = curve.contracts[pool.gauge].multicallContract;
|
|
134
|
+
if (hasCrvReward[i]) {
|
|
135
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
136
|
+
}
|
|
137
|
+
for (const token of rewardTokens[poolId]) {
|
|
138
|
+
_setContracts(token, ERC20Abi);
|
|
139
|
+
const tokenMulticallContract = curve.contracts[token].multicallContract;
|
|
140
|
+
rewardInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
141
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
142
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
|
|
297
143
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
_claimable = [];
|
|
301
|
-
for (_f = 0, pools_2 = pools; _f < pools_2.length; _f++) {
|
|
302
|
-
poolId = pools_2[_f];
|
|
303
|
-
_claimable.push((_g = _userClaimableCache[address]) === null || _g === void 0 ? void 0 : _g[poolId].rewards);
|
|
144
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
145
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
304
146
|
}
|
|
305
|
-
|
|
147
|
+
}
|
|
306
148
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
pool = (0, poolConstructor_1.getPool)(poolsToFetch[i]);
|
|
334
|
-
return [4 /*yield*/, (0, utils_1._getRewardsFromApi)()];
|
|
335
|
-
case 2:
|
|
336
|
-
rewards = _h.sent();
|
|
337
|
-
rewardTokens[poolsToFetch[i]] = ((_f = rewards[pool.gauge]) !== null && _f !== void 0 ? _f : []).map(function (r) { return ({ token: r.tokenAddress, symbol: r.symbol, decimals: r.decimals }); });
|
|
338
|
-
_h.label = 3;
|
|
339
|
-
case 3:
|
|
340
|
-
i++;
|
|
341
|
-
return [3 /*break*/, 1];
|
|
342
|
-
case 4:
|
|
343
|
-
rewardInfoCalls = [];
|
|
344
|
-
for (i = 0; i < poolsToFetch.length; i++) {
|
|
345
|
-
poolId = poolsToFetch[i];
|
|
346
|
-
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
347
|
-
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
348
|
-
continue;
|
|
349
|
-
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
350
|
-
gaugeMulticallContract = curve_1.curve.contracts[pool.gauge].multicallContract;
|
|
351
|
-
if (hasCrvReward[i]) {
|
|
352
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
353
|
-
}
|
|
354
|
-
for (_a = 0, _b = rewardTokens[poolId]; _a < _b.length; _a++) {
|
|
355
|
-
r = _b[_a];
|
|
356
|
-
(0, utils_1._setContracts)(r.token, ERC20_json_1.default);
|
|
357
|
-
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
358
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, r.token));
|
|
359
|
-
}
|
|
360
|
-
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
361
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
149
|
+
const rawRewardInfo = await curve.multicallProvider.all(rewardInfoCalls);
|
|
150
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
151
|
+
const poolId = poolsToFetch[i];
|
|
152
|
+
const pool = getPool(poolId);
|
|
153
|
+
if (!_userClaimableCache[address])
|
|
154
|
+
_userClaimableCache[address] = {};
|
|
155
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
156
|
+
if (pool.gauge === curve.constants.ZERO_ADDRESS)
|
|
157
|
+
continue;
|
|
158
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
159
|
+
if (hasCrvReward[i]) {
|
|
160
|
+
const token = curve.constants.ALIASES.crv;
|
|
161
|
+
const symbol = 'CRV';
|
|
162
|
+
const decimals = 18;
|
|
163
|
+
const _amount = rawRewardInfo.shift();
|
|
164
|
+
const amount = curve.formatUnits(_amount, decimals);
|
|
165
|
+
if (Number(amount) > 0)
|
|
166
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
167
|
+
}
|
|
168
|
+
for (const token of rewardTokens[poolId]) {
|
|
169
|
+
const symbol = rawRewardInfo.shift();
|
|
170
|
+
const decimals = rawRewardInfo.shift();
|
|
171
|
+
let _amount = rawRewardInfo.shift();
|
|
172
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
173
|
+
const _claimedAmount = rawRewardInfo.shift();
|
|
174
|
+
_amount = _amount - _claimedAmount;
|
|
364
175
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
176
|
+
const amount = curve.formatUnits(_amount, decimals);
|
|
177
|
+
if (Number(amount) > 0)
|
|
178
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const _claimable = [];
|
|
183
|
+
for (const poolId of pools) {
|
|
184
|
+
_claimable.push(_userClaimableCache[address]?.[poolId].rewards);
|
|
185
|
+
}
|
|
186
|
+
return _claimable;
|
|
187
|
+
};
|
|
188
|
+
const _getUserClaimableUseApi = async (pools, address, useCache) => {
|
|
189
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
|
|
190
|
+
if (poolsToFetch.length > 0) {
|
|
191
|
+
// --- 1. CRV ---
|
|
192
|
+
const hasCrvReward = [];
|
|
193
|
+
for (const poolId of poolsToFetch) {
|
|
194
|
+
const pool = getPool(poolId);
|
|
195
|
+
if (curve.chainId === 2222 || pool.gauge === curve.constants.ZERO_ADDRESS) { // TODO remove this for Kava
|
|
196
|
+
hasCrvReward.push(false);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
200
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
201
|
+
}
|
|
202
|
+
// --- 2. Reward tokens ---
|
|
203
|
+
const rewardTokens = {};
|
|
204
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
205
|
+
const pool = getPool(poolsToFetch[i]);
|
|
206
|
+
const rewards = await _getRewardsFromApi();
|
|
207
|
+
rewardTokens[poolsToFetch[i]] = (rewards[pool.gauge] ?? []).map((r) => ({ token: r.tokenAddress, symbol: r.symbol, decimals: r.decimals }));
|
|
208
|
+
}
|
|
209
|
+
// --- 3. Reward info ---
|
|
210
|
+
const rewardInfoCalls = [];
|
|
211
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
212
|
+
const poolId = poolsToFetch[i];
|
|
213
|
+
const pool = getPool(poolId);
|
|
214
|
+
if (pool.gauge === curve.constants.ZERO_ADDRESS)
|
|
215
|
+
continue;
|
|
216
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
217
|
+
const gaugeMulticallContract = curve.contracts[pool.gauge].multicallContract;
|
|
218
|
+
if (hasCrvReward[i]) {
|
|
219
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
220
|
+
}
|
|
221
|
+
for (const r of rewardTokens[poolId]) {
|
|
222
|
+
_setContracts(r.token, ERC20Abi);
|
|
223
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
224
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, r.token));
|
|
397
225
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
_claimable = [];
|
|
401
|
-
for (_e = 0, pools_3 = pools; _e < pools_3.length; _e++) {
|
|
402
|
-
poolId = pools_3[_e];
|
|
403
|
-
_claimable.push((_g = _userClaimableCache[address]) === null || _g === void 0 ? void 0 : _g[poolId].rewards);
|
|
226
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
227
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
404
228
|
}
|
|
405
|
-
|
|
229
|
+
}
|
|
406
230
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
return [2 /*return*/, userPoolList];
|
|
231
|
+
const rawRewardInfo = await curve.multicallProvider.all(rewardInfoCalls);
|
|
232
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
233
|
+
const poolId = poolsToFetch[i];
|
|
234
|
+
const pool = getPool(poolId);
|
|
235
|
+
if (!_userClaimableCache[address])
|
|
236
|
+
_userClaimableCache[address] = {};
|
|
237
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
238
|
+
if (pool.gauge === curve.constants.ZERO_ADDRESS)
|
|
239
|
+
continue;
|
|
240
|
+
const gaugeContract = curve.contracts[pool.gauge].contract;
|
|
241
|
+
if (hasCrvReward[i]) {
|
|
242
|
+
const token = curve.constants.ALIASES.crv;
|
|
243
|
+
const symbol = 'CRV';
|
|
244
|
+
const decimals = 18;
|
|
245
|
+
const _amount = rawRewardInfo.shift();
|
|
246
|
+
const amount = curve.formatUnits(_amount, decimals);
|
|
247
|
+
if (Number(amount) > 0)
|
|
248
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
427
249
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
switch (_b.label) {
|
|
438
|
-
case 0: return [4 /*yield*/, _getUserClaimable(pools, address, true)];
|
|
439
|
-
case 1:
|
|
440
|
-
_claimable = _b.sent();
|
|
441
|
-
claimableWithPrice = [];
|
|
442
|
-
i = 0;
|
|
443
|
-
_b.label = 2;
|
|
444
|
-
case 2:
|
|
445
|
-
if (!(i < pools.length)) return [3 /*break*/, 7];
|
|
446
|
-
claimableWithPrice.push([]);
|
|
447
|
-
_i = 0, _a = _claimable[i];
|
|
448
|
-
_b.label = 3;
|
|
449
|
-
case 3:
|
|
450
|
-
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
451
|
-
c = _a[_i];
|
|
452
|
-
return [4 /*yield*/, (0, utils_1._getUsdRate)(c.token)];
|
|
453
|
-
case 4:
|
|
454
|
-
price = _b.sent();
|
|
455
|
-
claimableWithPrice[claimableWithPrice.length - 1].push(__assign(__assign({}, c), { price: price }));
|
|
456
|
-
_b.label = 5;
|
|
457
|
-
case 5:
|
|
458
|
-
_i++;
|
|
459
|
-
return [3 /*break*/, 3];
|
|
460
|
-
case 6:
|
|
461
|
-
i++;
|
|
462
|
-
return [3 /*break*/, 2];
|
|
463
|
-
case 7: return [2 /*return*/, claimableWithPrice];
|
|
250
|
+
for (const r of rewardTokens[poolId]) {
|
|
251
|
+
let _amount = rawRewardInfo.shift();
|
|
252
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
253
|
+
const _claimedAmount = rawRewardInfo.shift();
|
|
254
|
+
_amount = _amount - _claimedAmount;
|
|
255
|
+
}
|
|
256
|
+
const amount = curve.formatUnits(_amount, r.decimals);
|
|
257
|
+
if (Number(amount) > 0)
|
|
258
|
+
_userClaimableCache[address][poolId].rewards.push({ token: r.token, symbol: r.symbol, amount });
|
|
464
259
|
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const _claimable = [];
|
|
263
|
+
for (const poolId of pools) {
|
|
264
|
+
_claimable.push(_userClaimableCache[address]?.[poolId].rewards);
|
|
265
|
+
}
|
|
266
|
+
return _claimable;
|
|
467
267
|
};
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return [4 /*yield*/, Promise.all([
|
|
479
|
-
_getUserLpBalances(pools, address, false),
|
|
480
|
-
useApi ? _getUserClaimableUseApi(pools, address, false) : _getUserClaimable(pools, address, false),
|
|
481
|
-
])];
|
|
482
|
-
case 1:
|
|
483
|
-
_a = _b.sent(), _lpBalances = _a[0], _claimable = _a[1];
|
|
484
|
-
userPoolList = [];
|
|
485
|
-
for (i = 0; i < pools.length; i++) {
|
|
486
|
-
if (_lpBalances[i].gt(0) || _claimable[i].length > 0) {
|
|
487
|
-
userPoolList.push(pools[i]);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return [2 /*return*/, userPoolList];
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
});
|
|
268
|
+
export const getUserPoolListByClaimable = async (address = curve.signerAddress) => {
|
|
269
|
+
const pools = [...curve.getPoolList(), ...curve.getFactoryPoolList(), ...curve.getCryptoFactoryPoolList()];
|
|
270
|
+
const _claimable = await _getUserClaimable(pools, address, false);
|
|
271
|
+
const userPoolList = [];
|
|
272
|
+
for (let i = 0; i < pools.length; i++) {
|
|
273
|
+
if (_claimable[i].length > 0) {
|
|
274
|
+
userPoolList.push(pools[i]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return userPoolList;
|
|
494
278
|
};
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return [2 /*return*/, amplificationCoefficientDict];
|
|
279
|
+
export const getUserClaimable = async (pools, address = curve.signerAddress) => {
|
|
280
|
+
const _claimable = await _getUserClaimable(pools, address, true);
|
|
281
|
+
const claimableWithPrice = [];
|
|
282
|
+
for (let i = 0; i < pools.length; i++) {
|
|
283
|
+
claimableWithPrice.push([]);
|
|
284
|
+
for (const c of _claimable[i]) {
|
|
285
|
+
const price = await _getUsdRate(c.token);
|
|
286
|
+
claimableWithPrice[claimableWithPrice.length - 1].push({ ...c, price });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return claimableWithPrice;
|
|
290
|
+
};
|
|
291
|
+
export const getUserPoolList = async (address = curve.signerAddress, useApi = true) => {
|
|
292
|
+
const pools = [...curve.getPoolList(), ...curve.getFactoryPoolList(), ...curve.getCryptoFactoryPoolList()];
|
|
293
|
+
const [_lpBalances, _claimable] = await Promise.all([
|
|
294
|
+
_getUserLpBalances(pools, address, false),
|
|
295
|
+
useApi ? _getUserClaimableUseApi(pools, address, false) : _getUserClaimable(pools, address, false),
|
|
296
|
+
]);
|
|
297
|
+
const userPoolList = [];
|
|
298
|
+
for (let i = 0; i < pools.length; i++) {
|
|
299
|
+
if (_lpBalances[i] > 0 || _claimable[i].length > 0) {
|
|
300
|
+
userPoolList.push(pools[i]);
|
|
520
301
|
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
302
|
+
}
|
|
303
|
+
return userPoolList;
|
|
304
|
+
};
|
|
305
|
+
export const _getAmplificationCoefficientsFromApi = async () => {
|
|
306
|
+
const network = curve.constants.NETWORK_NAME;
|
|
307
|
+
const promises = [
|
|
308
|
+
_getPoolsFromApi(network, "main"),
|
|
309
|
+
_getPoolsFromApi(network, "crypto"),
|
|
310
|
+
_getPoolsFromApi(network, "factory"),
|
|
311
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
312
|
+
];
|
|
313
|
+
const allTypesExtendedPoolData = await Promise.all(promises);
|
|
314
|
+
const amplificationCoefficientDict = {};
|
|
315
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
316
|
+
for (const pool of extendedPoolData.poolData) {
|
|
317
|
+
amplificationCoefficientDict[pool.address] = Number(pool.amplificationCoefficient);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return amplificationCoefficientDict;
|
|
321
|
+
};
|