v3-core icon indicating copy to clipboard operation
v3-core copied to clipboard

Redundant code and optimization

Open octaviusp opened this issue 2 years ago • 0 comments

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);
    }

octaviusp avatar Jan 21 '23 15:01 octaviusp