Fix precision-related bugs in TidalProtocol calculations#26
Merged
sisyphusSmiling merged 1 commit intogio/update-decimal-precisionfrom Jul 14, 2025
Merged
Conversation
- Changed interestMul division from e8 to 10^9 to match 18-decimal indices - Fixed missing division by targetHealth in fundsRequiredForTargetHealthAfterWithdrawing - Added underflow protection when subtracting debt values
Contributor
Author
Test Results UpdateAll rebalance scenario tests in tidal-sc have been updated with precise expected values from the Google Sheet (truncated to 8 decimal places for UFix64 compatibility). Current Test Results:
Key Findings:
Recommendations:
The enhanced error logging added in this PR has been very helpful in debugging these precision issues. Full precision comparison report is available in the tidal-sc repository. |
sisyphusSmiling
approved these changes
Jul 14, 2025
Comment on lines
+1838
to
+1839
| let aScaled = a / 1_000_000_000 // 10^9 | ||
| let bScaled = b / 1_000_000_000 // 10^9 |
Contributor
There was a problem hiding this comment.
We should update TidalProtocolUtils.e8 to e9 = 1_000_000_000
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
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.
Summary
This PR fixes critical bugs discovered during integration testing of the decimal precision updates.
Changes
1. Fixed Interest Multiplication Overflow
interestMulfunction to use correct divisor for 18-decimal precision2. Fixed Underflow in fundsRequiredForTargetHealthAfterWithdrawing
(effectiveDebtAfterWithdrawal - effectiveCollateralAfterWithdrawal) / targetHealtheffectiveDebtAfterWithdrawal - (effectiveCollateralAfterWithdrawal / targetHealth)3. Enhanced Error Logging
Impact
These fixes ensure:
Related Issues
Part of the decimal precision migration from UFix64 to UInt256.