-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and optimizations #34
Merged
Merged
+487
−345
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gnarlycow
approved these changes
May 1, 2024
`mulDiv96` method was renamed to `mulDivQ96` in multiple files to improve code clarity. The updated method naming now provides a more accurate representation of its functionality and usage within the mathematics performing code.
A new function mulDivQ128 was added to FullMath.sol to calculate a * b / 2^128 with full precision. Corresponding test cases have been added to FullMath.t.sol. The package version in package.json has been updated from 2.0.2 to 2.1.0 to reflect this enhancement. Additionally, .gas-snapshot has been adjusted accordingly.
This commit refactors the `TickBitmap` code to enhance readability. It includes wrapping some lines into `unchecked` blocks and changing the calculation of the `initialized` variable to a simple non-zero check. These changes don't affect functionality, but they make the code cleaner and easier to comprehend.
Two new functions, `absDiff` and `absDiffU160`, have been added to `TernaryLib.sol`, both of which perform absolute difference operations. The `sort2` function was also added and the `sort2` function used for sorting `uint160`s has been renamed to `sort2U160` for better distinction. All calls to `sort2` in `SqrtPriceMath.sol` have been updated to use `sort2U160` instead.
The method `absDiffU160` from the `TernaryLib` is now used in the `getAmount1Delta` function inside `SqrtPriceMath.sol`. This change has streamlined the subtraction operation that was previously done using `sort2U160` and `sub` methods. Accordingly, the gas usage for several methods in the `.gas-snapshot` file has also been updated.
Introduced new functions for calculating the amount of liquidity received for a given amount of tokens and price range. These functions, getLiquidityForAmount0Sorted and getLiquidityForAmount1Sorted, work with sorted boundaries. This change simplifies and improves the efficiency of the code by eliminating the need for boundary sort in multiple places. Updated method references in current pool price computations accordingly.
Refactor the `computeSwapStep` method in 'SwapMath.sol' to remove assembly blocks for computing 'amountRemainingAbs'. Implemented using plain Solidity for better readability, maintainability, and security.
The overflow/underflow prevention comment within the `TickBitmap.sol` file was moved for better clarity and accuracy. In `PoolCaller.sol`, a new TODO comment was added to suggest the use of `mcopy` for future data copying tasks, aiming for code optimization and efficiency improvement.
…napshot The code was adjusted by eliminating an unnecessary sign extension inside SqrtPriceMath.sol. This results in cleaner assembly with less operations. In addition, the gas snapshot file has been updated to reflect alterations in gas usage metrics across multiple areas, showcasing the effects of the modification.
The assembly code used for handling integer sign has been updated for optimization. Changes involve replacing subtraction operations with signed bit shift for better computational performance. This alteration significantly improves the efficiency of absolute value and absolute difference operations in the Solidity library.
The process of determining the sign of 'liquidity' in the SqrtPriceMath.sol file has been simplified by directly using a mask. This modification has led to small improvements in gas consumption as reflected in the .gas-snapshot file. The performance tests showed minor variations in runtimes.
The absDiff function in TernaryLib.sol has been updated to prevent overflow of int256 when computing the difference between two uint256 values. This is achieved by handling the subtraction operation differently based on whether 'a' is greater than 'b'. Additionally, the snapshot and snapshot:diff command in package.json was simplified by removing unnecessary options (--via-ir and --evm-version cancun).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.