Skip to content

Commit 591e620

Browse files
committed
feat(flashloan-logic): use ray_div_down for conservative treasury accrual
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
1 parent 00b7c96 commit 591e620

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

aave-core/sources/aave-logic/flashloan_logic.move

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,12 @@ module aave_pool::flashloan_logic {
765765
pool_logic::set_next_liquidity_index(&mut reserve_cache, next_liquidity_index);
766766

767767
// update accrued to treasury
768+
// Note: Use ray_div_down for conservative treasury accrual
769+
// Ensures protocol treasury doesn't accumulate optimistic amounts
770+
// Aligns with mint_to_treasury's conservative minting approach
768771
let new_reserve_accrued_to_treasury =
769772
reserve_accrued_to_treasury
770-
+ wad_ray_math::ray_div(premium_to_protocol, next_liquidity_index);
773+
+ wad_ray_math::ray_div_down(premium_to_protocol, next_liquidity_index);
771774
pool::set_reserve_accrued_to_treasury(
772775
reserve_data, new_reserve_accrued_to_treasury
773776
);

0 commit comments

Comments
 (0)