Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/[locale]/enterprise/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -97,7 +97,7 @@ const loadData = dataLoader(
["growThePieData", fetchGrowThePie],
["ethereumStablecoins", fetchEthereumStablecoinsMcap],
["ethPrice", fetchEthPrice],
["totalEthStaked", fetchTotalEthStaked],
["totalEthStaked", fetchEthStakedBeaconchain],
],
BASE_TIME_UNIT * 1000
)
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/enterprise/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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],
Expand Down
12 changes: 6 additions & 6 deletions app/[locale]/staking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ const fetchBeaconchainData = async (): Promise<StakingStatsData> => {
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 }
}

Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion src/intl/en/page-staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
19 changes: 19 additions & 0 deletions src/lib/api/fetchEthStakedBeaconchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { EpochResponse, MetricReturnData } from "@/lib/types"

export const fetchEthStakedBeaconchain =
async (): Promise<MetricReturnData> => {
// 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() }
}
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ export type EthStakedResponse = {

export type EpochResponse = Data<{
validatorscount: number
eligibleether: number
}>

export type StakingStatsData = {
Expand Down
Loading