@curvefi/api 2.63.10 → 2.64.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 (77) 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/fantom.d.ts +0 -2
  14. package/lib/constants/coins/fantom.js +0 -2
  15. package/lib/constants/coins/fraxtal.d.ts +0 -4
  16. package/lib/constants/coins/fraxtal.js +0 -4
  17. package/lib/constants/coins/index.d.ts +18 -0
  18. package/lib/constants/coins/index.js +18 -0
  19. package/lib/constants/coins/kava.d.ts +0 -4
  20. package/lib/constants/coins/kava.js +0 -4
  21. package/lib/constants/coins/mantle.d.ts +0 -4
  22. package/lib/constants/coins/mantle.js +0 -4
  23. package/lib/constants/coins/moonbeam.d.ts +0 -4
  24. package/lib/constants/coins/moonbeam.js +0 -4
  25. package/lib/constants/coins/optimism.d.ts +0 -4
  26. package/lib/constants/coins/optimism.js +0 -4
  27. package/lib/constants/coins/polygon.d.ts +0 -3
  28. package/lib/constants/coins/polygon.js +0 -3
  29. package/lib/constants/coins/xdai.d.ts +0 -4
  30. package/lib/constants/coins/xdai.js +0 -4
  31. package/lib/constants/coins/xlayer.d.ts +0 -4
  32. package/lib/constants/coins/xlayer.js +0 -4
  33. package/lib/constants/coins/zksync.d.ts +0 -4
  34. package/lib/constants/coins/zksync.js +0 -4
  35. package/lib/constants/{tricryptoDeployImplementations.d.ts → factory/crypto.d.ts} +21 -0
  36. package/lib/constants/{tricryptoDeployImplementations.js → factory/crypto.js} +85 -0
  37. package/lib/constants/factory/index.d.ts +3 -0
  38. package/lib/constants/factory/index.js +3 -0
  39. package/lib/{factory/constants.d.ts → constants/factory/stable.d.ts} +6 -52
  40. package/lib/{factory/constants.js → constants/factory/stable.js} +41 -151
  41. package/lib/constants/network_constants.d.ts +3 -0
  42. package/lib/constants/{aliases.js → network_constants.js} +253 -96
  43. package/lib/curve.d.ts +22 -16
  44. package/lib/curve.js +94 -362
  45. package/lib/external-api.d.ts +5 -3
  46. package/lib/external-api.js +86 -12
  47. package/lib/factory/common.js +2 -3
  48. package/lib/factory/deploy.js +5 -4
  49. package/lib/factory/factory-api.js +53 -61
  50. package/lib/factory/factory-crypto.js +3 -3
  51. package/lib/factory/factory-tricrypto.js +2 -2
  52. package/lib/factory/factory.js +22 -11
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +2 -1
  55. package/lib/interfaces.d.ts +26 -1
  56. package/lib/pools/PoolTemplate.d.ts +9 -82
  57. package/lib/pools/PoolTemplate.js +37 -379
  58. package/lib/pools/mixins/depositBalancedAmountsMixins.js +3 -3
  59. package/lib/pools/mixins/poolBalancesMixin.d.ts +3 -3
  60. package/lib/pools/mixins/poolBalancesMixin.js +11 -11
  61. package/lib/pools/poolConstructor.js +14 -7
  62. package/lib/pools/subClasses/corePool.d.ts +68 -0
  63. package/lib/pools/subClasses/corePool.js +39 -0
  64. package/lib/pools/{gaugePool.d.ts → subClasses/gaugePool.d.ts} +1 -1
  65. package/lib/pools/{gaugePool.js → subClasses/gaugePool.js} +2 -2
  66. package/lib/pools/subClasses/statsPool.d.ts +45 -0
  67. package/lib/pools/subClasses/statsPool.js +227 -0
  68. package/lib/pools/subClasses/walletPool.d.ts +19 -0
  69. package/lib/pools/subClasses/walletPool.js +72 -0
  70. package/lib/pools/utils.d.ts +1 -0
  71. package/lib/pools/utils.js +36 -0
  72. package/lib/utils.d.ts +10 -1
  73. package/lib/utils.js +45 -7
  74. package/package.json +1 -1
  75. package/lib/constants/aliases.d.ts +0 -17
  76. package/lib/factory/constants-crypto.d.ts +0 -90
  77. package/lib/factory/constants-crypto.js +0 -122
@@ -16,16 +16,23 @@ import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin
16
16
  import { swapTricrypto2Mixin, swapMetaFactoryMixin, swapCryptoMetaFactoryMixin, swapMixin } from "./mixins/swapMixins.js";
17
17
  import { swapWrappedExpectedAndApproveMixin, swapWrappedTricrypto2Mixin, swapWrappedMixin, swapWrappedRequiredMixin, } from "./mixins/swapWrappedMixins.js";
18
18
  import { getCountArgsOfMethodByAbi, findAbiSignature } from "../utils.js";
19
+ import { StatsPool } from "./subClasses/statsPool.js";
19
20
  export const getPool = (poolId) => {
20
21
  const poolDummy = new PoolTemplate(poolId);
21
22
  class Pool extends PoolTemplate {
22
- }
23
- // statsBalances
24
- if (poolDummy.isMeta) {
25
- Object.assign(Pool.prototype, poolBalancesMetaMixin);
26
- }
27
- else if (poolDummy.useLending.reduce((x, y) => x || y)) {
28
- Object.assign(Pool.prototype, poolBalancesLendingMixin);
23
+ constructor(poolId) {
24
+ super(poolId);
25
+ this.stats = new StatsPool(this);
26
+ this.configureStats(poolDummy);
27
+ }
28
+ configureStats(poolDummy) {
29
+ if (poolDummy.isMeta) {
30
+ Object.assign(this.stats, poolBalancesMetaMixin);
31
+ }
32
+ else if (poolDummy.useLending.reduce((x, y) => x || y)) {
33
+ Object.assign(this.stats, poolBalancesLendingMixin);
34
+ }
35
+ }
29
36
  }
30
37
  // depositBalancedAmounts
31
38
  if (poolDummy.isCrypto) {
@@ -0,0 +1,68 @@
1
+ import { IGaugePool } from "./gaugePool.js";
2
+ export interface ICorePool {
3
+ id: string;
4
+ name: string;
5
+ fullName: string;
6
+ symbol: string;
7
+ referenceAsset: string;
8
+ address: string;
9
+ lpToken: string;
10
+ gauge: IGaugePool;
11
+ zap: string | null;
12
+ sRewardContract: string | null;
13
+ rewardContract: string | null;
14
+ implementation: string | null;
15
+ isPlain: boolean;
16
+ isLending: boolean;
17
+ isMeta: boolean;
18
+ isCrypto: boolean;
19
+ isFake: boolean;
20
+ isFactory: boolean;
21
+ isMetaFactory: boolean;
22
+ isNg: boolean;
23
+ isLlamma: boolean;
24
+ basePool: string;
25
+ metaCoinIdx: number;
26
+ underlyingCoins: string[];
27
+ wrappedCoins: string[];
28
+ underlyingCoinAddresses: string[];
29
+ wrappedCoinAddresses: string[];
30
+ underlyingDecimals: number[];
31
+ wrappedDecimals: number[];
32
+ useLending: boolean[];
33
+ inApi: boolean;
34
+ }
35
+ export declare class CorePool implements ICorePool {
36
+ id: string;
37
+ name: string;
38
+ fullName: string;
39
+ symbol: string;
40
+ referenceAsset: string;
41
+ address: string;
42
+ lpToken: string;
43
+ gauge: IGaugePool;
44
+ zap: string | null;
45
+ sRewardContract: string | null;
46
+ rewardContract: string | null;
47
+ implementation: string | null;
48
+ isPlain: boolean;
49
+ isLending: boolean;
50
+ isMeta: boolean;
51
+ isCrypto: boolean;
52
+ isFake: boolean;
53
+ isFactory: boolean;
54
+ isMetaFactory: boolean;
55
+ isNg: boolean;
56
+ isLlamma: boolean;
57
+ basePool: string;
58
+ metaCoinIdx: number;
59
+ underlyingCoins: string[];
60
+ wrappedCoins: string[];
61
+ underlyingCoinAddresses: string[];
62
+ wrappedCoinAddresses: string[];
63
+ underlyingDecimals: number[];
64
+ wrappedDecimals: number[];
65
+ useLending: boolean[];
66
+ inApi: boolean;
67
+ constructor(id: string);
68
+ }
@@ -0,0 +1,39 @@
1
+ import { curve } from "../../curve.js";
2
+ import { GaugePool } from "./gaugePool.js";
3
+ export class CorePool {
4
+ constructor(id) {
5
+ var _a, _b;
6
+ const poolData = curve.getPoolsData()[id];
7
+ this.id = id;
8
+ this.name = poolData.name;
9
+ this.fullName = poolData.full_name;
10
+ this.symbol = poolData.symbol;
11
+ this.referenceAsset = poolData.reference_asset;
12
+ this.address = poolData.swap_address;
13
+ this.lpToken = poolData.token_address;
14
+ this.gauge = new GaugePool(poolData.gauge_address, poolData.name);
15
+ this.zap = poolData.deposit_address || null;
16
+ this.sRewardContract = poolData.sCurveRewards_address || null;
17
+ this.rewardContract = poolData.reward_contract || null;
18
+ this.implementation = poolData.implementation_address || null;
19
+ this.isPlain = poolData.is_plain || false;
20
+ this.isLending = poolData.is_lending || false;
21
+ this.isMeta = poolData.is_meta || false;
22
+ this.isCrypto = poolData.is_crypto || false;
23
+ this.isFake = poolData.is_fake || false;
24
+ this.isFactory = poolData.is_factory || false;
25
+ this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
26
+ this.isNg = poolData.is_ng || false;
27
+ this.isLlamma = poolData.is_llamma || false;
28
+ this.basePool = poolData.base_pool || '';
29
+ this.metaCoinIdx = this.isMeta ? (_a = poolData.meta_coin_idx) !== null && _a !== void 0 ? _a : poolData.wrapped_coins.length - 1 : -1;
30
+ this.underlyingCoins = poolData.underlying_coins;
31
+ this.wrappedCoins = poolData.wrapped_coins;
32
+ this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
33
+ this.wrappedCoinAddresses = poolData.wrapped_coin_addresses;
34
+ this.underlyingDecimals = poolData.underlying_decimals;
35
+ this.wrappedDecimals = poolData.wrapped_decimals;
36
+ this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(() => false);
37
+ this.inApi = (_b = poolData.in_api) !== null && _b !== void 0 ? _b : false;
38
+ }
39
+ }
@@ -1,4 +1,4 @@
1
- import { IDict } from '../interfaces';
1
+ import { IDict } from '../../interfaces.js';
2
2
  export interface IGaugePool {
3
3
  address: string;
4
4
  poolName: string;
@@ -7,8 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { curve } from "../curve.js";
11
- import { DIGas, ensureAllowance, ensureAllowanceEstimateGas, getCoinsData, hasAllowance, mulBy1_3, parseUnits, smartNumber, } from "../utils.js";
10
+ import { curve } from "../../curve.js";
11
+ import { DIGas, ensureAllowance, ensureAllowanceEstimateGas, getCoinsData, hasAllowance, mulBy1_3, parseUnits, smartNumber, } from "../../utils.js";
12
12
  export class GaugePool {
13
13
  constructor(address, poolName) {
14
14
  this.address = address;
@@ -0,0 +1,45 @@
1
+ import { IReward } from '../../interfaces.js';
2
+ import { PoolTemplate } from "../PoolTemplate.js";
3
+ export interface IStatsParameters {
4
+ lpTokenSupply: string;
5
+ virtualPrice: string;
6
+ fee: string;
7
+ adminFee: string;
8
+ A: string;
9
+ future_A?: string;
10
+ initial_A?: string;
11
+ future_A_time?: number;
12
+ initial_A_time?: number;
13
+ gamma?: string;
14
+ priceOracle?: string[];
15
+ priceScale?: string[];
16
+ }
17
+ export interface IStatsPool {
18
+ pool: PoolTemplate;
19
+ parameters(): Promise<IStatsParameters>;
20
+ underlyingBalances(): Promise<string[]>;
21
+ wrappedBalances(): Promise<string[]>;
22
+ totalLiquidity(useApi?: boolean): Promise<string>;
23
+ volume(): Promise<string>;
24
+ baseApy(): Promise<{
25
+ day: string;
26
+ week: string;
27
+ }>;
28
+ tokenApy(useApi?: boolean): Promise<[number, number]>;
29
+ rewardsApy(useApi?: boolean): Promise<IReward[]>;
30
+ }
31
+ export declare class StatsPool implements IStatsPool {
32
+ pool: PoolTemplate;
33
+ constructor(pool: PoolTemplate);
34
+ parameters: () => Promise<IStatsParameters>;
35
+ wrappedBalances(): Promise<string[]>;
36
+ underlyingBalances(): Promise<string[]>;
37
+ totalLiquidity: (useApi?: boolean) => Promise<string>;
38
+ volume: () => Promise<string>;
39
+ baseApy: () => Promise<{
40
+ day: string;
41
+ week: string;
42
+ }>;
43
+ tokenApy: (useApi?: boolean) => Promise<[baseApy: number, boostedApy: number]>;
44
+ rewardsApy: (useApi?: boolean) => Promise<IReward[]>;
45
+ }
@@ -0,0 +1,227 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { curve } from "../../curve.js";
11
+ import { _getPoolsFromApi } from '../../external-api.js';
12
+ import { _getUsdRate, BN, toBN, _getCrvApyFromApi, _getRewardsFromApi, getVolumeApiController, } from '../../utils.js';
13
+ export class StatsPool {
14
+ constructor(pool) {
15
+ this.parameters = () => __awaiter(this, void 0, void 0, function* () {
16
+ const multicallContract = curve.contracts[this.pool.address].multicallContract;
17
+ const lpMulticallContract = curve.contracts[this.pool.lpToken].multicallContract;
18
+ const calls = [
19
+ multicallContract.get_virtual_price(),
20
+ multicallContract.fee(),
21
+ "admin_fee" in multicallContract ? multicallContract.admin_fee() : multicallContract.ADMIN_FEE(),
22
+ multicallContract.A(),
23
+ lpMulticallContract.totalSupply(),
24
+ ];
25
+ if (this.pool.isCrypto) {
26
+ calls.push(multicallContract.gamma());
27
+ if (this.pool.wrappedCoins.length === 2) {
28
+ calls.push(multicallContract.price_oracle());
29
+ calls.push(multicallContract.price_scale());
30
+ }
31
+ else {
32
+ for (let i = 0; i < this.pool.wrappedCoins.length - 1; i++) {
33
+ calls.push(multicallContract.price_oracle(i));
34
+ calls.push(multicallContract.price_scale(i));
35
+ }
36
+ }
37
+ }
38
+ const additionalCalls = this.pool.isCrypto ? [] : [multicallContract.future_A()];
39
+ if ('initial_A' in multicallContract) {
40
+ additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
41
+ }
42
+ let _virtualPrice = curve.parseUnits("0");
43
+ let _fee = curve.parseUnits("0");
44
+ let _prices, _adminFee, _A, _lpTokenSupply, _gamma;
45
+ try {
46
+ [_virtualPrice, _fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
47
+ }
48
+ catch (e) { // Empty pool
49
+ calls.shift();
50
+ if (this.pool.isCrypto) {
51
+ calls.shift();
52
+ [_adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
53
+ }
54
+ else {
55
+ [_fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
56
+ }
57
+ }
58
+ const [virtualPrice, fee, adminFee, A, lpTokenSupply, gamma] = [
59
+ curve.formatUnits(_virtualPrice),
60
+ curve.formatUnits(_fee, 8),
61
+ curve.formatUnits(_adminFee * _fee),
62
+ curve.formatUnits(_A, 0),
63
+ curve.formatUnits(_lpTokenSupply),
64
+ _gamma ? curve.formatUnits(_gamma) : undefined,
65
+ ];
66
+ let priceOracle, priceScale;
67
+ if (this.pool.isCrypto) {
68
+ const prices = _prices.map((_p) => curve.formatUnits(_p));
69
+ priceOracle = [];
70
+ priceScale = [];
71
+ for (let i = 0; i < this.pool.wrappedCoins.length - 1; i++) {
72
+ priceOracle.push(prices.shift());
73
+ priceScale.push(prices.shift());
74
+ }
75
+ }
76
+ const A_PRECISION = curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.pool.id) ? 1 : 100;
77
+ const [_future_A, _initial_A, _future_A_time, _initial_A_time] = yield curve.multicallProvider.all(additionalCalls);
78
+ const [future_A, initial_A, future_A_time, initial_A_time] = [
79
+ _future_A ? String(Number(curve.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
80
+ _initial_A ? String(Number(curve.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
81
+ _future_A_time ? Number(curve.formatUnits(_future_A_time, 0)) * 1000 : undefined,
82
+ _initial_A_time ? Number(curve.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
83
+ ];
84
+ return { lpTokenSupply, virtualPrice, fee, adminFee, A, future_A, initial_A, future_A_time, initial_A_time, gamma, priceOracle, priceScale };
85
+ });
86
+ this.totalLiquidity = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
87
+ if (curve.chainId === 1 && this.pool.id === "crveth")
88
+ return "0";
89
+ if (this.pool.isLlamma) {
90
+ const stablecoinContract = curve.contracts[this.pool.underlyingCoinAddresses[0]].multicallContract;
91
+ const collateralContract = curve.contracts[this.pool.underlyingCoinAddresses[1]].multicallContract;
92
+ const ammContract = curve.contracts[this.pool.address].multicallContract;
93
+ const [_balance_x, _fee_x, _balance_y, _fee_y] = yield curve.multicallProvider.all([
94
+ stablecoinContract.balanceOf(this.pool.address),
95
+ ammContract.admin_fees_x(),
96
+ collateralContract.balanceOf(this.pool.address),
97
+ ammContract.admin_fees_y(),
98
+ ]);
99
+ const collateralRate = yield _getUsdRate(this.pool.underlyingCoinAddresses[1]);
100
+ const stablecoinTvlBN = toBN(_balance_x).minus(toBN(_fee_x));
101
+ const collateralTvlBN = toBN(_balance_y).minus(toBN(_fee_y)).times(collateralRate);
102
+ return stablecoinTvlBN.plus(collateralTvlBN).toString();
103
+ }
104
+ if (useApi) {
105
+ const network = curve.constants.NETWORK_NAME;
106
+ let poolType = this.pool.isCrypto ? "crypto" : "main";
107
+ if (this.pool.id.startsWith("factory")) {
108
+ poolType = this.pool.id.replace(/-\d+$/, '');
109
+ poolType = poolType.replace(/-v2$/, '');
110
+ }
111
+ const poolsData = (yield _getPoolsFromApi(network, poolType)).poolData;
112
+ try {
113
+ const totalLiquidity = poolsData.filter((data) => data.address.toLowerCase() === this.pool.address.toLowerCase())[0].usdTotal;
114
+ return String(totalLiquidity);
115
+ }
116
+ catch (err) {
117
+ console.log(this.pool.id, err.message);
118
+ }
119
+ }
120
+ const balances = yield this.underlyingBalances();
121
+ const promises = [];
122
+ for (const addr of this.pool.underlyingCoinAddresses) {
123
+ promises.push(_getUsdRate(addr));
124
+ }
125
+ const prices = yield Promise.all(promises);
126
+ const totalLiquidity = balances.reduce((liquidity, b, i) => liquidity + (Number(b) * prices[i]), 0);
127
+ return totalLiquidity.toFixed(8);
128
+ });
129
+ this.volume = () => __awaiter(this, void 0, void 0, function* () {
130
+ if (curve.isLiteChain) {
131
+ throw Error('This method is not supported for the lite version');
132
+ }
133
+ const network = curve.constants.NETWORK_NAME;
134
+ const { poolsData } = yield getVolumeApiController(network);
135
+ const poolData = poolsData.find((d) => d.address.toLowerCase() === this.pool.address);
136
+ if (poolData) {
137
+ return poolData.volumeUSD.toString();
138
+ }
139
+ throw Error(`Can't get Volume for ${this.pool.name} (id: ${this.pool.id})`);
140
+ });
141
+ this.baseApy = () => __awaiter(this, void 0, void 0, function* () {
142
+ if (curve.isLiteChain) {
143
+ throw Error('baseApy is not supported for the lite version');
144
+ }
145
+ const network = curve.constants.NETWORK_NAME;
146
+ const { poolsData } = yield getVolumeApiController(network);
147
+ const poolData = poolsData.find((d) => d.address.toLowerCase() === this.pool.address);
148
+ if (poolData) {
149
+ return {
150
+ day: poolData.day.toString(),
151
+ week: poolData.week.toString(),
152
+ };
153
+ }
154
+ throw Error(`Can't get base APY for ${this.pool.name} (id: ${this.pool.id})`);
155
+ });
156
+ this.tokenApy = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
157
+ var _a;
158
+ if (curve.isLiteChain) {
159
+ throw Error('tokenApy is not supported for the lite version');
160
+ }
161
+ if (this.pool.rewardsOnly())
162
+ throw Error(`${this.pool.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
163
+ const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
164
+ if (useApi && !isDisabledChain) {
165
+ const crvAPYs = yield _getCrvApyFromApi();
166
+ const poolCrvApy = (_a = crvAPYs[this.pool.gauge.address]) !== null && _a !== void 0 ? _a : [0, 0]; // new pools might be missing
167
+ return [poolCrvApy[0], poolCrvApy[1]];
168
+ }
169
+ return yield this.pool._calcTokenApy();
170
+ });
171
+ this.rewardsApy = (useApi = true) => __awaiter(this, void 0, void 0, function* () {
172
+ if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS)
173
+ return [];
174
+ const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
175
+ if (useApi && !isDisabledChain) {
176
+ const rewards = yield _getRewardsFromApi();
177
+ if (!rewards[this.pool.gauge.address])
178
+ return [];
179
+ return rewards[this.pool.gauge.address].map((r) => ({ gaugeAddress: r.gaugeAddress, tokenAddress: r.tokenAddress, symbol: r.symbol, apy: r.apy }));
180
+ }
181
+ const apy = [];
182
+ const rewardTokens = yield this.pool.rewardTokens(false);
183
+ for (const rewardToken of rewardTokens) {
184
+ const gaugeContract = curve.contracts[this.pool.gauge.address].multicallContract;
185
+ const lpTokenContract = curve.contracts[this.pool.lpToken].multicallContract;
186
+ const rewardContract = curve.contracts[this.pool.sRewardContract || this.pool.gauge.address].multicallContract;
187
+ const totalLiquidityUSD = yield this.totalLiquidity();
188
+ const rewardRate = yield _getUsdRate(rewardToken.token);
189
+ const [rewardData, _stakedSupply, _totalSupply] = yield curve.multicallProvider.all([
190
+ rewardContract.reward_data(rewardToken.token),
191
+ gaugeContract.totalSupply(),
192
+ lpTokenContract.totalSupply(),
193
+ ]);
194
+ const stakedSupplyBN = toBN(_stakedSupply);
195
+ const totalSupplyBN = toBN(_totalSupply);
196
+ const inflationBN = toBN(rewardData.rate, rewardToken.decimals);
197
+ const periodFinish = Number(curve.formatUnits(rewardData.period_finish, 0)) * 1000;
198
+ const baseApy = periodFinish > Date.now() ?
199
+ inflationBN.times(31536000).times(rewardRate).div(stakedSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)) :
200
+ BN(0);
201
+ apy.push({
202
+ gaugeAddress: this.pool.gauge.address,
203
+ tokenAddress: rewardToken.token,
204
+ symbol: rewardToken.symbol,
205
+ apy: baseApy.times(100).toNumber(),
206
+ });
207
+ }
208
+ return apy;
209
+ });
210
+ this.pool = pool;
211
+ }
212
+ wrappedBalances() {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ const contract = curve.contracts[this.pool.address].multicallContract;
215
+ const calls = [];
216
+ for (let i = 0; i < this.pool.wrappedCoins.length; i++)
217
+ calls.push(contract.balances(i));
218
+ const _wrappedBalances = yield curve.multicallProvider.all(calls);
219
+ return _wrappedBalances.map((_b, i) => curve.formatUnits(_b, this.pool.wrappedDecimals[i]));
220
+ });
221
+ }
222
+ underlyingBalances() {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ return yield this.wrappedBalances();
225
+ });
226
+ }
227
+ }
@@ -0,0 +1,19 @@
1
+ import { IDict } from '../../interfaces';
2
+ import { PoolTemplate } from "../PoolTemplate";
3
+ export interface IWalletPool {
4
+ balances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
5
+ lpTokenBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
6
+ underlyingCoinBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
7
+ wrappedCoinBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
8
+ allCoinBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
9
+ }
10
+ export declare class WalletPool implements IWalletPool {
11
+ private pool;
12
+ constructor(pool: PoolTemplate);
13
+ private _balances;
14
+ balances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
15
+ lpTokenBalances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
16
+ underlyingCoinBalances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
17
+ wrappedCoinBalances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
18
+ allCoinBalances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
19
+ }
@@ -0,0 +1,72 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { curve } from "../../curve.js";
11
+ import { _prepareAddresses, _getBalances, } from '../../utils.js';
12
+ export class WalletPool {
13
+ constructor(pool) {
14
+ this._balances = (rawCoinNames, rawCoinAddresses, ...addresses) => __awaiter(this, void 0, void 0, function* () {
15
+ const coinNames = [];
16
+ const coinAddresses = [];
17
+ // removing duplicates
18
+ for (let i = 0; i < rawCoinAddresses.length; i++) {
19
+ if (!coinAddresses.includes(rawCoinAddresses[i])) {
20
+ coinNames.push(rawCoinNames[i]);
21
+ coinAddresses.push(rawCoinAddresses[i]);
22
+ }
23
+ }
24
+ addresses = _prepareAddresses(addresses);
25
+ const rawBalances = yield _getBalances(coinAddresses, addresses);
26
+ const balances = {};
27
+ for (const address of addresses) {
28
+ balances[address] = {};
29
+ for (const coinName of coinNames) {
30
+ balances[address][coinName] = rawBalances[address].shift();
31
+ }
32
+ }
33
+ return addresses.length === 1 ? balances[addresses[0]] : balances;
34
+ });
35
+ this.pool = pool;
36
+ }
37
+ balances(...addresses) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS) {
40
+ return yield this._balances(['lpToken', ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], [this.pool.lpToken, ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], ...addresses);
41
+ }
42
+ else {
43
+ return yield this._balances(['lpToken', 'gauge', ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], [this.pool.lpToken, this.pool.gauge.address, ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], ...addresses);
44
+ }
45
+ });
46
+ }
47
+ lpTokenBalances(...addresses) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS) {
50
+ return yield this._balances(['lpToken'], [this.pool.lpToken], ...addresses);
51
+ }
52
+ else {
53
+ return yield this._balances(['lpToken', 'gauge'], [this.pool.lpToken, this.pool.gauge.address], ...addresses);
54
+ }
55
+ });
56
+ }
57
+ underlyingCoinBalances(...addresses) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return yield this._balances(this.pool.underlyingCoinAddresses, this.pool.underlyingCoinAddresses, ...addresses);
60
+ });
61
+ }
62
+ wrappedCoinBalances(...addresses) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return yield this._balances(this.pool.wrappedCoinAddresses, this.pool.wrappedCoinAddresses, ...addresses);
65
+ });
66
+ }
67
+ allCoinBalances(...addresses) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return yield this._balances([...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], [...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], ...addresses);
70
+ });
71
+ }
72
+ }
@@ -10,3 +10,4 @@ export declare const getUserClaimable: (pools: string[], address?: string) => Pr
10
10
  }[][]>;
11
11
  export declare const getUserPoolList: (address?: string, useApi?: boolean) => Promise<string[]>;
12
12
  export declare const _getAmplificationCoefficientsFromApi: () => Promise<IDict<number>>;
13
+ export declare const checkVyperVulnerability: (chainId: number, poolId: string, implementation: string | null) => boolean;
@@ -328,3 +328,39 @@ export const _getAmplificationCoefficientsFromApi = () => __awaiter(void 0, void
328
328
  }
329
329
  return amplificationCoefficientDict;
330
330
  });
331
+ export const checkVyperVulnerability = (chainId, poolId, implementation) => {
332
+ var _a, _b;
333
+ if (chainId === 1 && poolId === "crveth")
334
+ return true;
335
+ if (chainId === 42161 && poolId === "tricrypto")
336
+ return true;
337
+ const vulnerableImplementations = {
338
+ 1: [
339
+ "0x6326DEbBAa15bCFE603d831e7D75f4fc10d9B43E",
340
+ "0x8c1aB78601c259E1B43F19816923609dC7d7de9B",
341
+ "0x88855cdF2b0A8413D470B86952E726684de915be",
342
+ ].map((a) => a.toLowerCase()),
343
+ 137: [
344
+ "0xAe00f57663F4C85FC948B13963cd4627dAF01061",
345
+ "0xA9134FaE98F92217f457918505375Ae91fdc5e3c",
346
+ "0xf31bcdf0B9a5eCD7AB463eB905551fBc32e51856",
347
+ ].map((a) => a.toLowerCase()),
348
+ 250: [
349
+ "0xE6358f6a45B502477e83CC1CDa759f540E4459ee",
350
+ "0x5d58Eb45e97B43e471AF05cD2b11CeB4106E1b1a",
351
+ "0xb11Dc44A9f981fAF1669dca6DD40c3cc2554A2ce",
352
+ ].map((a) => a.toLowerCase()),
353
+ 42161: [
354
+ "0x7DA64233Fefb352f8F501B357c018158ED8aA455",
355
+ "0xAAe75FAebCae43b9d541Fd875622BE48D9B4f5D0",
356
+ "0x89287c32c2CAC1C76227F6d300B2DBbab6b75C08",
357
+ ].map((a) => a.toLowerCase()),
358
+ 43114: [
359
+ "0x64448B78561690B70E17CBE8029a3e5c1bB7136e",
360
+ "0xF1f85a74AD6c64315F85af52d3d46bF715236ADc",
361
+ "0x0eb0F1FaF5F509Ac53fA224477509EAD167cf410",
362
+ ].map((a) => a.toLowerCase()),
363
+ };
364
+ const implementations = (_a = vulnerableImplementations[chainId]) !== null && _a !== void 0 ? _a : [];
365
+ return implementations.includes((_b = implementation === null || implementation === void 0 ? void 0 : implementation.toLowerCase()) !== null && _b !== void 0 ? _b : "");
366
+ };
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { Abi, AbiFunction, IBasePoolShortItem, IChainId, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
2
+ import { Abi, AbiFunction, IBasePoolShortItem, IChainId, ICurveLiteNetwork, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
3
3
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
4
4
  export declare const MAX_ALLOWANCE: bigint;
5
5
  export declare const _cutZeros: (strn: string) => string;
@@ -70,3 +70,12 @@ export declare function log(fnName: string, ...args: unknown[]): void;
70
70
  export declare function runWorker<In extends {
71
71
  type: string;
72
72
  }, Out>(code: string, syncFn: () => ((val: In) => Out) | undefined, inputData: In, timeout?: number): Promise<Out>;
73
+ export declare const getCurveLiteNetworks: () => Promise<ICurveLiteNetwork[]>;
74
+ export declare const getNetworkNameByChainId: (chainId: number, networks: ICurveLiteNetwork[]) => string;
75
+ export declare const getNetworkConstants: (chainId: IChainId | number, isLiteChain: boolean) => Promise<any>;
76
+ export declare const PERIODS: {
77
+ DAY: number;
78
+ WEEK: number;
79
+ MONTH: number;
80
+ YEAR: number;
81
+ };