Skip to content

Commit

Permalink
Merge pull request #100 from lidofinance/develop
Browse files Browse the repository at this point in the history
Merge into main from develop
  • Loading branch information
AnnaSila authored Oct 19, 2023
2 parents edf091d + 001e729 commit 6c35838
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 143 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
branches-ignore:
- main
- goerli

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"react-hook-form": "^7.45.2",
"react-is": "^18.2.0",
"react-transition-group": "^4.4.2",
"reef-knot": "^1.8.0",
"reef-knot": "^1.9.0",
"remark": "^13.0.0",
"remark-external-links": "^8.0.0",
"remark-html": "^13.0.1",
Expand Down
2 changes: 1 addition & 1 deletion pages/api/short-lido-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const shortLidoStats: API = async (req, res) => {
} else {
const [lidoHolders, totalStaked, stEthPrice] = await parallelizePromises([
getLidoHoldersViaSubgraphs(chainId),
getTotalStaked(),
getTotalStaked(chainId),
getStEthPrice(),
]);

Expand Down
4 changes: 2 additions & 2 deletions test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const STAND_CONFIGS = new Map<string, StandConfig>([
[
'testnet',
{
chainId: 5,
chainId: 17000,
},
],
[
'staging',
'staging-critical',
{
chainId: 1,
},
Expand Down
15 changes: 5 additions & 10 deletions utilsApi/getLidoHoldersViaSubgraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ interface LidoHolders extends Response {
};
}

const cache = new Cache<
typeof CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY,
LidoHolders
>();
const cache = new Cache<string, LidoHolders>();

type GetLidoHoldersViaSubgraphs = (
chainId: SubgraphChains,
Expand All @@ -35,6 +32,8 @@ type GetLidoHoldersViaSubgraphs = (
export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async (
chainId: SubgraphChains,
) => {
const cacheKey = `${CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY}_${chainId}`;

console.debug('[getLidoHoldersViaSubgraphs] Started fetching... ');
const query = `
query {
Expand Down Expand Up @@ -72,15 +71,11 @@ export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async (

console.debug('[getLidoHoldersViaSubgraphs] Lido holders:', responseJsoned);

cache.put(
CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY,
responseJsoned,
CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL,
);
cache.put(cacheKey, responseJsoned, CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL);

return responseJsoned;
} catch (error) {
const data = cache.get(CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY);
const data = cache.get(cacheKey);

if (data) {
console.error(`${SUBGRAPH_ERROR_MESSAGE} Using long-term cache...`);
Expand Down
21 changes: 11 additions & 10 deletions utilsApi/getTotalStaked.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { formatEther } from '@ethersproject/units';
import { getStaticRpcBatchProvider } from './rpcProviders';
import { StethAbiFactory } from '@lido-sdk/contracts';
import { getTokenAddress, TOKENS, CHAINS } from '@lido-sdk/constants';
import { getTokenAddress, TOKENS } from '@lido-sdk/constants';
import { CHAINS } from 'utils/chains';
import { HEALTHY_RPC_SERVICES_ARE_OVER } from 'config';
import { rpcUrls } from './rpcUrls';

export const getTotalStaked = async (): Promise<string> => {
const urls = rpcUrls[CHAINS.Mainnet];
return getTotalStakedWithFallbacks(urls, 0);
export const getTotalStaked = async (
chainId = CHAINS.Mainnet,
): Promise<string> => {
const urls = rpcUrls[chainId];
return getTotalStakedWithFallbacks(urls, 0, chainId);
};

const getTotalStakedWithFallbacks = async (
urls: Array<string>,
urlIndex: number,
chainId = CHAINS.Mainnet,
): Promise<string> => {
try {
const staticProvider = getStaticRpcBatchProvider(
CHAINS.Mainnet,
urls[urlIndex],
);
const staticProvider = getStaticRpcBatchProvider(chainId, urls[urlIndex]);

const stethAddress = getTokenAddress(CHAINS.Mainnet, TOKENS.STETH);
const stethAddress = getTokenAddress(chainId as number, TOKENS.STETH);
const stethContract = StethAbiFactory.connect(stethAddress, staticProvider);

const totalSupplyStWei = await stethContract.totalSupply();
Expand All @@ -33,6 +34,6 @@ const getTotalStakedWithFallbacks = async (
console.error(error);
throw new Error(error);
}
return await getTotalStakedWithFallbacks(urls, urlIndex + 1);
return await getTotalStakedWithFallbacks(urls, urlIndex + 1, chainId);
}
};
Loading

0 comments on commit 6c35838

Please sign in to comment.