diff --git a/.env.example b/.env.example index 7377b198e..48520aad5 100644 --- a/.env.example +++ b/.env.example @@ -21,32 +21,18 @@ SUPPORTED_CHAINS=1,17000,11155111 # this chain uses when a wallet is not connected DEFAULT_CHAIN=1 -# api key for ethplorer for token data -ETHPLORER_API_KEY=freekey # comma-separated trusted hosts for Content Security Policy # e.g. http://localhost:PORT for local development CSP_TRUSTED_HOSTS=https://*.lido.fi - # put "true" enable report only mode for CSP CSP_REPORT_ONLY=true - # api endpoint for reporting csp violations CSP_REPORT_URI=https://stake.lido.fi/api/csp-report -# Subgraph endpoint -SUBGRAPH_MAINNET=https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/Sxx812XgeKyzQPaBpR5YZWmGV5fZuBaPdh7DFhzSwiQ -SUBGRAPH_HOLESKY= -SUBGRAPH_SEPOLIA= - -SUBGRAPH_REQUEST_TIMEOUT=5000 - # allow some state overrides from browser console for QA ENABLE_QA_HELPERS=false -# 1inch API token to power /api/oneinch-rate -ONE_INCH_API_KEY= - REWARDS_BACKEND=http://127.0.0.1:4000 # rate limit diff --git a/consts/metrics.ts b/consts/metrics.ts index 5e1ac3074..574e821f1 100644 --- a/consts/metrics.ts +++ b/consts/metrics.ts @@ -3,6 +3,5 @@ export const METRICS_PREFIX = 'eth_stake_widget_ui_'; export const enum METRIC_NAMES { REQUESTS_TOTAL = 'requests_total', API_RESPONSE = 'api_response', - SUBGRAPHS_RESPONSE = 'subgraphs_response', ETH_CALL_ADDRESS_TO = 'eth_call_address_to', } diff --git a/global.d.ts b/global.d.ts index efc35a096..6210ca609 100644 --- a/global.d.ts +++ b/global.d.ts @@ -28,7 +28,6 @@ declare module 'next/config' { rpcUrls_1: string | undefined; rpcUrls_17000: string | undefined; rpcUrls_11155111: string | undefined; - ethplorerApiKey: string | undefined; cspTrustedHosts: string | undefined; cspReportUri: string | undefined; diff --git a/next.config.mjs b/next.config.mjs index b2ef406ef..9cd936eb3 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -146,7 +146,6 @@ export default withBundleAnalyzer({ rpcUrls_1: process.env.EL_RPC_URLS_1, rpcUrls_17000: process.env.EL_RPC_URLS_17000, rpcUrls_11155111: process.env.EL_RPC_URLS_11155111, - ethplorerApiKey: process.env.ETHPLORER_API_KEY, cspTrustedHosts: process.env.CSP_TRUSTED_HOSTS, cspReportUri: process.env.CSP_REPORT_URI, diff --git a/pages/api/ldo-stats.ts b/pages/api/ldo-stats.ts index 42555b972..b214aa172 100644 --- a/pages/api/ldo-stats.ts +++ b/pages/api/ldo-stats.ts @@ -1,52 +1,8 @@ -import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; +import { httpMethodGuard, HttpMethod, cors, gone } from 'utilsApi'; -import { config } from 'config'; - -import { API_DEFAULT_SUNSET_TIMESTAMP, API_ROUTES } from 'consts/api'; -import { - getLdoStats, - errorAndCacheDefaultWrappers, - responseTimeMetric, - rateLimit, - sunsetBy, - httpMethodGuard, - HttpMethod, - cors, -} from 'utilsApi'; -import Metrics from 'utilsApi/metrics'; -import { API } from 'types'; - -const cache = new Cache(); - -// Proxy for third-party API. -// Returns LDO token information -// DEPRECATED: In future will be delete!!! -const ldoStats: API = async (req, res) => { - const cachedLidoStats = cache.get(config.CACHE_LDO_STATS_KEY); - - if (cachedLidoStats) { - res.json(cachedLidoStats); - } else { - const ldoStats = await getLdoStats(); - - cache.put( - config.CACHE_LDO_STATS_KEY, - { data: ldoStats }, - config.CACHE_LDO_STATS_TTL, - ); - - res.json({ data: ldoStats }); - } -}; - +// TODO: delete after all other endpoints are deprecated on 9th september 2024 export default wrapNextRequest([ httpMethodGuard([HttpMethod.GET]), cors({ origin: ['*'], methods: [HttpMethod.GET] }), - rateLimit, - responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LDO_STATS), - sunsetBy({ - sunsetTimestamp: API_DEFAULT_SUNSET_TIMESTAMP, - }), - ...errorAndCacheDefaultWrappers, -])(ldoStats); +])(gone); diff --git a/pages/api/lido-stats.ts b/pages/api/lido-stats.ts index e1213de4c..5344b09d0 100644 --- a/pages/api/lido-stats.ts +++ b/pages/api/lido-stats.ts @@ -1,50 +1,9 @@ -import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { config } from 'config'; -import { API_DEFAULT_SUNSET_TIMESTAMP, API_ROUTES } from 'consts/api'; -import { - getLidoStats, - errorAndCacheDefaultWrappers, - responseTimeMetric, - rateLimit, - sunsetBy, - httpMethodGuard, - HttpMethod, - cors, -} from 'utilsApi'; -import Metrics from 'utilsApi/metrics'; -import { API } from 'types'; - -const cache = new Cache(); - -// Proxy for third-party API. -// Returns steth token information -// DEPRECATED: In future will be delete!!! -export const lidoStats: API = async (req, res) => { - const cachedLidoStats = cache.get(config.CACHE_LIDO_STATS_KEY); - - if (cachedLidoStats) { - res.json(cachedLidoStats); - } else { - const lidoStats = await getLidoStats(); - cache.put( - config.CACHE_LIDO_STATS_KEY, - { data: lidoStats }, - config.CACHE_LIDO_STATS_TTL, - ); - - res.json({ data: lidoStats }); - } -}; +import { httpMethodGuard, HttpMethod, cors, gone } from 'utilsApi'; +// TODO: delete after all other endpoints are deprecated on 9th september 24 export default wrapNextRequest([ httpMethodGuard([HttpMethod.GET]), cors({ origin: ['*'], methods: [HttpMethod.GET] }), - rateLimit, - responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LIDO_STATS), - sunsetBy({ - sunsetTimestamp: API_DEFAULT_SUNSET_TIMESTAMP, - }), - ...errorAndCacheDefaultWrappers, -])(lidoStats); +])(gone); diff --git a/pages/api/lidostats.ts b/pages/api/lidostats.ts index 1d3055943..b71f23a6f 100644 --- a/pages/api/lidostats.ts +++ b/pages/api/lidostats.ts @@ -1,26 +1,9 @@ import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { API_DEFAULT_SUNSET_TIMESTAMP, API_ROUTES } from 'consts/api'; -import { - responseTimeMetric, - errorAndCacheDefaultWrappers, - rateLimit, - sunsetBy, - httpMethodGuard, - HttpMethod, - cors, -} from 'utilsApi'; -import Metrics from 'utilsApi/metrics'; -import lidoStats from './lido-stats'; +import { httpMethodGuard, HttpMethod, cors, gone } from 'utilsApi'; -// Mirror for /lido-stats +// TODO: delete after all other endpoints are deprecated on 9th september 2024 export default wrapNextRequest([ httpMethodGuard([HttpMethod.GET]), cors({ origin: ['*'], methods: [HttpMethod.GET] }), - rateLimit, - responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LIDOSTATS), - sunsetBy({ - sunsetTimestamp: API_DEFAULT_SUNSET_TIMESTAMP, - }), - ...errorAndCacheDefaultWrappers, -])(lidoStats); +])(gone); diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts deleted file mode 100644 index 577b9c15e..000000000 --- a/utilsApi/getLdoStats.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; - -import { secretConfig } from 'config'; -import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; -import { CHAINS } from 'consts/chains'; -import { standardFetcher } from 'utils/standardFetcher'; -import { responseTimeExternalMetricWrapper } from 'utilsApi'; - -type GetLdoStats = () => Promise; - -// DEPRECATED: In future will be delete!!! Because we don't want to use https://api.ethplorer.io/ -export const getLdoStats: GetLdoStats = async () => { - console.debug('Fetching LDO stats...'); - // IMPORTANT: ETHPLORER_TOKEN_ENDPOINT (api.ethplorer.io) works only with Mainnet chain! - const api = `${ETHPLORER_TOKEN_ENDPOINT}${getTokenAddress( - CHAINS.Mainnet as number, - TOKENS.LDO, - )}`; - const query = new URLSearchParams({ - apiKey: secretConfig.ethplorerApiKey ?? '', - }); - const url = `${api}?${query.toString()}`; - - const ldoStats = await responseTimeExternalMetricWrapper({ - payload: ETHPLORER_TOKEN_ENDPOINT, - request: () => standardFetcher(url), - }); - console.debug('LDO stats: ' + ldoStats); - - return ldoStats; -}; diff --git a/utilsApi/getLidoStats.ts b/utilsApi/getLidoStats.ts deleted file mode 100644 index d0f0598d8..000000000 --- a/utilsApi/getLidoStats.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { TOKENS, getTokenAddress, CHAINS } from '@lido-sdk/constants'; - -import { secretConfig } from 'config'; -import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; -import { standardFetcher } from 'utils/standardFetcher'; -import { responseTimeExternalMetricWrapper } from 'utilsApi'; - -type GetLidoStats = () => Promise; - -// DEPRECATED: In future will be delete!!! Because we don't want to use https://api.ethplorer.io/ -export const getLidoStats: GetLidoStats = async () => { - console.debug('[getLidoStats] Started fetching...'); - // IMPORTANT: ETHPLORER_TOKEN_ENDPOINT (api.ethplorer.io) works only with Mainnet chain! - const api = `${ETHPLORER_TOKEN_ENDPOINT}${getTokenAddress( - CHAINS.Mainnet, - TOKENS.STETH, - )}`; - const query = new URLSearchParams({ - apiKey: secretConfig.ethplorerApiKey ?? '', - }); - const url = `${api}?${query.toString()}`; - - const lidoStats = await responseTimeExternalMetricWrapper({ - payload: ETHPLORER_TOKEN_ENDPOINT, - request: () => standardFetcher(url), - }); - console.debug('[getLidoStats] Lido stats:', lidoStats); - return lidoStats; -}; diff --git a/utilsApi/gone.ts b/utilsApi/gone.ts new file mode 100644 index 000000000..6b872e985 --- /dev/null +++ b/utilsApi/gone.ts @@ -0,0 +1,6 @@ +import { API } from 'types/api.js'; + +export const gone: API = async (_, res) => { + res.status(410); + res.end(); +}; diff --git a/utilsApi/index.ts b/utilsApi/index.ts index de210ed39..a98b393ff 100644 --- a/utilsApi/index.ts +++ b/utilsApi/index.ts @@ -1,4 +1,4 @@ -export * from './getLdoStats'; -export * from './getLidoStats'; export * from './nextApiWrappers'; export * from './fetchApiWrapper'; +export * from './cached-proxy'; +export * from './gone'; diff --git a/utilsApi/metrics/metrics.ts b/utilsApi/metrics/metrics.ts index 18d00cb51..3c5b2337e 100644 --- a/utilsApi/metrics/metrics.ts +++ b/utilsApi/metrics/metrics.ts @@ -6,13 +6,11 @@ import { METRICS_PREFIX } from 'consts/metrics'; import buildInfoJson from 'build-info.json'; import { RequestMetrics } from './request'; -import { SubgraphMetrics } from './subgraph'; class Metrics { registry = new Registry(); // compositions of metric types - subgraph = new SubgraphMetrics(this.registry); request = new RequestMetrics(this.registry); constructor() { diff --git a/utilsApi/metrics/subgraph.ts b/utilsApi/metrics/subgraph.ts deleted file mode 100644 index fef942f47..000000000 --- a/utilsApi/metrics/subgraph.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Histogram, Registry } from 'prom-client'; -import { METRICS_PREFIX, METRIC_NAMES } from 'consts/metrics'; - -export class SubgraphMetrics { - subgraphsResponseTime: Histogram<'subgraphs'>; - - constructor(public registry: Registry) { - this.subgraphsResponseTime = this.subgraphsResponseTimeInit(); - } - - subgraphsResponseTimeInit() { - const subgraphsResponseTimeName = - METRICS_PREFIX + METRIC_NAMES.SUBGRAPHS_RESPONSE; - - return new Histogram({ - name: subgraphsResponseTimeName, - help: 'Subgraphs response time seconds', - buckets: [0.1, 0.2, 0.3, 0.6, 1, 1.5, 2, 5], - registers: [this.registry], - }); - } -} diff --git a/yarn.lock b/yarn.lock index 9f1bb5b2a..6bb8dd6f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1005,6 +1005,13 @@ resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310" integrity sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA== +"@babel/runtime@^7.12.5": + version "7.25.0" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.0.tgz#3af9a91c1b739c569d5d80cc917280919c544ecb" + integrity sha512-7dRy4DwXwtzBrPbZflqxnvfxLF8kdZXPkhymtDeFoFqE6ldzjQFgYTtYIFARcLEYDrqfBfYcZt1WqFxRoyC9Rw== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/runtime@^7.19.4", "@babel/runtime@^7.21.0": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.7.tgz#f4f0d5530e8dbdf59b3451b9b3e594b6ba082e12"