- A+
质押挖矿是继流动性后挖矿后由各大DEX推出的新的挖矿模式,即质押母币挖矿子币。项目大致流程如下:前期先发行母币,随着母币的生态建设逐步完善,打通其在多个场景的应用落地。母币真正流通后,通证质押池,用户质押部分母币到质押池来获取子币,从而,实现子币的逐步流通,具体过程如下。
1、前期发行母币通证,为母币寻找合适的应用落地场景,完善生态建设
2、发行子币,设置子币的获取方式只能是通过母币质押获得
3、通过合约控制质押挖矿的业务逻辑,通过dapp与用户实现业务层面的交互。
质押合约主要包含的元素属性:母币合约地址、子币合约地址、质押周期,母币年收益率、子币年收益率,子母币的兑换比例、最少质押数量等。
质押合约的核心代码如下:
function stake(uint256 i) external nonReentrant {
require(i < ledger[msg.sender].length, "Invalid index");
require(ledger[msg.sender][i].ended==false, "Invalid stake");
// penalization
if(block.timestamp.sub(ledger[msg.sender][i].from) < maturity) {
uint256 _penalization = ledger[msg.sender][i].amount.mul(penalization).div(100);
asset.transfer(msg.sender, ledger[msg.sender][i].amount.sub(_penalization));
asset.transfer(getOwner(), _penalization);
ledger[msg.sender][i].penalization = _penalization;
ledger[msg.sender][i].ended = true;
emit StakeEnd(msg.sender, ledger[msg.sender][i].amount, _penalization, 0, i);
// interest gained
} else {
// interest is calculated in asset2
uint256 _interest = get_gains(msg.sender, i);
// check that the owner can pay interest before trying to pay, token 1
if (_interest>0 && asset.allowance(getOwner(), address(this)) >= _interest && asset.balanceOf(getOwner()) >= _interest) {
//transfer logical
} else {
_interest = 0;
}
// interest is calculated in asset2
uint256 _interest2 = get_gains2(msg.sender, i);
// check that the owner can pay interest before trying to pay, token 1
if (_interest2>0 && asset2.allowance(getOwner(), address(this)) >= _interest2 && asset2.balanceOf(getOwner()) >= _interest2) {
//asset2.transfer.logical
} else {
_interest2 = 0;
}
// the original asset is returned to the investor
asset.transfer(msg.sender, ledger[msg.sender][i].amount);
ledger[msg.sender][i].to = block.timestamp;
ledger[msg.sender][i].ended = true;
emit StakeEnd(msg.sender, ledger[msg.sender][i].amount, 0, _interest, i);
}
}
前台用户操作页面提供质押合约owner的approve授权到质押合约的转账数量。合约owner可以直接授权母币质押额度。用户可以通过stake功能,设置质押母币数量,根据合约的规则挖矿子币。
至此,完成币安BSC智能链质押挖矿,质押母币挖矿子币模式合约代码。
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载:
多模式(燃烧、回流指定营销地址、分红本币及任意币种,邀请推广八代收益,LP加池分红、交易分红、复利分红、NFT分红、自动筑池、动态手续费、定时开盘、回购)组合合约源代码下载:
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载地址:
本文是全系列中第195 / 243篇:通证发行
- 我的微信
- 这是我的微信扫一扫
-
- 我的电报
- 这是我的电报扫一扫
-