SUN.io Docs
SUN.ioSunPump
  • SUN.io Overview
    • Get Started(TRON)
      • Create a Wallet
      • TRON Network Token Standards
      • Connect Your Wallet to SUN.io
    • Risks
    • Whitepaper
    • Terms of Service
    • Privacy Policy
    • Announcement
  • GET START
    • Exchange
      • Token Swaps
        • How to authorize a token?
        • How to exchange tokens?
        • How to check my recent transaction history?
        • How to view 24h price trend of a pair ?
      • Stablecoin Pool
        • Stablecoin pool overview
        • How to swap stablecoins?
        • How to provide liquidity for a stablecoin pool?
        • How to withdraw liquidity from a stablecoin pool?
        • How to check the liquidity you have provided?
      • Smart Router
      • Trading Fee
        • Claim Fee Rewards
      • Liquidity Pool
        • How to create a trading pair?
        • How to add liquidity?
        • How to remove liquidity?
        • How to calculate the ratio of tokens to be added to/removed from the pool?
        • How to record a new token?
        • What's the initial price for creating a fund pool?
      • Token Lists
    • Mining Pool
      • Mining Rules of SUN.io
      • How to participate in liquidity mining?
      • How to earn liquidity mining rewards?
      • How to exit liquidity mining?
      • How to calculate the boost rate of LP mining pool?
      • How to lock SUN?
      • How to vote?
      • How to reset votes?
      • Intelligent Boost Mining Pool
        • How to participate in Fixed Staking?
        • How to stake more assets in Fixed Staking?
        • How to extend duration in Fixed Staking?
        • How to make an early withdrawal in Fixed Staking?
        • How to claim rewards in Fixed Staking?
      • Farm
      • Ended Farming Pools
    • SunPump
      • 🌞 How to Participate?
      • 🚀 How to Launch?
      • 💡 Token Details
      • 👤 Personal Profile
      • 🏦 Service Fees
      • How to Use DLive Streaming on SunPump
    • SunPump Referral
      • How to Join
      • Rules
      • FAQ
    • PSM
      • How to swap between USDD and other stablecoins at 1:1 ratio in PSM?
    • Tokenomics
      • SUN Tokenomics
        • Buyback & Burning of the SUN Token
      • veSUN
      • Airdrop
  • GOVERNANCE
    • SUN DAO Governance
    • Participating Governance
      • Proposal
        • SUN DAO Forum
        • How to get more votes?
        • Create Proposal
        • How to vote on the SUN DAO?
        • SUN DAO proposal
      • Governance Rights
        • Weight
        • veSUN
  • DEVELOPERS
    • Swap
      • StableSwap Overview
      • SunSwap Overview
      • SunSwap V3 Overview
      • Smart Router
        • Contract
        • Calculation Service
        • Exchange Functions
        • Detailed Development Steps
    • Mining
      • Smart Mining V1
      • Smart Mining V2
      • Governance Mining
    • Sunpump
      • Sunpump Contracts
    • Github
    • Contracts and ABIs
  • FAQ
    • How to use Sun.io in TronLink Mobile?
    • How is price determined?
    • What tokens are supported for swap?
    • Why does my exchange fail?
    • Detailed Explanation of SUN.io Platform Energy Subsidies
Powered by GitBook
On this page
  • Background
  • Explanation
  • Mining pools
  • Contract interaction
  • Get mining pool information
  • Transaction execution
  1. DEVELOPERS
  2. Mining

Smart Mining V1

Smart Mining V1: A flexible on-demand mining mode

PreviousMiningNextSmart Mining V2

Last updated 10 months ago

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(ti−ti−1)rt∗UiSi(1)f(t_i,t_n)=\sum_{i=1}^{n}(t_i-t_{i-1})r_t * \frac {U_i}{S_i}(1)f(ti​,tn​)=i=1∑n​(ti​−ti−1​)rt​∗Si​Ui​​(1)

rtr_trt​ denotes the expansion factor of token rewards, tit_iti​ denotes the i-th change, SiS_iSi​ denotes the total staked assets during the period from ti−1 to ti, and UiU_iUi​ denotes users' staked assets during the period from ti−1t_{i-1}ti−1​ to tit_iti​.

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=1mUi∑j=startiendi(ti−ti−1)rtSi(2)f(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)f(ti​,tn​)=i=1∑m​Ui​j=starti​∑endi​​Si​(ti​−ti−1​)rt​​(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(ti−ti−1)rtSi(3)\sum_{j=start_i}^{end_i} \frac{(t_i-t_{i-1})r_t}{S_i}(3)j=starti​∑endi​​Si​(ti​−ti−1​)rt​​(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;
    }
    _;
}

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()