@curvefi/api 2.63.10 → 2.65.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 (79) hide show
  1. package/lib/constants/coins/arbitrum.d.ts +0 -4
  2. package/lib/constants/coins/arbitrum.js +0 -4
  3. package/lib/constants/coins/aurora.d.ts +0 -4
  4. package/lib/constants/coins/aurora.js +0 -4
  5. package/lib/constants/coins/avalanche.d.ts +0 -3
  6. package/lib/constants/coins/avalanche.js +0 -3
  7. package/lib/constants/coins/base.d.ts +0 -4
  8. package/lib/constants/coins/base.js +0 -4
  9. package/lib/constants/coins/bsc.d.ts +0 -4
  10. package/lib/constants/coins/bsc.js +0 -4
  11. package/lib/constants/coins/celo.d.ts +0 -4
  12. package/lib/constants/coins/celo.js +0 -4
  13. package/lib/constants/coins/ethereum.js +4 -1
  14. package/lib/constants/coins/fantom.d.ts +0 -2
  15. package/lib/constants/coins/fantom.js +0 -2
  16. package/lib/constants/coins/fraxtal.d.ts +0 -4
  17. package/lib/constants/coins/fraxtal.js +0 -4
  18. package/lib/constants/coins/index.d.ts +18 -0
  19. package/lib/constants/coins/index.js +18 -0
  20. package/lib/constants/coins/kava.d.ts +0 -4
  21. package/lib/constants/coins/kava.js +0 -4
  22. package/lib/constants/coins/mantle.d.ts +0 -4
  23. package/lib/constants/coins/mantle.js +0 -4
  24. package/lib/constants/coins/moonbeam.d.ts +0 -4
  25. package/lib/constants/coins/moonbeam.js +0 -4
  26. package/lib/constants/coins/optimism.d.ts +0 -4
  27. package/lib/constants/coins/optimism.js +0 -4
  28. package/lib/constants/coins/polygon.d.ts +0 -3
  29. package/lib/constants/coins/polygon.js +0 -3
  30. package/lib/constants/coins/xdai.d.ts +0 -4
  31. package/lib/constants/coins/xdai.js +0 -4
  32. package/lib/constants/coins/xlayer.d.ts +0 -4
  33. package/lib/constants/coins/xlayer.js +0 -4
  34. package/lib/constants/coins/zksync.d.ts +0 -4
  35. package/lib/constants/coins/zksync.js +0 -4
  36. package/lib/constants/{tricryptoDeployImplementations.d.ts → factory/crypto.d.ts} +21 -0
  37. package/lib/constants/{tricryptoDeployImplementations.js → factory/crypto.js} +85 -0
  38. package/lib/constants/factory/index.d.ts +3 -0
  39. package/lib/constants/factory/index.js +3 -0
  40. package/lib/{factory/constants.d.ts → constants/factory/stable.d.ts} +6 -52
  41. package/lib/{factory/constants.js → constants/factory/stable.js} +41 -151
  42. package/lib/constants/network_constants.d.ts +3 -0
  43. package/lib/constants/{aliases.js → network_constants.js} +255 -97
  44. package/lib/curve.d.ts +22 -16
  45. package/lib/curve.js +96 -362
  46. package/lib/external-api.d.ts +5 -3
  47. package/lib/external-api.js +86 -12
  48. package/lib/factory/common.js +2 -3
  49. package/lib/factory/deploy.js +5 -4
  50. package/lib/factory/factory-api.js +53 -61
  51. package/lib/factory/factory-crypto.js +3 -3
  52. package/lib/factory/factory-tricrypto.js +2 -2
  53. package/lib/factory/factory.js +22 -11
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.js +2 -1
  56. package/lib/interfaces.d.ts +26 -1
  57. package/lib/pools/PoolTemplate.d.ts +9 -82
  58. package/lib/pools/PoolTemplate.js +37 -379
  59. package/lib/pools/mixins/depositBalancedAmountsMixins.js +3 -3
  60. package/lib/pools/mixins/poolBalancesMixin.d.ts +3 -3
  61. package/lib/pools/mixins/poolBalancesMixin.js +11 -11
  62. package/lib/pools/poolConstructor.js +14 -7
  63. package/lib/pools/subClasses/corePool.d.ts +68 -0
  64. package/lib/pools/subClasses/corePool.js +39 -0
  65. package/lib/pools/{gaugePool.d.ts → subClasses/gaugePool.d.ts} +1 -1
  66. package/lib/pools/{gaugePool.js → subClasses/gaugePool.js} +2 -2
  67. package/lib/pools/subClasses/statsPool.d.ts +45 -0
  68. package/lib/pools/subClasses/statsPool.js +227 -0
  69. package/lib/pools/subClasses/walletPool.d.ts +19 -0
  70. package/lib/pools/subClasses/walletPool.js +72 -0
  71. package/lib/pools/utils.d.ts +1 -0
  72. package/lib/pools/utils.js +36 -0
  73. package/lib/route-graph.worker.js +50 -2
  74. package/lib/utils.d.ts +10 -1
  75. package/lib/utils.js +45 -7
  76. package/package.json +1 -1
  77. package/lib/constants/aliases.d.ts +0 -17
  78. package/lib/factory/constants-crypto.d.ts +0 -90
  79. package/lib/factory/constants-crypto.js +0 -122
@@ -8,155 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import memoize from "memoizee";
11
- import { _getAllGaugesFormatted, _getPoolsFromApi } from '../external-api.js';
12
- import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, findAbiFunction, getVolumeApiController, } from '../utils.js';
11
+ import { _getAllGaugesFormatted } from '../external-api.js';
12
+ import { _getCoinAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, findAbiFunction, PERIODS, } from '../utils.js';
13
13
  import { curve } from "../curve.js";
14
14
  import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
15
- import { GaugePool } from "./gaugePool.js";
16
- const DAY = 86400;
17
- const WEEK = 7 * DAY;
18
- const MONTH = 30 * DAY;
19
- const YEAR = 365 * DAY;
20
- export class PoolTemplate {
15
+ import { CorePool } from "./subClasses/corePool.js";
16
+ import { StatsPool } from "./subClasses/statsPool.js";
17
+ import { WalletPool } from "./subClasses/walletPool.js";
18
+ import { checkVyperVulnerability } from "./utils.js";
19
+ export class PoolTemplate extends CorePool {
21
20
  constructor(id) {
22
- var _c, _d;
23
- this.statsParameters = () => __awaiter(this, void 0, void 0, function* () {
24
- const multicallContract = curve.contracts[this.address].multicallContract;
25
- const lpMulticallContract = curve.contracts[this.lpToken].multicallContract;
26
- const calls = [
27
- multicallContract.get_virtual_price(),
28
- multicallContract.fee(),
29
- "admin_fee" in multicallContract ? multicallContract.admin_fee() : multicallContract.ADMIN_FEE(),
30
- multicallContract.A(),
31
- lpMulticallContract.totalSupply(),
32
- ];
33
- if (this.isCrypto) {
34
- calls.push(multicallContract.gamma());
35
- if (this.wrappedCoins.length === 2) {
36
- calls.push(multicallContract.price_oracle());
37
- calls.push(multicallContract.price_scale());
38
- }
39
- else {
40
- for (let i = 0; i < this.wrappedCoins.length - 1; i++) {
41
- calls.push(multicallContract.price_oracle(i));
42
- calls.push(multicallContract.price_scale(i));
43
- }
44
- }
45
- }
46
- const additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
47
- if ('initial_A' in multicallContract) {
48
- additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
49
- }
50
- let _virtualPrice = curve.parseUnits("0");
51
- let _fee = curve.parseUnits("0");
52
- let _prices, _adminFee, _A, _lpTokenSupply, _gamma;
53
- try {
54
- [_virtualPrice, _fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
55
- }
56
- catch (e) { // Empty pool
57
- calls.shift();
58
- if (this.isCrypto) {
59
- calls.shift();
60
- [_adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
61
- }
62
- else {
63
- [_fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
64
- }
65
- }
66
- const [virtualPrice, fee, adminFee, A, lpTokenSupply, gamma] = [
67
- curve.formatUnits(_virtualPrice),
68
- curve.formatUnits(_fee, 8),
69
- curve.formatUnits(_adminFee * _fee),
70
- curve.formatUnits(_A, 0),
71
- curve.formatUnits(_lpTokenSupply),
72
- _gamma ? curve.formatUnits(_gamma) : undefined,
73
- ];
74
- let priceOracle, priceScale;
75
- if (this.isCrypto) {
76
- const prices = _prices.map((_p) => curve.formatUnits(_p));
77
- priceOracle = [];
78
- priceScale = [];
79
- for (let i = 0; i < this.wrappedCoins.length - 1; i++) {
80
- priceOracle.push(prices.shift());
81
- priceScale.push(prices.shift());
82
- }
83
- }
84
- const A_PRECISION = curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
85
- const [_future_A, _initial_A, _future_A_time, _initial_A_time] = yield curve.multicallProvider.all(additionalCalls);
86
- const [future_A, initial_A, future_A_time, initial_A_time] = [
87
- _future_A ? String(Number(curve.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
88
- _initial_A ? String(Number(curve.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
89
- _future_A_time ? Number(curve.formatUnits(_future_A_time, 0)) * 1000 : undefined,
90
- _initial_A_time ? Number(curve.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
91
- ];
92
- return { lpTokenSupply, virtualPrice, fee, adminFee, A, future_A, initial_A, future_A_time, initial_A_time, gamma, priceOracle, priceScale };
93
- });
94
- this.statsTotalLiquidity = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
95
- if (curve.chainId === 1 && this.id === "crveth")
96
- return "0";
97
- if (this.isLlamma) {
98
- const stablecoinContract = curve.contracts[this.underlyingCoinAddresses[0]].multicallContract;
99
- const collateralContract = curve.contracts[this.underlyingCoinAddresses[1]].multicallContract;
100
- const ammContract = curve.contracts[this.address].multicallContract;
101
- const [_balance_x, _fee_x, _balance_y, _fee_y] = yield curve.multicallProvider.all([
102
- stablecoinContract.balanceOf(this.address),
103
- ammContract.admin_fees_x(),
104
- collateralContract.balanceOf(this.address),
105
- ammContract.admin_fees_y(),
106
- ]);
107
- const collateralRate = yield _getUsdRate(this.underlyingCoinAddresses[1]);
108
- const stablecoinTvlBN = toBN(_balance_x).minus(toBN(_fee_x));
109
- const collateralTvlBN = toBN(_balance_y).minus(toBN(_fee_y)).times(collateralRate);
110
- return stablecoinTvlBN.plus(collateralTvlBN).toString();
111
- }
112
- if (useApi) {
113
- const network = curve.constants.NETWORK_NAME;
114
- let poolType = this.isCrypto ? "crypto" : "main";
115
- if (this.id.startsWith("factory")) {
116
- poolType = this.id.replace(/-\d+$/, '');
117
- poolType = poolType.replace(/-v2$/, '');
118
- }
119
- const poolsData = (yield _getPoolsFromApi(network, poolType)).poolData;
120
- try {
121
- const totalLiquidity = poolsData.filter((data) => data.address.toLowerCase() === this.address.toLowerCase())[0].usdTotal;
122
- return String(totalLiquidity);
123
- }
124
- catch (err) {
125
- console.log(this.id, err.message);
126
- }
127
- }
128
- const balances = yield this.statsUnderlyingBalances();
129
- const promises = [];
130
- for (const addr of this.underlyingCoinAddresses) {
131
- promises.push(_getUsdRate(addr));
132
- }
133
- const prices = yield Promise.all(promises);
134
- const totalLiquidity = balances.reduce((liquidity, b, i) => liquidity + (Number(b) * prices[i]), 0);
135
- return totalLiquidity.toFixed(8);
136
- });
137
- this.statsVolume = () => __awaiter(this, void 0, void 0, function* () {
138
- const network = curve.constants.NETWORK_NAME;
139
- const { poolsData } = yield getVolumeApiController(network);
140
- const poolData = poolsData.find((d) => d.address.toLowerCase() === this.address);
141
- if (poolData) {
142
- return poolData.volumeUSD.toString();
143
- }
144
- throw Error(`Can't get Volume for ${this.name} (id: ${this.id})`);
145
- });
146
- this.statsBaseApy = () => __awaiter(this, void 0, void 0, function* () {
147
- const network = curve.constants.NETWORK_NAME;
148
- const { poolsData } = yield getVolumeApiController(network);
149
- const poolData = poolsData.find((d) => d.address.toLowerCase() === this.address);
150
- if (poolData) {
151
- return {
152
- day: poolData.day.toString(),
153
- week: poolData.week.toString(),
154
- };
155
- }
156
- throw Error(`Can't get base APY for ${this.name} (id: ${this.id})`);
157
- });
21
+ super(id);
158
22
  this._calcTokenApy = (futureWorkingSupplyBN = null) => __awaiter(this, void 0, void 0, function* () {
159
- const totalLiquidityUSD = yield this.statsTotalLiquidity();
23
+ const totalLiquidityUSD = yield this.stats.totalLiquidity();
160
24
  if (Number(totalLiquidityUSD) === 0)
161
25
  return [0, 0];
162
26
  let inflationRateBN, workingSupplyBN, totalSupplyBN;
@@ -164,14 +28,14 @@ export class PoolTemplate {
164
28
  const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
165
29
  const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
166
30
  const crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
167
- const currentWeek = Math.floor(Date.now() / 1000 / WEEK);
31
+ const currentWeek = Math.floor(Date.now() / 1000 / PERIODS.WEEK);
168
32
  [inflationRateBN, workingSupplyBN, totalSupplyBN] = (yield curve.multicallProvider.all([
169
33
  gaugeContract.inflation_rate(currentWeek),
170
34
  gaugeContract.working_supply(),
171
35
  lpTokenContract.totalSupply(),
172
36
  ])).map((value) => toBN(value));
173
37
  if (inflationRateBN.eq(0)) {
174
- inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(WEEK);
38
+ inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(PERIODS.WEEK);
175
39
  }
176
40
  }
177
41
  else {
@@ -199,57 +63,6 @@ export class PoolTemplate {
199
63
  const boostedApyBN = baseApyBN.times(2.5);
200
64
  return [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()];
201
65
  });
202
- this.statsTokenApy = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
203
- var _e;
204
- if (this.rewardsOnly())
205
- throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
206
- const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
207
- if (useApi && !isDisabledChain) {
208
- const crvAPYs = yield _getCrvApyFromApi();
209
- const poolCrvApy = (_e = crvAPYs[this.gauge.address]) !== null && _e !== void 0 ? _e : [0, 0]; // new pools might be missing
210
- return [poolCrvApy[0], poolCrvApy[1]];
211
- }
212
- return yield this._calcTokenApy();
213
- });
214
- this.statsRewardsApy = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
215
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
216
- return [];
217
- const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
218
- if (useApi && !isDisabledChain) {
219
- const rewards = yield _getRewardsFromApi();
220
- if (!rewards[this.gauge.address])
221
- return [];
222
- return rewards[this.gauge.address].map((r) => ({ gaugeAddress: r.gaugeAddress, tokenAddress: r.tokenAddress, symbol: r.symbol, apy: r.apy }));
223
- }
224
- const apy = [];
225
- const rewardTokens = yield this.rewardTokens(false);
226
- for (const rewardToken of rewardTokens) {
227
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
228
- const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
229
- const rewardContract = curve.contracts[this.sRewardContract || this.gauge.address].multicallContract;
230
- const totalLiquidityUSD = yield this.statsTotalLiquidity();
231
- const rewardRate = yield _getUsdRate(rewardToken.token);
232
- const [rewardData, _stakedSupply, _totalSupply] = yield curve.multicallProvider.all([
233
- rewardContract.reward_data(rewardToken.token),
234
- gaugeContract.totalSupply(),
235
- lpTokenContract.totalSupply(),
236
- ]);
237
- const stakedSupplyBN = toBN(_stakedSupply);
238
- const totalSupplyBN = toBN(_totalSupply);
239
- const inflationBN = toBN(rewardData.rate, rewardToken.decimals);
240
- const periodFinish = Number(curve.formatUnits(rewardData.period_finish, 0)) * 1000;
241
- const baseApy = periodFinish > Date.now() ?
242
- inflationBN.times(31536000).times(rewardRate).div(stakedSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)) :
243
- BN(0);
244
- apy.push({
245
- gaugeAddress: this.gauge.address,
246
- tokenAddress: rewardToken.token,
247
- symbol: rewardToken.symbol,
248
- apy: baseApy.times(100).toNumber(),
249
- });
250
- }
251
- return apy;
252
- });
253
66
  this._calcLpTokenAmount = memoize((_amounts, isDeposit = true, useUnderlying = true) => __awaiter(this, void 0, void 0, function* () {
254
67
  if (this.isCrypto) {
255
68
  try {
@@ -273,16 +86,14 @@ export class PoolTemplate {
273
86
  }
274
87
  }
275
88
  try {
276
- const contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
277
- if (curve.constants.ALIASES.stable_calc === curve.constants.ZERO_ADDRESS || this.id.startsWith("factory-stable-ng")) {
89
+ if (this.isNg)
278
90
  return yield this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying);
279
- }
280
- else if (this.isMeta) {
91
+ if (this.isMeta) {
281
92
  const basePool = new PoolTemplate(this.basePool);
282
- return yield contract.calc_token_amount_meta(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, basePool.address, basePool.lpToken, isDeposit, useUnderlying);
93
+ return yield curve.contracts[curve.constants.ALIASES.stable_calc].contract.calc_token_amount_meta(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, basePool.address, basePool.lpToken, isDeposit, useUnderlying);
283
94
  }
284
95
  else {
285
- return yield contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending);
96
+ return yield curve.contracts[curve.constants.ALIASES.stable_calc].contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending);
286
97
  }
287
98
  }
288
99
  catch (e) { // Seeding
@@ -319,14 +130,14 @@ export class PoolTemplate {
319
130
  if (curve.chainId !== 1) {
320
131
  const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
321
132
  const crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
322
- const currentWeek = Math.floor(Date.now() / 1000 / WEEK);
133
+ const currentWeek = Math.floor(Date.now() / 1000 / PERIODS.WEEK);
323
134
  [inflationRateBN, workingBalanceBN, workingSupplyBN] = (yield curve.multicallProvider.all([
324
135
  gaugeContract.inflation_rate(currentWeek),
325
136
  gaugeContract.working_balances(address),
326
137
  gaugeContract.working_supply(),
327
138
  ])).map((value) => toBN(value));
328
139
  if (inflationRateBN.eq(0)) {
329
- inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(WEEK);
140
+ inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(PERIODS.WEEK);
330
141
  }
331
142
  }
332
143
  else {
@@ -352,10 +163,10 @@ export class PoolTemplate {
352
163
  symbol: 'CRV',
353
164
  price: crvPrice,
354
165
  };
355
- const dailyIncome = inflationRateBN.times(DAY).times(workingBalanceBN).div(workingSupplyBN);
356
- const weeklyIncome = inflationRateBN.times(WEEK).times(workingBalanceBN).div(workingSupplyBN);
357
- const monthlyIncome = inflationRateBN.times(MONTH).times(workingBalanceBN).div(workingSupplyBN);
358
- const annualIncome = inflationRateBN.times(YEAR).times(workingBalanceBN).div(workingSupplyBN);
166
+ const dailyIncome = inflationRateBN.times(PERIODS.DAY).times(workingBalanceBN).div(workingSupplyBN);
167
+ const weeklyIncome = inflationRateBN.times(PERIODS.WEEK).times(workingBalanceBN).div(workingSupplyBN);
168
+ const monthlyIncome = inflationRateBN.times(PERIODS.MONTH).times(workingBalanceBN).div(workingSupplyBN);
169
+ const annualIncome = inflationRateBN.times(PERIODS.YEAR).times(workingBalanceBN).div(workingSupplyBN);
359
170
  return {
360
171
  day: dailyIncome.toString(),
361
172
  week: weeklyIncome.toString(),
@@ -424,7 +235,7 @@ export class PoolTemplate {
424
235
  if (this.rewardsOnly())
425
236
  throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
426
237
  address = _getAddress(address);
427
- const [minApy, maxApy] = yield this.statsTokenApy();
238
+ const [minApy, maxApy] = yield this.stats.tokenApy();
428
239
  const boost = yield this.userBoost(address);
429
240
  if (boost == "2.5")
430
241
  return maxApy;
@@ -552,10 +363,10 @@ export class PoolTemplate {
552
363
  const inflationRateBN = periodFinish > Date.now() ? toBN(_rewardData.rate, rewardToken.decimals) : BN(0);
553
364
  const tokenPrice = yield _getUsdRate(rewardToken.token);
554
365
  result.push({
555
- day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
556
- week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
557
- month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
558
- year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
366
+ day: inflationRateBN.times(PERIODS.DAY).times(balanceBN).div(totalSupplyBN).toString(),
367
+ week: inflationRateBN.times(PERIODS.WEEK).times(balanceBN).div(totalSupplyBN).toString(),
368
+ month: inflationRateBN.times(PERIODS.MONTH).times(balanceBN).div(totalSupplyBN).toString(),
369
+ year: inflationRateBN.times(PERIODS.YEAR).times(balanceBN).div(totalSupplyBN).toString(),
559
370
  token: rewardToken.token,
560
371
  symbol: rewardToken.symbol,
561
372
  price: tokenPrice,
@@ -577,10 +388,10 @@ export class PoolTemplate {
577
388
  const totalSupplyBN = toBN(_totalSupply);
578
389
  const tokenPrice = yield _getUsdRate(rewardToken.token);
579
390
  result.push({
580
- day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
581
- week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
582
- month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
583
- year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
391
+ day: inflationRateBN.times(PERIODS.DAY).times(balanceBN).div(totalSupplyBN).toString(),
392
+ week: inflationRateBN.times(PERIODS.WEEK).times(balanceBN).div(totalSupplyBN).toString(),
393
+ month: inflationRateBN.times(PERIODS.MONTH).times(balanceBN).div(totalSupplyBN).toString(),
394
+ year: inflationRateBN.times(PERIODS.YEAR).times(balanceBN).div(totalSupplyBN).toString(),
584
395
  token: rewardToken.token,
585
396
  symbol: rewardToken.symbol,
586
397
  price: tokenPrice,
@@ -701,27 +512,6 @@ export class PoolTemplate {
701
512
  }
702
513
  return _rates;
703
514
  });
704
- this._balances = (rawCoinNames, rawCoinAddresses, ...addresses) => __awaiter(this, void 0, void 0, function* () {
705
- const coinNames = [];
706
- const coinAddresses = [];
707
- // removing duplicates
708
- for (let i = 0; i < rawCoinAddresses.length; i++) {
709
- if (!coinAddresses.includes(rawCoinAddresses[i])) {
710
- coinNames.push(rawCoinNames[i]);
711
- coinAddresses.push(rawCoinAddresses[i]);
712
- }
713
- }
714
- addresses = _prepareAddresses(addresses);
715
- const rawBalances = yield _getBalances(coinAddresses, addresses);
716
- const balances = {};
717
- for (const address of addresses) {
718
- balances[address] = {};
719
- for (const coinName of coinNames) {
720
- balances[address][coinName] = rawBalances[address].shift();
721
- }
722
- }
723
- return addresses.length === 1 ? balances[addresses[0]] : balances;
724
- });
725
515
  this._storedRatesBN = (useUnderlying) => __awaiter(this, void 0, void 0, function* () {
726
516
  if (this.isMeta) {
727
517
  if (useUnderlying)
@@ -751,38 +541,8 @@ export class PoolTemplate {
751
541
  }
752
542
  return yield Promise.all(promises);
753
543
  });
754
- const poolData = curve.getPoolsData()[id];
755
- this.id = id;
756
- this.name = poolData.name;
757
- this.fullName = poolData.full_name;
758
- this.symbol = poolData.symbol;
759
- this.referenceAsset = poolData.reference_asset;
760
- this.address = poolData.swap_address;
761
- this.lpToken = poolData.token_address;
762
- this.gauge = new GaugePool(poolData.gauge_address, poolData.name);
763
- this.zap = poolData.deposit_address || null;
764
- this.sRewardContract = poolData.sCurveRewards_address || null;
765
- this.rewardContract = poolData.reward_contract || null;
766
- this.implementation = poolData.implementation_address || null;
767
- this.isPlain = poolData.is_plain || false;
768
- this.isLending = poolData.is_lending || false;
769
- this.isMeta = poolData.is_meta || false;
770
- this.isCrypto = poolData.is_crypto || false;
771
- this.isFake = poolData.is_fake || false;
772
- this.isFactory = poolData.is_factory || false;
773
- this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
774
- this.isNg = poolData.is_ng || false;
775
- this.isLlamma = poolData.is_llamma || false;
776
- this.basePool = poolData.base_pool || '';
777
- this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
778
- this.underlyingCoins = poolData.underlying_coins;
779
- this.wrappedCoins = poolData.wrapped_coins;
780
- this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
781
- this.wrappedCoinAddresses = poolData.wrapped_coin_addresses;
782
- this.underlyingDecimals = poolData.underlying_decimals;
783
- this.wrappedDecimals = poolData.wrapped_decimals;
784
- this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(() => false);
785
- this.inApi = (_d = poolData.in_api) !== null && _d !== void 0 ? _d : false;
544
+ this.stats = new StatsPool(this);
545
+ this.wallet = new WalletPool(this);
786
546
  this.isGaugeKilled = this.getIsGaugeKilled.bind(this);
787
547
  this.gaugeStatus = this.getGaugeStatus.bind(this);
788
548
  this.estimateGas = {
@@ -813,59 +573,9 @@ export class PoolTemplate {
813
573
  swapWrappedApprove: this.swapWrappedApproveEstimateGas.bind(this),
814
574
  swapWrapped: this.swapWrappedEstimateGas.bind(this),
815
575
  };
816
- this.stats = {
817
- parameters: this.statsParameters.bind(this),
818
- underlyingBalances: this.statsUnderlyingBalances.bind(this),
819
- wrappedBalances: this.statsWrappedBalances.bind(this),
820
- totalLiquidity: this.statsTotalLiquidity.bind(this),
821
- volume: this.statsVolume.bind(this),
822
- baseApy: this.statsBaseApy.bind(this),
823
- tokenApy: this.statsTokenApy.bind(this),
824
- rewardsApy: this.statsRewardsApy.bind(this),
825
- };
826
- this.wallet = {
827
- balances: this.walletBalances.bind(this),
828
- lpTokenBalances: this.walletLpTokenBalances.bind(this),
829
- underlyingCoinBalances: this.walletUnderlyingCoinBalances.bind(this),
830
- wrappedCoinBalances: this.walletWrappedCoinBalances.bind(this),
831
- allCoinBalances: this.walletAllCoinBalances.bind(this),
832
- };
833
576
  }
834
577
  hasVyperVulnerability() {
835
- var _c, _d;
836
- if (curve.chainId === 1 && this.id === "crveth")
837
- return true;
838
- if (curve.chainId === 42161 && this.id === "tricrypto")
839
- return true;
840
- // @ts-ignore
841
- const vulnerable_implementations = (_c = {
842
- 1: [
843
- "0x6326DEbBAa15bCFE603d831e7D75f4fc10d9B43E",
844
- "0x8c1aB78601c259E1B43F19816923609dC7d7de9B",
845
- "0x88855cdF2b0A8413D470B86952E726684de915be",
846
- ].map((a) => a.toLowerCase()),
847
- 137: [
848
- "0xAe00f57663F4C85FC948B13963cd4627dAF01061",
849
- "0xA9134FaE98F92217f457918505375Ae91fdc5e3c",
850
- "0xf31bcdf0B9a5eCD7AB463eB905551fBc32e51856",
851
- ].map((a) => a.toLowerCase()),
852
- 250: [
853
- "0xE6358f6a45B502477e83CC1CDa759f540E4459ee",
854
- "0x5d58Eb45e97B43e471AF05cD2b11CeB4106E1b1a",
855
- "0xb11Dc44A9f981fAF1669dca6DD40c3cc2554A2ce",
856
- ].map((a) => a.toLowerCase()),
857
- 42161: [
858
- "0x7DA64233Fefb352f8F501B357c018158ED8aA455",
859
- "0xAAe75FAebCae43b9d541Fd875622BE48D9B4f5D0",
860
- "0x89287c32c2CAC1C76227F6d300B2DBbab6b75C08",
861
- ].map((a) => a.toLowerCase()),
862
- 43114: [
863
- "0x64448B78561690B70E17CBE8029a3e5c1bB7136e",
864
- "0xF1f85a74AD6c64315F85af52d3d46bF715236ADc",
865
- "0x0eb0F1FaF5F509Ac53fA224477509EAD167cf410",
866
- ].map((a) => a.toLowerCase()),
867
- }[curve.chainId]) !== null && _c !== void 0 ? _c : [];
868
- return vulnerable_implementations.includes((_d = this.implementation) !== null && _d !== void 0 ? _d : "");
578
+ return checkVyperVulnerability(curve.chainId, this.id, this.implementation);
869
579
  }
870
580
  rewardsOnly() {
871
581
  if (curve.chainId === 2222 || curve.chainId === 324)
@@ -875,22 +585,6 @@ export class PoolTemplate {
875
585
  return !findAbiFunction(curve.contracts[this.gauge.address].abi, 'inflation_rate')
876
586
  .find((func) => ['', 'uint256'].includes(func.inputs.map((a) => `${a.type}`).join(',')));
877
587
  }
878
- statsWrappedBalances() {
879
- return __awaiter(this, void 0, void 0, function* () {
880
- const contract = curve.contracts[this.address].multicallContract;
881
- const calls = [];
882
- for (let i = 0; i < this.wrappedCoins.length; i++)
883
- calls.push(contract.balances(i));
884
- const _wrappedBalances = yield curve.multicallProvider.all(calls);
885
- return _wrappedBalances.map((_b, i) => curve.formatUnits(_b, this.wrappedDecimals[i]));
886
- });
887
- }
888
- // OVERRIDE
889
- statsUnderlyingBalances() {
890
- return __awaiter(this, void 0, void 0, function* () {
891
- return yield this.statsWrappedBalances();
892
- });
893
- }
894
588
  _pureCalcLpTokenAmount(_amounts, isDeposit = true, useUnderlying = true) {
895
589
  return __awaiter(this, void 0, void 0, function* () {
896
590
  const calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
@@ -1507,7 +1201,7 @@ export class PoolTemplate {
1507
1201
  if (amounts.length !== coinAddresses.length) {
1508
1202
  throw Error(`${this.name} pool has ${coinAddresses.length} coins (amounts provided for ${amounts.length})`);
1509
1203
  }
1510
- const balances = isUnderlying ? Object.values(yield this.walletUnderlyingCoinBalances()) : Object.values(yield this.walletWrappedCoinBalances());
1204
+ const balances = isUnderlying ? Object.values(yield this.wallet.underlyingCoinBalances()) : Object.values(yield this.wallet.wrappedCoinBalances());
1511
1205
  for (let i = 0; i < balances.length; i++) {
1512
1206
  if (Number(balances[i]) < Number(amounts[i])) {
1513
1207
  throw Error(`Not enough ${coins[i]}. Actual: ${balances[i]}, required: ${amounts[i]}`);
@@ -1807,46 +1501,10 @@ export class PoolTemplate {
1807
1501
  throw Error(`withdrawOneCoinWrapped method doesn't exist for pool ${this.name} (id: ${this.name})`);
1808
1502
  });
1809
1503
  }
1810
- // ---------------- WALLET BALANCES ----------------
1811
- walletBalances(...addresses) {
1812
- return __awaiter(this, void 0, void 0, function* () {
1813
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1814
- return yield this._balances(['lpToken', ...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], [this.lpToken, ...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], ...addresses);
1815
- }
1816
- else {
1817
- return yield this._balances(['lpToken', 'gauge', ...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], [this.lpToken, this.gauge.address, ...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], ...addresses);
1818
- }
1819
- });
1820
- }
1821
- walletLpTokenBalances(...addresses) {
1822
- return __awaiter(this, void 0, void 0, function* () {
1823
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1824
- return yield this._balances(['lpToken'], [this.lpToken], ...addresses);
1825
- }
1826
- else {
1827
- return yield this._balances(['lpToken', 'gauge'], [this.lpToken, this.gauge.address], ...addresses);
1828
- }
1829
- });
1830
- }
1831
- walletUnderlyingCoinBalances(...addresses) {
1832
- return __awaiter(this, void 0, void 0, function* () {
1833
- return yield this._balances(this.underlyingCoinAddresses, this.underlyingCoinAddresses, ...addresses);
1834
- });
1835
- }
1836
- walletWrappedCoinBalances(...addresses) {
1837
- return __awaiter(this, void 0, void 0, function* () {
1838
- return yield this._balances(this.wrappedCoinAddresses, this.wrappedCoinAddresses, ...addresses);
1839
- });
1840
- }
1841
- walletAllCoinBalances(...addresses) {
1842
- return __awaiter(this, void 0, void 0, function* () {
1843
- return yield this._balances([...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], [...this.underlyingCoinAddresses, ...this.wrappedCoinAddresses], ...addresses);
1844
- });
1845
- }
1846
1504
  // ---------------- USER BALANCES, BASE PROFIT AND SHARE ----------------
1847
1505
  _userLpTotalBalance(address) {
1848
1506
  return __awaiter(this, void 0, void 0, function* () {
1849
- const lpBalances = yield this.walletLpTokenBalances(address);
1507
+ const lpBalances = yield this.wallet.lpTokenBalances(address);
1850
1508
  let lpTotalBalanceBN = BN(lpBalances.lpToken);
1851
1509
  if ('gauge' in lpBalances)
1852
1510
  lpTotalBalanceBN = lpTotalBalanceBN.plus(BN(lpBalances.gauge));
@@ -1884,7 +1542,7 @@ export class PoolTemplate {
1884
1542
  }
1885
1543
  baseProfit(address = "") {
1886
1544
  return __awaiter(this, void 0, void 0, function* () {
1887
- const apyData = yield this.statsBaseApy();
1545
+ const apyData = yield this.stats.baseApy();
1888
1546
  if (!('week' in apyData))
1889
1547
  return { day: "0", week: "0", month: "0", year: "0" };
1890
1548
  const apyBN = BN(apyData.week).div(100);
@@ -1907,7 +1565,7 @@ export class PoolTemplate {
1907
1565
  address = address || curve.signerAddress;
1908
1566
  if (!address)
1909
1567
  throw Error("Need to connect wallet or pass address into args");
1910
- const userLpBalance = yield this.walletLpTokenBalances(address);
1568
+ const userLpBalance = yield this.wallet.lpTokenBalances(address);
1911
1569
  let userLpTotalBalanceBN = BN(userLpBalance.lpToken);
1912
1570
  if (withGauge)
1913
1571
  userLpTotalBalanceBN = userLpTotalBalanceBN.plus(BN(userLpBalance.gauge));
@@ -28,7 +28,7 @@ export const depositBalancedAmountsMixin = {
28
28
  // @ts-ignore
29
29
  const poolBalances = yield this.stats.underlyingBalances();
30
30
  // @ts-ignore
31
- const walletBalances = Object.values(yield this.walletUnderlyingCoinBalances());
31
+ const walletBalances = Object.values(yield this.wallet.underlyingCoinBalances());
32
32
  const balancedAmountsBN = (_depositBalancedAmounts(poolBalances, walletBalances, this.underlyingDecimals));
33
33
  return balancedAmountsBN.map((b, i) => BigNumber.min(BN(b), BN(walletBalances[i])).toString());
34
34
  });
@@ -41,7 +41,7 @@ export const depositBalancedAmountsCryptoMixin = {
41
41
  // @ts-ignore
42
42
  const poolBalances = yield this.stats.underlyingBalances();
43
43
  // @ts-ignore
44
- const walletBalances = Object.values(yield this.walletUnderlyingCoinBalances());
44
+ const walletBalances = Object.values(yield this.wallet.underlyingCoinBalances());
45
45
  // @ts-ignore
46
46
  const prices = yield this._underlyingPrices();
47
47
  const poolBalancesUSD = poolBalances.map((b, i) => BN(b).times(prices[i]).toString());
@@ -58,7 +58,7 @@ export const depositWrappedBalancedAmountsMixin = {
58
58
  // @ts-ignore
59
59
  const poolBalances = yield this.stats.wrappedBalances();
60
60
  // @ts-ignore
61
- const walletBalances = Object.values(yield this.walletWrappedCoinBalances());
61
+ const walletBalances = Object.values(yield this.wallet.wrappedCoinBalances());
62
62
  const balancedAmountsBN = (_depositBalancedAmounts(poolBalances, walletBalances, this.underlyingDecimals));
63
63
  return balancedAmountsBN.map((b, i) => BigNumber.min(BN(b), BN(walletBalances[i])).toString());
64
64
  });
@@ -1,3 +1,3 @@
1
- import { PoolTemplate } from "../PoolTemplate.js";
2
- export declare const poolBalancesMetaMixin: PoolTemplate;
3
- export declare const poolBalancesLendingMixin: PoolTemplate;
1
+ import { IStatsPool } from "../subClasses/statsPool";
2
+ export declare const poolBalancesMetaMixin: IStatsPool;
3
+ export declare const poolBalancesLendingMixin: IStatsPool;
@@ -12,33 +12,33 @@ import { PoolTemplate } from "../PoolTemplate.js";
12
12
  import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
13
13
  // @ts-ignore
14
14
  export const poolBalancesMetaMixin = {
15
- statsUnderlyingBalances() {
15
+ underlyingBalances() {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- const swapContract = curve.contracts[this.address].multicallContract;
18
- const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
17
+ const swapContract = curve.contracts[this.pool.address].multicallContract;
18
+ const contractCalls = this.pool.wrappedCoins.map((_, i) => swapContract.balances(i));
19
19
  const _poolWrappedBalances = yield curve.multicallProvider.all(contractCalls);
20
- const [_poolMetaCoinBalance] = _poolWrappedBalances.splice(this.metaCoinIdx, 1);
20
+ const [_poolMetaCoinBalance] = _poolWrappedBalances.splice(this.pool.metaCoinIdx, 1);
21
21
  const _poolUnderlyingBalances = _poolWrappedBalances;
22
- const basePool = new PoolTemplate(this.basePool);
22
+ const basePool = new PoolTemplate(this.pool.basePool);
23
23
  const _basePoolExpectedAmounts = basePool.isMeta ?
24
24
  yield _calcExpectedUnderlyingAmountsMeta.call(basePool, _poolMetaCoinBalance) :
25
25
  yield _calcExpectedAmounts.call(basePool, _poolMetaCoinBalance);
26
- _poolUnderlyingBalances.splice(this.metaCoinIdx, 0, ..._basePoolExpectedAmounts);
27
- return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
26
+ _poolUnderlyingBalances.splice(this.pool.metaCoinIdx, 0, ..._basePoolExpectedAmounts);
27
+ return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.pool.underlyingDecimals[i]));
28
28
  });
29
29
  },
30
30
  };
31
31
  // @ts-ignore
32
32
  export const poolBalancesLendingMixin = {
33
- statsUnderlyingBalances() {
33
+ underlyingBalances() {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- const swapContract = curve.contracts[this.address].multicallContract;
36
- const contractCalls = this.wrappedCoins.map((_, i) => swapContract.balances(i));
35
+ const swapContract = curve.contracts[this.pool.address].multicallContract;
36
+ const contractCalls = this.pool.wrappedCoins.map((_, i) => swapContract.balances(i));
37
37
  const _poolWrappedBalances = yield curve.multicallProvider.all(contractCalls);
38
38
  // @ts-ignore
39
39
  const _rates = yield this._getRates();
40
40
  const _poolUnderlyingBalances = _poolWrappedBalances.map((_b, i) => _b * _rates[i] / curve.parseUnits(String(Math.pow(10, 18)), 0));
41
- return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.underlyingDecimals[i]));
41
+ return _poolUnderlyingBalances.map((_b, i) => curve.formatUnits(_b, this.pool.underlyingDecimals[i]));
42
42
  });
43
43
  },
44
44
  };