diff --git a/app/[locale]/enterprise/page.tsx b/app/[locale]/enterprise/page.tsx index fb02dac1a25..02c54787f28 100644 --- a/app/[locale]/enterprise/page.tsx +++ b/app/[locale]/enterprise/page.tsx @@ -64,8 +64,8 @@ import { parseActivity } from "./utils" import { fetchEthereumStablecoinsMcap } from "@/lib/api/fetchEthereumStablecoinsMcap" import { fetchEthPrice } from "@/lib/api/fetchEthPrice" +import { fetchEthStakedBeaconchain } from "@/lib/api/fetchEthStakedBeaconchain" import { fetchGrowThePie } from "@/lib/api/fetchGrowThePie" -import { fetchTotalEthStaked } from "@/lib/api/fetchTotalEthStaked" import EthGlyph from "@/public/images/assets/svgs/eth-diamond-rainbow.svg" import heroImage from "@/public/images/heroes/enterprise-hero-white.png" @@ -97,7 +97,7 @@ const loadData = dataLoader( ["growThePieData", fetchGrowThePie], ["ethereumStablecoins", fetchEthereumStablecoinsMcap], ["ethPrice", fetchEthPrice], - ["totalEthStaked", fetchTotalEthStaked], + ["totalEthStaked", fetchEthStakedBeaconchain], ], BASE_TIME_UNIT * 1000 ) diff --git a/app/[locale]/enterprise/utils.ts b/app/[locale]/enterprise/utils.ts index 05d1766d8f5..8ee4af35a60 100644 --- a/app/[locale]/enterprise/utils.ts +++ b/app/[locale]/enterprise/utils.ts @@ -88,8 +88,8 @@ export const parseActivity = async ({ }, { label: t("page-enterprise-activity-value-protecting"), - apiProvider: "Dune Analytics", - apiUrl: "https://dune.com/hildobby/eth2-staking", + apiProvider: "Beaconcha.in", + apiUrl: "https://beaconcha.in", state: totalValueSecuringFormatted, }, diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index e48ae1b97cf..450264cd36b 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -90,10 +90,10 @@ import { routing } from "@/i18n/routing" import { getABTestAssignment } from "@/lib/ab-testing/server" import { fetchCommunityEvents } from "@/lib/api/calendarEvents" import { fetchEthPrice } from "@/lib/api/fetchEthPrice" +import { fetchEthStakedBeaconchain } from "@/lib/api/fetchEthStakedBeaconchain" import { fetchGrowThePie } from "@/lib/api/fetchGrowThePie" import { fetchAttestantPosts } from "@/lib/api/fetchPosts" import { fetchRSS } from "@/lib/api/fetchRSS" -import { fetchTotalEthStaked } from "@/lib/api/fetchTotalEthStaked" import { fetchTotalValueLocked } from "@/lib/api/fetchTotalValueLocked" import EventFallback from "@/public/images/events/event-placeholder.png" @@ -142,7 +142,7 @@ const REVALIDATE_TIME = BASE_TIME_UNIT * 1 const loadData = dataLoader( [ ["ethPrice", fetchEthPrice], - ["totalEthStaked", fetchTotalEthStaked], + ["totalEthStaked", fetchEthStakedBeaconchain], ["totalValueLocked", fetchTotalValueLocked], ["growThePieData", fetchGrowThePie], ["communityEvents", fetchCommunityEvents], diff --git a/app/[locale]/staking/page.tsx b/app/[locale]/staking/page.tsx index 602411ae4c2..83c0d63dc77 100644 --- a/app/[locale]/staking/page.tsx +++ b/app/[locale]/staking/page.tsx @@ -31,26 +31,26 @@ const fetchBeaconchainData = async (): Promise => { const { href: ethstore } = new URL("api/v1/ethstore/latest", base) const { href: epoch } = new URL("api/v1/epoch/latest", base) - // Get total ETH staked and current APR from ethstore endpoint + // Get current APR from ethstore endpoint const ethStoreResponse = await fetch(ethstore) if (!ethStoreResponse.ok) throw new Error("Network response from Beaconcha.in ETHSTORE was not ok") const ethStoreResponseJson: EthStoreResponse = await ethStoreResponse.json() const { - data: { apr, effective_balances_sum_wei }, + data: { apr }, } = ethStoreResponseJson - const totalEffectiveBalance = effective_balances_sum_wei * 1e-18 - const totalEthStaked = Math.floor(totalEffectiveBalance) - // Get total active validators from latest epoch endpoint + // Get total eligible ETH staked and total active validators from latest epoch endpoint const epochResponse = await fetch(epoch) if (!epochResponse.ok) throw new Error("Network response from Beaconcha.in EPOCH was not ok") const epochResponseJson: EpochResponse = await epochResponse.json() const { - data: { validatorscount }, + data: { validatorscount, eligibleether: eligibleGwei }, } = epochResponseJson + const totalEthStaked = Math.floor(eligibleGwei * 1e-9) + return { totalEthStaked, validatorscount, apr } } diff --git a/app/[locale]/utils.ts b/app/[locale]/utils.ts index 9cf747f3a01..ccf4cc6563c 100644 --- a/app/[locale]/utils.ts +++ b/app/[locale]/utils.ts @@ -111,8 +111,8 @@ export const getActivity = async ( state: valueLocked, }, { - apiProvider: "Dune Analytics", - apiUrl: "https://dune.com/hildobby/eth2-staking", + apiProvider: "Beaconcha.in", + apiUrl: "https://beaconcha.in", label: t("page-index-network-stats-total-eth-staked"), state: totalEtherStaked, }, diff --git a/src/intl/en/page-staking.json b/src/intl/en/page-staking.json index 6854bbfe4f1..7792be32213 100644 --- a/src/intl/en/page-staking.json +++ b/src/intl/en/page-staking.json @@ -168,7 +168,7 @@ "page-staking-stats-box-metric-1": "Total ETH staked", "page-staking-stats-box-metric-2": "Total validators", "page-staking-stats-box-metric-3": "Current APR", - "page-staking-stats-box-metric-1-tooltip": "Sum of ETH at stake on the Beacon Chain, not including balances over 32 ETH", + "page-staking-stats-box-metric-1-tooltip": "Sum of eligible ETH at stake on the Beacon Chain", "page-staking-stats-box-metric-2-tooltip": "Number of validator accounts currently activated on the Beacon Chain", "page-staking-stats-box-metric-3-tooltip": "Average annualized financial return per validator over the past 24-hour period", "page-staking-section-comparison-subtitle": "There is no one-size-fits-all solution for staking, and each is unique. Here we'll compare some of the risks, rewards and requirements of the different ways you can stake.", diff --git a/src/lib/api/fetchEthStakedBeaconchain.ts b/src/lib/api/fetchEthStakedBeaconchain.ts new file mode 100644 index 00000000000..2e97d0d484c --- /dev/null +++ b/src/lib/api/fetchEthStakedBeaconchain.ts @@ -0,0 +1,19 @@ +import type { EpochResponse, MetricReturnData } from "@/lib/types" + +export const fetchEthStakedBeaconchain = + async (): Promise => { + // Fetch Beaconcha.in data + const base = "https://beaconcha.in" + const { href } = new URL("api/v1/epoch/latest", base) + + // Get total eligible ETH staked from latest epoch endpoint + const response = await fetch(href) + if (!response.ok) + throw new Error("Network response from Beaconcha.in EPOCH was not ok") + const json: EpochResponse = await response.json() + const { eligibleether: eligibleGwei } = json.data + + const totalEthStaked = Math.floor(eligibleGwei * 1e-9) + + return { value: totalEthStaked, timestamp: Date.now() } + } diff --git a/src/lib/types.ts b/src/lib/types.ts index e5eb09d1df4..1d7d2ee8985 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -521,6 +521,7 @@ export type EthStakedResponse = { export type EpochResponse = Data<{ validatorscount: number + eligibleether: number }> export type StakingStatsData = {