how to add liquidity using smart contract?

1.6k views Asked by At

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

0

There are 0 answers