gas optimizations for the FullRange hook #85
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.
Related Issue
#84
Description of changes
This PR attempts to improve the FullRange hook code.
The rationale for increasing the tick spacing is described in #84.
The existing tests show some gas improvements, for most of the tests. However, the main benefits would for large swaps, something that is not captured by the existing tests. A new test
testFullRange_swap_LargeSwap
is added, with a gas snapshot of its own. With 60 tick spacing the gas cost is 175,523. With the new 0x7000 tick spacing it is just 150,173.Unfortunately the large tick spacing adds some rounding errors to the liquidity distribution, so most of the existing tests were failing. I modified the tests, mostly by changing from
assertEq
toassertApproxEqAbs
with the accuracy ofDUST
(30 wei).Let me know how you feel about increasing the tick spacing, if this is contentious I can make a simple PR that just adds the
immutable
fields and the other minor changes.Also I did not attempt to do the more tricky optimizations like adding
unchecked
to the code, so I believe there's room for further improvements.