Skip to content

Conversation

@matchv
Copy link
Collaborator

@matchv matchv commented Oct 11, 2025

  • get_user_debt_in_base_currency: use ray_mul_up to round up debt
  • get_user_debt_in_base_currency: use ceil_div to avoid smaller debt truncating to zero
  • get_user_balance_in_base_currency: ray_mul_down to round down collateral balance

Apply directional rounding for conservative debt calculation.

Changes:
- Modified get_user_debt_in_base_currency function L37
- Changed ray_mul to ray_mul_up for debt index multiplication

Rationale:
- Debt should never be underestimated for protocol safety
- Conservative calculation protects against liquidation edge cases
- Aligns with Solidity Aave V3 implementation pattern

Impact:
- Health factor calculations become more conservative
- Slight increase in debt amounts (~0.0001% per operation)
- Better protection against dust debt scenarios
Apply ceiling division for conservative debt amount calculation.

Changes:
- Modified get_user_debt_in_base_currency function L42-45
- Changed regular division to ceil_div for price conversion
- Simplified code by combining multiplication and division

Rationale:
- Prevents small debt × low price from rounding down to zero
- Critical fix for test_issue_2 scenario
- Ensures debt is always counted in base currency calculations

Impact:
- Fixes dust debt being ignored in health factor calculations
- Small debt amounts will now be properly tracked
- More accurate liquidation threshold determinations
Apply directional rounding for conservative collateral valuation.

Changes:
- Modified get_user_balance_in_base_currency function L62-70
- Changed ray_mul to ray_mul_down for collateral index multiplication

Rationale:
- Collateral should never be overestimated for protocol safety
- Conservative calculation prevents over-leveraging
- Consistent with a_token_factory::balance_of behavior

Impact:
- Health factor calculations become more conservative
- Slight decrease in collateral value (~0.0001% per operation)
- Better protection against liquidation edge cases
@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.70%. Comparing base (6a2b16a) to head (32aa70b).

Additional details and impacted files
@@                      Coverage Diff                       @@
##           mike/improve/pool-token-logic      #68   +/-   ##
==============================================================
  Coverage                          97.70%   97.70%           
==============================================================
  Files                                 38       38           
  Lines                                785      785           
==============================================================
  Hits                                 767      767           
  Misses                                18       18           
Flag Coverage Δ
move 97.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@matchv matchv closed this Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants