Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release] - RBS Market Check Improvements #3146

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/views/Range/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const DetermineRangePrice = (bidOrAsk: "bid" | "ask") => {
const { data: lowerBondMarket } = useBondV3({ id: rangeData.low.market.toString(), isInverseBond: true });

const {
data = { price: 0, contract: "swap" },
data = { price: 0, contract: "swap", activeBondMarket: false },
isFetched,
isLoading,
} = useQuery(
Expand Down Expand Up @@ -266,6 +266,7 @@ export const DetermineRangePrice = (bidOrAsk: "bid" | "ask") => {
bidOrAsk === "ask"
? Number(upperBondMarket?.discount.toString())
: Number(lowerBondMarket?.discount.toString()),
activeBondMarket,
};
} else {
return {
Expand Down
20 changes: 11 additions & 9 deletions src/views/Range/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,10 @@ export const Range = () => {
addresses: [DAI_ADDRESSES[1], OHM_ADDRESSES[1]],
});
const { data: nextBeat } = RangeNextBeat();
//format date for display in local time
const nextBeatDateString = nextBeat && nextBeat.toLocaleString();

const daiPriceUSD = currentMarketPrices?.[`ethereum:${DAI_ADDRESSES[1]}`].price;
const ohmPriceUSD = currentMarketPrices?.[`ethereum:${OHM_ADDRESSES[1]}`].price;
const marketOhmPriceDAI = daiPriceUSD && ohmPriceUSD ? ohmPriceUSD / daiPriceUSD : 0;

console;
const marketOhmPriceDAI = daiPriceUSD && ohmPriceUSD ? ohmPriceUSD / daiPriceUSD : undefined;

const maxString = sellActive ? `Max You Can Sell` : `Max You Can Buy`;

Expand Down Expand Up @@ -105,8 +101,12 @@ export const Range = () => {
}
}, [sellActive]);

// Set sell active if market price is defined and is below lower cushion OR if there is a active lower bond market.
useEffect(() => {
if (marketOhmPriceDAI < parseBigNumber(rangeData.low.cushion.price, 18)) {
if (
(marketOhmPriceDAI && marketOhmPriceDAI < parseBigNumber(rangeData.low.cushion.price, 18)) ||
bidPrice.activeBondMarket
) {
setSellActive(true);
}
}, [rangeData.low.cushion.price, marketOhmPriceDAI]);
Expand Down Expand Up @@ -137,7 +137,8 @@ export const Range = () => {

const swapPriceFormatted = formatNumber(swapPrice, 2);

const discount = (marketOhmPriceDAI - swapPrice) / (sellActive ? -marketOhmPriceDAI : marketOhmPriceDAI);
const discount =
(marketOhmPriceDAI && (marketOhmPriceDAI - swapPrice) / (sellActive ? -marketOhmPriceDAI : marketOhmPriceDAI)) || 0;

const hasPrice = (sellActive && askPrice.price) || (!sellActive && bidPrice.price) ? true : false;

Expand Down Expand Up @@ -175,8 +176,9 @@ export const Range = () => {
<>
<Metric
label="Market Price"
metric={`${formatNumber(marketOhmPriceDAI, 2)} DAI`}
metric={`${formatNumber(marketOhmPriceDAI || 0, 2)} DAI`}
tooltip="Market Price uses DefiLlama API, and is also used when calculating premium/discount on RBS"
isLoading={!marketOhmPriceDAI}
/>
<Grid container>
<Grid item xs={12} lg={6}>
Expand Down Expand Up @@ -253,7 +255,7 @@ export const Range = () => {
? "premium"
: "discount"}{" "}
of {formatNumber(Math.abs(discount) * 100, 2)}% relative to market price of{" "}
{formatNumber(marketOhmPriceDAI, 2)} {reserveSymbol}
{formatNumber(marketOhmPriceDAI || 0, 2)} {reserveSymbol}
</InfoNotification>
</Box>
<div data-testid="max-row">
Expand Down
Loading