@curvefi/api 2.65.10 → 2.65.12

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/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,23 +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}`);
553
- }
554
- };
555
- export const getTVL = (network = curve.chainId) => __awaiter(void 0, void 0, void 0, function* () {
556
- if (curve.isLiteChain) {
557
- throw Error('This method is not supported for the lite version');
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 });
558
560
  }
559
- network = _getNetworkName(network);
560
- 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);
561
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);
562
566
  });
563
567
  export const getVolumeApiController = (network) => __awaiter(void 0, void 0, void 0, function* () {
@@ -575,12 +579,12 @@ export const getVolumeApiController = (network) => __awaiter(void 0, void 0, voi
575
579
  }
576
580
  throw Error(`Can't get volume for network: ${network}`);
577
581
  });
578
- 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* () {
579
583
  if (curve.isLiteChain) {
580
584
  throw Error('This method is not supported for the lite version');
581
585
  }
582
- network = _getNetworkName(network);
583
- const { totalVolume, cryptoVolume, cryptoShare } = yield getVolumeApiController(network);
586
+ const networkConstants = yield getNetworkConstants(chainId);
587
+ const { totalVolume, cryptoVolume, cryptoShare } = yield getVolumeApiController(networkConstants.NAME);
584
588
  return { totalVolume, cryptoVolume, cryptoShare };
585
589
  });
586
590
  export const _setContracts = (address, abi) => {
@@ -719,22 +723,6 @@ export function runWorker(code, syncFn, inputData, timeout = 30000) {
719
723
  worker.terminate();
720
724
  });
721
725
  }
722
- export const getCurveLiteNetworks = () => __awaiter(void 0, void 0, void 0, function* () {
723
- return yield _getCurveLiteNetworks();
724
- });
725
- export const getNetworkNameByChainId = (chainId, networks) => {
726
- const network = networks.find((network) => network.chainId === chainId);
727
- return network ? network.id : "Unknown Network";
728
- };
729
- export const getNetworkConstants = (chainId, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
730
- if (isLiteChain) {
731
- const NAME = getNetworkNameByChainId(chainId, yield _getCurveLiteNetworks());
732
- return Object.assign(Object.assign({}, yield _getLiteNetworksData(NAME)), { NAME });
733
- }
734
- else {
735
- return NETWORK_CONSTANTS[chainId];
736
- }
737
- });
738
726
  export const PERIODS = {
739
727
  DAY: 86400,
740
728
  WEEK: 604800,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.65.10",
3
+ "version": "2.65.12",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",