◆ Purpose

to decrease(burn) lp token

◆ Input & Return value

(address to) ⇒ (uint amount0, uint amount1)

◆ Example

to[pair(USDC/WETH)] = 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc

I’m using some values from mint

liqudity (LP token amount): 18265152.653

balance0: 43086702975516(reserve0)+1000(amount0) = 43086702976516

balance1: 41997552572672937696884(reserve1) + 974721890337(amount1) = 4.19976E+22

totalSupply: 786985207163076840 + 18265152.653 = 7.8698521e+17

amount0 = liquidity.mul(balance0) / _totalSupply = 1000

amount1 = liquidity.mul(balance1) / _totalSupply = 974721890336

◆ Code and Explain

function burn(address to) external lock returns (uint amount0, uint amount1) {
        (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
        address _token0 = token0;                                // gas savings
        address _token1 = token1;                                // gas savings
        uint balance0 = IERC20(_token0).balanceOf(address(this));
        uint balance1 = IERC20(_token1).balanceOf(address(this));
        uint liquidity = balanceOf[address(this)]; // this is a balance of LP token

        bool feeOn = _mintFee(_reserve0, _reserve1);
        uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
        amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
        amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
        require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED');
        _burn(address(this), liquidity);//liquidity is burned
        _safeTransfer(_token0, to, amount0);
        _safeTransfer(_token1, to, amount1);
        balance0 = IERC20(_token0).balanceOf(address(this));
        balance1 = IERC20(_token1).balanceOf(address(this));

        _update(balance0, balance1, _reserve0, _reserve1);
        if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
        emit Burn(msg.sender, amount0, amount1, to);
    }

◆ Resources

https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Pair.sol#L134

mint