Skip to content

Commit

Permalink
fix reward predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
F-OBrien committed Jan 29, 2024
1 parent e74d7cc commit bf132c4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions components/charts/operatorCharts/OperatorsTokensAssigned.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const OperatorsTokensAssigned = () => {
const divisor = 10 ** tokenDecimals;
const {
eraInfo: { currentEra },
stakingConstants: { fixedYearlyReward, maxVariableInflationTotalIssuance },
stakingConstants: { fixedYearlyReward },
} = useStakingContext();

const [chartData, setChartData] = useState<ChartData<'bar' | 'line'>>();
Expand Down Expand Up @@ -176,22 +176,19 @@ const OperatorsTokensAssigned = () => {

const stakedRatio = currentEraTotalStaked.data.toNumber() / totalIssuance?.toNumber();

let inflation;
let calculatedInflation;

if (totalIssuance?.toNumber() < maxVariableInflationTotalIssuance.toNumber()) {
if (stakedRatio <= xIdeal) {
inflation = iZero + (iIdeal - iZero) * (stakedRatio / xIdeal);
} else {
inflation = iZero + (iIdeal - iZero) * 2 ** ((xIdeal - stakedRatio) / decay);
}
if (stakedRatio <= xIdeal) {
calculatedInflation = iZero + (iIdeal - iZero) * (stakedRatio / xIdeal);
} else {
inflation = fixedYearlyReward.toNumber() / totalIssuance?.toNumber();
calculatedInflation = iZero + (iIdeal - iZero) * 2 ** ((xIdeal - stakedRatio) / decay);
}

const maxInflation = fixedYearlyReward.toNumber() / totalIssuance?.toNumber();
const inflation = Math.min(maxInflation, calculatedInflation);
const annualTotalReward = (inflation * totalIssuance?.toNumber()) / divisor;

return annualTotalReward;
}, [totalIssuance, currentEraTotalStaked.data, maxVariableInflationTotalIssuance, divisor, fixedYearlyReward]);
}, [currentEraTotalStaked.data, divisor, fixedYearlyReward, totalIssuance]);

// Set `dataIsFetching` to true while any of the queries are fetching.
const dataIsFetching = useMemo(() => {
Expand Down

0 comments on commit bf132c4

Please sign in to comment.