✅BurnLiquid
We need to transfer LP tokens that we hold to pair first, then burn it. This code shows that the pair will burn every LP token the pair holds when pair.burn() is called, which means the pair expects you to transfer your LP tokens within the same tx before calling pair.burn()
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "./interfaces/IUniswapV2Pair.sol";
import "./interfaces/IERC20.sol";
contract BurnLiquid {
/**
* BURN LIQUIDITY WITHOUT ROUTER EXERCISE
*
* The contract has an initial balance of 0.01 UNI-V2-LP tokens.
* Burn a position (remove liquidity) from USDC/ETH pool to this contract.
* The challenge is to use the `burn` function in the pool contract to remove all the liquidity from the pool.
*
*/
function burnLiquidity(address pool) public {
/**
* burn(address to);
*
* to: recipient address to receive tokenA and tokenB.
*/
IUniswapV2Pair pair = IUniswapV2Pair(pool);
uint256 lpBalance = pair.balanceOf(address(this));
pair.transfer(pool, lpBalance);
pair.burn(address(this));
}
}
Last updated