***APR calculation***
The goal is to calculate the return of a delegator if one delegates tokens to a particular collator. We start with the fact that
there is inflation config (*inflation_config = [ParachainStaking.InflationConfig](https://github.com/PureStake/moonbeam/blob/master/pallets/parachain-staking/src/inflation.rs#L104)*) value that determines how many tokens are issued per round based on amount
of currently issued tokens (*total_issued = Balances.TotalIssued*).
Also there is total staked amount (*total_staked = [ParachainStaking.Staked](https://github.com/PureStake/moonbeam/blob/master/pallets/parachain-staking/src/lib.rs#L588)*) which is updated each round. Having this information one can calculate
annual return per staked token:
```
staked_portion = total_staked / total_issued
annual_return = annual_inflation / staked_portion
```
For *annual_inflation* the following logic is applied:
```
1) annual_inflation = inflation_config.annual.min when total_staked < inflation_config.expect.min;
2) annual_inflation = inflation_config.annual.max when total_staked > inflation_config.expect.max;
3) annual_inflation = inflation_config.annual.ideal otherwise;
```
Then one also need to take into account that part of the tokens goes to parachain
bond account (*par_bond_percent = [ParachainStaking.ParachainBondInfo.percent_of_inflation](https://github.com/PureStake/moonbeam/blob/master/pallets/parachain-staking/src/types.rs#L1567)*) and the fact that the lower collator's stake the higher reward will be given
per delegator. Last important point is that collator's commission (*commission = [ParachainStaking.CollatorCommission](https://github.com/PureStake/moonbeam/blob/master/pallets/parachain-staking/src/lib.rs#L446)*) must be taken into account too. So the final formulat is the following:
```
apr(collator) = annual_return * (1 - par_bond_percent - commission) * (average_stake/collator.stake);
average_stake = sum(collators.stake) / count(collators);
apr_avg = annual_return * (1 - par_bond_percent - commission);
apr_max = apr(c) where c is a selected collator with minimum stake;
```
***Turing APR calculation***
For Turing network APR calculation is different in a way that inflation is not only depends on ```total_issued``` but also from a ```additional``` value that is retrived from the storage Vesting.TotalUnvestedAllocation. Thus the ```staked_portion``` is calculated in the following way:
```
staked_portion = total_staked / (total_issued + additional)
```

or

By clicking below, you agree to our terms of service.

Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet

Wallet
(
)

Connect another wallet
New to HackMD? Sign up