use original coeff for tokenValue correction

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2026-03-01 19:58:36 +03:00
parent 83761d54ca
commit 98a6a5b5d2
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
7 changed files with 42 additions and 36 deletions

View File

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

View File

@ -9,7 +9,7 @@ import { TokenAllowanceGuard } from "../../components/TokenAllowanceGuard/TokenA
import { SecondaryButton } from "../../components/Button";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { formatNumber, formatCurrency } from "../../helpers";
import { formatNumber, formatCurrency, bigIntSqrt } from "../../helpers";
import { useBalance, useTotalSupply } from "../../hooks/tokens";
import { useUniswapV2Pair, useUniswapV2PairReserves, addLiquidity } from "../../hooks/uniswapv2";
@ -75,34 +75,6 @@ const PoolContainer = ({
const setMaxTop = () => setAmountTop(balanceTop.toString());
const setMaxBottom = () => setAmountBottom(balanceBottom.toString());
const bigIntSqrt = (n) => {
if (n < 0n) {
throw new Error("Cannot compute the square root of a negative number.");
}
if (n < 2n) {
return n; // The square root of 0 or 1 is the number itself
}
let low = 0n;
let high = n;
let mid;
while (low <= high) {
mid = (low + high) / 2n;
const midSquared = mid * mid;
if (midSquared === n) {
return mid; // Found the exact square root
} else if (midSquared < n) {
low = mid + 1n; // Move to the right half
} else {
high = mid - 1n; // Move to the left half
}
}
return high; // The integer part of the square root
}
const estimatedAmountOut = useMemo(() => {
const pairReserves0 = addressTop.toUpperCase() === tokenAddresses.token0.toUpperCase()
? pairReserves.reserve0

View File

@ -198,7 +198,7 @@ const ProposalDetails = ({ chainId, address, connect, config }) => {
return (
<Box>
<PageTitle
name={`GBP-${id.slice(-5)}`}
name={`GDP-${id.slice(-5)}`}
subtitle={
<Typography component="span">
{`Cast $${ghstSymbol} to shape this proposal's outcome`}

View File

@ -52,3 +52,16 @@ export const timeConverter = (time, max = 7200, maxText = "long ago") => {
return `${mins}m ${secs < 10 ? '0' : ''}${secs}s`;
}
}
export const bigIntSqrt = (n) => {
if (n < 0n) return 0n;
if (n < 2n) return n;
let x = n / 2n + 1n;
let y = (x + n / x) / 2n;
while (y < x) {
x = y;
y = (x + n / x) / 2n;
}
return x;
}

View File

@ -13,14 +13,16 @@ import { abi as BondAbi } from "../../abi/GhostBondDepository.json";
import { abi as TreasuryAbi } from "../../abi/GhostTreasury.json";
import { abi as BondingCalculatorAbi } from "../../abi/GhostBondingCalculator.json";
import { useFtsoPrice } from "../prices";
import { useReservePrice } from "../prices";
import { useOrinalCoefficient } from "../treasury";
import { useTokenSymbol, useTokenSymbols } from "../tokens";
import { getTokenAddress, getTokenIcons, getBondNameDisplayName, getTokenPurchaseLink } from "../helpers";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { shorten } from "../../helpers";
export const useLiveBonds = (chainId) => {
const baseTokenPerUsd = useFtsoPrice(chainId);
const baseTokenPerUsd = useReservePrice(chainId);
const originalCoefficient = useOrinalCoefficient(chainId);
const { data: liveIndexesRaw, refetch } = useReadContract({
abi: BondAbi,
@ -126,7 +128,11 @@ export const useLiveBonds = (chainId) => {
const quoteTokenSymbol = quoteTokenSymbols?.at(index).result ? quoteTokenSymbols.at(index).result : "";
const quoteTokenPerBaseToken = new DecimalBigNumber(marketPrice, 9);
const priceInUsd = quoteTokenPerUsd.mul(quoteTokenPerBaseToken).mul(markdown);
let priceInUsd = baseTokenPerUsd.mul(quoteTokenPerBaseToken);
if (Number(markdown?.toString() ?? "1") !== 1) {
priceInUsd = priceInUsd.div(originalCoefficient)
}
const discount = baseTokenPerUsd._value > 0n
? baseTokenPerUsd.sub(priceInUsd).div(baseTokenPerUsd)
: new DecimalBigNumber("0", baseTokenPerUsd._decimals);

View File

@ -116,7 +116,7 @@ export const useReservePrice = (chainId) => {
.then(response => {
if ('data' in response) {
const coinPrice = Number(response?.data?.amount ?? 0.0);
const priceInWei = Math.floor(coinPrice * 1e18 / 0.99);
const priceInWei = Math.floor(coinPrice * 1e18);
setReservePrice(new DecimalBigNumber(BigInt(priceInWei), 18));
} else if ('price' in response) {
const coinPrice = Number(response?.price ?? 0.0);

View File

@ -5,6 +5,7 @@ import { abi as TreasuryAbi } from "../../abi/GhostTreasury.json";
import { useReservePrice } from "../prices/index";
import { bigIntSqrt } from "../../helpers";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { getTokenAddress } from "../helpers";
@ -40,6 +41,9 @@ export const useTotalReserves = (chainId) => {
export const useLpValuation = (chainId, pairAddress, pairSupply) => {
const convertedPairAddress = getTokenAddress(chainId, pairAddress);
const originalCoefficient = useOrinalCoefficient(chainId);
const reservePrice = useReservePrice(chainId);
const { data: valuationRaw } = useReadContract({
abi: TreasuryAbi,
address: DAO_TREASURY_ADDRESSES[chainId],
@ -52,7 +56,18 @@ export const useLpValuation = (chainId, pairAddress, pairSupply) => {
chainId,
});
const valuationPrepared = valuationRaw ? valuationRaw : 0n;
const sqrtReservePrice = reservePrice?._value
? bigIntSqrt(reservePrice._value)
: 0n;
const sqrtOriginalCoefficient = originalCoefficient?._value
? bigIntSqrt(originalCoefficient._value)
: 1n;
const valuationPrepared = valuationRaw
? valuationRaw * sqrtReservePrice / sqrtOriginalCoefficient
: 0n;
const valuation = new DecimalBigNumber(valuationPrepared, 9);
return valuation;