Skip to content

Commit

Permalink
Merge pull request #41 from dmccartney/daniel-estimate-interval
Browse files Browse the repository at this point in the history
feat: estimate the remainder of the interval
  • Loading branch information
dmccartney authored May 20, 2024
2 parents a12a570 + ab29670 commit 72b1631
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/web-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
- uses: actions/checkout@v2
- run: npm install
working-directory: ./web
- run: npm run pretty:check
working-directory: ./web
- run: npm run build
working-directory: ./web
env:
Expand Down
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"clean": "rm -rf build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"pretty": "npx prettier '**/*.js' --write"
"pretty": "npx prettier '**/*.js' --write",
"pretty:check": "npx prettier '**/*.js' --check"
},
"eslintConfig": {
"extends": [
Expand Down
8 changes: 4 additions & 4 deletions web/src/components/NodePeriodicRewardsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const INTERVAL_COLS = [
sx={{ cursor: "help" }}
title={
type === "ongoing"
? "This is the node’s share of the current smoothing pool balance. It will continue to grow until the end of the interval."
? `This estimates the node’s share of the smoothing pool. It will fluctuate until the end of the interval.`
: "This is the node’s share of the smoothing pool for the interval."
}
>
Expand All @@ -105,7 +105,7 @@ const INTERVAL_COLS = [
variant="inherit"
color="text.secondary"
>
≥
≈
</Typography>
)}
<CurrencyValue
Expand Down Expand Up @@ -135,7 +135,7 @@ const INTERVAL_COLS = [
sx={{ cursor: "help" }}
title={
type === "ongoing"
? "This is the node’s share of RPL inflation for the interval. It will continue to grow until the end of the interval. At the end of the interval, if the node’s RPL stake is below 10% of borrowed ETH, then they receive no inflation RPL and this value becomes zero."
? "This estimates the node’s share of RPL inflation for the interval. It will fluctuate until the end of the interval. At the end of the interval, if the node’s RPL stake is below 10% of borrowed ETH, then they receive no inflation RPL and this value becomes zero."
: "This is the node’s share of RPL inflation for the interval."
}
>
Expand All @@ -146,7 +146,7 @@ const INTERVAL_COLS = [
variant="inherit"
color="text.secondary"
>
&ge;
&asymp;
</Typography>
)}
<CurrencyValue size="small" currency="rpl" value={value} />
Expand Down
22 changes: 21 additions & 1 deletion web/src/hooks/useNodeOngoingRewardSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,48 @@ import useOngoingRewardSnapshot from "./useOngoingRewardSnapshot";
import useFinalizedRewardSnapshots from "./useFinalizedRewardSnapshots";
import _ from "lodash";
import moment from "moment";
import { ethers } from "ethers";

export default function useNodeOngoingRewardSnapshot({ nodeAddress }) {
let rewardIndex = useOngoingRewardIndex();
let data = useOngoingRewardSnapshot({ rewardIndex });
let finalized = useFinalizedRewardSnapshots({});
let last = _.maxBy(finalized, "rewardIndex");
let endTime = null;
let percentDone = 1.0;
if (last) {
endTime =
moment(last.endTime * 1000)
.add(28, "days")
.valueOf() / 1000;
let startTime = moment(last.endTime * 1000).valueOf() / 1000;
let now = moment().valueOf() / 1000;
percentDone =
now > endTime ? 1.0 : (now - startTime) / (endTime - startTime);
}
if (!rewardIndex) {
return null;
}
let nodeData = (data?.nodeRewards || {})[nodeAddress.toLowerCase()] || {};
if (percentDone < 1.0) {
let predict = (bn) => bn.mul(100000).div(Math.round(100000 * percentDone));
nodeData = {
...nodeData,
collateralRpl: predict(
ethers.BigNumber.from(nodeData.collateralRpl || "0")
).toString(),
smoothingPoolEth: predict(
ethers.BigNumber.from(nodeData.smoothingPoolEth || "0")
).toString(),
};
}
return {
type: "ongoing",
percentDone,
rewardIndex,
endTime,
nodeAddress,
isClaimed: false,
...((data?.nodeRewards || {})[nodeAddress.toLowerCase()] || {}),
...nodeData,
};
}

0 comments on commit 72b1631

Please sign in to comment.