State Twins: Off-chain replicas let AI agents test DeFi scenarios instantly
Fork live AMM pools in-memory, run 100s of 'what-if' queries without gas costs.
Ian Moore's new paper proposes State Twins, an off-chain substrate that solves the fundamental coupling between agentic reasoning and blockchain time in decentralized finance (DeFi). Today, every "what if" query from an AI agent requires either a fresh RPC read or a real on-chain transaction, bounded by block confirmation latency and gas fees. Moore argues this is a structural problem, not a performance one. The State Twin is a typed, in-memory, replayable replica of an automated market maker (AMM) pool that preserves the protocol's exact mathematics while enabling operations on-chain state cannot: forking, replay, branching, and counterfactual rollout. The paper formalizes four AMM families (Uniswap V2, V3, Balancer, Stableswap) as discrete-time controlled dynamical systems and proves a quantitative fidelity bound on divergence between twin and chain.
The open-source implementation ships as part of DeFiPy v2, an Python toolkit that includes a reference Model Context Protocol server exposing typed analytical primitives as LLM tools. Crucially, the same Python class and calling pattern works for notebook quants, backtests, and LLM agents without modification. Moore demonstrates a worked example: a single live RPC read seeds N independent in-memory twins under distinct price-shock scenarios in sub-second wall-clock time. The contribution is the substrate, not a particular agent — it provides the missing layer for truly reasoning-based DeFi agents that can explore outcomes off-chain before committing to on-chain actions.
- State Twins replicate live AMM pools (Uniswap V2/V3, Balancer, Stableswap) as in-memory typed models for zero-cost querying.
- DeFiPy v2 ships the substrate with a Model Context Protocol server, enabling LLM agents to use analytical primitives as tools.
- A single RPC seed can fork into N independent twins under different price shocks in sub-second wall-clock time.
Why It Matters
Unlocks real-time agentic DeFi reasoning without gas overhead, enabling sophisticated on-chain strategies through offline simulation.