v3-core
v3-core copied to clipboard
Redundant code and optimization
https://github.com/Uniswap/v3-core/blob/05c10bf6d547d6121622ac51c457f93775e1df09/contracts/UniswapV3Pool.sol#L140
We could rewrite this set of functions as:
function balanceTokens(address token) private view returns (uint256) {
(bool success, bytes memory data) = token.staticcall(
abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this))
);
require(success && data.length >= 32);
return abi.decode(data, (uint256));
}
/// @dev Get the pool's balance of token0
function balance0() private view returns (uint256) {
return balanceTokens(token0);
}
/// @dev Get the pool's balance of token1
function balance1() private view returns (uint256) {
return balanceTokens(token1);
}