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:

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:

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:

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;
    }
    _;
}

Mining pools

2pool farm

Mainnet contract address:TFpg63byqDwniXnyxVYpSzBfWGBwZExM9J

USDD-USDT V2 farm

Mainnet contract address:TCkNadwxyik1D66qCGmavuneowDRXPgdkL

Contract interaction

We use TronWeb to interact with contracts. One can easily interact with online contracts after initializing TronWeb instances.

const TronWeb = require('tronweb')
const privateKey = process.env.PRIVATE_KEY
const apiKey = process.env.API_KEY

var tronWeb = new TronWeb({
	fullHost: "https://api.trongrid.io",
	headers: { "TRON-PRO-API-KEY": apiKey },
	privateKey: privateKey,
      })
     

Get mining pool information

View addresses of fixed-term/on-demand mining pools

  • Function: reward_contract()

>>> let contract = await tronWeb.getContract('TFpg63byqDwniXnyxVYpSzBfWGBwZExM9J')
>>> await contract.methods.reward_contract().call()
TWHM9Lkf78pHy68yhxdP8SUaRpn1hgaCpS

View rewards of on-demand mining pools

  • Function:earned(address)

  • Parameter: user's address

>>> let contract = await tronWeb.getContract('TUgVp8FzZcFLHwruuncXaQo2js5Ym2GqSj')
>>> await contract.methods.earned('TF5MekHgFz6neU7zTpX4h2tha5miPDUj3z').call()
1000000000000000000

Transaction execution

Deposit

  • Function:deposit(uint256)

  • Parameter:Deposit amount

>>> let contract = await tronWeb.getContract('TFpg63byqDwniXnyxVYpSzBfWGBwZExM9J')
>>> await contract.methods.deposit(1000000000000000000).send()

Withdrawal

  • Function:withdraw(uint256)

  • Parameter:Withdrawal amount

>>> let contract = await tronWeb.getContract('TFpg63byqDwniXnyxVYpSzBfWGBwZExM9J')
>>> await contract.methods.withdraw(1000000000000000000).send()

Last updated