Governance Mining

Governance Mining: A mining mode that gives users more governance rights and rewards

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. Governance mining is an important part of SUN.io's mining service. As shown in the graph below, the reward distributed to users is closely related to the number of veSun tokens they hold and the weights of the liquidity pools. And users are free to redeem their assets at any time.

Explanation

After a user stakes tokens in a liquidity pool, a corresponding amount of virtual stake value will be generated:

Contract code

def _checkpoint(addr: address):
    Controller(_controller).checkpoint_gauge(convert(self.controller_key, bytes32))
    _working_balance: uint256 = self.working_balances[addr]
    _working_supply: uint256 = self.working_supply

    if block.timestamp > _period_time:
        prev_week_time: uint256 = _period_time
        week_time: uint256 = min((_period_time + WEEK) / WEEK * WEEK, block.timestamp)

        for i in range(500):
            dt: uint256 = week_time - prev_week_time
            w: uint256 = Controller(_controller).gauge_relative_weight(convert(self.controller_key, bytes32), prev_week_time / WEEK * WEEK)

            if _working_supply > 0:
                if prev_future_epoch >= prev_week_time and prev_future_epoch < week_time:
                    _integrate_inv_supply += rate * w * (prev_future_epoch - prev_week_time) / _working_supply
                    rate = new_rate
                    _integrate_inv_supply += rate * w * (week_time - prev_future_epoch) / _working_supply
                else:
                    _integrate_inv_supply += rate * w * dt / _working_supply
            if week_time == block.timestamp:
                break
            prev_week_time = week_time
            week_time = min(week_time + WEEK, block.timestamp)

    _period += 1
    self.period = _period
    self.period_timestamp[_period] = block.timestamp
    self.integrate_inv_supply[_period] = _integrate_inv_supply
    
    self.integrate_fraction[addr] += _working_balance * (_integrate_inv_supply - self.integrate_inv_supply_of[addr]) / 10 ** 18
    self.integrate_inv_supply_of[addr] = _integrate_inv_supply
    self.integrate_checkpoint_of[addr] = block.timestamp

Mining Pools

Old 3pool farm

Mainnet contract address:TCpu3GnK6PPZV9ama85mRP97YqRuVXdcSd

SUN-TRX farm

Mainnet contract address:TAkrcKsS5FW9f3ZfzvWy6Zvsz9uEjUxPoV

Old USDC farm

Mainnet contract address:TJ3Qnm9VhzJzhcxk49ZpHBRatD1bsD4xYq

USDT-SUN V2 farm

Mainnet contract address:TPx8BXTgiB1tiL9A9BZuz67bZBvFGYdJS8

BTT-USDT V2 farm

Mainnet contract address:TEULJy4MJeRUTMPGTTvsBkmDPM4PEsMBTw

USDT-TRX farm

Mainnet contract address:TSRhvs1R2hoNf5PuMG4nUrDa4XVBqBaKgF

USDJ-TRX farm

Mainnet contract address:TGJ8LcijTaLmzBhqtp2jWQ1DRCpCWPAmD1

TUSD-TRX farm

Mainnet contract address:TBPEX4Bu3rc8RAvv3qTBFVvSVAFNttinqe

USDC-TRX farm

Mainnet contract address:TDsuMrbQ8wHrM8cKpxFczBbaxhJwpmwRHr

WBTT-TRX farm

Mainnet contract address:TH1XkkkPa7aF1oi7xqFYuUdXR1UvTEd4Ld

BTT-TRX farm

Mainnet contract address:TVjuRFx5dUn4u386DJRJS8zxgWKKcPocXo

NFT-TRX farm

Mainnet contract address:TViH23SgGKWfX4EHB4Q7UMeo1wgvfSvyPS

WIN-TRX farm

Mainnet contract address:TBd8sxVK47adcaLZgbqvN5LTUQGEpawXnx

JST-TRX farm

Mainnet contract address:TFw58b9t55FsmFeZHjLooS3SkMYDKXZoW7

USDT-TRX V2 farm

Mainnet contract address:TUnkvMyZKt4HT2qGWaMwy35c9QTmjiMCWL

NFT-USDT V2 farm

Mainnet contract address:TSYJHJA5rDYhaiadNXDqA6Fk6sq1yqZKwT

WIN-USDT V2 farm

Mainnet contract address:TEHtYRLUTGLq4Z5Pyy5C7LYZBBVVcRuvUU

JST-USDT V2 farm

Mainnet contract address:TKAQajxhQscgakWaokd7uNeTxwBp97xhSD

USDD-USDT V2 farm

Mainnet contract address:TCkNadwxyik1D66qCGmavuneowDRXPgdkL

USDD-TRX farm

Mainnet contract address:TCpXumigVHd2iuSkotNgkSduKqksUfpcvc

3poolnew farm

Mainnet contract address:THZgwb6LTg9LydbLw6gT4YMdu9y4nA5dnp

Usdd2pool farm

Mainnet contract address:TBSRZYLZ2pguF3EqLz86Kt9hZ4eqKEQMSY

2pool farm

Mainnet contract address:TFpg63byqDwniXnyxVYpSzBfWGBwZExM9J

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.

初始化TronWeb实例
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,
      })
     

Transaction execution

View Governance Rewards

  • Function:claimable_tokens(address)

  • Parameter: user's address

>>> let contract = await tronWeb.getContract('TJmn1bjmNfE2F1sw2x6P224i8sFQj5mnbg')
>>> await contract.methods.claimable_tokens('TF5MekHgFz6neU7zTpX4h2tha5miPDUj3z').send()

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

Last updated