REVM Transaction Simulator and Asset Tracer
A Rust library for simulating EVM-compatible blockchain transactions and tracking asset transfers, logs, and events using REVM. This library provides a safe and efficient way to simulate transactions and analyze their effects without actually submitting them to the blockchain.
Features
- Transaction Simulation: Simulate transactions on any EVM-compatible chain (Ethereum, BSC, Polygon, etc.)
- Asset Transfer Tracking: Track both native tokens (ETH, BNB, MATIC, etc.) and ERC20 token transfers
- Event Collection: Capture and analyze all transaction logs and events
- Token Information: Automatically collect token symbols and decimals
- Proxy Support: Handle proxy contracts with implementation resolution
- Safe Execution: Simulate transactions without affecting the blockchain
- Flexible Inspector: Customizable transaction tracing
Installation
Add this to your Cargo.toml
:
= "1.0.0"
Quick Start
use ;
async
Usage Examples
Tracking DeFi Transactions
// Example of tracking a Uniswap-like DEX swap on any EVM chain
let router = address!;
let result = trace_tx_assets.await;
// Process transfers and logs
for transfer in result.asset_transfers
for log in result.logs
Reusing EVM Instance
When simulating multiple transactions using the same EVM instance, you need to reset the inspector state between simulations:
use ;
async
Setting Block Environment
You can customize the block environment for simulation:
use ;
async
Thread Safety and Parallel Processing
Important Note on Thread Safety
The core Evm
instance from REVM is not thread-safe, and consequently, our tracing functionality cannot be used across threads. This means you cannot share an Evm
instance between threads or use it in parallel operations.
Recommended Usage Patterns
❌ What to Avoid
// This will NOT work - do not share Evm across threads
let mut evm = create_evm_instance_with_tracer?;
let handles: = transactions
.into_par_iter // ❌ Parallel processing will fail
.map
.collect;
✅ Correct Usage
// Create separate EVM instances for each thread
let handles: = transactions
.into_iter // ✅ Sequential processing
.map
.collect;
// Alternative: If you need parallel processing
use ;
let results: = transactions
.par_iter
.map
.collect;
Performance Considerations
-
Create new EVM instances for parallel operations
-
Consider connection pool limits of your RPC provider
-
Balance between parallelism and RPC rate limits
Working with Proxy Contracts
The library automatically handles proxy contracts by resolving their implementations:
- EIP-1967 proxies
- EIP-1967 beacon proxies
- OpenZeppelin transparent proxies
- EIP-1822 (UUPS) proxies
Features in Detail
Asset Transfer Tracking
- Native token transfers (including internal transfers)
- ERC20 token transfers
- Transaction logs and events
- Chronological ordering of transfers
- Complete token information collection
Transaction Simulation
- Full EVM context simulation
- Custom environment configuration
- Detailed execution results
- Error handling and revert messages
Historical State Access
When accessing historical blockchain state, capabilities depend on the node type:
- Archive Nodes: Can access any historical block state
- Full Nodes: Limited to recent blocks (typically ~128 blocks)
The actual accessible block range varies by provider and node configuration.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.