-
Notifications
You must be signed in to change notification settings - Fork 2
Simplify max amount calculation using price impact #54
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
Closed
+63
−308
Conversation
This file contains hidden or 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
Kay-Zee
approved these changes
Nov 15, 2025
Contributor
Author
|
Please hold off on merging this PR for now, as I still need to complete testing and performance benchmarking. |
refactor(UniswapV3SwapConnectors.cdc): rename variable slot0Res to s0Res for brevity and consistency in naming conventions refactor(UniswapV3SwapConnectors.cdc): change maxAmount type from UInt to UFix128 for improved precision in calculations fix(UniswapV3SwapConnectors.cdc): update calculations to use UFix128 for consistent handling of decimal values in price impact logic
a58fd64 to
a8dd82c
Compare
…ns to use UInt256 to prevent overflow and improve accuracy in arithmetic operations
4253daf to
ce17ca4
Compare
…m 500 to 600 basis points to reflect new configuration requirements
ce17ca4 to
6fe99aa
Compare
…mount-calculation
nialexsan
approved these changes
Nov 27, 2025
…s for better project structure fix(UniswapV3SwapConnectors.cdc): change maxPriceImpactBps from let to var to allow updates and add setter function for maxPriceImpactBps with validation
…ngs to simplify configuration
6943f61 to
c44e449
Compare
nialexsan
reviewed
Nov 27, 2025
Comment on lines
116
to
122
| access(all) fun setMaxPriceImpactBps(_ bps: UInt) { | ||
| pre { | ||
| bps > 0 && bps <= 5000: "maxPriceImpactBps must be between 1 and 5000 (0.01% to 50%)" | ||
| } | ||
| self.maxPriceImpactBps = bps | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to guard this method?
…variable to constant to ensure immutability chore(UniswapV3SwapConnectors.cdc): remove setMaxPriceImpactBps function as it is no longer needed with constant maxPriceImpactBps
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.
Fix computation limits in Uniswap V3 connector
Problem
getMaxAmount()was hitting computation limits due to expensive tick bitmap scanning (20-30+ EVM calls per transaction).Solution
Replaced tick-scanning with lightweight price impact heuristic:
Changes
getMaxAmount()calculationmaxPriceImpactBpsparameterTrade-off
Less precise but significantly faster. Sufficient for preventing oversized swap requests.