I'm looking into Uniswap V2 code and found that it uses _safeTransfer
function to transfer ERC20 tokens in the Pair contract.
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
...
function burn(address to) external lock returns (uint amount0, uint amount1) {
...
_safeTransfer(_token0, to, amount0);
...
}
Why doesn't it simply call IERC20(_token).transfer(to, amount0)
?