智能挖矿V2

智能挖矿V2:一种定期存取的高收益挖矿模式

背景

挖矿服务是SUN.io平台数字金融衍生品之一,为加密数字资产持有用户提供稳定、安全、可靠的理财产品申购和赎回服务。智能挖矿V2又名定期挖矿,是SUN.io挖矿服务重要组成部分。其原理是根据存款用户质押金额和定期时长转换为虚拟质押金额,所有用户虚拟质押金额的总量作为虚拟总质押,根据用户的虚拟质押在虚拟总质押的占比分配奖励,且用户需在规定时间赎回相关资产。

原理简介

奖励分成

质押数量为amount的token,锁定时间为 DurationlockDuration_{lock}满足Durationmin<=Durationlock<=DurationmaxDuration_{min}<=Duration_{lock}<=Duration_{max}。其中DurationmaxDuration_{ma x}max为1080天,DurationminDuration_{min}为30天,最大加速倍率weightmaxweight_{max}为1400%(放大e12e^{12}倍),获得的veToken计算公式:

weight=Durationlockweightamxe12Durationmax1weight=\frac{Duration_{lock}*weight_{amx}*e^{12}}{Duration_{max}}(1)
balanceveToken=amount+amountweighte122balance_{veToken}=amount+amount*weight*e^{-12}(2)

其中balanceveTokenbalance_{veToken}为用户的虚拟质押金额。根据智能挖矿V1的奖励分成公式(2),用户的奖励公式如下:

f(ti,tn)=i=1mbalanceveTokenj=startiendi(titi1)rtTi3f(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)

其中 rtr_t表示奖励代币的膨胀系数, tit_i表示第i次变化, TiT_i表示ti1t_{i-1}tit_i阶段时刻虚拟质押总额,balanceveTokenbalance_{veToken}表示用户在ti1t_{i-1}tit_i阶段时刻的虚拟质押金额。

对应合约代码

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

定期赎回时间限制

锁定时间为DurationlockDuration_{lock},复投犹豫期DurationmaintenanceDuration_{maintenance},定期质押时间tstaket_{stake},当前时间tnowt_{no w},同时满足一下条件可以赎回:

tnowtstake>=Durationlock4t_{now}-t_{stake}>=Duration_{lock}(4)
(tnowtstake)modDurationlock<=Durationmaintenance5(t_{now}-t_{stake}) mod Duration_{lock} <= Duration_{maintenance}(5)

总奖励rewards,已结算分成rewardsprevrewards_{prev},结算时间tlastActiont_{lastAction}未结算定投时间DurationrewardDuration_{reward},其中超过且不满一个定投周期的时间DurationoverdueDuration_{overdue},提取分成奖励公式:

Durationreward=tnowtlastAction6Duration_{reward}=t_{now}-t_{lastAction}(6)
Durationoverdue=DurationrewardmodDurationlock7Duration_{overdue}=Duration_{reward} mod Duration_{lock}(7)
rewardsoverdue=DurationoverdueDurationreward(rewardsrewardsprev)8rewards_{overdue}=\frac{Duration_{overdue}}{Duration_{reward}}*(rewards-rewards_{prev})(8)
rewards=rewardsrewardsoverdue9rewards=rewards-rewards_{overdue}(9)

对应合约代码

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

矿池

USDD_USDT LOCK V2 farm

主网合约地址:TY1mxnpL18oDP8hsSrrxNZgUMj71pcyFS8

2pool LOCK farm

主网合约地址:TJmn1bjmNfE2F1sw2x6P224i8sFQj5mnbg

与合约交互

我们利用TronWeb与合约交互, 初始化TronWeb实例后, 就能很方便的与线上合约交互。

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

获取矿池信息

查看定活期矿池地址

  • 函数名称:sub_pool()

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

查看定期奖励

  • 函数名称:earned(address)

  • 参数:用户地址

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

执行交易

存款

  • 函数名称:deposit(uint256)

  • 参数:存款金额

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

取款

  • 函数名称:withdraw(uint256)

  • 参数:取款金额

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

Last updated