You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(pool-token-logic): use ray_mul_down for transfer balance checks
Apply directional rounding for balance consistency in transfer function.
Changes in transfer() function:
- Calculate from_balance_before using ray_mul_down instead of ray_mul
- Calculate to_balance_before using ray_mul_down instead of ray_mul
- Reuses pre-fetched index for atomic snapshot guarantee
Rationale:
- Matches a_token_factory::balance_of behavior (uses ray_mul_down)
- Ensures atomic consistency: all balance calculations use same index value
- Prevents race conditions where index changes between balance calculations
- Enables correct detection of full withdrawal and first-time receipt scenarios
- Manual calculation reuses pre-fetched index (also used by token_base::transfer
and balance transfer event), ensuring consistent state snapshot
Impact:
- Fixes collateral flag updates for full withdrawal and first receipt
- Guarantees atomic snapshot of user balances (critical for HF validation)
- Consistent with user-facing balance_of query results
- Gas optimized: single index fetch reused across all operations
- Aligns with Solidity Aave V3 implementation pattern
Security: Prevents non-atomic balance calculations that could lead to
inconsistent state and incorrect health factor validation
0 commit comments