@@ -212,7 +212,7 @@ module aave_pool::a_token_factory {
212212 };
213213 let underlying_token_address = get_underlying_asset_address (metadata_address);
214214
215- wad_ray_math::ray_mul_down (// Round down: count less asset (conservative)
215+ wad_ray_math::ray_mul_down (
216216 current_scaled_balance,
217217 pool::get_reserve_normalized_income (underlying_token_address)
218218 )
@@ -240,7 +240,7 @@ module aave_pool::a_token_factory {
240240
241241 let underlying_token_address = get_underlying_asset_address (metadata_address);
242242
243- wad_ray_math::ray_mul_down (// Round down: count less total supply (conservative)
243+ wad_ray_math::ray_mul_down (
244244 current_supply_scaled,
245245 pool::get_reserve_normalized_income (underlying_token_address)
246246 )
@@ -492,7 +492,7 @@ module aave_pool::a_token_factory {
492492 amount,
493493 index,
494494 metadata_address,
495- false // Round down: mint less aToken (safer for protocol)
495+ false
496496 )
497497 }
498498
@@ -519,7 +519,7 @@ module aave_pool::a_token_factory {
519519 amount,
520520 index,
521521 metadata_address,
522- true // Round up: burn more aToken scaled balance (safer for protocol)
522+ true
523523 );
524524
525525 let token_data = get_token_data (metadata_address);
@@ -550,9 +550,6 @@ module aave_pool::a_token_factory {
550550 // Early return if amount is 0 to avoid unnecessary computation
551551 if (amount == 0 ) { return };
552552
553- // Pre-calculate scaled amount to check for dust
554- // Treasury accrued fees can be tiny (1-2 octa), which round down to 0
555- // We must skip these dust amounts to prevent assert failure in token_base::mint_scaled
556553 let amount_scaled = wad_ray_math::ray_div_down (amount, index);
557554
558555 if (amount_scaled != 0 ) {
@@ -566,7 +563,7 @@ module aave_pool::a_token_factory {
566563 amount,
567564 index,
568565 metadata_address,
569- false // Round down: mint less to treasury (conservative)
566+ false
570567 );
571568 }
572569 }
@@ -621,23 +618,13 @@ module aave_pool::a_token_factory {
621618 ) acquires TokenMap {
622619 assert_token_exists (metadata_address);
623620
624- // Pre-calculate scaled amount using directional rounding based on rounding_up parameter
625- // Reasons for pre-calculation:
626- // 1. Event accuracy: Must match the actual transferred scaled amount for event consistency
627- // 2. Dust handling: Liquidation protocol fees can be tiny (1-2 octa), which may round to 0
628- // We must check and skip these dust transfers to prevent assert failure in token_base::transfer
629- // 3. Directional rounding: rounding_up=true for collateral transfer (favor protocol, consistent with burn),
630- // rounding_up=false for protocol fees (conservative charging, favor user)
631621 let amount_scaled =
632622 if (rounding_up) {
633- wad_ray_math::ray_div_up (amount, index) // Round up, consistent with burn path
623+ wad_ray_math::ray_div_up (amount, index)
634624 } else {
635- wad_ray_math::ray_div (amount, index) // Round half up, conservative charging
625+ wad_ray_math::ray_div (amount, index)
636626 };
637627
638- // Skip transfer if scaled amount is 0 (dust)
639- // This prevents assertion failure in token_base::transfer
640- // Dust amounts are acceptable to skip as they are too small to be meaningful
641628 if (amount_scaled == 0 ) { return };
642629
643630 token_base::transfer (
@@ -649,8 +636,6 @@ module aave_pool::a_token_factory {
649636 rounding_up
650637 );
651638
652- // Emit event with the actual transferred scaled amount
653- // This ensures event accurately reflects the on-chain state change
654639 events::emit_balance_transfer (
655640 from,
656641 to,
@@ -772,6 +757,6 @@ module aave_pool::a_token_factory {
772757 index: u256 ,
773758 metadata_address: address
774759 ) acquires TokenMap {
775- transfer_on_liquidation (from, to, amount, index, metadata_address, false ) // Use round half up, conservative handling
760+ transfer_on_liquidation (from, to, amount, index, metadata_address, false )
776761 }
777762}
0 commit comments