From 82373536600945d58baa37a7762f5ca7cd48b4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Wed, 22 Nov 2023 16:53:50 +0100 Subject: [PATCH] fix: Wrap up Mana Calculator (#1345) --- .../iota2.0/core-concepts/mana-calculator.md | 41 ++++--- .../ManaCalculator/actions/calculateBPS.ts | 4 +- .../components/BlocksAllowance.tsx | 60 ---------- .../components/DelegatorSettings.tsx | 40 +++++++ .../components/ManaCalculator.tsx | 4 +- .../components/OtherParametersSection.tsx | 9 +- .../ManaCalculator/components/OutputForm.tsx | 112 ++++++++++++++---- .../ManaCalculator/components/RoleSection.tsx | 55 ++------- .../components/ValidatorSettings.tsx | 57 +++------ .../ManaCalculator/components/index.ts | 2 +- src/components/ManaCalculator/constants.ts | 8 +- .../ManaCalculator/enums/parameters.enum.ts | 1 + .../ManaCalculator/hooks/useManaState.ts | 31 ++--- .../ManaCalculator/hooks/useResults.ts | 52 ++++++-- .../hooks/useResultsWithUnit.ts | 2 - src/components/ManaCalculator/utils.ts | 3 +- 16 files changed, 249 insertions(+), 232 deletions(-) delete mode 100644 src/components/ManaCalculator/components/BlocksAllowance.tsx create mode 100644 src/components/ManaCalculator/components/DelegatorSettings.tsx diff --git a/docs/learn/protocols/iota2.0/core-concepts/mana-calculator.md b/docs/learn/protocols/iota2.0/core-concepts/mana-calculator.md index 441d8987aea..c47b57c4940 100644 --- a/docs/learn/protocols/iota2.0/core-concepts/mana-calculator.md +++ b/docs/learn/protocols/iota2.0/core-concepts/mana-calculator.md @@ -6,35 +6,42 @@ Mana is a reward resource generated by holding IOTA tokens. It is utilized for b Here, we introduce the Mana calculator: a tool to help you make decisions about the type of participation that will suit you best, to help you predict the Mana generation you’ll be granted, and to decide the number of IOTA tokens you should hold to guarantee your desired level of access in the future. -## How to use the Calculator: Step-by-step instructions +## How to use the Calculator: Simplified Step-by-step instructions -- **Choose your network:** This calculator works for both Shimmer and the future IOTA 2.0 network. Both networks will have their own type of Mana (IOTA Mana and Shimmer Mana), with their own parameters and, consequently, their own behavior. Be sure you select the correct scenario you want to simulate! +- **Network Configuration:** This calculator works for Shimmer and the future IOTA 2.0 network. Both networks will have their own type of Mana (IOTA Mana and Shimmer Mana), with their own parameters and, consequently, their own behavior. Be sure you select the correct scenario you want to simulate! -- **Choose your role:** Will you delegate to a validator, become a validator yourself, or just hold tokens? To be a validator, you must run a node and lock your tokens while performing validation services, which will give you higher rewards. If you want to delegate to a validator, your tokens will not be locked and you won’t need to run a node, but this will give you fewer rewards than validating. Finally, just holding tokens grants you a certain amount of Mana, which will be less than by validating or delegating. +- **Role Configuration:** Will you delegate to a validator, become a validator yourself, or just hold tokens? To be a validator, you must run a node and lock your tokens while performing validation services, giving you higher rewards. If you want to delegate to a validator, your tokens will not be locked and you won’t need to run a node, but this will give you fewer rewards than validating. Finally, just holding tokens grants you a certain amount of Mana, which will be less than by validating or delegating. Additionally, no matter which network and role you choose, your Mana generation will depend on how many available tokens you have. Pay attention to the units! The input should be done in IOTA or Shimmer (not microIota or Glow). -- **Input the number of tokens you own:** No matter which network and role you choose, your Mana generation will depend on how many available tokens you have. Pay attention to the units! The input should be done in IOTA or Shimmer (not microIota or Glow). +With above inputs, you can already estimate how much Mana you’ll be granted per epoch. But what does it mean in BPS? How many blocks per second does your Mana grant you? The answer depends on the size of your block and the network congestion levels. However, we can use a default block size, which will be enough for most applications, and assume particular congestion levels. This takes us to the last essential configuration step in this calculator: -With the inputs above, you can already estimate how much Mana you’ll be granted per epoch. But what does it mean in BPS? How many blocks per second does your Mana grant you? The answer depends on the size of your block and the network congestion levels. However, we can use a default block size, which will be enough for most applications, and assume certain levels of congestion. This takes us to the last step in this calculator: +- **Choose a congestion level:** Given a particular Mana generation per epoch, this can be translated into a number of blocks issued per second that depend on the congestion level. Choose one of the given congestion levels (low, stable, or extreme) to estimate the time until block issuance, which tells you in which periodicity you’ll be able to issue a block. + +By default, this calculator shows you the acquired Mana and Block Allowance you have granted by participating between epochs 1 and 10. +But you can also play with these values! +Inputting different values for `Initial Epoch` and `Final Epoch` allows you to visualize results for any period desired. +Additionally, you can edit several other default parameters used in this tool in the advanced settings tabs. +In case you want more details, see the description of these parameters [here](/learn/protocols/iota2.0/core-concepts/mana-calculator/#advanced-settings) -- **Choose a congestion level:** Given a certain Mana generation per epoch, this can be translated into a number of blocks issued per second that depends on the congestion level. Choose one of the given congestion levels (low, stable, or extreme) to estimate how many blocks per second your tokens and participation grant you! This metric is also shown in another way: time until block issuance, which tells you in which periodicity you’ll be able to issue a block. ## Advanced settings -The steps outlined above can give you a rough estimate of your Mana generation and granted BPS. However, playing with the advanced settings will give you more precise results. +The steps outlined above can give you a rough estimate of your Mana generation and granted blocks allowance. However, playing with the advanced settings will give you more precise results. -- **Change the state of the system:** The calculator's default settings assume a certain level of participation in the consensus (i.e., locked stake, delegated stake, and performance factor of validators). Those settings can be changed under the “Advanced Settings - State of the System” tab. You can also add or delete validators and change their fixed costs. +- **Change the system’s state:** The calculator’s default settings assume a certain level of participation in the consensus (i.e., locked stake, delegated stake, and the performance factor of validators). Those settings can be changed under the “Advanced Settings - Validators” tab. You can also add or delete validators and change their fixed costs. -- If you choose to delegate: - - **Change the validator you delegate to:** Under the default settings, you'll delegate to Validator 1 (which is pool that, technically speaking, is under the "equilibrium state", see the WP for more details). However, you can change this setting and know your rewards if you participate in other pools, with different share of delegated to locked stake, and different performance factors. +- If you choose to delegate, you can change two default values under the "Delegator Settings" tab in "Role Configuration": + - **Change the validator you delegate to:** Under the default settings, you'll delegate to Validator 1 (which is a pool that, technically speaking, is under the "equilibrium state"; see the Whitepaper for more details). However, you can change this setting and know your rewards if you participate in other pools, with different shares of delegated to locked stakes and different performance factors. + - **Change the number of delegated tokens:** By default, you will delegate all your tokens to the pool selected above. + However, you can also simulate a scenario where you only delegate part of your tokens, with the rest remaining undelegated. + As usual, pay attention to the units! The input should be done in IOTA or Shimmer (not microIota or Glow). - If you choose to validate: - - **Change the amount of stake delegated to you:** The calculator's default settings automatically assign you a certain share of the delegated stake when you start validating. However, you can change this setting to know your rewards should you manage to attract more (or less) delegated stake than the default setting. - - **Change your performance factor:** Your performance factor under the calculator's default settings is 0.95. However, you can change this to simulate larger or smaller shares of online time. - - **Change your fixed costs:** By the default settings of the calculator, your fixed costs are zero. This setting can be changed so you spare part of the pool rowards just for yourself. However, notice that the fixed cost is a public parameter, that you define during registration. This means that the delegator knows how you set this value and might consider it when choosing a validator to delegate. Furthermore, if you set this value too high, you'll be punished and won't get any rewards. - -- **Simulate your Mana accumulation**: the default setting of the calculator assumes a stationary regime and calculates the block creation rate you guarantee depending on your stake and level of participation. However, especially in the early stages of the network, you might want to save your Mana to sell later. This tab simulates how much Mana you'll accumulate in a certain time period. For that (besides the other already defined inputs), you just need to choose an initial and final epoch, and the tool will plot a graph of your accumulation during that period. In the same graph, you can also have an idea of how many blocks can be issued with this accumulated amount of Mana, for the different congestion levels (already defined in the non-advanced settings). - - + - **Change the number of staked tokens:** As in the case of delegators, by default, you will stake all your tokens. + However, you can also simulate a scenario where you only stake part of your tokens, with the rest remaining unstaked. + As usual, pay attention to the units! The input should be done in IOTA or Shimmer (not microIota or Glow). + - **Change your performance factor:** Under the calculator's default settings, your performance factor is 1.0. However, you can change this to simulate smaller shares of online time. + - **Change your fixed costs:** By the calculator's default settings, your fixed costs are zero. This setting can be changed so you can spare part of the pool rewards for yourself. However, notice that the fixed cost is a public parameter you define during registration. This means that the delegator knows how you set this value and might consider it when choosing a validator to delegate. Furthermore, if you select this value too high, you'll be punished and won't get any rewards. + - **Change the amount of stake delegated to you:** The calculator's default settings automatically assign you a particular share of the delegated stake when you start validating, based on a specific "equilibrium state" (see the [Whitepaper](https://files.iota.org/papers/IOTA_2.0_Incentives_And_Tokenomics_Whitepaper.pdf) for more details). However, you can change this setting to know your rewards should you attract more (or less) delegated stakes than in the default setting. diff --git a/src/components/ManaCalculator/actions/calculateBPS.ts b/src/components/ManaCalculator/actions/calculateBPS.ts index adf6427c0ca..869be2b1e4b 100644 --- a/src/components/ManaCalculator/actions/calculateBPS.ts +++ b/src/components/ManaCalculator/actions/calculateBPS.ts @@ -1,5 +1,3 @@ -import { EPOCH_DURATION } from '../constants'; - export function calculateBPS(mana: number, congestion: number): number { - return mana / congestion / EPOCH_DURATION; + return mana / congestion; } diff --git a/src/components/ManaCalculator/components/BlocksAllowance.tsx b/src/components/ManaCalculator/components/BlocksAllowance.tsx deleted file mode 100644 index 3eb412d3566..00000000000 --- a/src/components/ManaCalculator/components/BlocksAllowance.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import React from 'react'; -import { - Area, - AreaChart, - CartesianGrid, - ResponsiveContainer, - Tooltip, - XAxis, - YAxis, -} from 'recharts'; -import { stringifyUnit, Unit } from '../hooks'; -import { EpochReward } from '../types'; -import { chartTooltip } from './ChartTooltip'; - -export function BlocksAllowance({ - results, - unit, -}: { - results: EpochReward[]; - unit: Unit; -}) { - const unitString = stringifyUnit(unit); - return ( - <> -

Blocks Allowance

- - - - - - - - - - - - - - - - - ); -} diff --git a/src/components/ManaCalculator/components/DelegatorSettings.tsx b/src/components/ManaCalculator/components/DelegatorSettings.tsx new file mode 100644 index 00000000000..37c8f0f3f10 --- /dev/null +++ b/src/components/ManaCalculator/components/DelegatorSettings.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import { Details } from '@docusaurus/theme-common/Details'; +import { useManaState } from '../hooks'; +import { fromMicro, toMicro } from '../utils'; +import Select from 'react-select'; + +export function DelegatorSettings() { + const { state, handleOwnStakeChange, handleValidatorChange } = useManaState(); + + const validatorOptions = state.validators.map((_, i) => { + return { value: i, label: `Validator ${i + 1}` }; + }); + + return ( +
+ + handleOwnStakeChange(toMicro(Number(e.target.value)))} + > +
+ ); +} diff --git a/src/components/ManaCalculator/components/ManaCalculator.tsx b/src/components/ManaCalculator/components/ManaCalculator.tsx index c28102e6dd8..131ae08dfe5 100644 --- a/src/components/ManaCalculator/components/ManaCalculator.tsx +++ b/src/components/ManaCalculator/components/ManaCalculator.tsx @@ -14,14 +14,13 @@ import { RoleSection, OtherParametersSection, ManaAccumulation, - BlocksAllowance, } from './'; export function ManaCalculator() { const [state, setState] = useState(getDefaultParameters(NetworkType.IOTA)); const manaState = useGivenManaState(state, setState); const results = useResultsPerEpoch(manaState.state); - const { data, manaUnit, blocksUnit } = useResultsWithUnit(results); + const { data, manaUnit } = useResultsWithUnit(results); return (

Configuration

@@ -32,7 +31,6 @@ export function ManaCalculator() {

Results

-
); } diff --git a/src/components/ManaCalculator/components/OtherParametersSection.tsx b/src/components/ManaCalculator/components/OtherParametersSection.tsx index 5d60e49610d..197e68d5ddd 100644 --- a/src/components/ManaCalculator/components/OtherParametersSection.tsx +++ b/src/components/ManaCalculator/components/OtherParametersSection.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useManaState } from '../hooks/useManaState'; import Select from 'react-select'; +import { UserType } from '../enums'; import { CongestionType } from '../enums'; import { AdvancedSettingsValidator } from './AdvancedSettingsValidator'; @@ -45,7 +46,13 @@ export function OtherParametersSection() { value={state.finalEpoch} onChange={(e) => handleFinalEpochChange(Number(e.target.value))} > - + {state.userType === UserType.HOLDER ? ( + <> + ) : ( + <> + + + )} ); } diff --git a/src/components/ManaCalculator/components/OutputForm.tsx b/src/components/ManaCalculator/components/OutputForm.tsx index 4a7a88340d0..711a873930c 100644 --- a/src/components/ManaCalculator/components/OutputForm.tsx +++ b/src/components/ManaCalculator/components/OutputForm.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useManaState, useResults } from '../hooks'; import { fromMicro, roundMax } from '../utils'; +import { UserType } from '../enums'; import humanizeDuration from 'humanize-duration'; export function OutputForm() { @@ -8,7 +9,7 @@ export function OutputForm() { const results = useResults(state); const passiveRewards = roundMax(fromMicro(results.passiveRewards), 6); const manaGenerated = roundMax(fromMicro(results.generatedRewards), 6); - const totalBPS = roundMax(results.totalBPS, 2); + const blockAllowance = roundMax(results.blockAllowance, 2); const humanizer = humanizeDuration.humanizer({ units: ['y', 'mo', 'w', 'd', 'h', 'm', 's', 'ms'], maxDecimalPoints: 3, @@ -18,27 +19,94 @@ export function OutputForm() { return (
-
- Mana generation (by holding):{' '} - {passiveRewards} -
-
- Mana rewards: {manaGenerated} -
-
- Total BPS granted: {totalBPS} -
-
- Time it takes to accumulate enough mana for a standard transaction... -
-
- ...as a delegator/validator:{' '} - {msToTransaction} -
-
- ...as a holder:{' '} - {passiveMsToTransaction} -
+ {state.userType === UserType.VALIDATOR ? ( + <> +
+ Generation (by just holding) in the input period:{' '} + {passiveRewards} Mana +
+
+ Mana rewards from staking in the input period:{' '} + {manaGenerated} Mana +
+
+ Total Block Allowance granted after the input period:{' '} + + {roundMax(blockAllowance, 3)} standard blocks + +
+
+ Time it takes to accumulate enough mana for a standard block... +
+
+ ...as a holder (owning{' '} + {fromMicro(state.heldTokens)}{' '} + tokens and not staking any of them):{' '} + {passiveMsToTransaction} +
+
+ ...as a validator (owning{' '} + {fromMicro(state.heldTokens)}{' '} + tokens and staking{' '} + + {fromMicro(state.stakedOrDelegatedTokens)} + {' '} + of them): {msToTransaction} +
+ + ) : state.userType === UserType.DELEGATOR ? ( + <> +
+ Generation (by just holding) in the input period:{' '} + {passiveRewards} Mana +
+
+ Mana rewards from delegating in the input period:{' '} + {manaGenerated} Mana +
+
+ Total Block Allowance granted after the input period:{' '} + + {roundMax(blockAllowance, 3)} standard blocks + +
+
+ Time it takes to accumulate enough mana for a standard block... +
+
+ ...as a holder (owning{' '} + {fromMicro(state.heldTokens)}{' '} + tokens and not delegating any of them):{' '} + {passiveMsToTransaction} +
+
+ ...as a delegator (owning{' '} + {fromMicro(state.heldTokens)}{' '} + tokens and delegating{' '} + + {fromMicro(state.stakedOrDelegatedTokens)} + {' '} + of them): {msToTransaction} +
+ + ) : ( + <> +
+ Generation in the input period:{' '} + {passiveRewards} Mana +
+
+ Total Block Allowance granted after the input period:{' '} + + {roundMax(blockAllowance, 3)} standard blocks + +
+
+ Time it takes to accumulate enough mana for a standard block:{' '} + {passiveMsToTransaction} +
+ + )}
); } diff --git a/src/components/ManaCalculator/components/RoleSection.tsx b/src/components/ManaCalculator/components/RoleSection.tsx index 48c4bc26f21..6897fdcb869 100644 --- a/src/components/ManaCalculator/components/RoleSection.tsx +++ b/src/components/ManaCalculator/components/RoleSection.tsx @@ -4,19 +4,10 @@ import Select from 'react-select'; import { UserType } from '../enums'; import { fromMicro, toMicro } from '../utils'; import { ValidatorSettings } from './ValidatorSettings'; +import { DelegatorSettings } from './DelegatorSettings'; export function RoleSection() { - const { - state, - handleOwnStakeChange, - handleUserChange, - handleValidatorChange, - handleOwnHoldChange, - } = useManaState(); - const validatorOptions = state.validators.map((_, i) => { - return { value: i, label: `Validator ${i + 1}` }; - }); - + const { state, handleUserChange, handleOwnHoldChange } = useManaState(); return (

Role configuration

@@ -31,10 +22,11 @@ export function RoleSection() { options={[ { value: UserType.DELEGATOR, label: `Delegator` }, { value: UserType.VALIDATOR, label: `Validator` }, + { value: UserType.HOLDER, label: `Holder` }, ]} />
- +
{state.userType === UserType.VALIDATOR ? ( - <> - - - handleOwnStakeChange(toMicro(Number(e.target.value))) - } - > -
- - + + ) : state.userType === UserType.DELEGATOR ? ( + ) : ( - <> - - - handleOwnStakeChange(toMicro(Number(e.target.value))) - } - > - + <> )}
); diff --git a/src/components/ManaCalculator/components/ValidatorSettings.tsx b/src/components/ManaCalculator/components/ValidatorSettings.tsx index 95be4df6508..bf69089a2da 100644 --- a/src/components/ManaCalculator/components/ValidatorSettings.tsx +++ b/src/components/ManaCalculator/components/ValidatorSettings.tsx @@ -1,35 +1,36 @@ import React from 'react'; import { Details } from '@docusaurus/theme-common/Details'; import { useManaState } from '../hooks'; +import { fromMicro, toMicro, roundMax } from '../utils'; export function ValidatorSettings() { const { - state: { - validator: { - performanceFactor, - fixedCost, - shareOfYourStakeLocked, - attractedNewDelegatedStake, - attractedDelegatedStakeFromOtherPools, - }, - }, + state, handleOwnPFChange, handleOwnFCChange, - handleShareOfYourStakeLockedChange, + handleOwnStakeChange, handleAttractedNewDelegatedStakeChange, - handleAttractedDelegatedStakeFromOtherPoolsChange, } = useManaState(); return (
+ + handleOwnStakeChange(toMicro(Number(e.target.value)))} + > +
handleOwnPFChange(Number(e.target.value))} >
@@ -38,42 +39,22 @@ export function ValidatorSettings() { className='mana_calculator__compact input--vertical-spaced' type='number' step='0.01' - value={fixedCost} + value={state.validator.fixedCost} onChange={(e) => handleOwnFCChange(Number(e.target.value))} > -
- - - handleShareOfYourStakeLockedChange(Number(e.target.value)) - } - > -
handleAttractedNewDelegatedStakeChange(Number(e.target.value)) } > -
- - - handleAttractedDelegatedStakeFromOtherPoolsChange( - Number(e.target.value), - ) - } - >
); } diff --git a/src/components/ManaCalculator/components/index.ts b/src/components/ManaCalculator/components/index.ts index 144baf9e54b..92fa8d84681 100644 --- a/src/components/ManaCalculator/components/index.ts +++ b/src/components/ManaCalculator/components/index.ts @@ -3,8 +3,8 @@ export * from './ManaCalculator'; export * from './OtherParametersSection'; export * from './ValidatorCard'; export * from './ValidatorSettings'; +export * from './DelegatorSettings'; export * from './RoleSection'; export * from './OutputForm'; export * from './NetworkSection'; export * from './ManaAcculation'; -export * from './BlocksAllowance'; diff --git a/src/components/ManaCalculator/constants.ts b/src/components/ManaCalculator/constants.ts index 3eeccf01891..2ccf3c798e7 100644 --- a/src/components/ManaCalculator/constants.ts +++ b/src/components/ManaCalculator/constants.ts @@ -3,7 +3,7 @@ import { CongestionType } from './enums/parameters.enum'; // GENERIC export const INITIAL_EPOCH = 1; -export const FINAL_EPOCH = 1000; +export const FINAL_EPOCH = 10; export const SLOT_DURATION = 10; export const SLOTS_IN_EPOCH = 8192; export const EPOCH_DURATION = SLOTS_IN_EPOCH * SLOT_DURATION; @@ -21,7 +21,7 @@ export const IOTA_SUPPLY = 4600000000000000; export const IOTA_CONGESTION = { [CongestionType.HIGH]: 350000000, [CongestionType.MEDIUM]: 0, // Dynamic - [CongestionType.LOW]: 5000000, + [CongestionType.LOW]: 500000, }; export const IOTA_GENERATION_PER_SLOT = Math.pow(2, -17); @@ -37,9 +37,9 @@ export const IOTA_DELEGATED = 600; // IOTA export const SHIMMER_SUPPLY = 1813620509000000; export const SHIMMER_CONGESTION = { - [CongestionType.HIGH]: 350000000, + [CongestionType.HIGH]: 275000000, [CongestionType.MEDIUM]: 0, // Dynamic - [CongestionType.LOW]: 5000000, + [CongestionType.LOW]: 500000, }; export const SHIMMER_GENERATION_PER_SLOT = Math.pow(2, -16); diff --git a/src/components/ManaCalculator/enums/parameters.enum.ts b/src/components/ManaCalculator/enums/parameters.enum.ts index faff9332bdb..5f5a8e8f4a5 100644 --- a/src/components/ManaCalculator/enums/parameters.enum.ts +++ b/src/components/ManaCalculator/enums/parameters.enum.ts @@ -1,6 +1,7 @@ export enum UserType { DELEGATOR, VALIDATOR, + HOLDER, } export enum NetworkType { diff --git a/src/components/ManaCalculator/hooks/useManaState.ts b/src/components/ManaCalculator/hooks/useManaState.ts index 92f5c47b90c..75cd3d844d0 100644 --- a/src/components/ManaCalculator/hooks/useManaState.ts +++ b/src/components/ManaCalculator/hooks/useManaState.ts @@ -122,13 +122,6 @@ export function useGivenManaState( }); } - function handleShareOfYourStakeLockedChange(value: number) { - setState({ - ...state, - validator: { ...state.validator, shareOfYourStakeLocked: value }, - }); - } - function handleAttractedNewDelegatedStakeChange(value: number) { setState({ ...state, @@ -136,16 +129,6 @@ export function useGivenManaState( }); } - function handleAttractedDelegatedStakeFromOtherPoolsChange(value: number) { - setState({ - ...state, - validator: { - ...state.validator, - attractedDelegatedStakeFromOtherPools: value, - }, - }); - } - function handleInitialEpochChange(value: number) { setState({ ...state, @@ -199,7 +182,6 @@ export function useGivenManaState( handleDelete, handleStakeChange, handleAddValidator, - handleAttractedDelegatedStakeFromOtherPoolsChange, handleAttractedNewDelegatedStakeChange, handleCongestionChange, handleDelegatedStakeChange, @@ -210,7 +192,6 @@ export function useGivenManaState( handleOwnFCChange, handleOwnPFChange, handleUserChange, - handleShareOfYourStakeLockedChange, handleOwnStakeChange, handlePFChange, handleValidatorChange, @@ -235,12 +216,13 @@ export function getDefaultParameters( }; const finalNetworkParams = networkParams[network]; + const validators = getValidators(network); return { ...finalNetworkParams, initialEpoch: INITIAL_EPOCH, finalEpoch: FINAL_EPOCH, - validators: getValidators(network), + validators, userType: UserType.DELEGATOR, congestion: CongestionType.LOW, delegator: { @@ -249,9 +231,12 @@ export function getDefaultParameters( validator: { performanceFactor: 1.0, fixedCost: 0.0, - shareOfYourStakeLocked: 100.0, - attractedNewDelegatedStake: finalNetworkParams.stakedTokens * 1.5, - attractedDelegatedStakeFromOtherPools: 0.1, + shareOfYourStakeLocked: 1.0, + attractedNewDelegatedStake: + (finalNetworkParams.stakedTokens * + validators.reduce((a, b) => a + b.delegatedStake, 0)) / + validators.reduce((a, b) => a + b.lockedStake, 0), + attractedDelegatedStakeFromOtherPools: 0, }, network, } as ManaCalculatorProps; diff --git a/src/components/ManaCalculator/hooks/useResults.ts b/src/components/ManaCalculator/hooks/useResults.ts index 3d883be690e..0750edaa79a 100644 --- a/src/components/ManaCalculator/hooks/useResults.ts +++ b/src/components/ManaCalculator/hooks/useResults.ts @@ -1,8 +1,5 @@ -import { - calculateManaRewards, - calculatePassiveRewards, - calculateBPS, -} from '../actions'; +import { calculateManaRewards, calculatePassiveRewards } from '../actions'; +import { EPOCH_DURATION } from '../constants'; import { UserType } from '../enums'; import { ManaState, ValidatorParameters } from '../types'; @@ -14,8 +11,6 @@ export function useResults(state: ManaState) { state.generationPerSlot, ); - const passiveBPS = calculateBPS(passiveRewards, state.congestionAmount); - const validatorParameters = state.userType === UserType.VALIDATOR ? ({ @@ -41,16 +36,53 @@ export function useResults(state: ManaState) { state.generationPerSlot, ); - const generatedBPS = calculateBPS(generatedRewards, state.congestionAmount); - const totalBPS = generatedBPS + passiveBPS; + const passiveRewardsInTheFirstEpoch = calculatePassiveRewards( + state.heldTokens, + state.initialEpoch, + state.initialEpoch + 1, + state.generationPerSlot, + ); + + const generatedRewardsInTheFirstEpoch = calculateManaRewards( + state.stakedOrDelegatedTokens, + state.delegator.validator, + validatorParameters, + state.validators, + state.initialEpoch, + state.initialEpoch + 1, + state.userType, + state.network, + state.generationPerSlot, + ); + + const yourPassiveBlocksInPeriod = passiveRewards / state.congestionAmount; + const yourAdditionalBlocksInPeriod = + generatedRewards / state.congestionAmount; + + const yourPassiveBlocksInTheFirstEpoch = + passiveRewardsInTheFirstEpoch / state.congestionAmount; + const yourAdditionalBlocksInTheFirstEpoch = + generatedRewardsInTheFirstEpoch / state.congestionAmount; + + const yourTotalBlocksInPeriod = + yourPassiveBlocksInPeriod + yourAdditionalBlocksInPeriod; + + const yourTotalBlocksInTheFirstEpoch = + yourPassiveBlocksInTheFirstEpoch + yourAdditionalBlocksInTheFirstEpoch; + + const blockAllowance = yourTotalBlocksInPeriod; + + const yourBPSasHolder = yourPassiveBlocksInTheFirstEpoch / EPOCH_DURATION; + const totalBPS = yourTotalBlocksInTheFirstEpoch / EPOCH_DURATION; const msToTransaction = (1 / totalBPS) * 1_000; - const passiveMsToTransaction = (1 / passiveBPS) * 1_000; + const passiveMsToTransaction = (1 / yourBPSasHolder) * 1_000; return { generatedRewards, passiveRewards, totalBPS, + blockAllowance, msToTransaction, passiveMsToTransaction, }; diff --git a/src/components/ManaCalculator/hooks/useResultsWithUnit.ts b/src/components/ManaCalculator/hooks/useResultsWithUnit.ts index 3f437dbd262..72fb955136d 100644 --- a/src/components/ManaCalculator/hooks/useResultsWithUnit.ts +++ b/src/components/ManaCalculator/hooks/useResultsWithUnit.ts @@ -49,7 +49,6 @@ const getUnit = (value: number): Unit => { interface UseResultsWithUnit { data: EpochReward[]; manaUnit: Unit; - blocksUnit: Unit; } export function getSizeOfUnit(unit: Unit): number { @@ -79,6 +78,5 @@ export function useResultsWithUnit(results: EpochReward[]): UseResultsWithUnit { return { data, manaUnit, - blocksUnit, }; } diff --git a/src/components/ManaCalculator/utils.ts b/src/components/ManaCalculator/utils.ts index 9a6ca572255..5d1f2f870f8 100644 --- a/src/components/ManaCalculator/utils.ts +++ b/src/components/ManaCalculator/utils.ts @@ -7,6 +7,7 @@ import { SHIMMER_GENERATION_PER_SLOT, SHIMMER_SUPPLY, SHIMMER_THROUGHPUT, + SLOT_DURATION, SLOTS_IN_EPOCH, } from './constants'; import { CongestionType, NetworkType, UserType } from './enums'; @@ -51,7 +52,7 @@ export function getNetworkCongestion( const generation = getNetworkGenerationPerSlot(network); const throughput = getNetworkThroughput(network); - return (supply * generation) / (10 * throughput); + return (supply * generation) / (SLOT_DURATION * throughput); } else { if (network == NetworkType.IOTA) { return IOTA_CONGESTION[congestionType];