一、准备
关于free自由协议合约代码部署及分析。free token自由协议主要包括如下模式:
1、持币生息,2%日复利模式,相当于原地对每个持币地址增发2%
2、买卖手续费不同,买入时十代推广收益加LP加池分红或者叫自动筑池,卖出时包括燃烧、自由基金会地址、共识基金地址(市场,营销,开发者钱包等),freedao等组合模式
3、设置定时开盘,未到规定时间不允许线上交易
4、开盘后6分钟内交易的代币加收55%的手续费,避免开盘即砸盘的现象
5、手续费可以动态调整,随时可变貔貅盘(只能买入,不能卖出)
二、合约部署
主要包括如下几个合约文件:IERC20.sol,SafeMathInt.sol,SafeMath.sol,IPancakeSwapPair.sol,IPancakeSwapRouter.sol,IPancakeSwapFactory.sol,Ownable.sol,ERC20Detailed.sol,IFreeDao.sol,IFree.sol,Free.sol
1、按照如下顺序编译合约
2、部署合约
输入相关构造函数参数,完成合约部署
其中构造函数输入如下:
a. pancakeswap的routerv2地址:0x10ED43C718714eb63d5aA57B78B54704E256024E
b. freeDAO代理地址:0x499f87dfa6cbb1b66ae82941f265023e78e27e45
c. LP自动加池后接受地址:0x69434e8512e5905b08df97e4aff70648fec1d6b2
d. 燃烧池地址:0x0058c350b1496db5d34da757ca793d8b930c2401
e. 发行总量:653815000
f. 开盘时间:1651820400
完成合约部署后,开源合约即可,在此不做赘述。
3、合约部署完成后,配置合约相关动态参数,直接在区块链浏览器配置即可。根据项目特定需求配置为适合自己的参数值即可。
三、合约源代码分析
1、构造函数如下:
constructor(address _swapRouter,address _freeDaoAddress,address _autoLiquidityReceiver,address _firePit,uint256 _initSupply,uint256 _startTradingTime) ERC20Detailed(_name,_symbol, uint8(DECIMALS)) Ownable() { require(_swapRouter!=address(0),"invalid swap router address"); require(_freeDaoAddress!=address(0),"invalid free dao address"); freeDaoAddress = _freeDaoAddress; usdtAddress = IFreeDao(_freeDaoAddress).payToken(); router = IPancakeSwapRouter(_swapRouter); pair = IPancakeSwapFactory(router.factory()).createPair( usdtAddress, address(this) ); require(_initSupply>0,"invalid init supply"); _totalSupply = _initSupply*10**DECIMALS; TOTAL_GONS = MAX_UINT256/1e10 - (MAX_UINT256/1e10 % _totalSupply); autoLiquidityReceiver = _autoLiquidityReceiver; firePit = _firePit; _gonBalances[msg.sender] = TOTAL_GONS; _gonsPerFragment = TOTAL_GONS.div(_totalSupply); //_lastRebasedTime = block.timestamp; _autoRebase = true; _autoSwapBack = true; _autoAddLiquidity = true; _isFeeExempt[msg.sender] = true; _isFeeExempt[address(this)] = true; _isFeeExempt[freeDaoAddress] = true; setStartTradingTime(_startTradingTime); autoLiquidityInterval = 10 minutes; emit Transfer(address(0x0), msg.sender, _totalSupply); }
2、复利模式的rebase核心函数如下:
function rebase() internal { if ( inSwap ) return; uint256 rebaseRate = 21447; uint256 deltaTime = block.timestamp - _lastRebasedTime; uint256 times = deltaTime.div(15 minutes); uint256 epoch = times.mul(15); for (uint256 i = 0; i < times; i++) { _totalSupply = _totalSupply .mul((10**RATE_DECIMALS).add(rebaseRate)) .div(10**RATE_DECIMALS); } _gonsPerFragment = TOTAL_GONS.div(_totalSupply); _lastRebasedTime = _lastRebasedTime.add(times.mul(15 minutes)); emit LogRebase(epoch, _totalSupply); }
3、transfer函数核心功能代码如下:
function transfer(address to, uint256 value) external override validRecipient(to) returns (bool) { _transferFrom(msg.sender, to, value); return true; } function transferFrom( address from, address to, uint256 value ) external override validRecipient(to) returns (bool) { if (_allowedFragments[from][msg.sender] != uint256(-1)) { _allowedFragments[from][msg.sender] = _allowedFragments[from][ msg.sender ].sub(value, "Insufficient Allowance"); } _transferFrom(from, to, value); return true; }
function takeFee( address sender, address recipient, uint256 gonAmount ) internal returns (uint256) { uint256 _totalFee = 0; uint256 _treasuryFee = treasuryFee; uint256 _robotsFee = 550; //sell token or transfer token if (sender != pair) { _totalFee = firePitFee.add(treasuryFee).add(daoFee).add(consensusFundFee);//when sell token . _gonBalances[firePit] = _gonBalances[firePit].add( gonAmount.div(feeDenominator).mul(firePitFee) ); _gonBalances[treasuryReceiver] = _gonBalances[treasuryReceiver].add( gonAmount.div(feeDenominator).mul(_treasuryFee.add(consensusFundFee)) ); _gonBalances[freeDaoAddress] = _gonBalances[freeDaoAddress].add( gonAmount.div(feeDenominator).mul(daoFee) ); IFreeDao(freeDaoAddress).setDaoReward(gonAmount.div(_gonsPerFragment).mul(daoFee).div(feeDenominator)); } if (sender == pair) {//when buy token _totalFee = inviteFee.add(liquidityFee); _gonBalances[autoLiquidityReceiver] = _gonBalances[autoLiquidityReceiver].add( gonAmount.div(feeDenominator).mul(liquidityFee) ); } if (recipient==pair||sender==pair){ //sell token require(startTradingTime>0&&block.timestamp>=startTradingTime,"can not trade now!"); if (block.timestamp<=startTradingTime+6){ _totalFee = _totalFee.add(_robotsFee); _gonBalances[autoLiquidityReceiver] = _gonBalances[autoLiquidityReceiver].add( gonAmount.div(feeDenominator).mul(_robotsFee) ); } } uint256 feeAmount = gonAmount.div(feeDenominator).mul(_totalFee); emit Transfer(sender, address(this), feeAmount.div(_gonsPerFragment)); if (sender == pair){ totalInviteAmount = totalInviteAmount.add(gonAmount.div(_gonsPerFragment).mul(inviteFee).div(feeDenominator)); address[] memory _parents = IFreeDao(freeDaoAddress).getRelations(recipient); for (uint8 i=0;i<_parents.length;i++){ uint256 _parentFee = gonAmount.mul(5).div(1000); if (i==0){ _parentFee = gonAmount.mul(4).div(100); } if(i==1){ _parentFee = gonAmount.mul(2).div(100); } _gonBalances[_parents[i]] = _gonBalances[_parents[i]].add( _parentFee ); emit Transfer(recipient, _parents[i], _parentFee.div(_gonsPerFragment)); } } return gonAmount.sub(feeAmount); }
四、完整版合约源代码代码如下
至此,完成持币生息分红复利模式NFT节点自由基金共识基金十代推广收益LP分红合约部署及代码分析所有操作流程。
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载:
多模式(燃烧、回流指定营销地址、分红本币及任意币种,邀请推广八代收益,LP加池分红、交易分红、复利分红、NFT分红、自动筑池、动态手续费、定时开盘、回购)组合合约源代码下载:
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载地址:
添加VX或者telegram获取全程线上免费指导
评论前必须登录!
注册