Smart Mining V1

Smart Mining V1: A flexible on-demand mining mode

Background

As one of the digital financial derivatives on SUN.io, mining provides crypto holders with stable, secure and reliable services for investment product subscription and redemption. Smart Mining V1, also known as flexible mining, is an important part of SUN.io's mining service. It distributes rewards according to the share of users' staked assets in the mining pool's total stake amount. And users can redeem their assets anytime.

Explanation

SUN.io's mining service distributes token rewards at an even inflation rate within a certain period of time, as shown in the graph below.

Changes in the total staked assets in the mining pool at the time point ti will lead to changes in rewards for individual users, who are rewarded according to the following formula:

f(ti,tn)=i=1n(titi1)rtUiSi1f(t_i,t_n)=\sum_{i=1}^{n}(t_i-t_{i-1})r_t * \frac {U_i}{S_i}(1)

rtr_t denotes the expansion factor of token rewards, tit_i denotes the i-th change, SiS_i denotes the total staked assets during the period from ti−1 to ti, and UiU_i denotes users' staked assets during the period from ti1t_{i-1} to tit_i.

According to the above formula, changes in the mining pool’s total staked assets will affect the distribution of rewards for all users. In order to avoid high gas fees incurred from updating the reward distribution for every user, the above formula is altered to the following one:

f(ti,tn)=i=1mUij=startiendi(titi1)rtSi2f(t_i,t_n)= \sum_{i=1}^{m}U_i \sum_{j=start_i}^{end_i}\frac{(t_i-t_{i-1})r_t}{S_i}(2)

When the total staked assets in the mining pool have changed while the users' staked assets have not during the period from starti to endi, only the following summation formula needs to be updated:

j=startiendi(titi1)rtSi3\sum_{j=start_i}^{end_i} \frac{(t_i-t_{i-1})r_t}{S_i}(3)

Contract code

modifier updateReward(address account) {
    rewardPerTokenStored = rewardPerToken();
    lastUpdateTime = lastTimeRewardApplicable();
    if (canNext && block.timestamp > periodFinish && DURATION_NEXT > 0) {
        rewardRate = rewardNext.div(DURATION_NEXT);
        uint256 nextRound = (block.timestamp - periodFinish) / DURATION_NEXT + 1;
        periodFinish = periodFinish.add(nextRound * DURATION_NEXT);
        rewardPerTokenStored = rewardPerToken();
        lastUpdateTime = lastTimeRewardApplicable();
        rewardNow = rewardNext;
        DURATION = DURATION_NEXT;
        emit RewardAdded(nextRound * rewardNext);
    }
    if (account != address(0)) {
        userInfo[account].rewards = earned(account);
        userInfo[account].rewardPerTokenPaid = rewardPerTokenStored;
    }
    _;
}

Last updated