Skip to content

Perf: Add transaction simulation cache for common pool operations #602

Description

@devdianax

Context

Transaction simulations (preview deposit, preview borrow) are recomputed on every call with no caching.

Current Limitation/Problem

Each simulation query recomputes state from scratch. Identical simulations within same block waste compute.

Expected Outcome

Block-scoped simulation cache that reuses results for identical simulation parameters within the same block.

Acceptance Criteria

  • Cache key: (operation, pool, user, asset, amount) hashed
  • Cache scope: single block, cleared on new block
  • Read path: check cache before computing simulation
  • Write-through: update cache as operations execute
  • Cache size limit: LRU eviction for large caches
  • Gas savings: identical simulation in same block uses cached result
  • Integration with frontend: batch simulation requests for position preview

Technical Scope

  • contracts/lending-pool/src/simulation_cache.rs - simulation cache
  • Frontend integration for batch simulations
  • Gas benchmark: cached vs uncached simulation
  • Edge cases: cache poisoning, state change mid-block invalidation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions