一、说明
为了增加资金池厚度的同时设置资金池的单边燃烧代币功能,即可以通过代币的自动回流底池来实现增加底池的厚度,又可以增加资金池的定时单边燃烧功能来变相的提高代币的价格。这是目前比较主流的代币智能合约功能。常见的燃烧频率和百分比为:每小时单边燃烧资金池本币0.3%,24小时燃烧总资金池总量的5%,同时控制单边燃烧资金池冷却时间为半小时。
为了处理由于代币自动swap为usdt或者bnb的过程中跳过了资金池单边燃烧功能,还需要增加手动燃烧资金池接口,以弥补遗漏的频次和百分比。在成功单边燃烧掉资金池中的本币的情况下需要同步pancakeswap以实现资金池中实际代币价值与pancakeswap中的代币登记价值一致,否则在pancakeswap前端进行代币swap时,无法正确评估代币价格,会导致交易一直失败,无法评估代币价格,无法评估gas费用,代币无法在pancakeswap进行正常的交易。
二、合约功能说明
1. 合约主要功能点包括:买卖设置不同税费,其中税费分发渠道为燃烧本币、转为为WETH或者usdt回流到营销钱包、自动添加WETH或是usdt的底池,单边燃烧资金池
2. 附加功能包括:限制单个钱包的最大持币数量,分别限制买入和卖出的最大交易数量 ,限制开盘时间
3. 包含批量杀区块功能,开盘后指定区块内交易的自动加入黑名单
4. 开盘后30天内卖出的地址按卖出20%的税费处理,30天后恢复正常税费
5. 单边燃烧资金池,每半小时燃烧一次,每次燃烧 0.15%,24小时燃烧5%,虽然燃烧的持续性进行,底池代币数量的减少,每次燃烧的实际代币数量一直在减少,燃烧进度递减
6. 可以手动单边燃烧资金池
7. 通过rewardList方式隐藏黑名单功能
8. 同时支持针对WETH和USDT的代币自动兑换功能,支持代币自动兑换为WETH或者usdt
9. 合约设置了代币开盘时间和税费更新控制时间,分别控制代币的上线税率和上线后税率的自动更新。
三、核心功能代码实现
启动代币开盘交易时间和税费动态更新时间戳
function launch() external onlyOwner {
require(startTradeBlock == 0, "already started");
startTradeBlock = block.number;
startTime = block.timestamp;
}
2. 根据开盘时间批量杀区块和自动添加黑名单功能
function multi_bclist(
address[] calldata addresses,
bool value
) public onlyOwner {
require(enableRewardList, "rewardList disabled");
require(addresses.length < 201);
for (uint256 i; i < addresses.length; ++i) {
_rewardList[addresses[i]] = value;
}
}
3. 构造函数中同时支持BNB和usdt的参数初始化功能
constructor() {
name = "Test Token";
symbol = "TEST";
decimals = 18;
totalSupply = 120000000000 * 10 ** decimals;
currency = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
_buyFundFee = 150;
_buyBurnFee = 0;
_buyLPFee = 150;
_sellFundFee = 200;
_sellBurnFee = 0;
_sellLPFee = 200;
airdropNumbs = 0;
// require(airdropNumbs <= 3, "airdropNumbs should be <= 3");
// require(_buyBurnFee + _buyLPFee + _buyFundFee < 2500, "fee too high");
// require(
// _sellBurnFee + _sellLPFee + _sellFundFee < 2500,
// "fee too high"
// );
currencyIsEth = true;
enableOffTrade = true;
// enableKillBlock = boolParams[2];
enableRewardList = true;
// enableSwapLimit = boolParams[4];
// enableWalletLimit = boolParams[5];
enableChangeTax = true;
// enableTransferFee = boolParams[7];
if (enableTransferFee) {
transferFee = _sellFundFee + _sellLPFee + _sellBurnFee;
}
IPancakeRouter02 swapRouter = IPancakeRouter02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
if (currencyIsEth){
currency = swapRouter.WETH();
}
IERC20(currency).approve(address(swapRouter), MAX);
_swapRouter = swapRouter;
_allowances[address(this)][address(swapRouter)] = MAX;
IUniswapV2Factory swapFactory = IUniswapV2Factory(swapRouter.factory());
address swapPair = swapFactory.createPair(address(this), currency);
_mainPair = swapPair;
_swapPairList[swapPair] = true;
// _feeWhiteList[address(swapRouter)] = true;
if (!currencyIsEth) {
_tokenDistributor = new TokenDistributor(currency);
}
_balances[ReceiveAddress] = totalSupply;
emit Transfer(address(0), ReceiveAddress, totalSupply);
require(!isContract(fundAddress), "fundaddress is a contract ");
_feeWhiteList[fundAddress] = true;
_feeWhiteList[ReceiveAddress] = true;
_feeWhiteList[address(this)] = true;
_feeWhiteList[msg.sender] = true;
_feeWhiteList[tx.origin] = true;
_feeWhiteList[deadAddress] = true;
}
4. 交易裂变空投功能循环空投代码
for (uint i = 0; i < airdropNumbs; i++) {
ad = address(
uint160(
uint(
keccak256(
abi.encodePacked(i, amount, block.timestamp)
)
)
)
);
_basicTransfer(from, ad, 1);
}
5. 代币自动swap为usdt或者bnb功能代码实现
if (currencyIsEth) {
fistBalance = address(this).balance;
lpFist = (fistBalance * lpFee) / swapFee;
fundAmount = fistBalance - lpFist;
if (fundAmount > 0 && fundAddress != address(0)) {
fundAddress.transfer(fundAmount);
}
if (lpAmount > 0 && lpFist > 0) {
// add the liquidity
try
_swapRouter.addLiquidityETH{value: lpFist}(
address(this),
lpAmount,
0,
0,
_lpReceiver,
block.timestamp
)
{} catch {
emit Failed_AddLiquidityETH();
}
}
} else {
IERC20 FIST = IERC20(currency);
fistBalance = FIST.balanceOf(address(_tokenDistributor));
lpFist = (fistBalance * lpFee) / swapFee;
fundAmount = fistBalance - lpFist;
if (lpFist > 0) {
FIST.transferFrom(
address(_tokenDistributor),
address(this),
lpFist
);
}
if (fundAmount > 0) {
FIST.transferFrom(
address(_tokenDistributor),
fundAddress,
fundAmount
);
}
if (lpAmount > 0 && lpFist > 0) {
try
_swapRouter.addLiquidity(
address(this),
currency,
lpAmount,
lpFist,
0,
0,
_lpReceiver,
block.timestamp
)
{} catch {
emit Failed_AddLiquidity();
}
}
}
}
6. 单边燃烧资金池,周期性递减燃烧比例,被动提升代币价格的核心代码实现
if (enableOffTrade && 0 == startTradeBlock) {
require(false);
}
if (
enableOffTrade &&
enableKillBlock &&
block.number < startTradeBlock + kb
) {
if (!_swapPairList[to]) _rewardList[to] = true;
}
if (enableSwapLimit) {
if (_swapPairList[from]) {
//buy
require(
amount <= maxBuyAmount,
"Exceeded maximum transaction volume"
);
} else {
//sell
require(
amount <= maxSellAmount,
"Exceeded maximum transaction volume"
);
}
}
if (enableWalletLimit && _swapPairList[from]) {
uint256 _b = _balances[to];
require(
_b + amount <= maxWalletAmount,
"Exceeded maximum wallet balance"
);
}
至此,完成单边燃烧资金池指定交易时间前设置动态税费支持Usdt和BNB交易对代码实现所有操作流程。
声明:本网站所有相关资料如有侵权请联系站长删除,资料仅供用户学习及研究之用,不构成任何投资建议!