@curvefi/api 2.70.5 → 2.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -494,13 +494,6 @@ import curve from "@curvefi/api";
494
494
  // true
495
495
  await pool.isGaugeKilled();
496
496
  // false
497
- await pool.gaugeStatus();
498
- // null OR
499
- //{
500
- // rewardsNeedNudging: false,
501
- // areCrvRewardsStuckInBridge: false,
502
- //
503
- // }
504
497
  })()
505
498
  ````
506
499
 
@@ -1505,8 +1505,8 @@ export const POOLS_DATA_ETHEREUM = lowerCasePoolDataAddresses({
1505
1505
  is_meta: true,
1506
1506
  is_crypto: true,
1507
1507
  base_pool: '3pool',
1508
- underlying_coins: ['EUROC', 'DAI', 'USDC', 'USDT'],
1509
- wrapped_coins: ['EUROC', '3Crv'],
1508
+ underlying_coins: ['EURC', 'DAI', 'USDC', 'USDT'],
1509
+ wrapped_coins: ['EURC', '3Crv'],
1510
1510
  underlying_coin_addresses: [
1511
1511
  '0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c',
1512
1512
  '0x6B175474E89094C44Da98b954EedeAC495271d0F',
@@ -1,7 +1,5 @@
1
1
  import { IChainId } from "../interfaces";
2
2
  export interface IVolumeNetworks {
3
3
  getVolumes: IChainId[];
4
- getSubgraphData: IChainId[];
5
- getFactoryAPYs: IChainId[];
6
4
  }
7
5
  export declare const volumeNetworks: IVolumeNetworks;
@@ -1,5 +1,3 @@
1
1
  export const volumeNetworks = {
2
- getVolumes: [1, 10, 56, 100, 137, 250, 252, 999, 8453, 42161, 146],
3
- getSubgraphData: [43114],
4
- getFactoryAPYs: [196, 324, 1284, 2222, 5000, 42220, 1313161554],
2
+ getVolumes: [1, 10, 56, 100, 137, 252, 999, 8453, 42161],
5
3
  };
package/lib/curve.js CHANGED
@@ -49,7 +49,7 @@ import circulatingSupplyABI from './constants/abis/circulating_supply.json' with
49
49
  import rootGaugeFactoryABI from "./constants/abis/gauge_factory/root_gauge_factory.json" with { type: "json" };
50
50
  import fastBridgeABI from './constants/abis/fastBridge.json' with { type: 'json' };
51
51
  import { extractDecimals, extractGauges, formatUnits, lowerCasePoolDataAddresses, parseUnits, } from "./constants/utils.js";
52
- import { _getHiddenPools, _getPoolFilters } from "./external-api.js";
52
+ import { _getPoolFilters } from "./external-api.js";
53
53
  import { L2Networks } from "./constants/L2Networks.js";
54
54
  import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
55
55
  import { applyFeeDataOverride, computeEip1559Fees, computeLegacyOrFallback, fetchFeeHistory, getNetworkConstants, } from "./utils.js";
@@ -661,14 +661,11 @@ export class Curve {
661
661
  }
662
662
  _filterHiddenPools(pools_1) {
663
663
  return __awaiter(this, arguments, void 0, function* (pools, isFiltered = false) {
664
- const hiddenPoolsAll = yield _getHiddenPools(this.isLiteChain);
665
- const hiddenPools = hiddenPoolsAll[this.constants.NETWORK_NAME];
666
- let filteredAddresses;
667
- if (isFiltered) {
668
- const poolFilters = yield _getPoolFilters();
669
- filteredAddresses = new Set(poolFilters[this.constants.NETWORK_NAME]);
670
- }
671
- return Object.fromEntries(Object.entries(pools).filter(([id, pool]) => !(hiddenPools === null || hiddenPools === void 0 ? void 0 : hiddenPools.includes(id)) && !(filteredAddresses === null || filteredAddresses === void 0 ? void 0 : filteredAddresses.has(pool.swap_address))));
664
+ if (!isFiltered)
665
+ return pools;
666
+ const poolFilters = yield _getPoolFilters();
667
+ const filteredAddresses = new Set(poolFilters[this.constants.NETWORK_NAME]);
668
+ return Object.fromEntries(Object.entries(pools).filter(([, pool]) => !filteredAddresses.has(pool.swap_address)));
672
669
  });
673
670
  }
674
671
  _updateDecimalsAndGauges(pools) {
package/lib/dao.js CHANGED
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Contract } from "ethers";
11
- import { _getAllGauges, _getDaoProposal, _getDaoProposalList } from './external-api.js';
11
+ import { _getDaoProposal, _getDaoProposalList } from './external-api.js';
12
+ import { getGaugesOverview } from './prices-api.js';
12
13
  import { _getAddress, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from './utils.js';
13
14
  import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: "json" };
14
15
  // ----------------- Refactored boosting stuff -----------------
@@ -230,26 +231,33 @@ export function claimFees() {
230
231
  });
231
232
  }
232
233
  // ----------------- Gauge weights -----------------
234
+ const toRelativeWeightPct = (gaugeRelativeWeight) => (gaugeRelativeWeight * 100).toString();
235
+ const assertHasNoRootGaugeGap = (gauge) => {
236
+ var _a;
237
+ if (((_a = gauge.pool) === null || _a === void 0 ? void 0 : _a.chain) && gauge.pool.chain !== 'ethereum') {
238
+ throw Error(`Cannot resolve mainnet root gauge for L2 gauge ${gauge.address} (chain: ${gauge.pool.chain}) - prices.curve.finance API doesn't provide a root-gauge field yet`);
239
+ }
240
+ };
233
241
  export function getVotingGaugeList() {
234
242
  return __awaiter(this, void 0, void 0, function* () {
235
- var _a, _b;
243
+ var _a, _b, _c, _d, _e, _f;
236
244
  if (this.chainId !== 1)
237
245
  throw Error("Ethereum-only method");
238
- const gaugeData = Object.values(yield _getAllGauges());
246
+ const gaugeData = yield getGaugesOverview();
239
247
  const res = [];
240
- for (let i = 0; i < gaugeData.length; i++) {
241
- if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
248
+ for (const gauge of gaugeData) {
249
+ if (gauge.is_killed && gauge.gauge_relative_weight === 0)
242
250
  continue;
243
251
  res.push({
244
- poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
245
- network: gaugeData[i].blockchainId,
246
- gaugeAddress: gaugeData[i].gauge,
247
- poolAddress: gaugeData[i].swap || '',
248
- lpTokenAddress: gaugeData[i].swap_token || '',
249
- poolName: gaugeData[i].shortName,
250
- totalVeCrv: this.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
251
- relativeWeight: this.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
252
- isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
252
+ poolUrl: '',
253
+ network: (_b = (_a = gauge.pool) === null || _a === void 0 ? void 0 : _a.chain) !== null && _b !== void 0 ? _b : '',
254
+ gaugeAddress: gauge.address,
255
+ poolAddress: (_d = (_c = gauge.pool) === null || _c === void 0 ? void 0 : _c.address) !== null && _d !== void 0 ? _d : '',
256
+ lpTokenAddress: gauge.lp_token,
257
+ poolName: (_f = (_e = gauge.pool) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : gauge.name,
258
+ totalVeCrv: this.formatUnits(gauge.gauge_weight, 18),
259
+ relativeWeight: toRelativeWeightPct(gauge.gauge_relative_weight),
260
+ isKilled: gauge.is_killed,
253
261
  });
254
262
  }
255
263
  return res;
@@ -257,17 +265,17 @@ export function getVotingGaugeList() {
257
265
  }
258
266
  export function userGaugeVotes() {
259
267
  return __awaiter(this, arguments, void 0, function* (address = "") {
260
- var _a, _b;
268
+ var _a, _b, _c, _d, _e, _f;
261
269
  if (this.chainId !== 1)
262
270
  throw Error("Ethereum-only method");
263
271
  address = _getAddress.call(this, address);
264
272
  const gcMulticallContract = this.contracts[this.constants.ALIASES.gauge_controller].multicallContract;
265
273
  const veMulticallContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
266
- const gaugeData = Object.values(yield _getAllGauges());
274
+ const gaugeData = yield getGaugesOverview();
267
275
  const calls = [veMulticallContract.balanceOf(address)];
268
- for (const d of gaugeData) {
269
- const gaugeAddress = d.rootGauge ? d.rootGauge : d.gauge;
270
- calls.push(gcMulticallContract.vote_user_slopes(address, gaugeAddress));
276
+ for (const gauge of gaugeData) {
277
+ assertHasNoRootGaugeGap(gauge);
278
+ calls.push(gcMulticallContract.vote_user_slopes(address, gauge.address));
271
279
  }
272
280
  const [veCrvBalance, ...votes] = yield this.multicallProvider.all(calls);
273
281
  const res = { gauges: [], powerUsed: "0.0", veCrvUsed: "0.0" };
@@ -279,21 +287,22 @@ export function userGaugeVotes() {
279
287
  let dt = votes[i][2] - BigInt(Math.floor(Date.now() / 1000));
280
288
  if (dt < BigInt(0))
281
289
  dt = BigInt(0);
290
+ const gauge = gaugeData[i];
282
291
  res.gauges.push({
283
292
  userPower: this.formatUnits(votes[i][1], 2),
284
293
  userVeCrv: this.formatUnits(votes[i][0] * dt, 18),
285
294
  userFutureVeCrv: this.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
286
295
  expired: dt === BigInt(0),
287
296
  gaugeData: {
288
- poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
289
- network: gaugeData[i].blockchainId,
290
- gaugeAddress: gaugeData[i].gauge,
291
- poolAddress: gaugeData[i].swap || '',
292
- lpTokenAddress: gaugeData[i].swap_token || '',
293
- poolName: gaugeData[i].shortName,
294
- totalVeCrv: this.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
295
- relativeWeight: this.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
296
- isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
297
+ poolUrl: '',
298
+ network: (_b = (_a = gauge.pool) === null || _a === void 0 ? void 0 : _a.chain) !== null && _b !== void 0 ? _b : '',
299
+ gaugeAddress: gauge.address,
300
+ poolAddress: (_d = (_c = gauge.pool) === null || _c === void 0 ? void 0 : _c.address) !== null && _d !== void 0 ? _d : '',
301
+ lpTokenAddress: gauge.lp_token,
302
+ poolName: (_f = (_e = gauge.pool) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : gauge.name,
303
+ totalVeCrv: this.formatUnits(gauge.gauge_weight, 18),
304
+ relativeWeight: toRelativeWeightPct(gauge.gauge_relative_weight),
305
+ isKilled: gauge.is_killed,
297
306
  },
298
307
  });
299
308
  powerUsed += votes[i][1];
@@ -1,14 +1,9 @@
1
1
  import memoize from "memoizee";
2
- import { ICurveLiteNetwork, IDaoProposal, IDaoProposalListItem, IDict, IExtendedPoolDataFromApi, IGaugesDataFromApi, INetworkName, IPoolType, IVolumeAndAPYs } from "./interfaces";
2
+ import { ICurveLiteNetwork, IDaoProposal, IDaoProposalListItem, IDict, IExtendedPoolDataFromApi, INetworkName, IPoolType, IVolumeAndAPYs } from "./interfaces";
3
3
  export declare const uncached_getAllPoolsFromApi: (network: INetworkName, isLiteChain: boolean) => Promise<Record<IPoolType, IExtendedPoolDataFromApi>>;
4
4
  export declare const createUsdPricesDict: (allTypesExtendedPoolData: IExtendedPoolDataFromApi[]) => IDict<number>;
5
5
  export declare const createCrvApyDict: (allTypesExtendedPoolData: IExtendedPoolDataFromApi[]) => IDict<[number, number]>;
6
- export declare const _getSubgraphData: ((network: INetworkName) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: INetworkName) => Promise<IVolumeAndAPYs>>;
7
- export declare const _getVolumes: ((network: string) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: string) => Promise<IVolumeAndAPYs>>;
8
- export declare const _getFactoryAPYs: ((network: string) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: string) => Promise<IVolumeAndAPYs>>;
9
- export declare const _getAllGauges: (() => Promise<IDict<IGaugesDataFromApi>>) & memoize.Memoized<() => Promise<IDict<IGaugesDataFromApi>>>;
10
- export declare const _getAllGaugesFormatted: (() => Promise<IDict<any>>) & memoize.Memoized<() => Promise<IDict<any>>>;
11
- export declare const _getHiddenPools: ((isLiteChain: boolean) => Promise<IDict<string[]>>) & memoize.Memoized<(isLiteChain: boolean) => Promise<IDict<string[]>>>;
6
+ export declare const _getVolumes: ((network: INetworkName) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: INetworkName) => Promise<IVolumeAndAPYs>>;
12
7
  export declare const _getPoolFilters: (() => Promise<IDict<string[]>>) & memoize.Memoized<() => Promise<IDict<string[]>>>;
13
8
  export declare const _generateBoostingProof: ((block: number, address: string) => Promise<{
14
9
  block_header_rlp: string;
@@ -19,5 +14,5 @@ export declare const _generateBoostingProof: ((block: number, address: string) =
19
14
  }>>;
20
15
  export declare const _getDaoProposalList: (() => Promise<IDaoProposalListItem[]>) & memoize.Memoized<() => Promise<IDaoProposalListItem[]>>;
21
16
  export declare const _getDaoProposal: ((type: "PARAMETER" | "OWNERSHIP", id: number) => Promise<IDaoProposal>) & memoize.Memoized<(type: "PARAMETER" | "OWNERSHIP", id: number) => Promise<IDaoProposal>>;
22
- export declare const _getLiteNetworksData: ((networkName: string) => Promise<any>) & memoize.Memoized<(networkName: string) => Promise<any>>;
17
+ export declare const _getLiteNetworksData: ((chainId: number) => Promise<any>) & memoize.Memoized<(chainId: number) => Promise<any>>;
23
18
  export declare const _getCurveLiteNetworks: (() => Promise<ICurveLiteNetwork[]>) & memoize.Memoized<() => Promise<ICurveLiteNetwork[]>>;
@@ -8,11 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import memoize from "memoizee";
11
+ import { getPoolsFromPricesApi, getVolumesFromPricesApi } from "./prices-api.js";
12
+ import { getLiteDeploymentFromApi2, getLiteNetworksFromApi2, getLitePoolsFromApi2, } from "./lite-api.js";
13
+ // Core chains that ARE fully configured in the library (static POOLS_DATA / ALIASES /
14
+ // implementationABIDict) but whose live pool data is NOT indexed by prices.curve.finance.
15
+ // Their factory pools live in api2 instead, so we fetch from there while keeping them core
16
+ // (static main/crypto pools + on-chain reconcile + impl-ABI dict all keep working).
17
+ const API2_BACKED_CORE_CHAINS = ["avalanche"];
11
18
  const uncached_getPoolsFromApi = (network, poolType, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
12
- var _a;
13
- const api = isLiteChain ? "https://api-core.curve.finance/v1/" : "https://api.curve.finance/api";
14
- const url = `${api}/getPools/${network}/${poolType}`;
15
- return (_a = yield fetchData(url)) !== null && _a !== void 0 ? _a : { poolData: [], tvl: 0, tvlAll: 0 };
19
+ if (isLiteChain || API2_BACKED_CORE_CHAINS.includes(network))
20
+ return yield getLitePoolsFromApi2(network, poolType);
21
+ return yield getPoolsFromPricesApi(network, poolType);
16
22
  });
17
23
  const getPoolTypes = (isLiteChain) => isLiteChain ? ["factory-twocrypto", "factory-tricrypto", "factory-stable-ng"] :
18
24
  ["main", "crypto", "factory", "factory-crvusd", "factory-crypto", "factory-twocrypto", "factory-tricrypto", "factory-stable-ng"];
@@ -107,86 +113,7 @@ export const createCrvApyDict = (allTypesExtendedPoolData) => {
107
113
  }
108
114
  return apyDict;
109
115
  };
110
- export const _getSubgraphData = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
111
- var _a, _b, _c;
112
- const data = yield fetchData(`https://api.curve.finance/api/getSubgraphData/${network}`);
113
- const poolsData = data.poolList.map((data) => ({
114
- address: data.address,
115
- volumeUSD: data.volumeUSD,
116
- day: data.latestDailyApy,
117
- week: data.latestWeeklyApy,
118
- }));
119
- return {
120
- poolsData: poolsData,
121
- totalVolume: (_a = data.totalVolume) !== null && _a !== void 0 ? _a : 0,
122
- cryptoVolume: (_b = data.cryptoVolume) !== null && _b !== void 0 ? _b : 0,
123
- cryptoShare: (_c = data.cryptoShare) !== null && _c !== void 0 ? _c : 0,
124
- };
125
- }), {
126
- promise: true,
127
- maxAge: 5 * 60 * 1000, // 5m
128
- });
129
- export const _getVolumes = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
130
- var _a, _b, _c;
131
- const { pools, totalVolumes } = yield fetchData(`https://api.curve.finance/api/getVolumes/${network}`);
132
- const poolsData = pools.map((data) => ({
133
- address: data.address,
134
- volumeUSD: data.volumeUSD,
135
- day: data.latestDailyApyPcent,
136
- week: data.latestWeeklyApyPcent,
137
- }));
138
- return {
139
- poolsData: poolsData !== null && poolsData !== void 0 ? poolsData : [],
140
- totalVolume: (_a = totalVolumes.totalVolume) !== null && _a !== void 0 ? _a : 0,
141
- cryptoVolume: (_b = totalVolumes.totalCryptoVolume) !== null && _b !== void 0 ? _b : 0,
142
- cryptoShare: (_c = totalVolumes.cryptoVolumeSharePcent) !== null && _c !== void 0 ? _c : 0,
143
- };
144
- }), {
145
- promise: true,
146
- maxAge: 5 * 60 * 1000, // 5m
147
- });
148
- export const _getFactoryAPYs = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
149
- const [stableData, cryptoData] = yield Promise.all(['stable', 'crypto'].map((type) => fetchData(`https://api.curve.finance/api/getFactoryAPYs/${network}/${type}`)));
150
- const stableVolume = stableData.totalVolumeUsd || stableData.totalVolume || 0;
151
- const cryptoVolume = cryptoData.totalVolumeUsd || cryptoData.totalVolume || 0;
152
- return {
153
- poolsData: [...stableData.poolDetails, ...cryptoData.poolDetails].map((item) => {
154
- var _a, _b, _c;
155
- return ({
156
- address: item.poolAddress,
157
- volumeUSD: (_a = item.totalVolumeUsd) !== null && _a !== void 0 ? _a : 0,
158
- day: (_b = item.apy) !== null && _b !== void 0 ? _b : 0,
159
- week: ((_c = item.apy) !== null && _c !== void 0 ? _c : 0) * 7, // Because api does not return week apy
160
- });
161
- }),
162
- totalVolume: stableVolume + cryptoVolume,
163
- cryptoVolume,
164
- cryptoShare: 100 * cryptoVolume / (stableVolume + cryptoVolume),
165
- };
166
- }), {
167
- promise: true,
168
- maxAge: 5 * 60 * 1000, // 5m
169
- });
170
- export const _getAllGauges = memoize(() => fetchData(`https://api.curve.finance/api/getAllGauges`), {
171
- promise: true,
172
- maxAge: 5 * 60 * 1000, // 5m
173
- });
174
- export const _getAllGaugesFormatted = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
175
- const data = yield fetchData(`https://api.curve.finance/api/getAllGauges`);
176
- const gaugesDict = {};
177
- Object.values(data).forEach((d) => {
178
- var _a, _b;
179
- gaugesDict[d.gauge.toLowerCase()] = {
180
- is_killed: (_a = d.is_killed) !== null && _a !== void 0 ? _a : false,
181
- gaugeStatus: (_b = d.gaugeStatus) !== null && _b !== void 0 ? _b : null,
182
- };
183
- });
184
- return gaugesDict;
185
- }), {
186
- promise: true,
187
- maxAge: 60 * 60 * 1000, // 60m
188
- });
189
- export const _getHiddenPools = memoize((isLiteChain) => fetchData(`https://${isLiteChain ? 'api-core' : 'api'}.curve.finance/v1/getHiddenPools`), {
116
+ export const _getVolumes = memoize((network) => getVolumesFromPricesApi(network), {
190
117
  promise: true,
191
118
  maxAge: 5 * 60 * 1000, // 5m
192
119
  });
@@ -225,22 +152,18 @@ export const _getDaoProposal = memoize((type, id) => fetchJson(`https://api-py.l
225
152
  maxAge: 5 * 60 * 1000, // 5m
226
153
  });
227
154
  // --- CURVE LITE ---
228
- export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, void 0, void 0, function* () {
229
- var _a, _b, _c, _d;
155
+ export const _getLiteNetworksData = memoize((chainId) => __awaiter(void 0, void 0, void 0, function* () {
156
+ var _a, _b, _c;
230
157
  try {
231
- const url = `https://api-core.curve.finance/v1/getDeployment/${networkName}`;
232
- const response = yield fetch(url);
233
- const { data } = (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
234
- if (response.status !== 200 || !data) {
235
- console.error('Failed to fetch network data:', response.status, data);
158
+ const data = yield getLiteDeploymentFromApi2(chainId);
159
+ if (!data)
236
160
  return null;
237
- }
238
161
  const { config, contracts } = data;
239
162
  const network_name = config.network_name || 'Unknown Network';
240
163
  const native_currency_symbol = config.native_currency_symbol || 'N/A';
241
- const wrapped_native_token = ((_b = config.wrapped_native_token) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '';
242
- const native_token = ((_c = config.native_token) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
243
- const wrapper = ((_d = config.wrapper) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || wrapped_native_token;
164
+ const wrapped_native_token = ((_a = config.wrapped_native_token) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
165
+ const native_token = ((_b = config.native_token) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
166
+ const wrapper = ((_c = config.wrapper) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || wrapped_native_token;
244
167
  return {
245
168
  NAME: network_name,
246
169
  ALIASES: {
@@ -278,29 +201,13 @@ export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, v
278
201
  maxAge: 5 * 60 * 1000, // 5 minutes
279
202
  });
280
203
  export const _getCurveLiteNetworks = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
281
- var _a;
282
- const response = yield fetch(`https://api-core.curve.finance/v1/getPlatforms`);
283
- const { data } = (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
284
- if (response.status !== 200 || !(data === null || data === void 0 ? void 0 : data.platforms)) {
285
- console.error('Failed to fetch Curve platforms:', response);
204
+ try {
205
+ return yield getLiteNetworksFromApi2();
206
+ }
207
+ catch (error) {
208
+ console.error('Failed to fetch Curve platforms:', error);
286
209
  return [];
287
210
  }
288
- const { platforms, platformsMetadata } = data;
289
- return Object.keys(platforms)
290
- .map((id) => {
291
- var _a;
292
- const { name, rpcUrl, nativeCurrencySymbol, explorerBaseUrl, isMainnet, chainId } = (_a = platformsMetadata[id]) !== null && _a !== void 0 ? _a : {};
293
- return name && {
294
- id,
295
- name,
296
- rpcUrl,
297
- chainId,
298
- explorerUrl: explorerBaseUrl,
299
- nativeCurrencySymbol,
300
- isTestnet: !isMainnet,
301
- };
302
- })
303
- .filter(Boolean);
304
211
  }), {
305
212
  promise: true,
306
213
  maxAge: 5 * 60 * 1000, // 5 minutes
@@ -312,9 +219,3 @@ function fetchJson(url) {
312
219
  return (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
313
220
  });
314
221
  }
315
- function fetchData(url) {
316
- return __awaiter(this, void 0, void 0, function* () {
317
- const { data } = yield fetchJson(url);
318
- return data;
319
- });
320
- }
@@ -22,6 +22,39 @@ import StableNgBasePoolZapABI from "../constants/abis/stable-ng-base-pool-zap.js
22
22
  import MetaStableSwapNGABI from "../constants/abis/factory-stable-ng/meta-stableswap-ng.json" with { type: "json" };
23
23
  import PlainStableSwapNGABI from "../constants/abis/factory-stable-ng/plain-stableswap-ng.json" with { type: "json" };
24
24
  import { isYBPool } from "../constants/ybPools.js";
25
+ const FACTORY_ALIAS_BY_TYPE = {
26
+ "factory": "factory",
27
+ "factory-crvusd": "crvusd_factory",
28
+ "factory-crypto": "crypto_factory",
29
+ "factory-twocrypto": "twocrypto_factory",
30
+ "factory-tricrypto": "tricrypto_factory",
31
+ "factory-stable-ng": "stable_ng_factory",
32
+ };
33
+ const ID_PREFIX_BY_FACTORY_TYPE = {
34
+ "factory": "factory-v2",
35
+ "factory-crvusd": "factory-crvusd",
36
+ "factory-crypto": "factory-crypto",
37
+ "factory-twocrypto": "factory-twocrypto",
38
+ "factory-tricrypto": "factory-tricrypto",
39
+ "factory-stable-ng": "factory-stable-ng",
40
+ };
41
+ function reconcilePoolIdsWithChain(poolList, factoryType) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const factoryAddress = this.constants.ALIASES[FACTORY_ALIAS_BY_TYPE[factoryType]];
44
+ const factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
45
+ const poolCount = Number(this.formatUnits(yield this.contracts[factoryAddress].contract.pool_count(this.constantOptions), 0));
46
+ const calls = [];
47
+ for (let i = 0; i < poolCount; i++)
48
+ calls.push(factoryMulticallContract.pool_list(i));
49
+ const addresses = (yield this.multicallProvider.all(calls));
50
+ const indexByAddress = new Map();
51
+ addresses.forEach((address, i) => indexByAddress.set(address.toLowerCase(), i));
52
+ const prefix = ID_PREFIX_BY_FACTORY_TYPE[factoryType];
53
+ return poolList
54
+ .filter((pool) => indexByAddress.has(pool.address))
55
+ .map((pool) => (Object.assign(Object.assign({}, pool), { id: `${prefix}-${indexByAddress.get(pool.address)}` })));
56
+ });
57
+ }
25
58
  export const lowerCasePoolDataAddresses = (poolsData) => {
26
59
  var _a;
27
60
  for (const poolData of poolsData) {
@@ -91,7 +124,8 @@ function setFactoryCoinsContracts(rawPoolList) {
91
124
  export function getFactoryPoolsDataFromApi(factoryType) {
92
125
  return __awaiter(this, void 0, void 0, function* () {
93
126
  const network = this.constants.NETWORK_NAME;
94
- const rawPoolList = lowerCasePoolDataAddresses((yield _getPoolsFromApi(network, factoryType, this.isLiteChain)).poolData);
127
+ let rawPoolList = lowerCasePoolDataAddresses((yield _getPoolsFromApi(network, factoryType, this.isLiteChain)).poolData);
128
+ rawPoolList = yield reconcilePoolIdsWithChain.call(this, rawPoolList, factoryType);
95
129
  return buildFactoryPoolsData.call(this, factoryType, rawPoolList);
96
130
  });
97
131
  }
@@ -102,7 +136,7 @@ export function buildFactoryPoolsData(factoryType, rawPoolListInput) {
102
136
  const implementationABIDict = (_a = this.constants.STABLE_FACTORY_CONSTANTS.implementationABIDict) !== null && _a !== void 0 ? _a : {};
103
137
  let rawPoolList = rawPoolListInput;
104
138
  if (!isCrypto)
105
- rawPoolList = rawPoolList.filter((p) => is_ng || p.implementationAddress in implementationABIDict);
139
+ rawPoolList = rawPoolList.filter((p) => is_ng || (!!p.implementationAddress && p.implementationAddress in implementationABIDict));
106
140
  // Filter duplications
107
141
  const mainAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address);
108
142
  rawPoolList = rawPoolList.filter((p) => !mainAddresses.includes(p.address));
@@ -130,6 +130,7 @@ function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, e
130
130
  }
131
131
  else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
132
132
  coinAddrNamesDict[addr] = "MKR";
133
+ coinAddrDecimalsDict[addr] = 18;
133
134
  }
134
135
  else {
135
136
  newCoinAddresses.push(addr);
@@ -136,6 +136,7 @@ function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, e
136
136
  }
137
137
  else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
138
138
  coinAddrNamesDict[addr] = "MKR";
139
+ coinAddrDecimalsDict[addr] = 18;
139
140
  }
140
141
  else {
141
142
  newCoinAddresses.push(addr);
@@ -77,6 +77,7 @@ function getFactoryIdsAndSwapAddresses() {
77
77
  const factoryContract = this.contracts[factoryAddress].contract;
78
78
  const factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
79
79
  const poolCount = Number(this.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
80
+ console.log('POOL COUNT:', poolCount);
80
81
  const calls = [];
81
82
  for (let i = fromIdx; i < poolCount; i++) {
82
83
  calls.push(factoryMulticallContract.pool_list(i));
@@ -202,6 +203,10 @@ function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrD
202
203
  coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
203
204
  coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
204
205
  }
206
+ else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
207
+ coinAddrNamesDict[addr] = "MKR";
208
+ coinAddrDecimalsDict[addr] = 18;
209
+ }
205
210
  else {
206
211
  newCoinAddresses.push(addr);
207
212
  }
@@ -22,7 +22,7 @@ export interface IPoolData {
22
22
  deposit_address?: string;
23
23
  sCurveRewards_address?: string;
24
24
  reward_contract?: string;
25
- implementation_address?: string;
25
+ implementation_address?: string | null;
26
26
  is_plain?: boolean;
27
27
  is_lending?: boolean;
28
28
  is_meta?: boolean;
@@ -130,7 +130,7 @@ export interface ICoinFromPoolDataApi {
130
130
  address: string;
131
131
  symbol: string;
132
132
  decimals: string;
133
- usdPrice: number | string;
133
+ usdPrice: number | string | null;
134
134
  }
135
135
  export interface IReward {
136
136
  gaugeAddress: string;
@@ -151,14 +151,14 @@ export interface IPoolDataFromApi {
151
151
  id: string;
152
152
  name: string;
153
153
  symbol: string;
154
- assetTypeName: string;
154
+ assetTypeName: string | null;
155
155
  address: string;
156
156
  isMetaPool: boolean;
157
157
  basePoolAddress?: string;
158
158
  lpTokenAddress?: string;
159
159
  gaugeAddress?: string;
160
- implementation: string;
161
- implementationAddress: string;
160
+ implementation: string | null;
161
+ implementationAddress: string | null;
162
162
  coins: ICoinFromPoolDataApi[];
163
163
  gaugeRewards: IRewardFromApi[];
164
164
  gaugeExtraRewards?: IRewardFromApi[];
@@ -230,24 +230,6 @@ export interface IProfit {
230
230
  symbol: string;
231
231
  price: number;
232
232
  }
233
- export interface IGaugesDataFromApi {
234
- blockchainId: string;
235
- gauge: string;
236
- rootGauge?: string;
237
- swap: string;
238
- swap_token: string;
239
- shortName: string;
240
- gauge_controller: {
241
- gauge_relative_weight: string;
242
- get_gauge_weight: string;
243
- };
244
- poolUrls?: {
245
- swap: string[];
246
- };
247
- is_killed?: boolean;
248
- hasNoCrv?: boolean;
249
- gaugeStatus?: Record<string, boolean> | null;
250
- }
251
233
  export interface IVotingGauge {
252
234
  poolUrl: string;
253
235
  network: string;
@@ -0,0 +1,4 @@
1
+ import { ICurveLiteNetwork, IExtendedPoolDataFromApi, INetworkName, IPoolType } from "./interfaces";
2
+ export declare const getLiteNetworksFromApi2: () => Promise<ICurveLiteNetwork[]>;
3
+ export declare const getLitePoolsFromApi2: (network: INetworkName, poolType: IPoolType) => Promise<IExtendedPoolDataFromApi>;
4
+ export declare const getLiteDeploymentFromApi2: (chainId: number) => Promise<any>;
@@ -0,0 +1,130 @@
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 memoize from "memoizee";
11
+ const API2 = "https://api2.curve.finance";
12
+ function fetchJson(url) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ var _a;
15
+ const response = yield fetch(url);
16
+ return (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
17
+ });
18
+ }
19
+ function fetchData(url) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const { data } = yield fetchJson(url);
22
+ return data;
23
+ });
24
+ }
25
+ const _getApi2Platforms = memoize(() => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = yield fetchData(`${API2}/get_platforms`)) !== null && _a !== void 0 ? _a : { platforms: {}, platforms_metadata: {} }; }), {
26
+ promise: true,
27
+ maxAge: 5 * 60 * 1000,
28
+ });
29
+ export const getLiteNetworksFromApi2 = () => __awaiter(void 0, void 0, void 0, function* () {
30
+ const { platforms, platforms_metadata } = yield _getApi2Platforms();
31
+ return Object.keys(platforms)
32
+ .map((id) => {
33
+ const meta = platforms_metadata[id];
34
+ return (meta === null || meta === void 0 ? void 0 : meta.name) && {
35
+ id,
36
+ name: meta.name,
37
+ rpcUrl: meta.rpc_url,
38
+ chainId: meta.chain_id,
39
+ explorerUrl: meta.explorer_base_url,
40
+ nativeCurrencySymbol: meta.native_currency_symbol,
41
+ isTestnet: !meta.is_mainnet,
42
+ };
43
+ })
44
+ .filter(Boolean);
45
+ });
46
+ const getChainIdByNetworkName = (network) => __awaiter(void 0, void 0, void 0, function* () {
47
+ var _a;
48
+ const { platforms_metadata } = yield _getApi2Platforms();
49
+ return (_a = platforms_metadata[network]) === null || _a === void 0 ? void 0 : _a.chain_id;
50
+ });
51
+ const API2_REGISTRY_TO_POOL_TYPE = {
52
+ factory_stable_ng: "factory-stable-ng",
53
+ factory_twocrypto: "factory-twocrypto",
54
+ factory_tricrypto: "factory-tricrypto",
55
+ // legacy registries — surfaced for api2-backed core chains (e.g. avalanche) whose
56
+ // data is not on prices.curve.finance. factory_v2 pools carry an implementation_address
57
+ // that is resolved against the chain's implementationABIDict, exactly like on prices/master.
58
+ // main & crypto are mapped only to feed the USD-price dict; those pools themselves are
59
+ // still built from static POOLS_DATA, not from the API.
60
+ factory_v2: "factory",
61
+ factory_crypto: "factory-crypto",
62
+ main: "main",
63
+ crypto: "crypto",
64
+ };
65
+ const _getApi2PoolsData = memoize((chainId) => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = yield fetchData(`${API2}/get_pools/${chainId}`)) !== null && _a !== void 0 ? _a : { pool_data: [], tvl: 0 }; }), {
66
+ promise: true,
67
+ maxAge: 5 * 60 * 1000,
68
+ });
69
+ const adaptLitePool = (pool, poolType) => {
70
+ var _a, _b, _c, _d, _e, _f, _g;
71
+ return ({
72
+ id: pool.id.replace(pool.registry_id, poolType),
73
+ name: pool.name,
74
+ symbol: pool.symbol,
75
+ assetTypeName: null,
76
+ address: pool.address,
77
+ isMetaPool: pool.is_meta_pool,
78
+ basePoolAddress: (_a = pool.base_pool) !== null && _a !== void 0 ? _a : undefined,
79
+ lpTokenAddress: (_b = pool.lp_token_address) !== null && _b !== void 0 ? _b : undefined,
80
+ gaugeAddress: (_c = pool.gauge_address) !== null && _c !== void 0 ? _c : undefined,
81
+ implementation: null,
82
+ implementationAddress: pool.implementation_address,
83
+ coins: pool.coins.map((coin) => ({
84
+ address: coin.address,
85
+ symbol: coin.symbol,
86
+ decimals: coin.decimals,
87
+ usdPrice: coin.usd_price,
88
+ })),
89
+ gaugeRewards: [],
90
+ gaugeExtraRewards: ((_d = pool.gauge_extra_rewards) !== null && _d !== void 0 ? _d : []).map((reward) => {
91
+ var _a, _b;
92
+ return ({
93
+ gaugeAddress: reward.gauge_address,
94
+ tokenAddress: reward.token_address,
95
+ tokenPrice: (_a = reward.token_price) !== null && _a !== void 0 ? _a : 0,
96
+ name: reward.name,
97
+ symbol: reward.symbol,
98
+ decimals: reward.decimals,
99
+ apy: (_b = reward.apy) !== null && _b !== void 0 ? _b : 0,
100
+ });
101
+ }),
102
+ usdTotal: (_e = pool.tvl) !== null && _e !== void 0 ? _e : 0,
103
+ totalSupply: Number((_f = pool.total_supply) !== null && _f !== void 0 ? _f : 0),
104
+ amplificationCoefficient: pool.amplification_coefficient != null ? String(pool.amplification_coefficient) : "0",
105
+ gaugeCrvApy: (_g = pool.gauge_crv_apy) !== null && _g !== void 0 ? _g : [null, null],
106
+ });
107
+ };
108
+ export const getLitePoolsFromApi2 = (network, poolType) => __awaiter(void 0, void 0, void 0, function* () {
109
+ const chainId = yield getChainIdByNetworkName(network);
110
+ if (chainId == null)
111
+ return { poolData: [], tvl: 0, tvlAll: 0 };
112
+ const { pool_data, tvl } = yield _getApi2PoolsData(chainId);
113
+ const poolsOfType = (pool_data !== null && pool_data !== void 0 ? pool_data : []).filter((pool) => API2_REGISTRY_TO_POOL_TYPE[pool.registry_id] === poolType);
114
+ const poolData = poolsOfType.map((pool) => adaptLitePool(pool, poolType));
115
+ return {
116
+ poolData,
117
+ tvl: poolData.reduce((sum, p) => sum + p.usdTotal, 0),
118
+ tvlAll: tvl !== null && tvl !== void 0 ? tvl : 0,
119
+ };
120
+ });
121
+ export const getLiteDeploymentFromApi2 = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
122
+ var _a;
123
+ const response = yield fetch(`${API2}/get_deployment/${chainId}`);
124
+ const { data } = (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
125
+ if (response.status !== 200 || !data) {
126
+ console.error('Failed to fetch network data:', response.status, data);
127
+ return null;
128
+ }
129
+ return data;
130
+ });
@@ -7,7 +7,6 @@ import { StatsPool } from "./subClasses/statsPool.js";
7
7
  import { WalletPool } from "./subClasses/walletPool.js";
8
8
  export declare class PoolTemplate extends CorePool {
9
9
  isGaugeKilled: () => Promise<boolean>;
10
- gaugeStatus: () => Promise<any>;
11
10
  estimateGas: {
12
11
  depositApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
13
12
  deposit: (amounts: (number | string)[], slippage?: number) => Promise<number | number[]>;
@@ -216,6 +215,5 @@ export declare class PoolTemplate extends CorePool {
216
215
  getStoredRates(useUnderlying?: boolean): Promise<string[]>;
217
216
  _underlyingPrices: () => Promise<number[]>;
218
217
  _wrappedPrices: () => Promise<number[]>;
219
- private getGaugeStatus;
220
218
  private getIsGaugeKilled;
221
219
  }
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import memoize from "memoizee";
11
- import { _getAllGaugesFormatted, _getPoolFilters } from '../external-api.js';
11
+ import { getGaugesOverview } from '../prices-api.js';
12
+ import { _getPoolFilters } from '../external-api.js';
12
13
  import { _cutZeros, _ensureAllowance, _get_price_impact, _get_small_x, _getAddress, _getCoinAddresses, _getRewardsFromApi, _getUsdRate, _setContracts, BN, checkNumber, DIGas, ensureAllowance, ensureAllowanceEstimateGas, findAbiFunction, fromBN, hasAllowance, mulBy1_3, parseUnits, PERIODS, smartNumber, toBN, toStringFromBN, } from '../utils.js';
13
14
  import { OLD_CHAINS } from "../curve.js";
14
15
  import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
@@ -549,7 +550,6 @@ export class PoolTemplate extends CorePool {
549
550
  this.stats = new StatsPool(this);
550
551
  this.wallet = new WalletPool(this);
551
552
  this.isGaugeKilled = this.getIsGaugeKilled.bind(this);
552
- this.gaugeStatus = this.getGaugeStatus.bind(this);
553
553
  this.estimateGas = {
554
554
  depositApprove: this.depositApproveEstimateGas.bind(this),
555
555
  deposit: this.depositEstimateGas.bind(this),
@@ -2005,16 +2005,12 @@ export class PoolTemplate extends CorePool {
2005
2005
  }
2006
2006
  });
2007
2007
  }
2008
- getGaugeStatus() {
2009
- return __awaiter(this, void 0, void 0, function* () {
2010
- const gaugeData = yield _getAllGaugesFormatted();
2011
- return gaugeData[this.gauge.address] ? gaugeData[this.gauge.address].gaugeStatus : null;
2012
- });
2013
- }
2014
2008
  getIsGaugeKilled() {
2015
2009
  return __awaiter(this, void 0, void 0, function* () {
2016
- const gaugeData = yield _getAllGaugesFormatted();
2017
- return gaugeData[this.gauge.address] ? gaugeData[this.gauge.address].is_killed : false;
2010
+ var _c;
2011
+ const gauges = yield getGaugesOverview();
2012
+ const gauge = gauges.find((g) => g.address.toLowerCase() === this.gauge.address.toLowerCase());
2013
+ return (_c = gauge === null || gauge === void 0 ? void 0 : gauge.is_killed) !== null && _c !== void 0 ? _c : false;
2018
2014
  });
2019
2015
  }
2020
2016
  }
@@ -0,0 +1,21 @@
1
+ import { IExtendedPoolDataFromApi, IPoolType, INetworkName, IVolumeAndAPYs } from "./interfaces";
2
+ export type TPricesPoolType = "main" | "crypto" | "factory" | "crvusd" | "factory_crypto" | "factory_tricrypto" | "stableswapng" | "twocryptong" | null;
3
+ export declare const LEGACY_POOL_TYPES: readonly IPoolType[];
4
+ export declare const PRICES_POOL_TYPE_TO_LEGACY: Record<NonNullable<TPricesPoolType>, IPoolType>;
5
+ export interface IPricesGauge {
6
+ address: string;
7
+ effective_address: string;
8
+ name: string;
9
+ lp_token: string;
10
+ pool: {
11
+ address: string;
12
+ name: string;
13
+ chain: string;
14
+ } | null;
15
+ is_killed: boolean;
16
+ gauge_weight: string;
17
+ gauge_relative_weight: number;
18
+ }
19
+ export declare const getGaugesOverview: () => Promise<IPricesGauge[]>;
20
+ export declare const getPoolsFromPricesApi: (network: INetworkName, poolType: IPoolType) => Promise<IExtendedPoolDataFromApi>;
21
+ export declare const getVolumesFromPricesApi: (network: INetworkName) => Promise<IVolumeAndAPYs>;
@@ -0,0 +1,149 @@
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 memoize from "memoizee";
11
+ export const LEGACY_POOL_TYPES = [
12
+ "main",
13
+ "crypto",
14
+ "factory",
15
+ "factory-crvusd",
16
+ "factory-crypto",
17
+ "factory-twocrypto",
18
+ "factory-tricrypto",
19
+ "factory-stable-ng",
20
+ ];
21
+ export const PRICES_POOL_TYPE_TO_LEGACY = {
22
+ main: "main",
23
+ crypto: "crypto",
24
+ factory: "factory",
25
+ crvusd: "factory-crvusd",
26
+ factory_crypto: "factory-crypto",
27
+ factory_tricrypto: "factory-tricrypto",
28
+ stableswapng: "factory-stable-ng",
29
+ twocryptong: "factory-twocrypto",
30
+ };
31
+ const ID_PREFIX_BY_POOL_TYPE = {
32
+ "main": "main",
33
+ "crypto": "crypto",
34
+ "factory": "factory-v2",
35
+ "factory-crvusd": "factory-crvusd",
36
+ "factory-crypto": "factory-crypto",
37
+ "factory-twocrypto": "factory-twocrypto",
38
+ "factory-tricrypto": "factory-tricrypto",
39
+ "factory-stable-ng": "factory-stable-ng",
40
+ };
41
+ function fetchJson(url) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ var _a;
44
+ const response = yield fetch(url);
45
+ return (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
46
+ });
47
+ }
48
+ const _getPricesChainData = memoize((network) => __awaiter(void 0, void 0, void 0, function* () { return fetchJson(`https://prices.curve.finance/v1/chains/${network}`); }), {
49
+ promise: true,
50
+ maxAge: 5 * 60 * 1000,
51
+ });
52
+ const _getGaugesOverview = memoize(() => __awaiter(void 0, void 0, void 0, function* () { return fetchJson(`https://prices.curve.finance/v1/dao/gauges/overview`); }), {
53
+ promise: true,
54
+ maxAge: 5 * 60 * 1000,
55
+ });
56
+ const getGaugeAddressByPoolAddress = (network) => __awaiter(void 0, void 0, void 0, function* () {
57
+ var _a;
58
+ const { gauges } = yield _getGaugesOverview();
59
+ const map = new Map();
60
+ for (const gauge of gauges !== null && gauges !== void 0 ? gauges : []) {
61
+ if (((_a = gauge.pool) === null || _a === void 0 ? void 0 : _a.chain) === network)
62
+ map.set(gauge.pool.address.toLowerCase(), gauge.address.toLowerCase());
63
+ }
64
+ return map;
65
+ });
66
+ export const getGaugesOverview = () => __awaiter(void 0, void 0, void 0, function* () {
67
+ const { gauges } = yield _getGaugesOverview();
68
+ return gauges !== null && gauges !== void 0 ? gauges : [];
69
+ });
70
+ const getPoolId = (poolType, indexWithinType) => `${ID_PREFIX_BY_POOL_TYPE[poolType]}-${indexWithinType}`;
71
+ const adaptPoolFromPricesApi = (pool, id, gaugeAddressByPoolAddress) => {
72
+ var _a, _b, _c, _d, _e;
73
+ const coins = [...pool.coins].sort((a, b) => a.pool_index - b.pool_index).slice(0, pool.n_coins);
74
+ return {
75
+ id,
76
+ name: pool.name,
77
+ symbol: (_a = pool.lp_token_symbol) !== null && _a !== void 0 ? _a : pool.name,
78
+ assetTypeName: null,
79
+ address: pool.address,
80
+ isMetaPool: pool.is_metapool,
81
+ basePoolAddress: (_b = pool.base_pool) !== null && _b !== void 0 ? _b : undefined,
82
+ lpTokenAddress: (_c = pool.lp_token_address) !== null && _c !== void 0 ? _c : undefined,
83
+ gaugeAddress: gaugeAddressByPoolAddress.get(pool.address.toLowerCase()),
84
+ implementation: null,
85
+ implementationAddress: pool.implementation_address,
86
+ coins: coins.map((coin) => {
87
+ var _a, _b;
88
+ const balance = (_a = pool.balances) === null || _a === void 0 ? void 0 : _a[coin.pool_index];
89
+ const balanceUsd = (_b = pool.balances_usd) === null || _b === void 0 ? void 0 : _b[coin.pool_index];
90
+ return {
91
+ address: coin.address,
92
+ symbol: coin.symbol,
93
+ decimals: String(coin.decimals),
94
+ usdPrice: balance ? (balanceUsd !== null && balanceUsd !== void 0 ? balanceUsd : 0) / balance : null,
95
+ };
96
+ }),
97
+ gaugeRewards: [],
98
+ gaugeExtraRewards: undefined,
99
+ usdTotal: (_d = pool.tvl_usd) !== null && _d !== void 0 ? _d : 0,
100
+ totalSupply: ((_e = pool.lp_token_supply) !== null && _e !== void 0 ? _e : 0) * 1e18,
101
+ amplificationCoefficient: pool.amplification_coefficient != null ? String(pool.amplification_coefficient) : "0",
102
+ gaugeCrvApy: [null, null],
103
+ };
104
+ };
105
+ export const getPoolsFromPricesApi = (network, poolType) => __awaiter(void 0, void 0, void 0, function* () {
106
+ var _a, _b;
107
+ const [chainData, gaugeAddressByPoolAddress] = yield Promise.all([
108
+ _getPricesChainData(network),
109
+ getGaugeAddressByPoolAddress(network),
110
+ ]);
111
+ if (!(chainData === null || chainData === void 0 ? void 0 : chainData.data))
112
+ return { poolData: [], tvl: 0, tvlAll: 0 };
113
+ const poolsOfType = chainData.data
114
+ .filter((pool) => PRICES_POOL_TYPE_TO_LEGACY[pool.pool_type] === poolType)
115
+ .sort((a, b) => a.creation_block_number - b.creation_block_number);
116
+ const poolData = poolsOfType.map((pool, i) => adaptPoolFromPricesApi(pool, getPoolId(poolType, i), gaugeAddressByPoolAddress));
117
+ return {
118
+ poolData,
119
+ tvl: poolData.reduce((sum, p) => sum + p.usdTotal, 0),
120
+ tvlAll: (_b = (_a = chainData.total) === null || _a === void 0 ? void 0 : _a.total_tvl) !== null && _b !== void 0 ? _b : 0,
121
+ };
122
+ });
123
+ const CRYPTO_POOL_TYPES = ["crypto", "factory_crypto", "factory_tricrypto", "twocryptong"];
124
+ export const getVolumesFromPricesApi = (network) => __awaiter(void 0, void 0, void 0, function* () {
125
+ const chainData = yield _getPricesChainData(network);
126
+ if (!(chainData === null || chainData === void 0 ? void 0 : chainData.data))
127
+ return { poolsData: [], totalVolume: 0, cryptoVolume: 0, cryptoShare: 0 };
128
+ let totalVolume = 0;
129
+ let cryptoVolume = 0;
130
+ const poolsData = chainData.data.map((pool) => {
131
+ var _a, _b, _c;
132
+ const volumeUSD = (_a = pool.trading_volume_24h) !== null && _a !== void 0 ? _a : 0;
133
+ totalVolume += volumeUSD;
134
+ if (CRYPTO_POOL_TYPES.includes(pool.pool_type))
135
+ cryptoVolume += volumeUSD;
136
+ return {
137
+ address: pool.address,
138
+ volumeUSD,
139
+ day: ((_b = pool.base_daily_apr) !== null && _b !== void 0 ? _b : 0) * 100,
140
+ week: ((_c = pool.base_weekly_apr) !== null && _c !== void 0 ? _c : 0) * 100,
141
+ };
142
+ });
143
+ return {
144
+ poolsData,
145
+ totalVolume,
146
+ cryptoVolume,
147
+ cryptoShare: totalVolume ? (cryptoVolume / totalVolume) * 100 : 0,
148
+ };
149
+ });
package/lib/router.js CHANGED
@@ -237,7 +237,7 @@ function _getBestRouteImpl(inputCoinAddress, outputCoinAddress, amount) {
237
237
  const [gasAmounts, outputCoinUsdRate, gasData, ethUsdRate] = yield Promise.all([
238
238
  _estimateGasForDifferentRoutes.call(this, routes.map((r) => r.route), inputCoinAddress, outputCoinAddress, _amount),
239
239
  _getUsdRate.call(this, outputCoinAddress),
240
- fetch("https://api.curve.finance/api/getGas").then((res) => res.json()),
240
+ fetch("https://prices.curve.finance/v1/gas").then((res) => res.json()),
241
241
  _getUsdRate.call(this, ETH_ADDRESS),
242
242
  ]);
243
243
  const gasPrice = gasData.data.gas.standard;
package/lib/utils.d.ts CHANGED
@@ -103,7 +103,7 @@ export declare const getCountArgsOfMethodByAbi: (abi: Abi, methodName: string) =
103
103
  export declare const findAbiSignature: (abi: Abi, methodName: string, signature: string) => AbiFunction | undefined;
104
104
  export declare const getPoolName: (name: string) => string;
105
105
  export declare const isStableNgPool: (name: string) => boolean;
106
- export declare const assetTypeNameHandler: (assetTypeName: string) => REFERENCE_ASSET;
106
+ export declare const assetTypeNameHandler: (assetTypeName: string | null) => REFERENCE_ASSET;
107
107
  export declare function getBasePools(this: Curve): Promise<IBasePoolShortItem[]>;
108
108
  export declare function log(fnName: string, ...args: unknown[]): void;
109
109
  export declare function runWorker<In extends {
package/lib/utils.js CHANGED
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { Contract, ethers } from 'ethers';
11
11
  import { Contract as MulticallContract } from "@curvefi/ethcall";
12
12
  import BigNumber from 'bignumber.js';
13
- import { _getCurveLiteNetworks, _getFactoryAPYs, _getLiteNetworksData, _getSubgraphData, _getVolumes, } from "./external-api.js";
13
+ import { _getCurveLiteNetworks, _getLiteNetworksData, _getVolumes, } from "./external-api.js";
14
14
  import { _getAllPoolsFromApi, _getUsdPricesFromApi } from "./cached.js";
15
15
  import ERC20Abi from './constants/abis/ERC20.json' with { type: 'json' };
16
16
  import { L2Networks } from './constants/L2Networks.js';
@@ -664,7 +664,7 @@ export function getNetworkConstants(chainId) {
664
664
  const NAME = getNetworkNameByChainId(chainId, yield _getCurveLiteNetworks());
665
665
  if (NAME === "Unknown Network")
666
666
  throw Error(`Wrong chain id: ${chainId}`);
667
- return Object.assign(Object.assign({}, yield _getLiteNetworksData(NAME)), { NAME, IS_LITE_CHAIN: true });
667
+ return Object.assign(Object.assign({}, yield _getLiteNetworksData(chainId)), { NAME, IS_LITE_CHAIN: true });
668
668
  }
669
669
  });
670
670
  }
@@ -683,12 +683,6 @@ export function getVolumeApiController(network) {
683
683
  if (volumeNetworks.getVolumes.includes(this.chainId)) {
684
684
  return yield _getVolumes(network);
685
685
  }
686
- if (volumeNetworks.getFactoryAPYs.includes(this.chainId)) {
687
- return yield _getFactoryAPYs(network);
688
- }
689
- if (volumeNetworks.getSubgraphData.includes(this.chainId)) {
690
- return yield _getSubgraphData(network);
691
- }
692
686
  throw Error(`Can't get volume for network: ${network}`);
693
687
  });
694
688
  }
@@ -787,7 +781,7 @@ export const getPoolName = (name) => {
787
781
  };
788
782
  export const isStableNgPool = (name) => name.includes('factory-stable-ng');
789
783
  export const assetTypeNameHandler = (assetTypeName) => {
790
- if (assetTypeName.toUpperCase() === 'UNKNOWN') {
784
+ if (!assetTypeName || assetTypeName.toUpperCase() === 'UNKNOWN') {
791
785
  return 'OTHER';
792
786
  }
793
787
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.70.5",
3
+ "version": "2.71.0",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -21,6 +21,8 @@
21
21
  "lint": "eslint src --ext .ts",
22
22
  "lint:fix": "eslint src --fix",
23
23
  "watch": "tsc --watch",
24
+ "test:core-pools": "tsc --project tsconfig.test.json && mocha --delay --timeout 600000 dist/test/corePoolsData.test.js",
25
+ "test:hidden-pools": "tsc --project tsconfig.test.json && mocha --delay --timeout 600000 dist/test/hiddenPools.test.js",
24
26
  "watch:lib": "rm -rf lib && tsc --watch --project tsconfig.build.json"
25
27
  },
26
28
  "type": "module",