@curvefi/api 2.65.11 → 2.65.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/curve.js CHANGED
@@ -432,7 +432,7 @@ class Curve {
432
432
  console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
433
433
  this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
434
434
  this.isLiteChain = !(this.chainId in NETWORK_CONSTANTS);
435
- const network_constants = yield getNetworkConstants(this.chainId, this.isLiteChain);
435
+ const network_constants = yield getNetworkConstants(this.chainId);
436
436
  this.constants.NATIVE_TOKEN = network_constants.NATIVE_COIN;
437
437
  this.constants.NETWORK_NAME = network_constants.NAME;
438
438
  this.constants.ALIASES = network_constants.ALIASES;
package/lib/index.d.ts CHANGED
@@ -45,7 +45,7 @@ declare const curve: {
45
45
  getGasPriceFromL2: () => Promise<number>;
46
46
  getGasInfoForL2: () => Promise<Record<string, number | null>>;
47
47
  getGasPrice: () => Promise<number>;
48
- getTVL: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<number>;
48
+ getTVL: (chainId?: number) => Promise<number>;
49
49
  getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces.js").IDict<string[]>>;
50
50
  getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
51
51
  hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
@@ -55,7 +55,7 @@ declare const curve: {
55
55
  symbol: string;
56
56
  decimals: number;
57
57
  }[]>;
58
- getVolume: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<{
58
+ getVolume: (chainId?: number) => Promise<{
59
59
  totalVolume: number;
60
60
  cryptoVolume: number;
61
61
  cryptoShare: number;
@@ -220,13 +220,13 @@ declare const curve: {
220
220
  lastEthBlock: () => Promise<number>;
221
221
  getAnycallBalance: () => Promise<string>;
222
222
  topUpAnycall: (amount?: string | number) => Promise<string>;
223
- lastBlockSent: (chainId: import("./interfaces.js").IChainId) => Promise<number>;
223
+ lastBlockSent: (chainId: number) => Promise<number>;
224
224
  blockToSend: () => Promise<number>;
225
- sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<string>;
225
+ sendBlockhash: (block: number, chainId: number) => Promise<string>;
226
226
  submitProof: (block: number, address?: string) => Promise<string>;
227
227
  estimateGas: {
228
228
  topUpAnycall: (amount?: string | number) => Promise<number>;
229
- sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<number>;
229
+ sendBlockhash: (block: number, chainId: number) => Promise<number>;
230
230
  submitProof: (block: number, address?: string) => Promise<number>;
231
231
  };
232
232
  };
@@ -3,9 +3,8 @@ import { Contract as MulticallContract, Provider as MulticallProvider } from "@c
3
3
  export interface IDict<T> {
4
4
  [index: string]: T;
5
5
  }
6
- export type INetworkName = "ethereum" | "optimism" | "bsc" | "xdai" | "polygon" | "x-layer" | "fantom" | "fraxtal" | "zksync" | "moonbeam" | "kava" | "mantle" | "base" | "arbitrum" | "celo" | "avalanche" | "aurora";
7
- export type IChainId = 1 | 10 | 56 | 100 | 137 | 196 | 250 | 252 | 324 | 1284 | 2222 | 5000 | 8453 | 42161 | 42220 | 43114 | 1313161554;
8
- export type IChainIdLite = number;
6
+ export type INetworkName = string;
7
+ export type IChainId = number;
9
8
  export type IFactoryPoolType = "factory" | "factory-crvusd" | "factory-eywa" | "factory-crypto" | "factory-twocrypto" | "factory-tricrypto" | "factory-stable-ng";
10
9
  export type IPoolType = "main" | "crypto" | IFactoryPoolType;
11
10
  export type ISwapType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
package/lib/router.js CHANGED
@@ -35,9 +35,8 @@ function mapDict(dict, mapper) {
35
35
  Object.entries(dict).forEach(([key, value]) => result[key] = mapper(key, value));
36
36
  return result;
37
37
  }
38
- const _buildRouteGraph = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
38
+ const _buildRouteGraph = memoize((chainId) => __awaiter(void 0, void 0, void 0, function* () {
39
39
  const constants = curve.constants;
40
- const chainId = curve.chainId;
41
40
  const allPools = Object.entries(curve.getPoolsData()).filter(([id]) => !["crveth", "y", "busd", "pax"].includes(id));
42
41
  const amplificationCoefficientDict = yield _getAmplificationCoefficientsFromApi();
43
42
  const poolTvlDict = yield entriesToDictAsync(allPools, _getTVL);
@@ -48,7 +47,7 @@ const _buildRouteGraph = memoize(() => __awaiter(void 0, void 0, void 0, functio
48
47
  maxAge: 5 * 60 * 1000, // 5m
49
48
  });
50
49
  const _findRoutes = (inputCoinAddress, outputCoinAddress) => __awaiter(void 0, void 0, void 0, function* () {
51
- const routerGraph = yield _buildRouteGraph();
50
+ const routerGraph = yield _buildRouteGraph(curve.chainId); // It's important to pass chainId to not use cache from another network
52
51
  // extract only the fields we need for the worker
53
52
  const poolData = mapDict(curve.getPoolsData(), (_, { is_lending, wrapped_coin_addresses, underlying_coin_addresses, token_address }) => ({ is_lending, wrapped_coin_addresses, underlying_coin_addresses, token_address }));
54
53
  const input = { inputCoinAddress, outputCoinAddress, routerGraph, poolData };
package/lib/utils.d.ts CHANGED
@@ -42,9 +42,12 @@ export declare const getGasPriceFromL1: () => Promise<number>;
42
42
  export declare const getGasPriceFromL2: () => Promise<number>;
43
43
  export declare const getGasInfoForL2: () => Promise<Record<string, number | null>>;
44
44
  export declare const getTxCostsUsd: (ethUsdRate: number, gasPrice: number, gas: number | number[], gasPriceL1?: number) => number;
45
- export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
45
+ export declare const getCurveLiteNetworks: () => Promise<ICurveLiteNetwork[]>;
46
+ export declare const getNetworkNameByChainId: (chainId: number, networks: ICurveLiteNetwork[]) => string;
47
+ export declare const getNetworkConstants: (chainId: IChainId | number) => Promise<IDict<any>>;
48
+ export declare const getTVL: (chainId?: number) => Promise<number>;
46
49
  export declare const getVolumeApiController: (network: INetworkName) => Promise<IVolumeAndAPYs>;
47
- export declare const getVolume: (network?: INetworkName | IChainId) => Promise<{
50
+ export declare const getVolume: (chainId?: number) => Promise<{
48
51
  totalVolume: number;
49
52
  cryptoVolume: number;
50
53
  cryptoShare: number;
@@ -70,9 +73,6 @@ export declare function log(fnName: string, ...args: unknown[]): void;
70
73
  export declare function runWorker<In extends {
71
74
  type: string;
72
75
  }, 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
76
  export declare const PERIODS: {
77
77
  DAY: number;
78
78
  WEEK: number;
package/lib/utils.js CHANGED
@@ -541,20 +541,27 @@ export const getTxCostsUsd = (ethUsdRate, gasPrice, gas, gasPriceL1 = 0) => {
541
541
  return ethUsdRate * gas * gasPrice / 1e18;
542
542
  }
543
543
  };
544
- const _getNetworkName = (network = curve.chainId) => {
545
- if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
546
- return NETWORK_CONSTANTS[network].NAME;
547
- }
548
- else if (typeof network === "string" && Object.values(NETWORK_CONSTANTS).map((n) => n.NAME).includes(network)) {
549
- return network;
544
+ export const getCurveLiteNetworks = () => __awaiter(void 0, void 0, void 0, function* () {
545
+ return yield _getCurveLiteNetworks();
546
+ });
547
+ export const getNetworkNameByChainId = (chainId, networks) => {
548
+ const network = networks.find((network) => network.chainId === chainId);
549
+ return network ? network.id : "Unknown Network";
550
+ };
551
+ export const getNetworkConstants = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
552
+ if (chainId in NETWORK_CONSTANTS) {
553
+ return Object.assign(Object.assign({}, NETWORK_CONSTANTS[chainId]), { IS_LITE_CHAIN: false });
550
554
  }
551
555
  else {
552
- throw Error(`Wrong network name or id: ${network}`);
556
+ const NAME = getNetworkNameByChainId(chainId, yield _getCurveLiteNetworks());
557
+ if (NAME === "Unknown Network")
558
+ throw Error(`Wrong chain id: ${chainId}`);
559
+ return Object.assign(Object.assign({}, yield _getLiteNetworksData(NAME)), { NAME, IS_LITE_CHAIN: true });
553
560
  }
554
- };
555
- export const getTVL = (network = curve.chainId) => __awaiter(void 0, void 0, void 0, function* () {
556
- network = _getNetworkName(network);
557
- const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network);
561
+ });
562
+ export const getTVL = (chainId = curve.chainId) => __awaiter(void 0, void 0, void 0, function* () {
563
+ const networkConstants = yield getNetworkConstants(chainId);
564
+ const allTypesExtendedPoolData = yield _getAllPoolsFromApi(networkConstants.NAME, networkConstants.IS_LITE_CHAIN);
558
565
  return allTypesExtendedPoolData.reduce((sum, data) => { var _a, _b; return sum + ((_b = (_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll) !== null && _b !== void 0 ? _b : 0); }, 0);
559
566
  });
560
567
  export const getVolumeApiController = (network) => __awaiter(void 0, void 0, void 0, function* () {
@@ -572,12 +579,12 @@ export const getVolumeApiController = (network) => __awaiter(void 0, void 0, voi
572
579
  }
573
580
  throw Error(`Can't get volume for network: ${network}`);
574
581
  });
575
- export const getVolume = (network = curve.chainId) => __awaiter(void 0, void 0, void 0, function* () {
582
+ export const getVolume = (chainId = curve.chainId) => __awaiter(void 0, void 0, void 0, function* () {
576
583
  if (curve.isLiteChain) {
577
584
  throw Error('This method is not supported for the lite version');
578
585
  }
579
- network = _getNetworkName(network);
580
- const { totalVolume, cryptoVolume, cryptoShare } = yield getVolumeApiController(network);
586
+ const networkConstants = yield getNetworkConstants(chainId);
587
+ const { totalVolume, cryptoVolume, cryptoShare } = yield getVolumeApiController(networkConstants.NAME);
581
588
  return { totalVolume, cryptoVolume, cryptoShare };
582
589
  });
583
590
  export const _setContracts = (address, abi) => {
@@ -716,22 +723,6 @@ export function runWorker(code, syncFn, inputData, timeout = 30000) {
716
723
  worker.terminate();
717
724
  });
718
725
  }
719
- export const getCurveLiteNetworks = () => __awaiter(void 0, void 0, void 0, function* () {
720
- return yield _getCurveLiteNetworks();
721
- });
722
- export const getNetworkNameByChainId = (chainId, networks) => {
723
- const network = networks.find((network) => network.chainId === chainId);
724
- return network ? network.id : "Unknown Network";
725
- };
726
- export const getNetworkConstants = (chainId, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
727
- if (isLiteChain) {
728
- const NAME = getNetworkNameByChainId(chainId, yield _getCurveLiteNetworks());
729
- return Object.assign(Object.assign({}, yield _getLiteNetworksData(NAME)), { NAME });
730
- }
731
- else {
732
- return NETWORK_CONSTANTS[chainId];
733
- }
734
- });
735
726
  export const PERIODS = {
736
727
  DAY: 86400,
737
728
  WEEK: 604800,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.65.11",
3
+ "version": "2.65.13",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",