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