@curvefi/api 2.66.30 → 2.67.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.
Files changed (94) hide show
  1. package/lib/boosting.d.ts +33 -32
  2. package/lib/boosting.js +320 -252
  3. package/lib/cached.d.ts +4 -3
  4. package/lib/cached.js +63 -19
  5. package/lib/constants/coins/hyperliquid.d.ts +2 -0
  6. package/lib/constants/coins/hyperliquid.js +5 -0
  7. package/lib/constants/coins/index.d.ts +2 -1
  8. package/lib/constants/coins/index.js +2 -1
  9. package/lib/constants/factory/crypto.d.ts +5 -0
  10. package/lib/constants/factory/crypto.js +8 -0
  11. package/lib/constants/factory/stable.js +3 -0
  12. package/lib/constants/network_constants.js +37 -11
  13. package/lib/constants/pools/hyperliquid.d.ts +2 -0
  14. package/lib/constants/pools/hyperliquid.js +2 -0
  15. package/lib/constants/pools/index.d.ts +2 -1
  16. package/lib/constants/pools/index.js +2 -1
  17. package/lib/constants/utils.d.ts +14 -1
  18. package/lib/constants/utils.js +21 -6
  19. package/lib/constants/volumeNetworks.js +1 -1
  20. package/lib/curve.d.ts +5 -5
  21. package/lib/curve.js +21 -38
  22. package/lib/dao.d.ts +32 -31
  23. package/lib/dao.js +420 -350
  24. package/lib/external-api.d.ts +1 -1
  25. package/lib/external-api.js +2 -2
  26. package/lib/factory/common.d.ts +2 -1
  27. package/lib/factory/common.js +1 -1
  28. package/lib/factory/deploy.d.ts +46 -45
  29. package/lib/factory/deploy.js +630 -551
  30. package/lib/factory/factory-api.d.ts +3 -2
  31. package/lib/factory/factory-api.js +22 -23
  32. package/lib/factory/factory-crypto.d.ts +1 -1
  33. package/lib/factory/factory-crypto.js +12 -15
  34. package/lib/factory/factory-tricrypto.d.ts +1 -1
  35. package/lib/factory/factory-tricrypto.js +14 -15
  36. package/lib/factory/factory-twocrypto.d.ts +1 -1
  37. package/lib/factory/factory-twocrypto.js +12 -13
  38. package/lib/factory/factory.d.ts +4 -3
  39. package/lib/factory/factory.js +21 -24
  40. package/lib/index.d.ts +413 -104
  41. package/lib/index.js +253 -257
  42. package/lib/interfaces.d.ts +2 -0
  43. package/lib/pools/PoolTemplate.d.ts +13 -12
  44. package/lib/pools/PoolTemplate.js +279 -285
  45. package/lib/pools/mixins/common.js +2 -2
  46. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
  47. package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
  48. package/lib/pools/mixins/depositMixins.d.ts +25 -5
  49. package/lib/pools/mixins/depositMixins.js +38 -76
  50. package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
  51. package/lib/pools/mixins/depositWrappedMixins.js +17 -33
  52. package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
  53. package/lib/pools/mixins/poolBalancesMixin.js +3 -5
  54. package/lib/pools/mixins/swapMixins.d.ts +20 -4
  55. package/lib/pools/mixins/swapMixins.js +36 -70
  56. package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
  57. package/lib/pools/mixins/swapWrappedMixins.js +32 -60
  58. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
  59. package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
  60. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
  61. package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
  62. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
  63. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
  64. package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
  65. package/lib/pools/mixins/withdrawMixins.js +33 -67
  66. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
  67. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
  68. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
  69. package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
  70. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
  73. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
  74. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
  75. package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
  76. package/lib/pools/poolConstructor.d.ts +2 -1
  77. package/lib/pools/poolConstructor.js +27 -28
  78. package/lib/pools/subClasses/corePool.d.ts +4 -1
  79. package/lib/pools/subClasses/corePool.js +5 -7
  80. package/lib/pools/subClasses/gaugePool.d.ts +5 -3
  81. package/lib/pools/subClasses/gaugePool.js +19 -18
  82. package/lib/pools/subClasses/statsPool.d.ts +2 -0
  83. package/lib/pools/subClasses/statsPool.js +22 -10
  84. package/lib/pools/subClasses/walletPool.d.ts +2 -1
  85. package/lib/pools/subClasses/walletPool.js +6 -6
  86. package/lib/pools/utils.d.ts +7 -6
  87. package/lib/pools/utils.js +316 -297
  88. package/lib/route-graph.worker.d.ts +2 -2
  89. package/lib/route-graph.worker.js +4 -6
  90. package/lib/router.d.ts +12 -11
  91. package/lib/router.js +331 -295
  92. package/lib/utils.d.ts +34 -33
  93. package/lib/utils.js +483 -435
  94. package/package.json +2 -2
@@ -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: 'json' };
13
+ import ERC20Abi from "../constants/abis/ERC20.json" with { type: "json" };
15
14
  const BATCH_SIZE = 50;
16
- const batchedMulticall = (calls) => __awaiter(void 0, 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 curve.multicallProvider.all(batch);
21
- results.push(...res);
22
- }
23
- return results;
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
- const _getUserLpBalances = (pools, address, useCache) => __awaiter(void 0, void 0, void 0, function* () {
29
- var _a;
30
- const poolsToFetch = useCache ? pools.filter((poolId) => _isUserLpBalanceCacheExpired(address, poolId)) : pools;
31
- if (poolsToFetch.length > 0) {
32
- const calls = [];
33
- for (const poolId of poolsToFetch) {
34
- const pool = getPool(poolId);
35
- calls.push(curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
36
- if (pool.gauge.address && pool.gauge.address !== curve.constants.ZERO_ADDRESS) {
37
- calls.push(curve.contracts[pool.gauge.address].multicallContract.balanceOf(address));
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 _rawBalances = yield batchedMulticall(calls);
41
- for (const poolId of poolsToFetch) {
42
- const pool = getPool(poolId);
43
- let _balance = _rawBalances.shift();
44
- if (pool.gauge.address && pool.gauge.address !== curve.constants.ZERO_ADDRESS)
45
- _balance = _balance + _rawBalances.shift();
46
- if (!_userLpBalanceCache[address])
47
- _userLpBalanceCache[address] = {};
48
- _userLpBalanceCache[address][poolId] = { '_lpBalance': _balance, 'time': Date.now() };
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
- const _lpBalances = [];
52
- for (const poolId of pools) {
53
- _lpBalances.push((_a = _userLpBalanceCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]._lpBalance);
54
- }
55
- return _lpBalances;
56
- });
57
- export const getUserPoolListByLiquidity = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = curve.signerAddress) {
58
- const pools = curve.getPoolList();
59
- const _lpBalances = yield _getUserLpBalances(pools, address, false);
60
- const userPoolList = [];
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
- return userPoolList;
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
- const _getUserClaimable = (pools, address, useCache) => __awaiter(void 0, void 0, void 0, function* () {
82
- var _a;
83
- const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
84
- if (poolsToFetch.length > 0) {
85
- // --- 1. CRV ---
86
- const hasCrvReward = [];
87
- for (const poolId of poolsToFetch) {
88
- const pool = getPool(poolId);
89
- if (curve.chainId === 324 || curve.chainId === 2222 || pool.gauge.address === curve.constants.ZERO_ADDRESS) { // TODO remove this for ZkSync and Kava
90
- hasCrvReward.push(false);
91
- continue;
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
- else { // gauge_synthetix
126
- rewardCount[i] = 1;
127
- const rewardContract = curve.contracts[pool.sRewardContract].contract;
128
- const rewardMulticallContract = curve.contracts[pool.sRewardContract].multicallContract;
129
- const method = "snx()" in rewardContract ? "snx" : "rewardsToken"; // susd, tbtc : dusd, musd, rsv, sbtc
130
- rewardTokenCalls.push(rewardMulticallContract[method]());
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
- rewardTokens[poolsToFetch[i]].push(rewardAddress);
147
- }
148
- }
149
- // --- 4. Reward info ---
150
- const rewardInfoCalls = [];
151
- for (let i = 0; i < poolsToFetch.length; i++) {
152
- const poolId = poolsToFetch[i];
153
- const pool = getPool(poolId);
154
- if (pool.gauge.address === curve.constants.ZERO_ADDRESS)
155
- continue;
156
- const gaugeContract = curve.contracts[pool.gauge.address].contract;
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
- for (const token of rewardTokens[poolId]) {
162
- // Don't reset the reward ABI if the reward is the LP token itself, otherwise we lose LP contract functions
163
- const { multicallContract } = token === pool.address ? curve.contracts[token] : _setContracts(token, ERC20Abi);
164
- rewardInfoCalls.push(multicallContract.symbol(), multicallContract.decimals());
165
- if ('claimable_reward(address,address)' in gaugeContract) {
166
- rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, token));
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 if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
169
- rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
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
- const rawRewardInfo = yield batchedMulticall(rewardInfoCalls);
174
- for (let i = 0; i < poolsToFetch.length; i++) {
175
- const poolId = poolsToFetch[i];
176
- const pool = getPool(poolId);
177
- if (!_userClaimableCache[address])
178
- _userClaimableCache[address] = {};
179
- _userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
180
- if (pool.gauge.address === curve.constants.ZERO_ADDRESS)
181
- continue;
182
- const gaugeContract = curve.contracts[pool.gauge.address].contract;
183
- if (hasCrvReward[i]) {
184
- const token = curve.constants.ALIASES.crv;
185
- const symbol = 'CRV';
186
- const decimals = 18;
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
- for (const token of rewardTokens[poolId]) {
193
- const symbol = rawRewardInfo.shift();
194
- const decimals = Number(rawRewardInfo.shift());
195
- let _amount = rawRewardInfo.shift();
196
- if ('claimable_reward(address)' in gaugeContract) {
197
- const _claimedAmount = rawRewardInfo.shift();
198
- _amount = _amount - _claimedAmount;
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
- const _claimable = [];
207
- for (const poolId of pools) {
208
- _claimable.push((_a = _userClaimableCache[address]) === null || _a === void 0 ? void 0 : _a[poolId].rewards);
209
- }
210
- return _claimable;
211
- });
212
- const _getUserClaimableUseApi = (pools, address, useCache) => __awaiter(void 0, void 0, void 0, function* () {
213
- var _a, _b;
214
- const poolsToFetch = useCache ? pools.filter((poolId) => _isUserClaimableCacheExpired(address, poolId)) : pools;
215
- if (poolsToFetch.length > 0) {
216
- // --- 1. CRV ---
217
- const hasCrvReward = [];
218
- for (const poolId of poolsToFetch) {
219
- const pool = getPool(poolId);
220
- if (curve.chainId === 324 || curve.chainId === 2222 || pool.gauge.address === curve.constants.ZERO_ADDRESS) { // TODO remove this for ZkSync and Kava
221
- hasCrvReward.push(false);
222
- continue;
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
- // --- 2. Reward tokens ---
228
- const rewardTokens = {};
229
- for (let i = 0; i < poolsToFetch.length; i++) {
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
- // --- 3. Reward info ---
236
- const rewardInfoCalls = [];
237
- for (let i = 0; i < poolsToFetch.length; i++) {
238
- const poolId = poolsToFetch[i];
239
- const pool = getPool(poolId);
240
- if (pool.gauge.address === curve.constants.ZERO_ADDRESS)
241
- continue;
242
- const gaugeContract = curve.contracts[pool.gauge.address].contract;
243
- const gaugeMulticallContract = curve.contracts[pool.gauge.address].multicallContract;
244
- if (hasCrvReward[i]) {
245
- rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
246
- }
247
- for (const r of rewardTokens[poolId]) {
248
- // Don't reset the reward ABI if the reward is the LP token itself, otherwise we lose LP contract functions
249
- if (r.token !== pool.address) {
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
- if ('claimable_reward(address,address)' in gaugeContract) {
253
- rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, r.token));
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
- else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
256
- rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
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
- const rawRewardInfo = yield batchedMulticall(rewardInfoCalls);
261
- for (let i = 0; i < poolsToFetch.length; i++) {
262
- const poolId = poolsToFetch[i];
263
- const pool = getPool(poolId);
264
- if (!_userClaimableCache[address])
265
- _userClaimableCache[address] = {};
266
- _userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
267
- if (pool.gauge.address === curve.constants.ZERO_ADDRESS)
268
- continue;
269
- const gaugeContract = curve.contracts[pool.gauge.address].contract;
270
- if (hasCrvReward[i]) {
271
- const token = curve.constants.ALIASES.crv;
272
- const symbol = 'CRV';
273
- const decimals = 18;
274
- const _amount = rawRewardInfo.shift();
275
- const amount = curve.formatUnits(_amount, decimals);
276
- if (Number(amount) > 0)
277
- _userClaimableCache[address][poolId].rewards.push({ token, symbol, amount });
278
- }
279
- for (const r of rewardTokens[poolId]) {
280
- let _amount = rawRewardInfo.shift();
281
- if ('claimable_reward(address)' in gaugeContract) {
282
- const _claimedAmount = rawRewardInfo.shift();
283
- _amount = _amount - _claimedAmount;
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
- const _claimable = [];
292
- for (const poolId of pools) {
293
- _claimable.push((_b = _userClaimableCache[address]) === null || _b === void 0 ? void 0 : _b[poolId].rewards);
294
- }
295
- return _claimable;
296
- });
297
- export const getUserPoolListByClaimable = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = curve.signerAddress) {
298
- const pools = curve.getPoolList();
299
- const _claimable = yield _getUserClaimable(pools, address, false);
300
- const userPoolList = [];
301
- for (let i = 0; i < pools.length; i++) {
302
- if (_claimable[i].length > 0) {
303
- userPoolList.push(pools[i]);
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
- return userPoolList;
307
- });
308
- export const getUserClaimable = (pools_1, ...args_1) => __awaiter(void 0, [pools_1, ...args_1], void 0, function* (pools, address = curve.signerAddress) {
309
- const _claimable = yield _getUserClaimable(pools, address, true);
310
- const claimableWithPrice = [];
311
- for (let i = 0; i < pools.length; i++) {
312
- claimableWithPrice.push([]);
313
- for (const c of _claimable[i]) {
314
- const price = yield _getUsdRate(c.token);
315
- claimableWithPrice[claimableWithPrice.length - 1].push(Object.assign(Object.assign({}, c), { price }));
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
- return claimableWithPrice;
319
- });
320
- export const getUserPoolList = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = curve.signerAddress, useApi = true) {
321
- const pools = curve.getPoolList();
322
- const [_lpBalances, _claimable] = yield Promise.all([
323
- _getUserLpBalances(pools, address, false),
324
- useApi ? _getUserClaimableUseApi(pools, address, false) : _getUserClaimable(pools, address, false),
325
- ]);
326
- const userPoolList = [];
327
- for (let i = 0; i < pools.length; i++) {
328
- if (_lpBalances[i] > 0 || _claimable[i].length > 0) {
329
- userPoolList.push(pools[i]);
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
- return userPoolList;
333
- });
334
- export const _getAmplificationCoefficientsFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
335
- const network = curve.constants.NETWORK_NAME;
336
- const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network, curve.isLiteChain);
337
- const amplificationCoefficientDict = {};
338
- for (const extendedPoolData of allTypesExtendedPoolData) {
339
- for (const pool of extendedPoolData.poolData) {
340
- amplificationCoefficientDict[pool.address.toLowerCase()] = Number(pool.amplificationCoefficient);
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
- return amplificationCoefficientDict;
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")