From 4b8c86446b6ff5dda911d9fb36175d069d0c76fb Mon Sep 17 00:00:00 2001 From: Daniel McCartney Date: Thu, 24 Oct 2024 01:14:04 -0700 Subject: [PATCH] feat: cleanup negative more in NS and describe deposits required --- web/src/hooks/useRplEthPrice.js | 4 +- web/src/pages/NodeSetPage.js | 268 +++++++++++++++++++++++++------- 2 files changed, 218 insertions(+), 54 deletions(-) diff --git a/web/src/hooks/useRplEthPrice.js b/web/src/hooks/useRplEthPrice.js index a705636..b595aff 100644 --- a/web/src/hooks/useRplEthPrice.js +++ b/web/src/hooks/useRplEthPrice.js @@ -1,7 +1,7 @@ import useK from "./useK"; import { ethers } from "ethers"; -export default function useRplEthPrice() { +export default function useRplEthPrice(defaultValue = ethers.constants.Zero) { let { data: rplEthPrice } = useK.RocketNetworkPrices.Read.getRPLPrice(); - return rplEthPrice || ethers.constants.Zero; + return rplEthPrice || defaultValue; } diff --git a/web/src/pages/NodeSetPage.js b/web/src/pages/NodeSetPage.js index 218e101..5cb5e7c 100644 --- a/web/src/pages/NodeSetPage.js +++ b/web/src/pages/NodeSetPage.js @@ -8,8 +8,10 @@ import { CardContent, CardHeader, Chip, + CircularProgress, Divider, Grid, + Paper, Stack, Tooltip, Typography, @@ -499,31 +501,36 @@ function NodeSetWalletChip({ walletAddress }) { ); } +const oneEth = ethers.utils.parseEther("1"); function NodeSetMiniPoolsColumn() { let [isShowingAll, setShowingAll] = useState(false); - let rplEthPrice = useRplEthPrice(); + let rplEthPrice = useRplEthPrice(ethers.utils.parseEther(".004")); // default until loaded const { data: superNodeDetails } = useNodeDetails({ nodeAddress: contracts.SuperNodeAccount.address, }); let { data: minimumStakeRatio } = useK.OperatorDistributor.Read.minimumStakeRatio(); - + minimumStakeRatio = minimumStakeRatio || oneEth; let { rplStake } = superNodeDetails || { rplStake: ethers.constants.Zero, }; let rplStakedInEth = rplStake - ?.mul(rplEthPrice) - .div(ethers.utils.parseEther("1")); - let { data: minipoolsInOrder } = useK.SuperNodeAccount.Find.MinipoolCreated({ - args: [null, null], - from: 0, - to: "latest", - }); + .mul(rplEthPrice) + .div(oneEth); + let { isLoading, data: minipoolsInOrder } = + useK.SuperNodeAccount.Find.MinipoolCreated({ + args: [null, null], + from: 0, + to: "latest", + }); let minipools = _.reverse(_.clone(minipoolsInOrder || [])); + + // TODO: detect no-longer active minipools let activeMinipools = minipools || []; + let maxMinipoolCountByRpl = rplStakedInEth - ?.mul(ethers.utils.parseEther("1")) - .div(minimumStakeRatio || ethers.utils.parseEther("1")) + .mul(oneEth) + .div(minimumStakeRatio) .div(ethers.utils.parseEther("24")) .toNumber(); let { data: xREthBalance } = useBalance({ @@ -539,6 +546,33 @@ function NodeSetMiniPoolsColumn() { .div(ethers.utils.parseEther("24")) .toNumber(); let moreMinipoolCountByRpl = maxMinipoolCountByRpl - activeMinipools.length; + let rplPerMinipool = ethers.utils + .parseEther("24") + .mul(minimumStakeRatio) + .div(rplEthPrice); + let moreRplRequiredForAnother = + moreMinipoolCountByRpl > 0 + ? ethers.constants.Zero + : ethers.utils + .parseEther("24") + .mul(activeMinipools.length + 1) + .mul(minimumStakeRatio) + .div(ethers.utils.parseEther("1")) + .sub(rplStakedInEth) + .mul(ethers.utils.parseEther("1")) + .div(rplEthPrice); + let moreXREthRequiredForAnother = + moreMinipoolCountByXREth > 0 + ? ethers.constants.Zero + : ethers.utils + .parseEther("8") + .sub(xREthBalance?.value || ethers.constants.Zero); + let moreREthRequiredForAnother = + moreMinipoolCountByREth > 0 + ? ethers.constants.Zero + : ethers.utils + .parseEther("24") + .sub(rEthBalance?.value || ethers.constants.Zero); let moreMinipoolCount = Math.min( moreMinipoolCountByXREth, moreMinipoolCountByREth, @@ -682,9 +716,17 @@ function NodeSetMiniPoolsColumn() { sx={{ cursor: "inherit" }} component="span" size="small" - label={Number( - activeMinipools.length - ).toLocaleString()} + label={ + isLoading ? ( + + ) : ( + Number(activeMinipools.length).toLocaleString() + ) + } /> + ) : ( + operators.length + ) + } /> - + more from available deposits @@ -881,7 +937,6 @@ function NodeSetMiniPoolsColumn() { - + - + @@ -947,7 +1006,6 @@ function NodeSetMiniPoolsColumn() { - + - + @@ -1015,7 +1075,7 @@ function NodeSetMiniPoolsColumn() { - + - + - - - more @ - - - - % borrow limit - + + + + more @ + + + + % borrow limit + + + + +      ≈ + + + + {isLoading || moreMinipoolCount > 0 || ( + + + + deposits required for the next minipool + + + {moreRplRequiredForAnother.gt(0) && ( + + + + from + + + + )} + {moreXREthRequiredForAnother.gt(0) && ( + + + + from + + + + )} + {moreREthRequiredForAnother.gt(0) && ( + + + + from + + + rETH + + + )} + + + + )}