Compare commits
3 Commits
ab8ca19a69
...
fb0f39e3e6
Author | SHA1 | Date | |
---|---|---|---|
fb0f39e3e6 | |||
a52372dbe5 | |||
bb98a8aea7 |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.26",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
@ -18,7 +18,7 @@ import NotFound from "../NotFound/NotFound";
|
||||
|
||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||
import { NetworkId } from "../../constants";
|
||||
import { formatNumber } from "../../helpers";
|
||||
import { formatCurrency } from "../../helpers";
|
||||
|
||||
import { useLiveBonds } from "../../hooks/bonds";
|
||||
import { useFtsoPrice } from "../../hooks/prices";
|
||||
@ -123,17 +123,16 @@ export const BondModal = ({ bond, chainId, address, connect }) => {
|
||||
label="Market Price"
|
||||
metric={
|
||||
<TokenPrice
|
||||
chainId={chainId}
|
||||
token={bond.baseToken}
|
||||
baseSymbol={bond.baseToken.name}
|
||||
quoteSymbol={bond.quoteToken.name}
|
||||
symbol={bond.quoteToken.name}
|
||||
priceInUsd={bond.price.marketPriceInUsd}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
/>
|
||||
<Metric
|
||||
label="Discount"
|
||||
metric={<BondDiscount discount={bond.discount} textOnly />}
|
||||
/>
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box width="100%" mt="24px">
|
||||
@ -155,21 +154,11 @@ export const BondModal = ({ bond, chainId, address, connect }) => {
|
||||
|
||||
const TokenPrice = ({
|
||||
token,
|
||||
chainId,
|
||||
quoteSymbol,
|
||||
baseSymbol,
|
||||
symbol,
|
||||
priceInUsd
|
||||
}) => {
|
||||
const priceToken = useFtsoPrice(chainId);
|
||||
const sameToken = quoteSymbol === baseSymbol;
|
||||
|
||||
const price = sameToken
|
||||
? formatNumber(1, 2)
|
||||
: `${formatNumber(priceToken, 2)}`;
|
||||
|
||||
return price ? (
|
||||
<>
|
||||
{price} {quoteSymbol}
|
||||
</>
|
||||
return priceInUsd ? (
|
||||
<>{formatCurrency(priceInUsd, 2, symbol)}</>
|
||||
) : (
|
||||
<Skeleton width={60} />
|
||||
);
|
||||
|
@ -5,7 +5,7 @@ import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber";
|
||||
|
||||
const BondDiscount = ({ discount, textOnly }) => {
|
||||
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 ? (
|
||||
<Box
|
||||
@ -17,7 +17,7 @@ const BondDiscount = ({ discount, textOnly }) => {
|
||||
</Box>
|
||||
) : (
|
||||
<Chip
|
||||
label={`${formatNumber(Number(discount.mul(new DecimalBigNumber("100")).toString()), 2)}%`}
|
||||
label={discountString}
|
||||
template={new DecimalBigNumber("0").gt(discount) ? "error" : "success"}
|
||||
/>
|
||||
);
|
||||
|
@ -124,7 +124,7 @@ const BondInputArea = ({
|
||||
|
||||
<TokenAllowanceGuard
|
||||
spendAmount={parsedAmount}
|
||||
tokenName={bond.quoteToken.name}
|
||||
tokenName={bond.quoteToken.quoteTokenAddress}
|
||||
owner={address}
|
||||
spender={BOND_DEPOSITORY_ADDRESSES[chainId]}
|
||||
decimals={parsedAmount._decimals}
|
||||
@ -186,7 +186,7 @@ const BondInputArea = ({
|
||||
tooltip={`The maximum quantity of payout token offered via bonds at this moment in time`}
|
||||
balance={
|
||||
<span>
|
||||
{bond.baseToken === bond.quoteToken
|
||||
{bond.baseToken.tokenAddress.toUpperCase() === bond.quoteToken.quoteTokenAddress.toUpperCase()
|
||||
? `${formatCurrency(baseTokenString, formatDecimals, "FTSO")}`
|
||||
: `${formatCurrency(baseTokenString, formatDecimals, "FTSO")} (≈${formatCurrency(quoteTokenString, formatDecimals, "GHST")})`}
|
||||
</span>
|
||||
|
@ -60,14 +60,11 @@ const PoolContainer = ({
|
||||
} = useTotalSupply(chainId, pairAddress);
|
||||
const {
|
||||
reserves: pairReserves,
|
||||
tokens: tokenAddresses,
|
||||
refetch: pairReservesRefetch,
|
||||
} = useUniswapV2PairReserves(
|
||||
chainId,
|
||||
pairAddress,
|
||||
balanceTop._decimals,
|
||||
balanceBottom._decimals,
|
||||
tokenNameTop,
|
||||
tokenNameBottom,
|
||||
);
|
||||
|
||||
const onSwap = () => {
|
||||
@ -110,19 +107,27 @@ const PoolContainer = ({
|
||||
}
|
||||
|
||||
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 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 amountToAddB = new DecimalBigNumber(value1._value.toBigInt(), balanceBottom._decimals);
|
||||
|
||||
if (
|
||||
pairReserves.reserve0.gt(zero) &&
|
||||
pairReserves.reserve1.gt(zero) &&
|
||||
pairReserves0.gt(zero) &&
|
||||
pairReserves1.gt(zero) &&
|
||||
lpTotalSupply.gt(new DecimalBigNumber(0n, 0))
|
||||
) {
|
||||
const lpTokensFromA = (amountToAddA.mul(lpTotalSupply).div(pairReserves.reserve0));
|
||||
const lpTokensFromB = (amountToAddB.mul(lpTotalSupply).div(pairReserves.reserve1));
|
||||
const lpTokensFromA = (amountToAddA.mul(lpTotalSupply).div(pairReserves0));
|
||||
const lpTokensFromB = (amountToAddB.mul(lpTotalSupply).div(pairReserves1));
|
||||
const lpTokensToMint = lpTokensFromA.gt(lpTokensFromB) ? lpTokensFromB : lpTokensFromA;
|
||||
return lpTokensToMint;
|
||||
} else {
|
||||
|
@ -9,7 +9,7 @@ import { abi as BondAbi } from "../../abi/GhostBondDepository.json";
|
||||
import { abi as TreasuryAbi } from "../../abi/GhostTreasury.json";
|
||||
|
||||
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 { shorten } from "../../helpers";
|
||||
|
||||
@ -100,7 +100,9 @@ export const useLiveBonds = (chainId) => {
|
||||
|
||||
const quoteTokenPerBaseToken = new DecimalBigNumber(marketPrice, 9);
|
||||
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
|
||||
? new DecimalBigNumber(marketPrice > 0n ? marketCapacity / marketPrice : 0n, 9)
|
||||
@ -124,7 +126,8 @@ export const useLiveBonds = (chainId) => {
|
||||
baseToken: {
|
||||
name: "FTSO",
|
||||
purchaseUrl: getTokenPurchaseLink(chainId, ""),
|
||||
icons: ["FTSO"]
|
||||
icons: ["FTSO"],
|
||||
tokenAddress: getTokenAddress(chainId, "FTSO")
|
||||
},
|
||||
quoteToken: {
|
||||
name: getTokenName(chainId, quoteTokenAddress),
|
||||
@ -140,6 +143,7 @@ export const useLiveBonds = (chainId) => {
|
||||
price: {
|
||||
inUsd: priceInUsd,
|
||||
inBaseToken: quoteTokenPerBaseToken,
|
||||
marketPriceInUsd: quoteTokenPerUsd
|
||||
},
|
||||
capacity: {
|
||||
inBaseToken: capacityInBaseToken,
|
||||
|
Loading…
Reference in New Issue
Block a user