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

feat/Show NDOL redemption rate and give warning when low #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions src/components/Exchange/ConfirmationBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default function ConfirmationBox(props) {
isSubmitting,
fromUsdMin,
toUsdMax,
averageRedemptionRate,
warnLowRedemptionRate,
} = props;

const [savedSlippageAmount] = useLocalStorageSerializeKey(
Expand Down Expand Up @@ -391,6 +393,12 @@ export default function ConfirmationBox(props) {
{renderMain()}
{renderTriggerRatioWarning()}
{renderSpreadWarning()}
{warnLowRedemptionRate && (
<div className="Confirmation-box-warning">
WARNING: NDOL average redemption rate is currently low! Slippage is greater than 10%.
By design, staking NDOL helps combat impermanent loss over time.
</div>
)}
{(isSwap || isBurn || isMint) && (
<React.Fragment>
<ExchangeInfoRow label="Minimum received">
Expand Down Expand Up @@ -445,6 +453,17 @@ export default function ConfirmationBox(props) {
<div className="align-right">{toTokenUsd} USD</div>
</div>
)}
{averageRedemptionRate && (
<div className="Exchange-info-row">
<div className="Exchange-info-label">
NDOL Average Redemption Rate
</div>
<div className="align-right">
{formatAmount(averageRedemptionRate, USD_DECIMALS, 2, true)}{" "}
USD
</div>
</div>
)}
</div>
)}
{(isLong || isShort) && (
Expand Down
32 changes: 32 additions & 0 deletions src/components/Exchange/MintBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ const MintBox = (props) => {
swapOption === "Burn"
? tokens.filter((token) => token.symbol !== "NDOL")
: tokens;
const collateralTokens = tokens.filter((token) =>
(token.symbol !== "NDOL") &&
(token.symbol !== "WETH") &&
(!token?.symbol?.toLowerCase()?.includes("lp")));

const orderBookAddress = getContract(CHAIN_ID, "OrderBook");
const nativeTokenAddress = getContract(CHAIN_ID, "NATIVE_TOKEN");
Expand Down Expand Up @@ -456,6 +460,19 @@ const MintBox = (props) => {
// console.log("redemptionValue?.toString()");
// console.log(redemptionValue?.toString());

// Get average rate, check if redemption rate is less than 90%
let averageRedemptionRate = bigNumberify(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this all ok? BigNumber got me trippin 😵‍💫

for (let i = 0; i < collateralTokens.length; i++) {
const tokenInfo = getTokenInfo(infoTokens, collateralTokens[i]?.address);
const redemptionVal = tokenInfo.redemptionAmount?.mul(tokenInfo.maxPrice)?.div(expandDecimals(1, tokenInfo.decimals));
if (redemptionVal) averageRedemptionRate = averageRedemptionRate.add(redemptionVal);
}
averageRedemptionRate = averageRedemptionRate.div(bigNumberify(3));
let warnLowRedemptionRate = ((averageRedemptionRate) &&
(!averageRedemptionRate.eq(bigNumberify(0)) &&
(averageRedemptionRate.gt(bigNumberify(800000000000000000000000000000))))) ?
true : false

useEffect(() => {
if (
fromTokenAddress === prevFromTokenAddress &&
Expand Down Expand Up @@ -723,6 +740,9 @@ const MintBox = (props) => {
if (toUsdMax.lt(fromUsdMin.mul(95).div(100))) {
return "High Slippage, Mint Anyway";
}
if (warnLowRedemptionRate) {
return "NDOL Redemption Rate is Low, Mint Anyway"
}
return "Mint";
}

Expand Down Expand Up @@ -1704,6 +1724,16 @@ const MintBox = (props) => {
USD
</div>
</div>
{isMint && (
<div className="Exchange-info-row">
<div className="Exchange-info-label">NDOL Average Redemption Rate</div>
<div className="align-right">
{averageRedemptionRate &&
formatAmount(averageRedemptionRate, USD_DECIMALS, 2, true)}{" "}
USD
</div>
</div>
)}
{!isMarketOrder && (
<ExchangeInfoRow label="Price">
{getExchangeRateDisplay(
Expand Down Expand Up @@ -1771,6 +1801,8 @@ const MintBox = (props) => {
isPendingConfirmation={isPendingConfirmation}
fromUsdMin={fromUsdMin}
toUsdMax={toUsdMax}
averageRedemptionRate={averageRedemptionRate}
warnLowRedemptionRate={warnLowRedemptionRate}
/>
)}
</div>
Expand Down