Skip to content

Update health precision from UFix64 to UInt256 with 18 decimals#31

Merged
sisyphusSmiling merged 9 commits intomainfrom
gio/update-health-precision
Jul 17, 2025
Merged

Update health precision from UFix64 to UInt256 with 18 decimals#31
sisyphusSmiling merged 9 commits intomainfrom
gio/update-health-precision

Conversation

@sisyphusSmiling
Copy link
Copy Markdown
Contributor

Description

  • Increases the decimal precision of the health metric from 8 to 18 decimals, necessarily updating the type from UFix64 to UInt256

@sisyphusSmiling sisyphusSmiling self-assigned this Jul 15, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 15, 2025

Codecov Report

Attention: Patch coverage is 88.63636% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/contracts/TidalProtocolUtils.cdc 62.50% 3 Missing ⚠️
cadence/contracts/TidalProtocol.cdc 94.44% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

access(all) let defaultTokenIdentifier = "A.0000000000000007.MOET.Vault"
access(all) let defaultVariance = 0.00000001
access(all) let defaultUFixVariance = 0.00000001
access(all) let defaultUIntVariance: UInt256 = 1_000_000_000
Copy link
Copy Markdown
Contributor Author

@sisyphusSmiling sisyphusSmiling Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default variance of 0.00000001 (as int) which is necessary in instances where withdrawal amounts at target health are truncated - e.g. 1,000 FLOW == 800 effective collateral / 1.3 target health == 615.384615384615384615 available which when converted to UFix64 withdrawal amount leave 0.000000004615384615 available in excess of target health.

@sisyphusSmiling sisyphusSmiling marked this pull request as ready for review July 15, 2025 23:16
@sisyphusSmiling sisyphusSmiling added the enhancement New feature or request label Jul 15, 2025
@sisyphusSmiling
Copy link
Copy Markdown
Contributor Author

sisyphusSmiling commented Jul 17, 2025

@nialexsan added some test cases to cover fundsRequiredForTargetHealth() as well as a fix in b4ee545. There was an oversight in #25 that assigned uintDepositPrice using the price for withdrawType.

Still, I'm not sure the expected & actual values are being computed correctly in fundsRequiredForTargetHealth(). @kgrgpg could you double check my work in the way the expected values are being computed and the logs to ensure the method is operating as expected?

Update: I think I fixed the issue in 3627bea. I believe the borrow factor had to be accounted for in the final calculation.

@sisyphusSmiling sisyphusSmiling merged commit fe79268 into main Jul 17, 2025
2 checks passed
@sisyphusSmiling sisyphusSmiling deleted the gio/update-health-precision branch July 17, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants