@curvefi/api 2.66.29 → 2.66.31
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.d.ts +33 -32
- package/lib/boosting.js +320 -252
- package/lib/cached.d.ts +4 -3
- package/lib/cached.js +63 -19
- package/lib/constants/utils.d.ts +14 -1
- package/lib/constants/utils.js +21 -6
- package/lib/curve.d.ts +5 -5
- package/lib/curve.js +21 -38
- package/lib/dao.d.ts +32 -31
- package/lib/dao.js +420 -350
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +2 -2
- package/lib/factory/common.d.ts +2 -1
- package/lib/factory/common.js +1 -1
- package/lib/factory/deploy.d.ts +46 -45
- package/lib/factory/deploy.js +630 -551
- package/lib/factory/factory-api.d.ts +3 -2
- package/lib/factory/factory-api.js +22 -23
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +12 -15
- package/lib/factory/factory-tricrypto.d.ts +1 -1
- package/lib/factory/factory-tricrypto.js +14 -15
- package/lib/factory/factory-twocrypto.d.ts +1 -1
- package/lib/factory/factory-twocrypto.js +12 -13
- package/lib/factory/factory.d.ts +4 -3
- package/lib/factory/factory.js +21 -24
- package/lib/index.d.ts +413 -104
- package/lib/index.js +253 -257
- package/lib/interfaces.d.ts +2 -0
- package/lib/pools/PoolTemplate.d.ts +13 -12
- package/lib/pools/PoolTemplate.js +279 -285
- package/lib/pools/mixins/common.js +2 -2
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
- package/lib/pools/mixins/depositMixins.d.ts +25 -5
- package/lib/pools/mixins/depositMixins.js +38 -76
- package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/depositWrappedMixins.js +17 -33
- package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
- package/lib/pools/mixins/poolBalancesMixin.js +3 -5
- package/lib/pools/mixins/swapMixins.d.ts +20 -4
- package/lib/pools/mixins/swapMixins.js +36 -70
- package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
- package/lib/pools/mixins/swapWrappedMixins.js +32 -60
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
- package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
- package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawMixins.js +33 -67
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
- package/lib/pools/poolConstructor.d.ts +2 -1
- package/lib/pools/poolConstructor.js +27 -28
- package/lib/pools/subClasses/corePool.d.ts +4 -1
- package/lib/pools/subClasses/corePool.js +5 -7
- package/lib/pools/subClasses/gaugePool.d.ts +5 -3
- package/lib/pools/subClasses/gaugePool.js +19 -18
- package/lib/pools/subClasses/statsPool.d.ts +2 -0
- package/lib/pools/subClasses/statsPool.js +22 -10
- package/lib/pools/subClasses/walletPool.d.ts +2 -1
- package/lib/pools/subClasses/walletPool.js +6 -6
- package/lib/pools/utils.d.ts +7 -6
- package/lib/pools/utils.js +316 -297
- package/lib/route-graph.worker.d.ts +2 -2
- package/lib/route-graph.worker.js +4 -6
- package/lib/router.d.ts +12 -11
- package/lib/router.js +331 -295
- package/lib/utils.d.ts +34 -33
- package/lib/utils.js +481 -435
- package/package.json +1 -1
package/lib/pools/utils.js
CHANGED
|
@@ -8,340 +8,359 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { getPool } from "./poolConstructor.js";
|
|
11
|
-
import { curve } from "../curve.js";
|
|
12
11
|
import { _getRewardsFromApi, _getUsdRate, _setContracts, toBN } from "../utils.js";
|
|
13
12
|
import { _getAllPoolsFromApi } from "../cached.js";
|
|
14
|
-
import ERC20Abi from "../constants/abis/ERC20.json" with { type:
|
|
13
|
+
import ERC20Abi from "../constants/abis/ERC20.json" with { type: "json" };
|
|
15
14
|
const BATCH_SIZE = 50;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
function batchedMulticall(calls) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const results = [];
|
|
18
|
+
for (let i = 0; i < calls.length; i += BATCH_SIZE) {
|
|
19
|
+
const batch = calls.slice(i, i + BATCH_SIZE);
|
|
20
|
+
const res = yield this.multicallProvider.all(batch);
|
|
21
|
+
results.push(...res);
|
|
22
|
+
}
|
|
23
|
+
return results;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
25
26
|
// _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
|
|
26
27
|
const _userLpBalanceCache = {};
|
|
27
28
|
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(); };
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
function _getUserLpBalances(pools, address, useCache) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a;
|
|
32
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserLpBalanceCacheExpired(address, poolId)) : pools;
|
|
33
|
+
if (poolsToFetch.length > 0) {
|
|
34
|
+
const calls = [];
|
|
35
|
+
for (const poolId of poolsToFetch) {
|
|
36
|
+
const pool = getPool.call(this, poolId);
|
|
37
|
+
calls.push(this.contracts[pool.lpToken].multicallContract.balanceOf(address));
|
|
38
|
+
if (pool.gauge.address && pool.gauge.address !== this.constants.ZERO_ADDRESS) {
|
|
39
|
+
calls.push(this.contracts[pool.gauge.address].multicallContract.balanceOf(address));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const _rawBalances = yield batchedMulticall.call(this, calls);
|
|
43
|
+
for (const poolId of poolsToFetch) {
|
|
44
|
+
const pool = getPool.call(this, poolId);
|
|
45
|
+
let _balance = _rawBalances.shift();
|
|
46
|
+
if (pool.gauge.address && pool.gauge.address !== this.constants.ZERO_ADDRESS)
|
|
47
|
+
_balance = _balance + _rawBalances.shift();
|
|
48
|
+
if (!_userLpBalanceCache[address])
|
|
49
|
+
_userLpBalanceCache[address] = {};
|
|
50
|
+
_userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
|
-
const
|
|
41
|
-
for (const poolId of
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
const _lpBalances = [];
|
|
54
|
+
for (const poolId of pools) {
|
|
55
|
+
_lpBalances.push((_a = _userLpBalanceCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]._lpBalance);
|
|
56
|
+
}
|
|
57
|
+
return _lpBalances;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function getUserPoolListByLiquidity() {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* (address = this.signerAddress) {
|
|
62
|
+
const pools = this.getPoolList();
|
|
63
|
+
const _lpBalances = yield _getUserLpBalances.call(this, pools, address, false);
|
|
64
|
+
const userPoolList = [];
|
|
65
|
+
for (let i = 0; i < pools.length; i++) {
|
|
66
|
+
if (_lpBalances[i] > 0) {
|
|
67
|
+
userPoolList.push(pools[i]);
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < pools.length; i++) {
|
|
62
|
-
if (_lpBalances[i] > 0) {
|
|
63
|
-
userPoolList.push(pools[i]);
|
|
70
|
+
return userPoolList;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function getUserLiquidityUSD(pools_1) {
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* (pools, address = this.signerAddress) {
|
|
75
|
+
const _lpBalances = yield _getUserLpBalances.call(this, pools, address, true);
|
|
76
|
+
const userLiquidityUSD = [];
|
|
77
|
+
for (let i = 0; i < pools.length; i++) {
|
|
78
|
+
const pool = getPool.call(this, pools[i]);
|
|
79
|
+
const price = yield _getUsdRate.call(this, pool.lpToken);
|
|
80
|
+
userLiquidityUSD.push(toBN(_lpBalances[i]).times(price).toFixed(8));
|
|
64
81
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
export const getUserLiquidityUSD = (pools_1, ...args_1) => __awaiter(void 0, [pools_1, ...args_1], void 0, function* (pools, address = curve.signerAddress) {
|
|
69
|
-
const _lpBalances = yield _getUserLpBalances(pools, address, true);
|
|
70
|
-
const userLiquidityUSD = [];
|
|
71
|
-
for (let i = 0; i < pools.length; i++) {
|
|
72
|
-
const pool = getPool(pools[i]);
|
|
73
|
-
const price = yield _getUsdRate(pool.lpToken);
|
|
74
|
-
userLiquidityUSD.push(toBN(_lpBalances[i]).times(price).toFixed(8));
|
|
75
|
-
}
|
|
76
|
-
return userLiquidityUSD;
|
|
77
|
-
});
|
|
82
|
+
return userLiquidityUSD;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
78
85
|
// _userClaimable: { address: { poolId: { rewards: [ { token: '0x111...', 'symbol': 'TST', '', 'amount': 0 } ], time: 0 } }
|
|
79
86
|
const _userClaimableCache = {};
|
|
80
87
|
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(); };
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const gaugeContract = curve.contracts[pool.gauge.address].contract;
|
|
94
|
-
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
95
|
-
}
|
|
96
|
-
// --- 2. The number of reward tokens ---
|
|
97
|
-
const rewardCount = [];
|
|
98
|
-
for (const poolId of poolsToFetch) {
|
|
99
|
-
const pool = getPool(poolId);
|
|
100
|
-
if (pool.gauge.address === curve.constants.ZERO_ADDRESS) {
|
|
101
|
-
rewardCount.push(0);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const gaugeContract = curve.contracts[pool.gauge.address].contract;
|
|
105
|
-
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
106
|
-
rewardCount.push(8);
|
|
107
|
-
}
|
|
108
|
-
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
109
|
-
rewardCount.push(-1);
|
|
110
|
-
}
|
|
111
|
-
else { // gauge
|
|
112
|
-
rewardCount.push(0);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// --- 3. Reward tokens ---
|
|
116
|
-
const rewardTokenCalls = [];
|
|
117
|
-
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
118
|
-
const pool = getPool(poolsToFetch[i]);
|
|
119
|
-
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
120
|
-
for (let count = 0; count < rewardCount[i]; count++) {
|
|
121
|
-
const gaugeContract = curve.contracts[pool.gauge.address].multicallContract;
|
|
122
|
-
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
88
|
+
function _getUserClaimable(pools, address, useCache) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
var _a;
|
|
91
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
|
|
92
|
+
if (poolsToFetch.length > 0) {
|
|
93
|
+
// --- 1. CRV ---
|
|
94
|
+
const hasCrvReward = [];
|
|
95
|
+
for (const poolId of poolsToFetch) {
|
|
96
|
+
const pool = getPool.call(this, poolId);
|
|
97
|
+
if (this.chainId === 324 || this.chainId === 2222 || pool.gauge.address === this.constants.ZERO_ADDRESS) { // TODO remove this for ZkSync and Kava
|
|
98
|
+
hasCrvReward.push(false);
|
|
99
|
+
continue;
|
|
123
100
|
}
|
|
101
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
102
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
124
103
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const rawRewardTokens = (yield batchedMulticall(rewardTokenCalls)).map((t) => t.toLowerCase());
|
|
134
|
-
const rewardTokens = {};
|
|
135
|
-
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
136
|
-
rewardTokens[poolsToFetch[i]] = [];
|
|
137
|
-
for (let j = 0; j < rewardCount[i]; j++) {
|
|
138
|
-
const rewardAddress = rawRewardTokens.shift();
|
|
139
|
-
if (rewardAddress === curve.constants.ZERO_ADDRESS)
|
|
140
|
-
continue;
|
|
141
|
-
if (curve.chainId !== 1 && rewardAddress === curve.constants.COINS.crv)
|
|
142
|
-
continue;
|
|
143
|
-
// REYIELD shitcoin which breaks things, because symbol() throws an error
|
|
144
|
-
if (rewardAddress === "0xf228ec3476318aCB4E719D2b290bb2ef8B34DFfA".toLowerCase())
|
|
104
|
+
// --- 2. The number of reward tokens ---
|
|
105
|
+
const rewardCount = [];
|
|
106
|
+
for (const poolId of poolsToFetch) {
|
|
107
|
+
const pool = getPool.call(this, poolId);
|
|
108
|
+
if (pool.gauge.address === this.constants.ZERO_ADDRESS) {
|
|
109
|
+
rewardCount.push(0);
|
|
145
110
|
continue;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const gaugeMulticallContract = curve.contracts[pool.gauge.address].multicallContract;
|
|
158
|
-
if (hasCrvReward[i]) {
|
|
159
|
-
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
111
|
+
}
|
|
112
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
113
|
+
if ("reward_tokens(uint256)" in gaugeContract) { // gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
114
|
+
rewardCount.push(8);
|
|
115
|
+
}
|
|
116
|
+
else if ('claimable_reward(address)' in gaugeContract) { // gauge_synthetix
|
|
117
|
+
rewardCount.push(-1);
|
|
118
|
+
}
|
|
119
|
+
else { // gauge
|
|
120
|
+
rewardCount.push(0);
|
|
121
|
+
}
|
|
160
122
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
123
|
+
// --- 3. Reward tokens ---
|
|
124
|
+
const rewardTokenCalls = [];
|
|
125
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
126
|
+
const pool = getPool.call(this, poolsToFetch[i]);
|
|
127
|
+
if (rewardCount[i] !== -1) { // no_gauge, gauge, gauge_v2, gauge_v3, gauge_v4, gauge_v5, gauge_factory, gauge_rewards_only, gauge_child
|
|
128
|
+
for (let count = 0; count < rewardCount[i]; count++) {
|
|
129
|
+
const gaugeContract = this.contracts[pool.gauge.address].multicallContract;
|
|
130
|
+
rewardTokenCalls.push(gaugeContract.reward_tokens(count));
|
|
131
|
+
}
|
|
167
132
|
}
|
|
168
|
-
else
|
|
169
|
-
|
|
133
|
+
else { // gauge_synthetix
|
|
134
|
+
rewardCount[i] = 1;
|
|
135
|
+
const rewardContract = this.contracts[pool.sRewardContract].contract;
|
|
136
|
+
const rewardMulticallContract = this.contracts[pool.sRewardContract].multicallContract;
|
|
137
|
+
const method = "snx()" in rewardContract ? "snx" : "rewardsToken"; // susd, tbtc : dusd, musd, rsv, sbtc
|
|
138
|
+
rewardTokenCalls.push(rewardMulticallContract[method]());
|
|
170
139
|
}
|
|
171
140
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const _amount = rawRewardInfo.shift();
|
|
188
|
-
const amount = curve.formatUnits(_amount, decimals);
|
|
189
|
-
if (Number(amount) > 0)
|
|
190
|
-
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
141
|
+
const rawRewardTokens = (yield batchedMulticall.call(this, rewardTokenCalls)).map((t) => t.toLowerCase());
|
|
142
|
+
const rewardTokens = {};
|
|
143
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
144
|
+
rewardTokens[poolsToFetch[i]] = [];
|
|
145
|
+
for (let j = 0; j < rewardCount[i]; j++) {
|
|
146
|
+
const rewardAddress = rawRewardTokens.shift();
|
|
147
|
+
if (rewardAddress === this.constants.ZERO_ADDRESS)
|
|
148
|
+
continue;
|
|
149
|
+
if (this.chainId !== 1 && rewardAddress === this.constants.COINS.crv)
|
|
150
|
+
continue;
|
|
151
|
+
// REYIELD shitcoin which breaks things, because symbol() throws an error
|
|
152
|
+
if (rewardAddress === "0xf228ec3476318aCB4E719D2b290bb2ef8B34DFfA".toLowerCase())
|
|
153
|
+
continue;
|
|
154
|
+
rewardTokens[poolsToFetch[i]].push(rewardAddress);
|
|
155
|
+
}
|
|
191
156
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
157
|
+
// --- 4. Reward info ---
|
|
158
|
+
const rewardInfoCalls = [];
|
|
159
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
160
|
+
const poolId = poolsToFetch[i];
|
|
161
|
+
const pool = getPool.call(this, poolId);
|
|
162
|
+
if (pool.gauge.address === this.constants.ZERO_ADDRESS)
|
|
163
|
+
continue;
|
|
164
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
165
|
+
const gaugeMulticallContract = this.contracts[pool.gauge.address].multicallContract;
|
|
166
|
+
if (hasCrvReward[i]) {
|
|
167
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
168
|
+
}
|
|
169
|
+
for (const token of rewardTokens[poolId]) {
|
|
170
|
+
// Don't reset the reward ABI if the reward is the LP token itself, otherwise we lose LP contract functions
|
|
171
|
+
const { multicallContract } = token === pool.address ? this.contracts[token] : _setContracts.call(this, token, ERC20Abi);
|
|
172
|
+
rewardInfoCalls.push(multicallContract.symbol(), multicallContract.decimals());
|
|
173
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
174
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
|
|
175
|
+
}
|
|
176
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
177
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
178
|
+
}
|
|
199
179
|
}
|
|
200
|
-
const amount = curve.formatUnits(_amount, decimals);
|
|
201
|
-
if (Number(amount) > 0)
|
|
202
|
-
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
203
180
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
181
|
+
const rawRewardInfo = yield batchedMulticall.call(this, rewardInfoCalls);
|
|
182
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
183
|
+
const poolId = poolsToFetch[i];
|
|
184
|
+
const pool = getPool.call(this, poolId);
|
|
185
|
+
if (!_userClaimableCache[address])
|
|
186
|
+
_userClaimableCache[address] = {};
|
|
187
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
188
|
+
if (pool.gauge.address === this.constants.ZERO_ADDRESS)
|
|
189
|
+
continue;
|
|
190
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
191
|
+
if (hasCrvReward[i]) {
|
|
192
|
+
const token = this.constants.ALIASES.crv;
|
|
193
|
+
const symbol = 'CRV';
|
|
194
|
+
const decimals = 18;
|
|
195
|
+
const _amount = rawRewardInfo.shift();
|
|
196
|
+
const amount = this.formatUnits(_amount, decimals);
|
|
197
|
+
if (Number(amount) > 0)
|
|
198
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
199
|
+
}
|
|
200
|
+
for (const token of rewardTokens[poolId]) {
|
|
201
|
+
const symbol = rawRewardInfo.shift();
|
|
202
|
+
const decimals = Number(rawRewardInfo.shift());
|
|
203
|
+
let _amount = rawRewardInfo.shift();
|
|
204
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
205
|
+
const _claimedAmount = rawRewardInfo.shift();
|
|
206
|
+
_amount = _amount - _claimedAmount;
|
|
207
|
+
}
|
|
208
|
+
const amount = this.formatUnits(_amount, decimals);
|
|
209
|
+
if (Number(amount) > 0)
|
|
210
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
211
|
+
}
|
|
223
212
|
}
|
|
224
|
-
const gaugeContract = curve.contracts[pool.gauge.address].contract;
|
|
225
|
-
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
226
213
|
}
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
const pool = getPool(poolsToFetch[i]);
|
|
231
|
-
const rewards = yield _getRewardsFromApi();
|
|
232
|
-
rewardTokens[poolsToFetch[i]] = ((_a = rewards[pool.gauge.address]) !== null && _a !== void 0 ? _a : [])
|
|
233
|
-
.map((r) => ({ token: r.tokenAddress, symbol: r.symbol, decimals: Number(r.decimals) }));
|
|
214
|
+
const _claimable = [];
|
|
215
|
+
for (const poolId of pools) {
|
|
216
|
+
_claimable.push((_a = _userClaimableCache[address]) === null || _a === void 0 ? void 0 : _a[poolId].rewards);
|
|
234
217
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
_setContracts(r.token, ERC20Abi);
|
|
218
|
+
return _claimable;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function _getUserClaimableUseApi(pools, address, useCache) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
|
|
225
|
+
if (poolsToFetch.length > 0) {
|
|
226
|
+
// --- 1. CRV ---
|
|
227
|
+
const hasCrvReward = [];
|
|
228
|
+
for (const poolId of poolsToFetch) {
|
|
229
|
+
const pool = getPool.call(this, poolId);
|
|
230
|
+
if (this.chainId === 324 || this.chainId === 2222 || pool.gauge.address === this.constants.ZERO_ADDRESS) { // TODO remove this for ZkSync and Kava
|
|
231
|
+
hasCrvReward.push(false);
|
|
232
|
+
continue;
|
|
251
233
|
}
|
|
252
|
-
|
|
253
|
-
|
|
234
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
235
|
+
hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
236
|
+
}
|
|
237
|
+
// --- 2. Reward tokens ---
|
|
238
|
+
const rewardTokens = {};
|
|
239
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
240
|
+
const pool = getPool.call(this, poolsToFetch[i]);
|
|
241
|
+
const rewards = yield _getRewardsFromApi.call(this);
|
|
242
|
+
rewardTokens[poolsToFetch[i]] = ((_a = rewards[pool.gauge.address]) !== null && _a !== void 0 ? _a : [])
|
|
243
|
+
.map((r) => ({ token: r.tokenAddress, symbol: r.symbol, decimals: Number(r.decimals) }));
|
|
244
|
+
}
|
|
245
|
+
// --- 3. Reward info ---
|
|
246
|
+
const rewardInfoCalls = [];
|
|
247
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
248
|
+
const poolId = poolsToFetch[i];
|
|
249
|
+
const pool = getPool.call(this, poolId);
|
|
250
|
+
if (pool.gauge.address === this.constants.ZERO_ADDRESS)
|
|
251
|
+
continue;
|
|
252
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
253
|
+
const gaugeMulticallContract = this.contracts[pool.gauge.address].multicallContract;
|
|
254
|
+
if (hasCrvReward[i]) {
|
|
255
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
|
|
254
256
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
+
for (const r of rewardTokens[poolId]) {
|
|
258
|
+
// Don't reset the reward ABI if the reward is the LP token itself, otherwise we lose LP contract functions
|
|
259
|
+
if (r.token !== pool.address) {
|
|
260
|
+
_setContracts.call(this, r.token, ERC20Abi);
|
|
261
|
+
}
|
|
262
|
+
if ('claimable_reward(address,address)' in gaugeContract) {
|
|
263
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, r.token));
|
|
264
|
+
}
|
|
265
|
+
else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
|
|
266
|
+
rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
|
|
267
|
+
}
|
|
257
268
|
}
|
|
258
269
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
_userClaimableCache[address] = {};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
270
|
+
const rawRewardInfo = yield batchedMulticall.call(this, rewardInfoCalls);
|
|
271
|
+
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
272
|
+
const poolId = poolsToFetch[i];
|
|
273
|
+
const pool = getPool.call(this, poolId);
|
|
274
|
+
if (!_userClaimableCache[address])
|
|
275
|
+
_userClaimableCache[address] = {};
|
|
276
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
277
|
+
if (pool.gauge.address === this.constants.ZERO_ADDRESS)
|
|
278
|
+
continue;
|
|
279
|
+
const gaugeContract = this.contracts[pool.gauge.address].contract;
|
|
280
|
+
if (hasCrvReward[i]) {
|
|
281
|
+
const token = this.constants.ALIASES.crv;
|
|
282
|
+
const symbol = 'CRV';
|
|
283
|
+
const decimals = 18;
|
|
284
|
+
const _amount = rawRewardInfo.shift();
|
|
285
|
+
const amount = this.formatUnits(_amount, decimals);
|
|
286
|
+
if (Number(amount) > 0)
|
|
287
|
+
_userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
|
|
288
|
+
}
|
|
289
|
+
for (const r of rewardTokens[poolId]) {
|
|
290
|
+
let _amount = rawRewardInfo.shift();
|
|
291
|
+
if ('claimable_reward(address)' in gaugeContract) {
|
|
292
|
+
const _claimedAmount = rawRewardInfo.shift();
|
|
293
|
+
_amount = _amount - _claimedAmount;
|
|
294
|
+
}
|
|
295
|
+
const amount = this.formatUnits(_amount, r.decimals);
|
|
296
|
+
if (Number(amount) > 0)
|
|
297
|
+
_userClaimableCache[address][poolId].rewards.push({ token: r.token, symbol: r.symbol, amount });
|
|
284
298
|
}
|
|
285
|
-
const amount = curve.formatUnits(_amount, r.decimals);
|
|
286
|
-
if (Number(amount) > 0)
|
|
287
|
-
_userClaimableCache[address][poolId].rewards.push({ token: r.token, symbol: r.symbol, amount });
|
|
288
299
|
}
|
|
289
300
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
export
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
const _claimable = [];
|
|
302
|
+
for (const poolId of pools) {
|
|
303
|
+
_claimable.push((_b = _userClaimableCache[address]) === null || _b === void 0 ? void 0 : _b[poolId].rewards);
|
|
304
|
+
}
|
|
305
|
+
return _claimable;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
export function getUserPoolListByClaimable() {
|
|
309
|
+
return __awaiter(this, arguments, void 0, function* (address = this.signerAddress) {
|
|
310
|
+
const pools = this.getPoolList();
|
|
311
|
+
const _claimable = yield _getUserClaimable.call(this, pools, address, false);
|
|
312
|
+
const userPoolList = [];
|
|
313
|
+
for (let i = 0; i < pools.length; i++) {
|
|
314
|
+
if (_claimable[i].length > 0) {
|
|
315
|
+
userPoolList.push(pools[i]);
|
|
316
|
+
}
|
|
304
317
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
export
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
318
|
+
return userPoolList;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
export function getUserClaimable(pools_1) {
|
|
322
|
+
return __awaiter(this, arguments, void 0, function* (pools, address = this.signerAddress) {
|
|
323
|
+
const _claimable = yield _getUserClaimable.call(this, pools, address, true);
|
|
324
|
+
const claimableWithPrice = [];
|
|
325
|
+
for (let i = 0; i < pools.length; i++) {
|
|
326
|
+
claimableWithPrice.push([]);
|
|
327
|
+
for (const c of _claimable[i]) {
|
|
328
|
+
const price = yield _getUsdRate.call(this, c.token);
|
|
329
|
+
claimableWithPrice[claimableWithPrice.length - 1].push(Object.assign(Object.assign({}, c), { price }));
|
|
330
|
+
}
|
|
316
331
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
export
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
332
|
+
return claimableWithPrice;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
export function getUserPoolList() {
|
|
336
|
+
return __awaiter(this, arguments, void 0, function* (address = this.signerAddress, useApi = true) {
|
|
337
|
+
const pools = this.getPoolList();
|
|
338
|
+
const [_lpBalances, _claimable] = yield Promise.all([
|
|
339
|
+
_getUserLpBalances.call(this, pools, address, false),
|
|
340
|
+
useApi ? _getUserClaimableUseApi.call(this, pools, address, false) : _getUserClaimable.call(this, pools, address, false),
|
|
341
|
+
]);
|
|
342
|
+
const userPoolList = [];
|
|
343
|
+
for (let i = 0; i < pools.length; i++) {
|
|
344
|
+
if (_lpBalances[i] > 0 || _claimable[i].length > 0) {
|
|
345
|
+
userPoolList.push(pools[i]);
|
|
346
|
+
}
|
|
330
347
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
export
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
for (const
|
|
340
|
-
|
|
348
|
+
return userPoolList;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
export function _getAmplificationCoefficientsFromApi() {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
+
const network = this.constants.NETWORK_NAME;
|
|
354
|
+
const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network, this.isLiteChain);
|
|
355
|
+
const amplificationCoefficientDict = {};
|
|
356
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
357
|
+
for (const pool of extendedPoolData.poolData) {
|
|
358
|
+
amplificationCoefficientDict[pool.address.toLowerCase()] = Number(pool.amplificationCoefficient);
|
|
359
|
+
}
|
|
341
360
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
361
|
+
return amplificationCoefficientDict;
|
|
362
|
+
});
|
|
363
|
+
}
|
|
345
364
|
export const checkVyperVulnerability = (chainId, poolId, implementation) => {
|
|
346
365
|
var _a, _b;
|
|
347
366
|
if (chainId === 1 && poolId === "crveth")
|