From f68551043e09f760a0d243831b1a7e77660372dc Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Thu, 7 May 2026 21:04:10 +0300 Subject: [PATCH] final fix for the boosted apy Signed-off-by: Uncle Fatso --- package.json | 2 +- src/constants/gatekeeper.js | 30 ++++++++++++++++++++++++++++++ src/hooks/staking/index.js | 21 ++++++++++++++------- 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/constants/gatekeeper.js diff --git a/package.json b/package.json index fc1a469..aba55bc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.7.41", + "version": "0.7.42", "type": "module", "scripts": { "dev": "vite", diff --git a/src/constants/gatekeeper.js b/src/constants/gatekeeper.js new file mode 100644 index 0000000..a39d10f --- /dev/null +++ b/src/constants/gatekeeper.js @@ -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; diff --git a/src/hooks/staking/index.js b/src/hooks/staking/index.js index 8cea140..c021bb8 100644 --- a/src/hooks/staking/index.js +++ b/src/hooks/staking/index.js @@ -1,6 +1,7 @@ import { useReadContract } from "wagmi"; import toast from "react-hot-toast"; +import * 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"; @@ -23,18 +24,24 @@ export const useGatekeeperApy = (chainId) => { 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[chainId] ?? 0n), 5); - const numerator = amountIn.mul(feeIn).add(amountOut.mul(feeOut)); + const numerator = amountIn.mul(feeInBig).add(amountOut.mul(feeOutBig)); const denominator = amountIn.mul(stakeRatio).sub(amountOut.mul(stakeRatio)); let apyInner = Infinity; @@ -50,7 +57,7 @@ export const useGatekeeperApy = (chainId) => { return { gatekeepedApy: apyInner, apyInner }; } const result = Number(numerator.div(denominator).toString()); - const gatekeepedApy = Math.pow(1 + result, power); + const gatekeepedApy = Math.pow(1 + result, power) * 100; return { gatekeepedApy: apyInner + gatekeepedApy + (apyInner * gatekeepedApy) / 100,