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