Skip to content

Conversation

@matchv
Copy link
Collaborator

@matchv matchv commented Oct 16, 2025

handle_flash_loan_repayment: total_supply => ray_mul_down, counting liquidity conservatively
handle_flash_loan_repayment: new_reserve_accrued_to_treasury => ray_mul_down, accrue treasury income conservatively

…lation

Apply directional rounding for conservative flashloan liquidity calculation.

Changes:
- Calculate total_liquidity using ray_mul_down instead of ray_mul
- Modified: handle_flash_loan_repayment function (L751-759)
- Convert reserve_accrued_to_treasury to actual amount using conservative rounding

Rationale:
- Available flashloan liquidity should not be overestimated for protocol safety
- Conservative calculation prevents lending more than actually available
- Ensures treasury accrued balance doesn't inflate available liquidity
- Aligns with mint_to_treasury's conservative approach

Impact:
- Flashloan availability becomes slightly more conservative (~0.0001%)
- Prevents protocol from over-lending during high utilization
- Better protection against liquidity miscalculation
- Consistent with other directional rounding implementations
…rual

Apply directional rounding for conservative flashloan treasury accumulation.

Changes:
- Calculate new_reserve_accrued_to_treasury using ray_div_down instead of ray_div
- Modified: handle_flash_loan_repayment function (L767-776)
- Convert premium_to_protocol from actual amount to scaled balance conservatively

Rationale:
- Protocol treasury should not accumulate optimistic amounts for safety
- Conservative calculation prevents treasury from over-accruing fees
- Ensures consistency with mint_to_treasury's conservative minting approach
- Prevents long-term accumulation of rounding errors favoring treasury

Impact:
- Treasury accrual becomes slightly more conservative (~0.0001%)
- Prevents protocol from recording more treasury fees than actually earned
- Better alignment with dual-conservative approach (liquidity + treasury)
- Consistent with other directional rounding implementations across protocol
@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.70%. Comparing base (3cf38a0) to head (591e620).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           mike/improve/liquidation-logic      #72   +/-   ##
===============================================================
  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.

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.

3 participants