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 V2

Smart Mining V2: A high-yield fixed-term mining mode

Background

As one of the digital financial derivatives on SUN.io, mining provides crypto holders with stable, secure, and reliable services for subscription and redemption of investment products. Smart Mining V2, also known as fixed-term mining, is an important part of SUN.io's mining service. It converts a user's staked assets to virtual assets of a certain amount according to the amount of assets staked and the staking duration. The total virtual stake is defined as the total amount of virtual assets converted from all users' staked assets. Users are rewarded based on their virtual assets' proportion in the total virtual stake, and they are only allowed to redeem their assets during a specified period of time.

Explanation

Reward Distribution

Suppose the stake amount of a token is "amount". The token's lock-up duration DurationlockDuration_{lock}Durationlock​ meets the following condition: Durationmin<=Durationlock<=DurationmaxDuration_{min}<=Duration_{lock}<=Duration_{max}Durationmin​<=Durationlock​<=Durationmax​。 where DurationmaxDuration_{ma x}Durationmax​ is 1080 days, DurationminDuration_{min}Durationmin​ is 30 days, and the maximum acceleration rateweightmaxweight_{max}weightmax​ is 1400% (magnifying by e12e^{12}e12 times). The veToken is calculated in the following way:

weight=Durationlock∗weightamx∗e12Durationmax(1)weight=\frac{Duration_{lock}*weight_{amx}*e^{12}}{Duration_{max}}(1)weight=Durationmax​Durationlock​∗weightamx​∗e12​(1)
balanceveToken=amount+amount∗weight∗e−12(2)balance_{veToken}=amount+amount*weight*e^{-12}(2)balanceveToken​=amount+amount∗weight∗e−12(2)

Here,balanceveTokenbalance_{veToken}balanceveToken​refers to the amount of a user's virtual assets. According to the reward distribution formula (2) of Smart Mining V1, the user's rewards are calculated in the following way:

f(ti,tn)=∑i=1mbalanceveToken∑j=startiendi(ti−ti−1)rtTi(3)f(t_i,t_n)= \sum_{i=1}^{m}balance_{veToken} \sum_{j=start_i}^{end_i}\frac{(t_i-t_{i-1})r_t}{T_i}(3)f(ti​,tn​)=i=1∑m​balanceveToken​j=starti​∑endi​​Ti​(ti​−ti−1​)rt​​(3)

Here, rtr_trt​ denotes the expansion factor of the reward token, tit_iti​ denotes the i-th change, TiT_iTi​ denotes the total virtual stake at the time ti−1t_{i-1}ti−1​to tit_iti​, and balanceveTokenbalance_{veToken}balanceveToken​ denotes the amount of the user's virtual assets at the time ti−1t_{i-1}ti−1​to tit_iti​.

Contract code

function calculateBoostedBalance(uint256 amount, uint256 lockDuration) public view returns (uint256) {
    if (lockDuration == 0) {
        return amount;
    }
    uint256 boostWeight = lockDuration.mul(BOOST_WEIGHT).div(DURATION_FACTOR);
    return amount.add(amount.mul(boostWeight).div(PRECISION_FACTOR));
}

Redemption Time of Fixed-Term Mining

DurationlockDuration_{lock}Durationlock​ denotes the length of a lock-up period, DurationmaintenanceDuration_{maintenance}Durationmaintenance​ denotes the length of a cooling-off period for re-staking, tstaket_{stake}tstake​ denotes the time when the assets are staked, and tnowt_{no w}tnow​ denotes the current time. Assets can be redeemed when the following conditions are both met:

tnow−tstake>=Durationlock(4)t_{now}-t_{stake}>=Duration_{lock}(4)tnow​−tstake​>=Durationlock​(4)
(tnow−tstake)modDurationlock<=Durationmaintenance(5)(t_{now}-t_{stake}) mod Duration_{lock} <= Duration_{maintenance}(5)(tnow​−tstake​)modDurationlock​<=Durationmaintenance​(5)

rewards denotes the total amount of rewards, rewardsprevrewards_{prev}rewardsprev​ denotes the amount of settled rewards, tlastActiont_{lastAction}tlastAction​ denotes the time of the last settlement, and DurationrewardDuration_{reward}Durationreward​ denotes the lock-up duration during which the rewards are not settled yet. DurationoverdueDuration_{overdue}Durationoverdue​ denotes the duration of time that is after the last lock-up period and shorter than a lock-up period. The user's rewards are calculated in the following way:

Durationreward=tnow−tlastAction(6)Duration_{reward}=t_{now}-t_{lastAction}(6)Durationreward​=tnow​−tlastAction​(6)
Durationoverdue=DurationrewardmodDurationlock(7)Duration_{overdue}=Duration_{reward} mod Duration_{lock}(7)Durationoverdue​=Durationreward​modDurationlock​(7)
rewardsoverdue=DurationoverdueDurationreward∗(rewards−rewardsprev)(8)rewards_{overdue}=\frac{Duration_{overdue}}{Duration_{reward}}*(rewards-rewards_{prev})(8)rewardsoverdue​=Durationreward​Durationoverdue​​∗(rewards−rewardsprev​)(8)
rewards=rewards−rewardsoverdue(9)rewards=rewards-rewards_{overdue}(9)rewards=rewards−rewardsoverdue​(9)

Contract code

function overdueDuration(address account) public view returns (bool, uint256, uint256){
    uint256 duration = userInfo[account].lockDuration;
    if (duration == 0) {
        return (true, 0, 0);
    }
    uint256 totalTime = block.timestamp.sub(userInfo[account].lockStartTime);
    uint256 round = totalTime.div(duration);
    uint256 overdue = totalTime.mod(duration);
    if (round < 1 || overdue > maintenanceDuration || block.timestamp < userInfo[account].lastActionTime) {
        return (false, 0, 0);
    }

    uint256 rewardsDuration = block.timestamp.sub(userInfo[account].lastActionTime);
    return (true, rewardsDuration, overdue);
}

Mining pools

USDD_USDT LOCK V2 farm

Mainnet contract address:TY1mxnpL18oDP8hsSrrxNZgUMj71pcyFS8

2pool LOCK farm

Mainnet contract address:TJmn1bjmNfE2F1sw2x6P224i8sFQj5mnbg

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

>>> let contract = await tronWeb.getContract('TJmn1bjmNfE2F1sw2x6P224i8sFQj5mnbg')
>>> await contract.methods.sub_pool().call()
TUgVp8FzZcFLHwruuncXaQo2js5Ym2GqSj

View rewards of on-demand mining pools

  • Function:earned(address)

  • Parameter: user's addres

>>> 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('TJmn1bjmNfE2F1sw2x6P224i8sFQj5mnbg')
>>> await contract.methods.deposit(1000000000000000000).send()

Withdrawal

  • Function:withdraw(uint256)

  • Parameter:Withdrawal amount

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

PreviousSmart Mining V1NextGovernance Mining

Last updated 10 months ago