如何使用智能合约添加流动性?
我们正在尝试使用智能合约来增加流动性。我们有通货膨胀令牌,这些代币收取的代币费用。但是,当我们试图使用uniswap或pancake交换其还收取税费时,要克服此问题并获得无流动性税,我们希望在我们自己的网站上创建使用“禁用费用和附加费”页面来创建自定义的附加功能。使用该网站的附加功能。
function addLiquidity() external onlyOwner() {
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
liquidityAdded = true;
// feeEnabled = true;
limitTX = true;
_maxTxAmount = 100000000 * 10**9; // 1%
_maxBuyAmount = 20000000 * 10**9; //0.2% buy cap
IERC20(pancakeswapPair).approve(address(uniswapV2Router),type(uint256).max);
}
function addLiquidityCustome1(address _tokenA,address _tokenB,uint _amountA,uint _amountB) external {
bool _temp_feeEnabled = feeEnabled;
feeEnabled = false;
IERC20(_tokenA).transferFrom(msg.sender, address(this), _amountA);
IERC20(_tokenB).transferFrom(msg.sender, address(this), _amountB);
IERC20(_tokenA).approve(routerAddress, _amountA);
IERC20(_tokenB).approve(routerAddress, _amountB);
(uint amountA, uint amountB, uint liquidity)=uniswapV2Router.addLiquidity(_tokenA,_tokenB,_amountA,_amountB,1,1,address(msg.sender),block.timestamp);
feeEnabled = _temp_feeEnabled;
emit CustomeAddLiquidityEvent(msg.sender,amountA,amountB,liquidity);
}
function addLiquidityCustome2(uint _tokenAmount,uint _ethAmount) external {
bool _temp_feeEnabled = feeEnabled;
feeEnabled = false;
_approve(address(this), address(uniswapV2Router), _tokenAmount);
(uint amountA, uint amountB, uint liquidity) = uniswapV2Router.addLiquidityETH{value: _ethAmount}(address(this),_tokenAmount,0,0,msg.sender,block.timestamp);
feeEnabled = _temp_feeEnabled;
emit CustomeAddLiquidityEvent(msg.sender,amountA,amountB,liquidity);
}
因此 我们创建了3个显示上述代码上方的附加功能函数,仅使所有者设置令牌的初始价格。第二和第三函数addliquisityCustome1,addliquisityCustome2是自定义函数。用户可以在哪里使用我们自己的网站直接增加流动性,以便在增加流动性的同时关闭费用。但是,此功能无法正常工作,并引发错误 - 警告!合同执行期间遇到的错误[恢复执行],
请指导我们如何在智能合约中实现自定义的附加功能。因此,我们可以在添加流动性并免费税收的同时删除费用。请帮助我解决这个问题确实是一个很好的帮助。随着漫长的努力。非常感谢您 请找到错误屏幕截图 错误屏幕截图
We are trying to add liquidity using smart contract. we have deflationary tokens which charge fee on buy and sell of token. but when we are trying to addLiquidity using uniswap or pancake swap its also charging tax fee ,So to overcome this issue and to have add liquidity tax free we want to create custom addLiquidity function with disable fee and addLiquidity page on our own website so user can addLiquidity using that website .
function addLiquidity() external onlyOwner() {
_approve(address(this), address(uniswapV2Router), _tTotal);
uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
swapEnabled = true;
liquidityAdded = true;
// feeEnabled = true;
limitTX = true;
_maxTxAmount = 100000000 * 10**9; // 1%
_maxBuyAmount = 20000000 * 10**9; //0.2% buy cap
IERC20(pancakeswapPair).approve(address(uniswapV2Router),type(uint256).max);
}
function addLiquidityCustome1(address _tokenA,address _tokenB,uint _amountA,uint _amountB) external {
bool _temp_feeEnabled = feeEnabled;
feeEnabled = false;
IERC20(_tokenA).transferFrom(msg.sender, address(this), _amountA);
IERC20(_tokenB).transferFrom(msg.sender, address(this), _amountB);
IERC20(_tokenA).approve(routerAddress, _amountA);
IERC20(_tokenB).approve(routerAddress, _amountB);
(uint amountA, uint amountB, uint liquidity)=uniswapV2Router.addLiquidity(_tokenA,_tokenB,_amountA,_amountB,1,1,address(msg.sender),block.timestamp);
feeEnabled = _temp_feeEnabled;
emit CustomeAddLiquidityEvent(msg.sender,amountA,amountB,liquidity);
}
function addLiquidityCustome2(uint _tokenAmount,uint _ethAmount) external {
bool _temp_feeEnabled = feeEnabled;
feeEnabled = false;
_approve(address(this), address(uniswapV2Router), _tokenAmount);
(uint amountA, uint amountB, uint liquidity) = uniswapV2Router.addLiquidityETH{value: _ethAmount}(address(this),_tokenAmount,0,0,msg.sender,block.timestamp);
feeEnabled = _temp_feeEnabled;
emit CustomeAddLiquidityEvent(msg.sender,amountA,amountB,liquidity);
}
So for this
We have created 3 addliquidity functions showing above code 1st one is for only owner to set the initial price of token . 2nd and 3rd function addLiquidityCustome1 ,addLiquidityCustome2 are custom function. where user can addliquidity directly using our own website so we turn off fee while adding liquidity. but this functions are not working and throwing an error as -- Warning! Error encountered during contract execution [execution reverted]
please guide us how we can implement custom addLiquidity function in smart contract .so we can remove fee while adding liquidity and make it tax free . please help me out to solve this issue will really be a great help. as struggling on this from long. thank you so much in advance
please find error screenshot
error screenshot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论