Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions aave-core/sources/aave-logic/flashloan_logic.move
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,12 @@ module aave_pool::flashloan_logic {
let a_token_total_supply = a_token_factory::total_supply(a_token_address);
let reserve_accrued_to_treasury =
pool::get_reserve_accrued_to_treasury(reserve_data);
// Note: Use ray_mul_down for conservative liquidity calculation
// Ensures available flashloan liquidity is not overestimated
// Prevents protocol from lending more than actually available
let total_liquidity =
a_token_total_supply
+ wad_ray_math::ray_mul(
+ wad_ray_math::ray_mul_down(
reserve_accrued_to_treasury,
pool_logic::get_next_liquidity_index(&reserve_cache)
);
Expand All @@ -762,9 +765,12 @@ module aave_pool::flashloan_logic {
pool_logic::set_next_liquidity_index(&mut reserve_cache, next_liquidity_index);

// update accrued to treasury
// Note: Use ray_div_down for conservative treasury accrual
// Ensures protocol treasury doesn't accumulate optimistic amounts
// Aligns with mint_to_treasury's conservative minting approach
let new_reserve_accrued_to_treasury =
reserve_accrued_to_treasury
+ wad_ray_math::ray_div(premium_to_protocol, next_liquidity_index);
+ wad_ray_math::ray_div_down(premium_to_protocol, next_liquidity_index);
pool::set_reserve_accrued_to_treasury(
reserve_data, new_reserve_accrued_to_treasury
);
Expand Down
Loading