Loss of precision in `twapPriceInEther` due to division before multiplication
When calculating `twapPriceInEther`, `twapPrice` is divided by 1e6 before multiplication with 1e18 is done.\\n```\\n    function baseOracleCircuitBreaker(\\n        uint256 protocolPrice,\\n        uint80 roundId,\\n        int256 chainlinkPrice,\\n        uint256 timeStamp,\\n        uint256 chainlinkPriceInEth\\n    ) private view returns (uint256 _protocolPrice) {\\n        \\n        // more code\\n\\n        if (invalidFetchData || priceDeviation) {\\n            uint256 twapPrice = IDiamond(payable(address(this))).estimateWETHInUSDC(\\n                Constants.UNISWAP_WETH_BASE_AMT, 30 minutes\\n            );\\n            uint256 twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1 ether;\\n```\\n\\nhttps://github.com/Cyfrin/2023-09-ditto/blob/a93b4276420a092913f43169a353a6198d3c21b9/contracts/libraries/LibOracle.sol#L64-L85\\nAccording to the above calculation, the `twapPrice` obtained would be precise upto 6 decimal places. Performing division before multiplying with 1e18 will result in loss of this precision and.\\nExample Scenario\\n```\\ntwapPrice = 1902501929\\ntwapPriceInEther = 1902000000000000000000\\n\\n// if multiplication is performed earlier,\\ntwapPriceInEther = 1902501929000000000000\\n```\\n
Perform the multiplication before division.\\n```\\ndiff // Remove the line below\\n// Remove the line below\\ngit a/contracts/libraries/LibOracle.sol b/contracts/libraries/LibOracle.sol\\nindex 23d1d0a..6962ad7 100644\\n// Remove the line below\\n// Remove the line below\\n// Remove the line below\\n a/contracts/libraries/LibOracle.sol\\n// Add the line below\\n// Add the line below\\n// Add the line below\\n b/contracts/libraries/LibOracle.sol\\n@@ // Remove the line below\\n82,7 // Add the line below\\n82,7 @@ library LibOracle {\\n             uint256 twapPrice = IDiamond(payable(address(this))).estimateWETHInUSDC(\\n                 Constants.UNISWAP_WETH_BASE_AMT, 30 minutes\\n             );\\n// Remove the line below\\n            uint256 twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1 ether;\\n// Add the line below\\n            uint256 twapPriceInEther = (twapPrice * 1 ether) / Constants.DECIMAL_USDC;\\n             uint256 twapPriceInv = twapPriceInEther.inv();\\n             if (twapPriceInEther == 0) {\\n                 revert Errors.InvalidTwapPrice();\\n```\\n
Price used can have -1 (in 18 decimals) difference from the original price.
```\\n    function baseOracleCircuitBreaker(\\n        uint256 protocolPrice,\\n        uint80 roundId,\\n        int256 chainlinkPrice,\\n        uint256 timeStamp,\\n        uint256 chainlinkPriceInEth\\n    ) private view returns (uint256 _protocolPrice) {\\n        \\n        // more code\\n\\n        if (invalidFetchData || priceDeviation) {\\n            uint256 twapPrice = IDiamond(payable(address(this))).estimateWETHInUSDC(\\n                Constants.UNISWAP_WETH_BASE_AMT, 30 minutes\\n            );\\n            uint256 twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1 ether;\\n```\\n