---
title: 'Kusama Reward Calculator'
---
Kusama Reward Calculator
===
## Table of Contents
[TOC]
## Implementation
#### Current Implementation
```js
const provider = new WsProvider("wss://poc3-rpc.polkadot.io");
const api = await ApiPromise.create({ provider: provider });
const [currentSessionReward, validators] = await Promise.all([
api.query.staking.currentSessionReward(),
api.query.session.validators()
]);
const validatorPoolReward = (currentSessionReward * 6) / 10 ** 12;
const validatorAddressList = validators.map(async validator => {
const currentStakeInfo = await api.derive.staking.info(validator);
const currentTotalStake =
currentStakeInfo.stakers.total.toString() / 10 ** 15;
const currentValidatorPayment =
(await currentStakeInfo.validatorPrefs.validatorPayment.toString()) /
10 ** 15;
return {
address: validator,
payment: currentValidatorPayment,
totalStake: currentTotalStake,
stakeInfo: currentStakeInfo,
accountId: currentStakeInfo.accountId.toString(),
stashId: currentStakeInfo.stashId.toString()
};
});
```
#### Changes to be made
**1.** `provider`: From `new WsProvider("wss://poc3-rpc.polkadot.io");` → to `new WsProvider("wss://kusama-rpc.polkadot.io")`
**2.** `currentSessionReward`: From `api.query.staking.currentSessionReward()` → to `api.query.staking.currentEraPointsEarned()`
---
#### The rest seem to require either no change or just a change in unit so far (Only 5. & 6. are changed)
**3.** `validators`: From `api.query.session.validators()` → to `api.query.session.validators()`
**4.** `currentStakeInfo`: From `await api.derive.staking.info(validator)` → to `await api.derive.staking.info(validator)`
**5.** `currentTotalStake`: From `currentStakeInfo.stakers.total.toString() / 10 ** 15` → to `xcurrentStakeInfo.stakers.total.toString() / 10 ** 12`
**6.** `currentValidatorPayment`: From `(await currentStakeInfo.validatorPrefs.validatorPayment.toString()) /
10 ** 15` → to `(await currentStakeInfo.validatorPrefs.validatorPayment.toString()) /
10 ** 12`
**7.** `stashId`: From `currentStakeInfo.stashId.toString()` → to `currentStakeInfo.stashId.toString()`
**8.** `accountId`: From `currentStakeInfo.accountId.toString()` → to `currentStakeInfo.accountId.toString()`
---
### Issues
- Rewards for all validators is calculated to be 0.
### New findings
:::info
`currentEraPointsEarned()` and `eraPoints` return the same value
:::
- For Kusama, the API directly offers eraPoints, not sure what that is exactly but that doesn't seem to be what we're looking for. Although, it is possible that this might be useful in calculating the rewards.
```js
const apiDerive = await api.derive.staking.overview(validator);
const eraPoints = await apiDerive.eraPoints.total.toString();
```
- The value for `currentEraPointsEarned` is changing rapidly (almost every second or sooner) whereas the `currentSessionReward` was very stable and didn't change before at least an era.
---
:::danger
The script below seems redundant because all that's doing is dividing the `validatorPayment` value returned by the API by 10^12
:::
- Found a script which calculates reward for the Kusama network.
> 0 KSM means all rewards are split between validator and nominator accounts according to their stake
>
> [name=Author of the Script]
>
>https://github.com/soc1c/kusama-scripts/tree/master/validator-rewards
---
- Got the following information from Polkadot Riot Chat:
> - eraPoints are divided into 2 sections - total (everything allocated) and individual, which is based on the index of the currentElected set
> - the points don't change once a second, new points are awarded at each block - at the end of the era the indv. points are then applied to the validator [name=Jaco, Polkadot Riot Chat]
> The payout is not exactly equal, it is based on points (which, over time, should be equal). the staking module emits an event with the era's total payout and amount to the treasury, so you will have to listen for events [name=joe, Polkadot Riot Chat]