Skip to content

Commit

Permalink
Merge pull request #432 from lidofinance/feature/si-1542-remove-code-…
Browse files Browse the repository at this point in the history
…from-deprecated-endpoints

[chore] remove ldo stats code
  • Loading branch information
itaven authored Aug 20, 2024
2 parents 84a98b2 + 5721885 commit 80f59c5
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 214 deletions.
14 changes: 0 additions & 14 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion consts/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
1 change: 0 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 3 additions & 47 deletions pages/api/ldo-stats.ts
Original file line number Diff line number Diff line change
@@ -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<typeof config.CACHE_LDO_STATS_KEY, unknown>();

// 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);
47 changes: 3 additions & 44 deletions pages/api/lido-stats.ts
Original file line number Diff line number Diff line change
@@ -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<typeof config.CACHE_LIDO_STATS_KEY, unknown>();

// 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);
23 changes: 3 additions & 20 deletions pages/api/lidostats.ts
Original file line number Diff line number Diff line change
@@ -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);
31 changes: 0 additions & 31 deletions utilsApi/getLdoStats.ts

This file was deleted.

29 changes: 0 additions & 29 deletions utilsApi/getLidoStats.ts

This file was deleted.

6 changes: 6 additions & 0 deletions utilsApi/gone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { API } from 'types/api.js';

export const gone: API = async (_, res) => {
res.status(410);
res.end();
};
4 changes: 2 additions & 2 deletions utilsApi/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './getLdoStats';
export * from './getLidoStats';
export * from './nextApiWrappers';
export * from './fetchApiWrapper';
export * from './cached-proxy';
export * from './gone';
2 changes: 0 additions & 2 deletions utilsApi/metrics/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 0 additions & 22 deletions utilsApi/metrics/subgraph.ts

This file was deleted.

7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 80f59c5

Please sign in to comment.