Skip to content

Commit

Permalink
Merge pull request #3146 from OlympusDAO/develop
Browse files Browse the repository at this point in the history
[Release] - RBS Market Check Improvements
  • Loading branch information
brightiron committed Jan 31, 2024
2 parents a127cbb + 9ea1129 commit a9c24b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
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

0 comments on commit a9c24b8

Please sign in to comment.