Compare commits

...

3 Commits

Author SHA1 Message Date
fb0f39e3e6
align values for the bond discout object
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-05-07 17:29:32 +03:00
a52372dbe5
use quote token address directly during LP bond purchase and minor fixes for the price output
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-05-07 17:17:54 +03:00
bb98a8aea7
fix for the estimated output amount of LP tokens during addLiquidity
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-05-07 16:14:16 +03:00
6 changed files with 35 additions and 37 deletions

View File

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

View File

@ -18,7 +18,7 @@ import NotFound from "../NotFound/NotFound";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { NetworkId } from "../../constants"; import { NetworkId } from "../../constants";
import { formatNumber } from "../../helpers"; import { formatCurrency } from "../../helpers";
import { useLiveBonds } from "../../hooks/bonds"; import { useLiveBonds } from "../../hooks/bonds";
import { useFtsoPrice } from "../../hooks/prices"; import { useFtsoPrice } from "../../hooks/prices";
@ -123,10 +123,9 @@ export const BondModal = ({ bond, chainId, address, connect }) => {
label="Market Price" label="Market Price"
metric={ metric={
<TokenPrice <TokenPrice
chainId={chainId}
token={bond.baseToken} token={bond.baseToken}
baseSymbol={bond.baseToken.name} symbol={bond.quoteToken.name}
quoteSymbol={bond.quoteToken.name} priceInUsd={bond.price.marketPriceInUsd}
/> />
} }
/> />
@ -155,21 +154,11 @@ export const BondModal = ({ bond, chainId, address, connect }) => {
const TokenPrice = ({ const TokenPrice = ({
token, token,
chainId, symbol,
quoteSymbol, priceInUsd
baseSymbol,
}) => { }) => {
const priceToken = useFtsoPrice(chainId); return priceInUsd ? (
const sameToken = quoteSymbol === baseSymbol; <>{formatCurrency(priceInUsd, 2, symbol)}</>
const price = sameToken
? formatNumber(1, 2)
: `${formatNumber(priceToken, 2)}`;
return price ? (
<>
{price} {quoteSymbol}
</>
) : ( ) : (
<Skeleton width={60} /> <Skeleton width={60} />
); );

View File

@ -5,7 +5,7 @@ import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber";
const BondDiscount = ({ discount, textOnly }) => { const BondDiscount = ({ discount, textOnly }) => {
const theme = useTheme(); const theme = useTheme();
const discountString = `${formatNumber(Number(discount.mul(new DecimalBigNumber("100").toString())), 2)}%`; const discountString = `${formatNumber(Number(discount.mul(new DecimalBigNumber("100")).toString()), 2)}%`;
return textOnly ? ( return textOnly ? (
<Box <Box
@ -17,7 +17,7 @@ const BondDiscount = ({ discount, textOnly }) => {
</Box> </Box>
) : ( ) : (
<Chip <Chip
label={`${formatNumber(Number(discount.mul(new DecimalBigNumber("100")).toString()), 2)}%`} label={discountString}
template={new DecimalBigNumber("0").gt(discount) ? "error" : "success"} template={new DecimalBigNumber("0").gt(discount) ? "error" : "success"}
/> />
); );

View File

@ -124,7 +124,7 @@ const BondInputArea = ({
<TokenAllowanceGuard <TokenAllowanceGuard
spendAmount={parsedAmount} spendAmount={parsedAmount}
tokenName={bond.quoteToken.name} tokenName={bond.quoteToken.quoteTokenAddress}
owner={address} owner={address}
spender={BOND_DEPOSITORY_ADDRESSES[chainId]} spender={BOND_DEPOSITORY_ADDRESSES[chainId]}
decimals={parsedAmount._decimals} decimals={parsedAmount._decimals}
@ -186,7 +186,7 @@ const BondInputArea = ({
tooltip={`The maximum quantity of payout token offered via bonds at this moment in time`} tooltip={`The maximum quantity of payout token offered via bonds at this moment in time`}
balance={ balance={
<span> <span>
{bond.baseToken === bond.quoteToken {bond.baseToken.tokenAddress.toUpperCase() === bond.quoteToken.quoteTokenAddress.toUpperCase()
? `${formatCurrency(baseTokenString, formatDecimals, "FTSO")}` ? `${formatCurrency(baseTokenString, formatDecimals, "FTSO")}`
: `${formatCurrency(baseTokenString, formatDecimals, "FTSO")} (≈${formatCurrency(quoteTokenString, formatDecimals, "GHST")})`} : `${formatCurrency(baseTokenString, formatDecimals, "FTSO")} (≈${formatCurrency(quoteTokenString, formatDecimals, "GHST")})`}
</span> </span>

View File

@ -60,14 +60,11 @@ const PoolContainer = ({
} = useTotalSupply(chainId, pairAddress); } = useTotalSupply(chainId, pairAddress);
const { const {
reserves: pairReserves, reserves: pairReserves,
tokens: tokenAddresses,
refetch: pairReservesRefetch, refetch: pairReservesRefetch,
} = useUniswapV2PairReserves( } = useUniswapV2PairReserves(
chainId, chainId,
pairAddress, pairAddress,
balanceTop._decimals,
balanceBottom._decimals,
tokenNameTop,
tokenNameBottom,
); );
const onSwap = () => { const onSwap = () => {
@ -110,19 +107,27 @@ const PoolContainer = ({
} }
const estimatedAmountOut = useMemo(() => { const estimatedAmountOut = useMemo(() => {
const pairReserves0 = addressTop.toUpperCase() === tokenAddresses.token0.toUpperCase()
? pairReserves.reserve0
: pairReserves.reserve1;
const pairReserves1 = addressBottom.toUpperCase() === tokenAddresses.token1.toUpperCase()
? pairReserves.reserve1
: pairReserves.reserve0;
const zero = new DecimalBigNumber(0n, 0); const zero = new DecimalBigNumber(0n, 0);
const value0 = new DecimalBigNumber(amountTop, balanceTop._decimals) const value0 = new DecimalBigNumber(amountTop, balanceTop._decimals)
const value1 = new DecimalBigNumber(amountBottom, balanceBottom._decimals) const value1 = new DecimalBigNumber(amountBottom, balanceBottom._decimals);
const amountToAddA = new DecimalBigNumber(value0._value.toBigInt(), balanceTop._decimals); const amountToAddA = new DecimalBigNumber(value0._value.toBigInt(), balanceTop._decimals);
const amountToAddB = new DecimalBigNumber(value1._value.toBigInt(), balanceBottom._decimals); const amountToAddB = new DecimalBigNumber(value1._value.toBigInt(), balanceBottom._decimals);
if ( if (
pairReserves.reserve0.gt(zero) && pairReserves0.gt(zero) &&
pairReserves.reserve1.gt(zero) && pairReserves1.gt(zero) &&
lpTotalSupply.gt(new DecimalBigNumber(0n, 0)) lpTotalSupply.gt(new DecimalBigNumber(0n, 0))
) { ) {
const lpTokensFromA = (amountToAddA.mul(lpTotalSupply).div(pairReserves.reserve0)); const lpTokensFromA = (amountToAddA.mul(lpTotalSupply).div(pairReserves0));
const lpTokensFromB = (amountToAddB.mul(lpTotalSupply).div(pairReserves.reserve1)); const lpTokensFromB = (amountToAddB.mul(lpTotalSupply).div(pairReserves1));
const lpTokensToMint = lpTokensFromA.gt(lpTokensFromB) ? lpTokensFromB : lpTokensFromA; const lpTokensToMint = lpTokensFromA.gt(lpTokensFromB) ? lpTokensFromB : lpTokensFromA;
return lpTokensToMint; return lpTokensToMint;
} else { } else {

View File

@ -9,7 +9,7 @@ import { abi as BondAbi } from "../../abi/GhostBondDepository.json";
import { abi as TreasuryAbi } from "../../abi/GhostTreasury.json"; import { abi as TreasuryAbi } from "../../abi/GhostTreasury.json";
import { useFtsoPrice } from "../prices"; import { useFtsoPrice } from "../prices";
import { getTokenIcons, getTokenName, getBondNameDisplayName, getTokenPurchaseLink } from "../helpers"; import { getTokenAddress, getTokenIcons, getTokenName, getBondNameDisplayName, getTokenPurchaseLink } from "../helpers";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { shorten } from "../../helpers"; import { shorten } from "../../helpers";
@ -100,7 +100,9 @@ export const useLiveBonds = (chainId) => {
const quoteTokenPerBaseToken = new DecimalBigNumber(marketPrice, 9); const quoteTokenPerBaseToken = new DecimalBigNumber(marketPrice, 9);
const priceInUsd = quoteTokenPerUsd.mul(quoteTokenPerBaseToken); const priceInUsd = quoteTokenPerUsd.mul(quoteTokenPerBaseToken);
const discount = baseTokenPerUsd.sub(priceInUsd).div(baseTokenPerUsd); const discount = quoteTokenPerUsd._value > 0n
? quoteTokenPerUsd.sub(priceInUsd).div(quoteTokenPerUsd)
: new DecimalBigNumber("0", quoteTokenDecimals);
const capacityInBaseToken = capacityInQuote const capacityInBaseToken = capacityInQuote
? new DecimalBigNumber(marketPrice > 0n ? marketCapacity / marketPrice : 0n, 9) ? new DecimalBigNumber(marketPrice > 0n ? marketCapacity / marketPrice : 0n, 9)
@ -124,7 +126,8 @@ export const useLiveBonds = (chainId) => {
baseToken: { baseToken: {
name: "FTSO", name: "FTSO",
purchaseUrl: getTokenPurchaseLink(chainId, ""), purchaseUrl: getTokenPurchaseLink(chainId, ""),
icons: ["FTSO"] icons: ["FTSO"],
tokenAddress: getTokenAddress(chainId, "FTSO")
}, },
quoteToken: { quoteToken: {
name: getTokenName(chainId, quoteTokenAddress), name: getTokenName(chainId, quoteTokenAddress),
@ -140,6 +143,7 @@ export const useLiveBonds = (chainId) => {
price: { price: {
inUsd: priceInUsd, inUsd: priceInUsd,
inBaseToken: quoteTokenPerBaseToken, inBaseToken: quoteTokenPerBaseToken,
marketPriceInUsd: quoteTokenPerUsd
}, },
capacity: { capacity: {
inBaseToken: capacityInBaseToken, inBaseToken: capacityInBaseToken,