first take on the exodus page
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
03400023f3
commit
e19c856403
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.12",
|
||||
"version": "0.8.14",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -43,6 +43,7 @@ const Governance = lazy(() => import("./containers/Governance/Governance"));
|
||||
const ProposalDetails = lazy(() => import("./containers/Governance/ProposalDetails"));
|
||||
const NewProposal = lazy(() => import("./containers/Governance/NewProposal"));
|
||||
const History = lazy(() => import("./containers/History/History"));
|
||||
const Exodus = lazy(() => import("./containers/Exodus/Exodus"));
|
||||
|
||||
const PREFIX = "App";
|
||||
|
||||
@ -208,6 +209,7 @@ function App() {
|
||||
<Route path="governance/:id" element={<ProposalDetails config={config} connect={tryConnectInjected} address={address} chainId={addressChainId ? addressChainId : chainId} />} />
|
||||
<Route path="governance/create" element={<NewProposal config={config} connect={tryConnectInjected} address={address} chainId={addressChainId ? addressChainId : chainId} />} />
|
||||
<Route path="history" element={<History config={config} connect={tryConnectInjected} address={address} chainId={addressChainId ? addressChainId : chainId} />} />
|
||||
<Route path="exodus" element={<Exodus config={config} connect={tryConnectInjected} address={address} chainId={addressChainId ? addressChainId : chainId} />} />
|
||||
</Route>
|
||||
}
|
||||
<Route path="/empty" element={<NotFound
|
||||
|
||||
1
src/abi/GhostStorageHistory.json
Normal file
1
src/abi/GhostStorageHistory.json
Normal file
@ -0,0 +1 @@
|
||||
{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyExecuted","type":"error"},{"inputs":[],"name":"BridgeOutImpossible","type":"error"},{"inputs":[],"name":"NotDeployer","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"bridgeImbalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deploymentSnapshot","outputs":[{"components":[{"internalType":"uint48","name":"deployedAt","type":"uint48"},{"internalType":"uint104","name":"amountIn","type":"uint104"},{"internalType":"uint104","name":"amountOut","type":"uint104"}],"internalType":"struct IStorageHistory.DeploymentSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"increaseBridgeIn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"session","type":"uint256"}],"name":"isTransactionExecuted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"tryIncreaseBridgeOut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"session","type":"uint256"}],"name":"trySetTransactionExecuted","outputs":[],"stateMutability":"nonpayable","type":"function"}]}
|
||||
@ -33,6 +33,8 @@ import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
|
||||
import BookIcon from '@mui/icons-material/Book';
|
||||
import CurrencyExchangeIcon from '@mui/icons-material/CurrencyExchange';
|
||||
import MergeIcon from '@mui/icons-material/Merge';
|
||||
import RampLeftIcon from '@mui/icons-material/RampLeft';
|
||||
import RouteIcon from '@mui/icons-material/Route';
|
||||
|
||||
import GhostIcon from "../../assets/icons/ghost-nav-header.svg?react";
|
||||
import NavItem from "../NavItem/NavItem";
|
||||
@ -186,7 +188,8 @@ const NavContent = ({ chainId, addressChainId, address }) => {
|
||||
}
|
||||
/>
|
||||
<NavItem icon={ForkRightIcon} label={`${bridgeNumbers()} Bridge-In`} to={`/${chainName}/bridge-in`} />
|
||||
<NavItem icon={MergeIcon} label={`${negativeBridgeNumbers()} Bridge-Out`} to={`/${chainName}/bridge-out`} />
|
||||
<NavItem icon={RampLeftIcon} label={`${negativeBridgeNumbers()} Bridge-Out`} to={`/${chainName}/bridge-out`} />
|
||||
<NavItem icon={RouteIcon} label="(1, 1) Ghost Exodus" to={`/${chainName}/exodus`} />
|
||||
{/* <NavItem icon={GavelIcon} label={`Governance`} to={`/${chainName}/governance`} /> */}
|
||||
<NavItem icon={HistoryIcon} chipColor="warning" chip={pendingTransactions} label="Transaction History" to={`/${chainName}/history`} />
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ export const BridgeInConfirmationModal = ({
|
||||
<Metric
|
||||
label="To Bridge"
|
||||
metric={formatNumber(preparedAmount, formatDecimals)}
|
||||
/>
|
||||
/>
|
||||
<Box
|
||||
sx={{ background: "" }}
|
||||
height="120px"
|
||||
|
||||
@ -389,7 +389,6 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
estimatedOutAmount={estimatedOutAmount}
|
||||
formatDecimals={formatDecimals}
|
||||
ghstSymbol={ghstSymbol}
|
||||
nativeSymbol={nativeSymbol}
|
||||
externalSymbol={chainProperties ? chainProperties.properties.tokenSymbol : "CSPR"}
|
||||
receiver={customReceiver ? customReceiver : receiver}
|
||||
sender={account}
|
||||
@ -518,7 +517,7 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
/>
|
||||
|
||||
<Box m="15px 0" display="flex" flexDirection="column" gap="1px" sx={{ "& .DataRow-root": { margin: 0 } }}>
|
||||
<Box m="15px 0" display="flex" flexDirection="column" gap="1px" sx={{ "& .DataRow-root": { margin: "0 !important" } }}>
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Min Bridge-Out</Typography>}
|
||||
tooltip="Minimum amount that could be handled by the bridge to avoid dust balances."
|
||||
|
||||
661
src/containers/Exodus/Exodus.jsx
Normal file
661
src/containers/Exodus/Exodus.jsx
Normal file
@ -0,0 +1,661 @@
|
||||
import useSWR from "swr";
|
||||
import { useMemo, useState, useCallback } from "react";
|
||||
import { useGasPrice } from 'wagmi';
|
||||
import { keccak256, hexToBytes, getAddress, toHex } from 'viem';
|
||||
|
||||
import {
|
||||
Box,
|
||||
Divider,
|
||||
Link,
|
||||
CircularProgress,
|
||||
Container,
|
||||
Typography,
|
||||
Skeleton,
|
||||
TableContainer,
|
||||
TableCell,
|
||||
Table,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableBody,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
|
||||
import SearchIcon from '@mui/icons-material/Search';
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
|
||||
import Chip from "../../components/Chip/Chip";
|
||||
import Modal from "../../components/Modal/Modal";
|
||||
import Paper from "../../components/Paper/Paper";
|
||||
import Metric from "../../components/Metric/Metric";
|
||||
import { Tab, Tabs } from "../../components/Tabs/Tabs";
|
||||
import DataRow from "../../components/DataRow/DataRow";
|
||||
import PageTitle from "../../components/PageTitle/PageTitle";
|
||||
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||
import TokenStack from "../../components/TokenStack/TokenStack";
|
||||
import MetricCollection from "../../components/Metric/MetricCollection";
|
||||
import { PrimaryButton, TertiaryButton } from "../../components/Button";
|
||||
import LinearProgressBar from "../../components/Progress/LinearProgressBar";
|
||||
|
||||
import { useTotalReserves, useCapturedPriceSnapshots } from "../../hooks/treasury";
|
||||
import { useCurrentGasPrice, useIsTransactionExecuted } from "../../hooks/staking";
|
||||
import { useFtsoPrice, useReservePrice } from "../../hooks/prices";
|
||||
import { useTokenSymbol } from "../../hooks/tokens";
|
||||
import { useUniswapV2Pair } from "../../hooks/uniswapv2";
|
||||
import { useUnstableProvider } from "../../hooks/ghost";
|
||||
import { getTokenAddress, getTokenDecimals } from "../../hooks/helpers";
|
||||
|
||||
import { formatCurrency, formatNumber, shorten } from "../../helpers";
|
||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||
import { UNISWAP_V2_FACTORY } from "../../constants/addresses";
|
||||
|
||||
const SELECTABLE_OPTIONS = ["All Exoduses", "Rotations", "Governance", "Bridge-Out"];
|
||||
|
||||
const KEY_ROTATION = "Key Rotation";
|
||||
|
||||
const GAS_USED = {
|
||||
[KEY_ROTATION]: 300000n,
|
||||
}
|
||||
|
||||
const ExodusStatusCard = ({ progressPercent, executionDiscount, currentGasPrice, maxGasPrice }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Box mt="30px" sx={{ mb: { xs: "0px", md: "-30px" }}}>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mt="2px">
|
||||
<Box display="flex" alignItems="center" gap="5px">
|
||||
<Typography variant="caption" fontWeight="bold">Execution Discount: </Typography>
|
||||
<Typography variant="caption" fontWeight="bold" sx={{
|
||||
color: Number(executionDiscount) > 0
|
||||
? theme.colors.feedback.success
|
||||
: theme.colors.feedback.error
|
||||
}}>
|
||||
{formatNumber(executionDiscount, 2)}%
|
||||
</Typography>
|
||||
</Box>
|
||||
<Typography variant="caption">
|
||||
<Box display="flex" flexDirection="row" gap="5px">
|
||||
<Typography variant="caption" sx={{ fontWeight: "700" }}>Gas Price:</Typography>
|
||||
<Typography variant="caption">{`${formatNumber(currentGasPrice, 5)} / ${formatNumber(maxGasPrice, 5)} gwei`}</Typography>
|
||||
</Box>
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<LinearProgressBar
|
||||
variant={"determinate"}
|
||||
value={Math.max(100, Number(currentGasPrice.div(maxGasPrice).toString()) * 100)}
|
||||
height={6}
|
||||
barColor={theme.colors.feedback.success}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
const ExodusItem = ({
|
||||
item,
|
||||
chainId,
|
||||
gasPrice,
|
||||
ftsoSymbol,
|
||||
nativeMetadata,
|
||||
setVerifiedItem,
|
||||
isSmallScreen,
|
||||
currentTwapPrice
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const isVerySmallScreen = useMediaQuery("(max-width: 450px)");
|
||||
|
||||
const {
|
||||
isTransactionExecuted,
|
||||
isTransactionExecutedLoading
|
||||
} = useIsTransactionExecuted(chainId, item.data.at(0)?.session);
|
||||
|
||||
const chipStatus = useMemo(() => {
|
||||
const width = isVerySmallScreen ? "21px" : "100px";
|
||||
|
||||
if (isTransactionExecuted && !isTransactionExecutedLoading) {
|
||||
return <Chip sx={{ width: width }} label={isVerySmallScreen ? "" : "Executed"} template={"gray"} />
|
||||
}
|
||||
|
||||
return <Chip sx={{ width: width }} label={isVerySmallScreen ? "" : "Ready"} template={"success"} />
|
||||
}, [isTransactionExecutedLoading, isTransactionExecuted]);
|
||||
|
||||
if (isSmallScreen || isVerySmallScreen) {
|
||||
return (
|
||||
<>
|
||||
<Box display="flex" flexDirection="column" gap="10px">
|
||||
<Box
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
flexDirection={isVerySmallScreen ? "row" : "row"}
|
||||
>
|
||||
<Box display="flex" gap="20px" p="10px 0">
|
||||
<TokenStack chainTokenNames={[nativeMetadata.symbol]} tokens={[ftsoSymbol]} />
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Typography>{item.type}</Typography>
|
||||
<Link
|
||||
href={`${nativeMetadata.url}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{"Something here"}</Typography>
|
||||
</Link>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" alignItems="flex-end">
|
||||
{chipStatus}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box width="100%" display="flex" flexDirection="row" justifyContent="space-between">
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Typography>{nativeMetadata.symbol} Cost</Typography>
|
||||
<Typography>{
|
||||
formatCurrency(
|
||||
currentTwapPrice(gasPrice * GAS_USED[item.type]).toString(),
|
||||
5,
|
||||
ftsoSymbol
|
||||
)
|
||||
}</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Typography>Reward</Typography>
|
||||
<Typography>
|
||||
{formatCurrency(
|
||||
new DecimalBigNumber(gasPrice * GAS_USED[item.type], 18),
|
||||
5,
|
||||
nativeMetadata.symbol
|
||||
)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="row" gap="20px">
|
||||
<TertiaryButton fullWidth onClick={setVerifiedItem}>Verify</TertiaryButton>
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableCell sx={{ padding: "10px 0" }}>
|
||||
<Box display="flex" alignItems="center">
|
||||
<TokenStack chainTokenNames={[nativeMetadata.symbol]} tokens={[ftsoSymbol]} />
|
||||
<Box ml="10px" display="flex" flexDirection="column" alignItems="flex-start">
|
||||
<Typography>{item.type}</Typography>
|
||||
<Link
|
||||
href={`${nativeMetadata.url}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{"Something here"}</Typography>
|
||||
</Link>
|
||||
</Box>
|
||||
</Box>
|
||||
</TableCell>
|
||||
|
||||
<TableCell align="center" sx={{ padding: "10px 0" }}>
|
||||
{chipStatus}
|
||||
</TableCell>
|
||||
|
||||
<TableCell align="center" sx={{ padding: "10px 0" }}>
|
||||
{formatCurrency(
|
||||
new DecimalBigNumber(gasPrice * GAS_USED[item.type], 18),
|
||||
5,
|
||||
nativeMetadata.symbol
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
<TableCell align="center" sx={{ padding: "10px 0" }}>
|
||||
<Typography>{
|
||||
formatCurrency(
|
||||
currentTwapPrice(gasPrice * GAS_USED[item.type]).toString(),
|
||||
5,
|
||||
ftsoSymbol
|
||||
)
|
||||
}</Typography>
|
||||
</TableCell>
|
||||
|
||||
<TableCell sx={{ padding: "10px 0" }}>
|
||||
<Box p="0 30px" display="flex" justifyContent="center" alignItems="center">
|
||||
<TertiaryButton
|
||||
fullWidth
|
||||
disabled={isTransactionExecuted || isTransactionExecutedLoading}
|
||||
onClick={() => setVerifiedItem({ dkgIndex: item.dkgIndex, type: item.type })}
|
||||
>
|
||||
Verify
|
||||
</TertiaryButton>
|
||||
</Box>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
}
|
||||
|
||||
const ExodusList = ({
|
||||
chainId,
|
||||
nativeMetadata,
|
||||
setVerifiedItem,
|
||||
ftsoSymbol,
|
||||
gasPrice,
|
||||
currentTwapPrice,
|
||||
signedExodusRotations,
|
||||
signedExodusRotationsLoading,
|
||||
}) => {
|
||||
const isSmallScreen = useMediaQuery("(max-width: 900px)");
|
||||
|
||||
const chainedExoduses = useMemo(() => {
|
||||
let chain = [];
|
||||
|
||||
if (Array.isArray(signedExodusRotations)) chain = [...chain, ...signedExodusRotations];
|
||||
|
||||
return chain;
|
||||
}, [signedExodusRotations]);
|
||||
|
||||
if (signedExodusRotationsLoading) {
|
||||
return (
|
||||
<Box my="20px" display="flex" flexDirection="column" justifyContent="center" alignItems="center" gap="50px">
|
||||
<CircularProgress color="primary" />
|
||||
<Typography>Loading Signed Rotations...</Typography>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
if (isSmallScreen) {
|
||||
return (
|
||||
<Box display="flex" flexDirection="column" gap="50px">
|
||||
{chainedExoduses.map((item, i) => {
|
||||
return (
|
||||
<ExodusItem
|
||||
key={i}
|
||||
item={item}
|
||||
chainId={chainId}
|
||||
gasPrice={gasPrice}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
setVerifiedItem={setVerifiedItem}
|
||||
currentTwapPrice={currentTwapPrice}
|
||||
nativeMetadata={nativeMetadata}
|
||||
isSmallScreen={isSmallScreen}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</Box>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<TableContainer>
|
||||
<Table aria-label="Available bonds" style={{ tableLayout: "fixed" }}>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell style={{ padding: "8px 0" }}>Exodus</TableCell>
|
||||
<TableCell style={{ padding: "8px 0" }} align="center">Status</TableCell>
|
||||
<TableCell style={{ padding: "8px 0" }} align="center">{nativeMetadata.symbol} Cost</TableCell>
|
||||
<TableCell style={{ padding: "8px 0" }} align="center">Reward</TableCell>
|
||||
<TableCell style={{ padding: "8px 0" }}></TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{chainedExoduses.map((item, i) => {
|
||||
return (
|
||||
<ExodusItem
|
||||
key={i}
|
||||
item={item}
|
||||
chainId={chainId}
|
||||
gasPrice={gasPrice}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
setVerifiedItem={setVerifiedItem}
|
||||
nativeMetadata={nativeMetadata}
|
||||
currentTwapPrice={currentTwapPrice}
|
||||
isSmallScreen={isSmallScreen}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const ExodusVerify = ({
|
||||
chainId,
|
||||
isOpen,
|
||||
onClose,
|
||||
nativeMetadata,
|
||||
address,
|
||||
casperApi,
|
||||
item,
|
||||
ftsoSymbol,
|
||||
gasPrice,
|
||||
currentTwapPrice,
|
||||
}) => {
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
|
||||
const { data: signedExodusRotation } = useSWR(
|
||||
casperApi && item ? ['signedExodusRotations', casperApi, item] : null,
|
||||
async ([_, api, it]) => api.query.GhostExodus.ExodusSignedRotations.getValue(it.dkgIndex, { type: "Evm" }),
|
||||
);
|
||||
|
||||
const upcomingGroupKey = useMemo(() => {
|
||||
if (!signedExodusRotation) return null;
|
||||
|
||||
const publicKey = signedExodusRotation?.at(1)["r#type"].value.public_key;
|
||||
if (!publicKey) return null;
|
||||
|
||||
const cleanHex = publicKey.startsWith('0x04') && publicKey.length === 130
|
||||
? `0x${publicKey.slice(4)}`
|
||||
: publicKey.startsWith('0x')
|
||||
? publicKey
|
||||
: `0x${publicKey}`;
|
||||
|
||||
const hash = keccak256(cleanHex);
|
||||
|
||||
return getAddress(`0x${hash.slice(-40)}`);
|
||||
}, [signedExodusRotation]);
|
||||
|
||||
const signedMessageMetadata = useMemo(() => {
|
||||
if (!signedExodusRotation) return null;
|
||||
|
||||
const nonce = signedExodusRotation?.at(1).nonce;
|
||||
const signature = signedExodusRotation?.at(1).signature;
|
||||
|
||||
return {
|
||||
nonce: nonce ? toHex(nonce) : null,
|
||||
signature: signature ? toHex(signature) : null,
|
||||
message: "0xdeadbeef",
|
||||
};
|
||||
}, [signedExodusRotation])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
maxWidth="426px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerContent={<Typography variant="h4">Verify {item?.type}</Typography>}
|
||||
onClose={!isPending && onClose}
|
||||
topRight={
|
||||
<GhostStyledIcon
|
||||
viewBox="0 0 23 23"
|
||||
component={CloseIcon}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box mb="15px" display="flex" flexDirection="column" gap="1px" sx={{ "& .DataRow-root": { margin: "0 !important" } }}>
|
||||
<DataRow
|
||||
title={<Typography variant="caption">New Group Key</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Link
|
||||
href={`${nativeMetadata.url}/address/${upcomingGroupKey}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography variant="caption">{
|
||||
upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : ""
|
||||
}</Typography>
|
||||
</Link>}
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Verification Reward</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Typography variant="caption">{
|
||||
formatCurrency(
|
||||
currentTwapPrice(
|
||||
(gasPrice ? gasPrice : 0n) *
|
||||
(GAS_USED[item?.type] ? GAS_USED[item?.type] : 0n)
|
||||
).toString(),
|
||||
5,
|
||||
ftsoSymbol
|
||||
)
|
||||
}</Typography>}
|
||||
/>
|
||||
|
||||
<Divider sx={{ my: "15px", width: "100%" }} />
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Nonce</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Typography variant="caption">
|
||||
{signedMessageMetadata?.nonce ? shorten(signedMessageMetadata.nonce, 12, -10) : ""}
|
||||
</Typography>}
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Signture</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Typography variant="caption">
|
||||
{signedMessageMetadata?.signature ? shorten(signedMessageMetadata.signature, 12, -10) : ""}
|
||||
</Typography>}
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Signed Message</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Typography variant="caption">
|
||||
{signedMessageMetadata?.message ? signedMessageMetadata.message : ""}
|
||||
</Typography>}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
onClick={() => {
|
||||
alert("not ready for now");
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
Verify
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
const Exodus = ({ chainId, address, config }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
const isSmallScreen = useMediaQuery("(max-width: 650px)");
|
||||
const isSemiSmallScreen = useMediaQuery("(max-width: 850px)");
|
||||
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
||||
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
const [dkgDeviation, setDkgDeviation] = useState(3);
|
||||
const [verifiedItem, setVerifiedItem] = useState(null);
|
||||
const [selected, setSelected] = useState(0);
|
||||
|
||||
const { casperApi } = useUnstableProvider();
|
||||
|
||||
const nativeMetadata = useMemo(() => {
|
||||
const client = config?.getClient();
|
||||
return {
|
||||
url: client?.chain?.blockExplorers?.default?.url,
|
||||
symbol: client?.chain?.nativeCurrency?.symbol,
|
||||
decimals: client?.chain?.nativeCurrency?.decimals,
|
||||
}
|
||||
}, [config]);
|
||||
|
||||
const { data: gasPrice } = useGasPrice(chainId);
|
||||
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
|
||||
|
||||
const totalReserves = useTotalReserves(chainId);
|
||||
const ftsoPrice = useFtsoPrice(chainId);
|
||||
const reservePrice = useReservePrice(chainId);
|
||||
const { currentGasPrice, maxGasPrice } = useCurrentGasPrice(chainId);
|
||||
|
||||
const { pairAddress } = useUniswapV2Pair(
|
||||
chainId,
|
||||
UNISWAP_V2_FACTORY[chainId],
|
||||
getTokenAddress(chainId, "WETH"),
|
||||
getTokenAddress(chainId, "FTSO")
|
||||
);
|
||||
|
||||
const { capturedPriceSnapshots } = useCapturedPriceSnapshots(chainId, pairAddress);
|
||||
|
||||
const currentTwapPrice = useCallback((amount) => {
|
||||
const value = ((capturedPriceSnapshots ? capturedPriceSnapshots._value : 0n) * amount) >> 112n;
|
||||
return (new DecimalBigNumber(value, getTokenDecimals("FTSO"))).mul(ftsoPrice);
|
||||
}, [capturedPriceSnapshots, ftsoPrice]);
|
||||
|
||||
const executionDiscount = useMemo(() => {
|
||||
const oneHundred = new DecimalBigNumber(100n, 0);
|
||||
const value = oneHundred.div(ftsoPrice);
|
||||
return ftsoPrice.sub(currentTwapPrice(10n ** BigInt(nativeMetadata.decimals))).mul(value);
|
||||
}, [currentTwapPrice, ftsoPrice, nativeMetadata]);
|
||||
|
||||
const { data: activeDkgAuthorities, isLoading: activeDkgAuthoritiesLoading } = useSWR(
|
||||
casperApi ? ['activeDkgAuthorities', casperApi] : null,
|
||||
() => casperApi.query.GhostExodus.ActiveDkgAuthorities.getValue({ type: "Secp256k1" }),
|
||||
{
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
const { data: signedExodusRotations, isLoading: signedExodusRotationsLoading } = useSWR(
|
||||
casperApi &&
|
||||
dkgDeviation &&
|
||||
(selected === 0 || selected === 1) &&
|
||||
activeDkgAuthorities
|
||||
? ['signedExodusRotations', casperApi, dkgDeviation]
|
||||
: null,
|
||||
async ([_, api, deviation]) => {
|
||||
const start = Math.max(0, activeDkgAuthorities.dkg_index - deviation);
|
||||
const length = activeDkgAuthorities.dkg_index - start;
|
||||
|
||||
const promises = Array.from({ length }, (_, index) => start + index).map(index =>
|
||||
api.query.GhostExodus.ExodusSignedRotations.getValue(index, { type: "Evm" })
|
||||
.then(data => ({ dkgIndex: index, type: KEY_ROTATION, data }))
|
||||
);
|
||||
|
||||
return Promise.all(promises);
|
||||
},
|
||||
{
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<Box minHeight="calc(100vh - 43px)">
|
||||
<PageTitle name="Ghost Exodus" subtitle="(1, 1) Verify Exodus for a treasury-backed reward" />
|
||||
<Container
|
||||
style={{
|
||||
paddingLeft: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem",
|
||||
paddingRight: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem",
|
||||
}}
|
||||
>
|
||||
<ExodusVerify
|
||||
chainId={chainId}
|
||||
address={address}
|
||||
isOpen={!!verifiedItem}
|
||||
casperApi={casperApi}
|
||||
item={verifiedItem}
|
||||
nativeMetadata={nativeMetadata}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
gasPrice={gasPrice}
|
||||
currentTwapPrice={currentTwapPrice}
|
||||
onClose={() => setVerifiedItem(null)}
|
||||
/>
|
||||
|
||||
<Box mt="15px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="center">
|
||||
<Paper
|
||||
fullWidth
|
||||
enableBackground
|
||||
headerContent={<Typography pr="5px" variant="h6">Exodus Metrics</Typography>}
|
||||
>
|
||||
<MetricCollection>
|
||||
<Metric
|
||||
metric={formatCurrency(totalReserves, 2)}
|
||||
label="Treasury Balance"
|
||||
tooltip="some description to be added"
|
||||
/>
|
||||
|
||||
<Metric
|
||||
metric={formatCurrency(currentTwapPrice(10n ** BigInt(nativeMetadata.decimals)), 2)}
|
||||
label="Execution Price"
|
||||
tooltip="some description to be added"
|
||||
/>
|
||||
|
||||
<Metric
|
||||
metric={formatCurrency(ftsoPrice, 2)}
|
||||
label="Market Price"
|
||||
tooltip="some description to be added"
|
||||
/>
|
||||
</MetricCollection>
|
||||
|
||||
<ExodusStatusCard
|
||||
executionDiscount={executionDiscount}
|
||||
currentGasPrice={currentGasPrice}
|
||||
maxGasPrice={maxGasPrice}
|
||||
/>
|
||||
</Paper>
|
||||
|
||||
<Paper
|
||||
fullWidth
|
||||
enableBackground
|
||||
topRight={
|
||||
<Box style={{ position: "absolute", top: "28px", right: "20px", zIndex: 10 }}>
|
||||
<GhostStyledIcon
|
||||
component={SearchIcon}
|
||||
viewBox="0 0 23 23"
|
||||
style={{ display: "flex", cursor: "pointer" }}
|
||||
onClick={() => alert("smart search for exodus will be here")}
|
||||
/>
|
||||
</Box>
|
||||
}
|
||||
headerContent={
|
||||
<Box
|
||||
width="100%"
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
justifyContent="space-between"
|
||||
alignItems="center"
|
||||
gap="15px"
|
||||
>
|
||||
<Tabs
|
||||
centered={!isSemiSmallScreen}
|
||||
orientation={isSemiSmallScreen ? "vertical" : "horizontal"}
|
||||
textColor="primary"
|
||||
indicatorColor="primary"
|
||||
value={SELECTABLE_OPTIONS[selected]}
|
||||
aria-label="Exodus menu"
|
||||
onChange={(_, selectedValue) => {
|
||||
const index = SELECTABLE_OPTIONS.indexOf(selectedValue);
|
||||
if (index !== -1) setSelected(index);
|
||||
}}
|
||||
TabIndicatorProps={{ style: { display: "none" } }}
|
||||
>
|
||||
{SELECTABLE_OPTIONS.map((option, i) => {
|
||||
return (
|
||||
<Tab
|
||||
key={i}
|
||||
value={option}
|
||||
aria-label={`exodus-${i}-button`}
|
||||
style={{ fontSize: "1.2rem" }}
|
||||
label={<Typography variant="h6">{option}</Typography>}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</Tabs>
|
||||
</Box>}
|
||||
>
|
||||
<ExodusList
|
||||
chainId={chainId}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
gasPrice={gasPrice}
|
||||
setVerifiedItem={setVerifiedItem}
|
||||
nativeMetadata={nativeMetadata}
|
||||
currentTwapPrice={currentTwapPrice}
|
||||
signedExodusRotations={signedExodusRotations}
|
||||
signedExodusRotationsLoading={activeDkgAuthoritiesLoading || signedExodusRotationsLoading}
|
||||
/>
|
||||
</Paper>
|
||||
</Box>
|
||||
</Container>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default Exodus;
|
||||
@ -46,7 +46,16 @@ import BridgeInModal from "./BridgeInModal";
|
||||
import BondModal from "./BondModal";
|
||||
import AddRecordModal from "./AddRecordModal";
|
||||
|
||||
const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewModalOpen, isSmallScreen, finalityDelay }) => {
|
||||
const HistoryItem = ({
|
||||
item,
|
||||
chainId,
|
||||
config,
|
||||
currentTime,
|
||||
eraseRecord,
|
||||
setViewModalOpen,
|
||||
isSmallScreen,
|
||||
finalityDelay
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const isVerySmallScreen = useMediaQuery("(max-width: 450px)");
|
||||
|
||||
|
||||
@ -141,7 +141,7 @@ export const useFtsoPrice = (chainId) => {
|
||||
const reserveAddress = RESERVE_ADDRESSES[chainId];
|
||||
const ftsoAddress = FTSO_ADDRESSES[chainId];
|
||||
if (!reserveAddress || !ftsoAddress) {
|
||||
return new DecimalBigNumber(0n, 9);
|
||||
return new DecimalBigNumber(1n, 9);
|
||||
}
|
||||
|
||||
const stableReserves = reserveAddress.toUpperCase() === tokens.token0.toUpperCase()
|
||||
|
||||
@ -11,12 +11,61 @@ import {
|
||||
import { STAKING_ADDRESSES } from "../../constants/addresses";
|
||||
import { abi as StakingAbi } from "../../abi/GhostStaking.json";
|
||||
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
|
||||
import { abi as GhostStorageHistoryAbi } from "../../abi/GhostStorageHistory.json";
|
||||
|
||||
import { shorten } from "../../helpers";
|
||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||
import { executeOnChainTransaction, getTokenDecimals } from "../helpers";
|
||||
import { useCirculatingSupply } from "../tokens";
|
||||
|
||||
export const useIsTransactionExecuted = (chainId, index) => {
|
||||
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
|
||||
|
||||
const { data: storageHistory } = useReadContract({
|
||||
abi: GatekeeperAbi,
|
||||
address: gatekeeperAddress,
|
||||
functionName: "storageHistory",
|
||||
scopeKey: `storageHistory-${chainId}-${gatekeeperAddress}`,
|
||||
chainId: chainId,
|
||||
});
|
||||
|
||||
const { data: isTransactionExecuted, isLoading: isTransactionExecutedLoading, error } = useReadContract({
|
||||
abi: GhostStorageHistoryAbi,
|
||||
address: storageHistory,
|
||||
functionName: "isTransactionExecuted",
|
||||
args: [index],
|
||||
scopeKey: `isTransactionExecuted-${chainId}-${storageHistory}`,
|
||||
chainId: chainId,
|
||||
});
|
||||
|
||||
return { isTransactionExecuted, isTransactionExecutedLoading }
|
||||
}
|
||||
|
||||
export const useCurrentGasPrice = (chainId) => {
|
||||
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
|
||||
|
||||
const { data: gasPrice } = useReadContract({
|
||||
abi: GatekeeperAbi,
|
||||
address: gatekeeperAddress,
|
||||
functionName: "getCurrentGasPrice",
|
||||
scopeKey: `currentGasPrice-${chainId}-${gatekeeperAddress}`,
|
||||
chainId: chainId,
|
||||
});
|
||||
|
||||
const { data } = useReadContract({
|
||||
abi: GatekeeperAbi,
|
||||
address: gatekeeperAddress,
|
||||
functionName: "MAX_ALLOWED_GAS_PRICE",
|
||||
scopeKey: `MAX_ALLOWED_GAS_PRICE-${chainId}-${gatekeeperAddress}`,
|
||||
chainId: chainId,
|
||||
});
|
||||
|
||||
const maxGasPrice = new DecimalBigNumber(data ? data : 1n, 9);
|
||||
const currentGasPrice = new DecimalBigNumber(gasPrice ? gasPrice : 1n, 9);
|
||||
|
||||
return { currentGasPrice, maxGasPrice };
|
||||
}
|
||||
|
||||
export const useRegistryIndex = (chainId) => {
|
||||
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
|
||||
|
||||
@ -28,7 +77,7 @@ export const useRegistryIndex = (chainId) => {
|
||||
chainId: chainId,
|
||||
});
|
||||
|
||||
return { registryIndex: !isLoading ? data : 69n };
|
||||
return { registryIndex: !isLoading ? data : 0n };
|
||||
}
|
||||
|
||||
export const useWeaverMaximumSlots = (chainId) => {
|
||||
|
||||
@ -10,6 +10,21 @@ import { bigIntSqrt } from "../../helpers";
|
||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||
import { getTokenAddress } from "../helpers";
|
||||
|
||||
export const useCapturedPriceSnapshots = (chainId, address) => {
|
||||
const { data } = useReadContract({
|
||||
abi: TreasuryAbi,
|
||||
address: DAO_TREASURY_ADDRESSES[chainId],
|
||||
functionName: "capturedPriceSnapshots",
|
||||
args: [address],
|
||||
scopeKey: `capturedPriceSnapshots-${address}-${chainId}`,
|
||||
chainId: chainId
|
||||
});
|
||||
|
||||
const capturedPriceSnapshots = new DecimalBigNumber(data ? data : 0n, 18);
|
||||
|
||||
return { capturedPriceSnapshots }
|
||||
}
|
||||
|
||||
export const useOrinalCoefficient = (chainId) => {
|
||||
const { data: original } = useReadContract({
|
||||
abi: TreasuryAbi,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user