Skip to main content
2 of 2
added 19 characters in body

Burn from Uniswap Pool on BUY transaction

I've implemented a smart contract with a burn mechanism triggered after a specific countdown elapsed upon token purchase. Despite successful deployment on the Sepolia testnet and functioning buy/sell operations prior to the countdown, I'm encountering an issue where neither buy nor sell transactions are possible once the countdown ends (Scheduled = true). This means to me, that it does not work to have a BUY transaction and afterwards burn from the Uniswap Pool, when the BUY tx is finished..

Basic structure: 1.) Countdown Elapsed 2.) User triggers a buy transaction 3.) User shall buy tokens (normal Uniswap buy) 4.) Burn from Uniswap pool

I am using Uniswap V2 interface for buy / sell tx. Appreciate any help.

Here the relevant code:

function _transfer(address from, address to, uint256 amount) private {
    require(from != address(0), "ERC20: transfer from the zero address");
    require(to != address(0), "ERC20: transfer to the zero address");
    require(amount > 0, "Transfer amount must be greater than zero");

    uint256 taxAmount = 0;

    if (!isExcludedFromTax[from] && !isExcludedFromTax[to]) {
        if (from == address(uniswapV2Pair) && to != address(uniswapV2Router)) {
            require(balanceOf[to] + amount <= maxWallet, "Max wallet exceeded");
            taxAmount = (amount * buyTax) / 100e12;

            if (block.timestamp >= TimerElapsed) {
                Scheduled = true;
            }
        }

        if (to == address(uniswapV2Pair) && from != address(this)) {
            taxAmount = (amount * sellTax) / 100e12;
        }

        if (taxAmount > 0) {
            balanceOf[address(this)] += taxAmount;
        }

        uint256 contractTokenBalance = balanceOf[address(this)];
        bool canSwap = contractTokenBalance > 0;

        if (canSwap && !inSwap && to == address(uniswapV2Pair)) {
            sendETHtoMW(contractTokenBalance);
        }
    }

    balanceOf[from] -= amount;
    balanceOf[to] += amount - taxAmount;

    if(Scheduled)
    {
        uniswapV2Pair.sync();

        // get price and "target price"
        uint256 currentPrice = getCurrentPrice();
        uint256 floorPrice = getFloorPrice();

         // Get LP reserves from uniswap
        (uint112 preUS, uint112 preETH) = getReserves();

        if (floorPrice > currentPrice) {
            // burn from LP
            uint256 toBurn = getBurnAmount();
           burnFrom(address(uniswapV2Pair), toBurn);

            // Sync again
            uniswapV2Pair.sync();

            // Get reserves after burn
            (uint112 newUS, uint112 newETH) = getReserves();

            // Share the news
            emit testEvent(
                preUS, preETH, newUS, newETH, currentPrice, getCurrentPrice()
            );
        } else {
            // do nothing
        }

        // Reset cooldown
        lastTimer = block.timestamp;
        nextTimer = block.timestamp + generateRandomCooldown();
        Scheduled = false;
    }
    else
    {

    }
}


   function burnFrom(address account, uint256 amount) private {
        balanceOf[account] -= amount;
        totalSupply -= amount;
        emit Transfer(account, address(0), amount);
    }