Skip to content

Commit 894edeb

Browse files
committed
feat(supply-logic): use ray_mul_down for withdraw balance calculation
Apply directional rounding for conservative withdrawal balance calculation. Changes: - Calculate user_balance using ray_mul_down instead of ray_mul in withdraw function - Modified: supply_logic.move line 199-206 Rationale: - User withdrawal balance should never be overestimated for protocol safety - Conservative calculation prevents users from withdrawing more than actual balance - Consistent with a_token_factory::balance_of behavior - Aligns with Solidity Aave V3 implementation pattern Impact: - Withdrawal balance calculations become more conservative - User may need to query real-time balance for complete withdrawal - Better protection against over-withdrawal scenarios - Consistent with balance_of external API behavior
1 parent 32aa70b commit 894edeb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ module aave_pool::supply_logic {
196196
// update pool state
197197
pool_logic::update_state(reserve_data, &mut reserve_cache);
198198

199+
// Note: Use ray_mul_down for conservative withdrawal balance calculation
200+
// Ensures user cannot withdraw more than their actual balance
201+
// Consistent with a_token_factory::balance_of behavior
199202
let user_balance =
200-
wad_ray_math::ray_mul(
203+
wad_ray_math::ray_mul_down(
201204
a_token_factory::scaled_balance_of(account_address, a_token_address),
202205
pool_logic::get_next_liquidity_index(&reserve_cache)
203206
);

0 commit comments

Comments
 (0)