Compare commits

...

3 Commits

Author SHA1 Message Date
96d7465436
no, this is final fix for the boosted apy... I belive so
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-05-07 21:13:43 +03:00
f68551043e
final fix for the boosted apy
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-05-07 21:04:10 +03:00
5faa7b0ba9
fix boosted apy calculation
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-05-07 13:09:29 +03:00
5 changed files with 80 additions and 51 deletions

View File

@ -1,7 +1,7 @@
{
"name": "ghost-dao-interface",
"private": true,
"version": "0.7.40",
"version": "0.7.43",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -0,0 +1,30 @@
import { NetworkId } from "../constants";
export const amountInHistory = {
[NetworkId.TESTNET_SEPOLIA]: 0n,
[NetworkId.TESTNET_HOODI]: 0n,
[NetworkId.TESTNET_MORDOR]: 0n,
}
export const amountOutHistory = {
[NetworkId.TESTNET_SEPOLIA]: 0n,
[NetworkId.TESTNET_HOODI]: 0n,
[NetworkId.TESTNET_MORDOR]: 0n,
}
// denominator is 1e5
export const feeIn = {
[NetworkId.TESTNET_SEPOLIA]: 6900n,
[NetworkId.TESTNET_HOODI]: 6900n,
[NetworkId.TESTNET_MORDOR]: 6900n,
}
// denominator is 1e5
export const feeOut = {
[NetworkId.TESTNET_SEPOLIA]: 0n,
[NetworkId.TESTNET_HOODI]: 0n,
[NetworkId.TESTNET_MORDOR]: 0n,
}
// denominator is 1e5
export const stakeRatio = 5000n;

View File

@ -20,7 +20,7 @@ import { GHOST_CONNECT } from "../../constants/ecosystem";
import { useLocalStorage } from "../../hooks/localstorage";
import { useBreakoutModal } from "../../hooks/breakoutModal";
import { useTokenSymbol, useCirculatingSupply } from "../../hooks/tokens";
import { useTokenSymbol } from "../../hooks/tokens";
import { useEpoch, useGatekeeperApy, useGatekeeperAddress } from "../../hooks/staking";
import { useEvmNetwork, useCurrentIndex, useUnstableProvider } from "../../hooks/ghost";
import { formatNumber, shorten } from "../../helpers";
@ -252,8 +252,7 @@ const WelcomeView = ({
const { epoch } = useEpoch(chainId);
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
const circulatingSupply = useCirculatingSupply(chainId, "STNK");
const gatekeepedApy = useGatekeeperApy(chainId);
const { gatekeepedApy, apyInner } = useGatekeeperApy(chainId);
const { isExtensionMissing } = useUnstableProvider();
@ -262,16 +261,6 @@ const WelcomeView = ({
closeModal();
}
const apyInner = useMemo(() => {
let apy = Infinity;
if (circulatingSupply._value > 0n) {
const value = epoch.distribute.div(circulatingSupply);
apy = 100 * (Math.pow(1 + parseFloat(value.toString()), 1095) - 1);
if (apy === 0) apy = Infinity;
}
return apy;
}, [circulatingSupply, epoch]);
const callDefaultFunction = useCallback(async () => {
setIsPending(true);
await defaultFunction()();
@ -314,7 +303,7 @@ const WelcomeView = ({
</Box>
<Box display="flex" justifyContent="center" flexDirection="column" alignItems="center">
<Typography variant="h5">{formatNumber(apyInner * gatekeepedApy, 2)}% APY</Typography>
<Typography variant="h5">{formatNumber(gatekeepedApy, 2)}% APY</Typography>
</Box>
<PrimaryButton

View File

@ -5,8 +5,8 @@ import { useNavigate, createSearchParams } from "react-router-dom";
import { formatNumber } from "../../../helpers";
import { useLiveBonds } from "../../../hooks/bonds/index";
import { useEpoch, useGatekeeperApy } from "../../../hooks/staking";
import { useTokenSymbol, useBalance, useCirculatingSupply } from "../../../hooks/tokens";
import { useGatekeeperApy } from "../../../hooks/staking";
import { useTokenSymbol, useBalance } from "../../../hooks/tokens";
import { SecondaryButton } from "../../../components/Button";
import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber";
@ -68,10 +68,7 @@ const ProtocolDetails = ({ chainId, isMobileScreen, theme, }) => {
const { symbol: csprSymbol } = useTokenSymbol(chainId, "CSPR");
const { contractAddress: ftsoAddress } = useBalance(chainId, "FTSO", EMPTY_ADDRESS);
const { liveBonds } = useLiveBonds(chainId);
const circulatingSupply = useCirculatingSupply(chainId, "STNK");
const gatekeepedApy = useGatekeeperApy(chainId);
const { epoch } = useEpoch(chainId);
const { gatekeepedApy, apyInner } = useGatekeeperApy(chainId);
const maxBondDiscountTest = useMemo(() => {
const sortedGhostBonds = liveBonds.filter((bond) => !bond.isSoldOut)
@ -83,16 +80,6 @@ const ProtocolDetails = ({ chainId, isMobileScreen, theme, }) => {
return `Up to ${formatNumber(maxDiscount, 0)}% Discount`;
}, [liveBonds]);
const apyInner = useMemo(() => {
let apy = Infinity;
if (circulatingSupply._value > 0n) {
const value = epoch.distribute.div(circulatingSupply);
apy = 100 * (Math.pow(1 + parseFloat(value.toString()), 1095) - 1);
if (apy === 0) apy = Infinity;
}
return apy;
}, [circulatingSupply, epoch]);
const bridgeNumbers = useMemo(() => {
const connectedNetworks = Object.keys(GATEKEEPER_ADDRESSES).length;
const number = 1 + connectedNetworks * 3;
@ -138,7 +125,7 @@ const ProtocolDetails = ({ chainId, isMobileScreen, theme, }) => {
theme={theme}
url={`/${networkName.toLowerCase()}/bridge`}
name={`${bridgeNumbers} Stake\u00B2`}
sideName={`${formatNumber(apyInner * gatekeepedApy, 0)}% APY`}
sideName={`${formatNumber(gatekeepedApy, 0)}% APY`}
description={`Staking\u00B2 strategy further deepens long-term incentives powered by sustainable crosschain bridging revenue. ${bridgeNumbers} Stake\u00B2 your ${csprSymbol} to receive organic APY with no warm-up and no dilution.`}
/>
</Box>

View File

@ -1,6 +1,13 @@
import { useReadContract } from "wagmi";
import toast from "react-hot-toast";
import {
amountInHistory,
amountOutHistory,
feeIn,
feeOut,
stakeRatio
} from "../../constants/gatekeeper";
import { STAKING_ADDRESSES } from "../../constants/addresses";
import { abi as StakingAbi } from "../../abi/GhostStaking.json";
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
@ -8,44 +15,60 @@ import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
import { shorten } from "../../helpers";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { executeOnChainTransaction } from "../helpers";
import { useCirculatingSupply } from "../tokens";
export const useGatekeeperApy = (chainId) => {
const { data: gatekeeper, refetch } = useReadContract({
abi: StakingAbi,
address: STAKING_ADDRESSES[chainId],
functionName: "gatekeeper",
scopeKey: `gatekeeper-${chainId}`,
chainId: chainId,
});
const circulatingSupply = useCirculatingSupply(chainId, "STNK");
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
const { epoch } = useEpoch(chainId);
const { data: metadata, error } = useReadContract({
abi: GatekeeperAbi,
address: gatekeeper,
address: gatekeeperAddress,
functionName: "metadata",
scopeKey: `gatekeeperMetadata-${chainId}-${gatekeeper}`,
scopeKey: `gatekeeperMetadata-${chainId}-${gatekeeperAddress}`,
chainId: chainId,
});
const amountIn = new DecimalBigNumber(metadata?.amountIn ?? 0n, 18);
const amountOut = new DecimalBigNumber(metadata?.amountOut ?? 0n, 18);
const amountIn = new DecimalBigNumber(
(metadata?.amountIn ?? 0n) + (amountInHistory[chainId] ?? 0n),
18,
);
const amountOut = new DecimalBigNumber(
(metadata?.amountOut ?? 0n) + (amountOutHistory[chainId] ?? 0n),
18,
);
const deployedAt = metadata?.deployedAt ?? 0;
const unixSeconds = Math.floor(Date.now() / 1000);
const power = 365 * 86400 / (unixSeconds - deployedAt);
const feeIn = new DecimalBigNumber(6900n, 2);
const feeOut = new DecimalBigNumber(6900n, 2);
const stakeRatio = new DecimalBigNumber(69000n, 3);
const feeInBig = new DecimalBigNumber((feeIn[chainId] ?? 0n), 5);
const feeOutBig = new DecimalBigNumber((feeOut[chainId] ?? 0n), 5);
const stakeRatioBig = new DecimalBigNumber((stakeRatio ?? 0n), 5);
const numerator = amountIn.mul(feeIn).add(amountOut.mul(feeOut));
const denominator = amountIn.mul(stakeRatio).sub(amountOut.mul(stakeRatio));
const numerator = amountIn.mul(feeInBig).add(amountOut.mul(feeOutBig));
const denominator = amountIn.mul(stakeRatioBig).sub(amountOut.mul(stakeRatioBig));
if (denominator?.toString() === "0") {
return 1;
let apyInner = Infinity;
if ((circulatingSupply?._value ?? 0n) === 0n) {
return { gatekeepedApy: apyInner, apyInner};
}
const value = epoch.distribute.div(circulatingSupply);
apyInner = 100 * (Math.pow(1 + parseFloat(value.toString()), 1095) - 1);
if (apyInner === 0) apyInner = Infinity;
if (!denominator?._value || denominator._value.isZero()) {
return { gatekeepedApy: apyInner, apyInner };
}
const result = Number(numerator.div(denominator).toString());
return Math.pow(1 + result, power);
const gatekeepedApy = Math.pow(1 + result, power) * 100;
return {
gatekeepedApy: apyInner + gatekeepedApy + (apyInner * gatekeepedApy) / 100,
apyInner,
}
}
export const useCurrentIndex = (chainId) => {