'how to add liquidity using smart contract
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 trying to addLiquidity using uniswap it also charge fee to overcome this issue we want to create custome 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);
}
we have create 3 addliquidity functions 1st one is for onlyowener for set the initial price of token . 2nd and 3rd function addLiquidityCustome1 ,addLiquidityCustome2 are custome function. whare user can addliquidity directly using our own website so we turn off fee while adding liquidity. function are not working.it throws an error . Warning! Error encountered during contract execution [execution reverted]
please guide us how we can implement custome addLiquidity function in smart contract .so we can can remove fee while adding liquidity . please help me out to solve this issue.it's much appreciated.
below error screen short attached please check. enter image description here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
