Staking Unstake - nostrum-coin/nostrum-coin GitHub Wiki

In order to reduce the use of Gas by the contract, Nostrum staking is done in a very simple way. The holder can choose to staking a certain amount of Nostrum. Each day the interest will be calculated for that amount. Interest is always calculated using the original amount. Thus, interest can be defined as:

interest = stakedAmount * daysPassed * dailyTax

The dailyTax is calculated according to the staking earn percentage, which is chosen by the holders. Staking earn percentage sets the interest percentage for the year. To find a day's interest, just use:

dailyTax = stakingPercentage / 365

Example: A holder decide stake 1000 Nostrum for 3 days. The staking earn percentage is 10%, so the dailyTax is ~0.00028. The interest is:

interest = 1000 * 3 * 0.00028
interest = 0.84

So, after 3 days the holder can unstake 1000.84 Nostrum (1000 from original amount + 0.84 from interest).

Important: interest in is calculated when performing the unstake, so it use the current staking earn percentage

This is important because the value of staking earn percentage can change according to the election. So, in the previous example, if the staking earn percentage changes to 0% in last day, when performing the unstake the holder would have:

interest = 1000 * 3 * 0.0
interest = 0.0

So maybe is a good idea do a unstake before each election.

Function call

To do a stake in contract simple call the doStake function, which has a single parameter, the amount of Nostrum you want to stake. The amount should be integer, so you need convert using this formula:

amount = amountStack * (10^18)

This is done to represent decimal as integer. For stake 1000 Nostrum, the function doStake should have 1000*(10^18) = 1000000000000000000000 as parameter (doStake(1000000000000000000000)).

The unstake function is similar to stake funtion. To do a unstake in contract call the unStake function, which has a single parameter, the amount of Nostrum you want to unstake. To unstake 1000 Nostrum, call unStake(1000000000000000000000).