"use client"; import { PythStakingClient } from "@pythnetwork/staking-sdk"; import { useConnection } from "@solana/wallet-adapter-react"; import type { Connection } from "@solana/web3.js"; import clsx from "clsx"; import type { HTMLProps } from "react"; import { StateType, useData } from "../../hooks/use-data"; import { Tokens } from "../Tokens"; const ONE_SECOND_IN_MS = 1000; const ONE_MINUTE_IN_MS = 60 * ONE_SECOND_IN_MS; const REFRESH_INTERVAL = 1 * ONE_MINUTE_IN_MS; const INITIAL_REWARD_POOL_SIZE = 60_000_000_000_000n; export const Stats = ({ className, ...props }: HTMLProps) => { const { connection } = useConnection(); const state = useData("poolStats", () => fetchStats(connection), { refreshInterval: REFRESH_INTERVAL, }); return (
{state.type === StateType.Loaded ? ( {state.data.totalStaked} ) : ( )}
OIS Total Staked
{state.type === StateType.Loaded ? ( {state.data.rewardsDistributed} ) : ( )}
OIS Rewards Distributed
{state.type === StateType.Loaded ? ( {state.data.totalGovernance} ) : ( )}
Pyth Governance Total Staked
); }; const Loading = () => (
); const fetchStats = async (connection: Connection) => { const client = new PythStakingClient({ connection }); const [targetAccount, poolData, rewardCustodyAccount] = await Promise.all([ client.getTargetAccount(), client.getPoolDataAccount(), client.getRewardCustodyAccount(), ]); return { totalGovernance: targetAccount.locked + targetAccount.deltaLocked, totalStaked: sumDelegations(poolData.delState) + sumDelegations(poolData.selfDelState), rewardsDistributed: poolData.claimableRewards + INITIAL_REWARD_POOL_SIZE - rewardCustodyAccount.amount, }; }; const sumDelegations = ( values: { totalDelegation: bigint; deltaDelegation: bigint }[], ) => values.reduce( (acc, value) => acc + value.totalDelegation + value.deltaDelegation, 0n, );