State Twins: An Off-Chain Substrate for Agentic Reasoning over Decentralized Finance Protocols

Ian C. Moore, PhD · 2026

Read State Twins: An Off-Chain Substrate for Agentic Reasoning over Decentralized Finance Protocols by Ian C. Moore, PhD (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-11522.txt.

Introduction

Ian Moore introduces the State Twin, a replayable in-memory replica of an on-chain market maker pool. It serves agentic reasoning over decentralized finance, where stacks tie reasoning to chain time. Every what-if query costs a new RPC read, bounding action space by block latency and gas. The Twin preserves protocol mathematics while allowing forking, replay, branching and counterfactual runs. Moore formalizes each AMM family as a controlled dynamical system, proves a fidelity bound, and ships it in DeFiPy v2 with a Model Context Protocol server.

Catalog record

CREATORIan C. Moore, PhD
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE55715
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.11522

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

State Twins: An Off-Chain Substrate for Agentic Reasoning over Decentralized Finance Protocols Ian C. Moore, PhD Abstract We introduce the State Twin : a typed, in-memory, replayable replica of an on-chain automated market maker (AMM) pool that serves as a substrate for agentic reasoning over decentralized finance (DeFi) protocols. Agentic DeFi stacks today couple reasoning to chain time, since every "what if?" query incurs a new RPC read or a real transaction, so the agent’s effective action space is bounded by block confirmation latency and gas. We argue this coupling is a structural problem rather than a performance one, and that the missing layer is an off-chain substrate that preserves the protocol’s exact mathematics while admitting the operations on-chain state cannot: forking, replay, branching, counterfactual rollout. We formalize each AMM family (Uniswap V2, V3, Balancer, Stableswap) as a discrete-time controlled dynamical system, prove a quantitative fidelity bound on the divergence between twin and chain, and give the open architecture used in DeFiPy v2, an open-source Python toolkit that ships the State Twin substrate and a reference Model Context Protocol server exposing typed analytical primitives as LLM tools. The same primitive (i.e., one Python class, one calling pattern) serves a notebook quant, a backtest, and an LLM agent without modification. We close with a fork-and-evaluate 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, which is what the specification of what an agentic DeFi substrate must look like . Keywords decentralized finance \cdot automated market makers \cdot digital twin \cdot agentic systems \cdot large language models \cdot model context protocol \cdot state-space models \cdot Python SDK 1 Introduction The dominant pattern for agentic DeFi systems today wires a reasoning model (typically a large language model) directly to chain reads and chain writes, mediated by a thin RPC wrapper or a vendor data API. We will call this architecture reactive : that is, every step the agent takes either returns a fresh on-chain query result or commits a transaction. There is no layer in between. The agent’s effective action space is therefore bounded by chain time (i.e., block confirmation latency, gas, sequential transaction ordering), and its reasoning is bounded by what one round-trip to the chain can answer. Counterfactual queries, multi-scenario evaluation, and what an analyst would casually call thinking before acting are not first-class operations in the reactive architecture; they are workflows the architecture silently disallows. This paper argues that reactive is the wrong default, and that agentic DeFi specifically has a clean structural fix. AMM pools are deterministic state machines: their on-chain state at block k , together with a transaction u_{k} , exactly determines their state at block k{+}1 via an invariant that is fully known and compactly expressible in software. There is no hidden state, no privileged side channel, no non-deterministic adversary. The implication is that an off-chain replica can be constructed that is mathematically faithful to chain reality at any pinned block: exact in the rational arithmetic of the protocol invariants, and exact up to a known additive rounding bound under the deployed fixed-point arithmetic [ 1 ] . Primitives consuming such a replica are equivalent in their outputs whether the replica was sourced from a live RPC read, a synthetic recipe, a fork node, or a historical archive. We call this replica the State Twin . The contribution of this paper is the formalization of the State Twin as the missing substrate for agentic DeFi, which admits a clean provider/builder factorization that survives across protocol families. This enables a class of agent workflows (i.e., fork, simulate, score, decide) that the reactive architecture cannot support at all. Contributions. This paper makes the following contributions: 1. We formalize each major AMM family as a discrete-time controlled dynamical system and show that this state-space framing is the natural mathematical structure for agentic DeFi reasoning (Section 2 ). 2. We define the State Twin as the canonical software realization of the state-space view, give a precise abstraction (provider \to snapshot \to builder \to twin \to primitive) that decouples state source from state shape and realizes the substrate-access path required for counterfactual reasoning, and prove a quantitative State Twin Fidelity bound on the divergence between twin and on-chain trajectories under the discretized constant-product update (Section 3 ). 3. We expose the State Twin pattern through DeFiPy v2, an open-source Python toolkit that ships 7 core operational primitives (Swap, Join, AddLiquidity, etc.) and 21 typed analytical primitives built on them, a State Twin substrate ( MockProvider , LiveProvider ), and a reference Model Context Protocol server exposing 10 of those primitives as LLM tools (Section 4 ). 4. We present a fork-and-evaluate pattern: a single chain read seeds N independent twins, each evaluated under a distinct scenario, producing a recommendation distribution in sub-second wall clock time (Section 5 ). 5. We discuss the substrate-vs-product distinction underlying the design: why the agentic surface is deliberately read-only, why the math layer remains LLM-free, and why this is the architecture most likely to compound across protocols (Section 6 ). The State Twin, as a named pattern with an explicit provider/builder split, is designed specifically for LLM-native agentic reasoning over AMM state. The reactive architecture is implicit in essentially every production agentic-DeFi system we surveyed during this work. 2 Preliminaries: AMMs as Controlled Dynamical Systems We adopt a state-space view of AMM protocols. The motivation is twofold: (1) the dynamical-systems formulation is the natural language for counterfactual queries (e.g., “what is the state if I apply this trade?”), which is what an agent that thinks before it acts most needs to ask; (2) the formulation makes explicit that an off-chain replica is mathematically well-posed, since the state-transition map is a pure function of state and input, with no hidden randomness on the protocol side. 2.1 General Form Let \mathcal{X} denote the protocol-specific state space, \mathcal{U} the input space (swaps, mints, burns, fee accrual), and \mathcal{W} the exogenous-disturbance space (e.g., oracle prices, external trades observed through the same pool). An AMM pool evolves as the discrete-time system: \boxed{\quad x_{k+1}\;=\;f(x_{k},\,u_{k},\,w_{k}),\qquad y_{k}\;=\;h(x_{k})\quad,} (1) where f:\mathcal{X}\times\mathcal{U}\times\mathcal{W}\to\mathcal{X} is the transition map (the protocol invariant in solver form) and h:\mathcal{X}\to\mathcal{Y} is the observation map (e.g. spot price, TVL, position value). Expression ( 1 ) is the discrete-time controlled state-space form introduced by Kalman [ 2 ] and standard in control and estimation theory; we adopt it here as the deterministic specialization for AMM protocols, with f fixed to the deployed protocol invariant and w_{k} treated as known exogenous disturbances, as substrate for off-chain agentic reasoning. The underlying state-update structure of ( 1 ) has appeared in several adjacent formalisms in prior work, each suited to a specific purpose: stochastic state-space for adaptive mechanism design [ 3 ] , where u_{k} and w_{k} are promoted to random variables and Kalman filtering recovers a hidden external price; constant-function characterization for theoretical analysis [ 4 ] , where f preserves a trading function \varphi over the level set of valid reserves; priced timed automata for verification [ 1 ] , where the state in \mathcal{X} includes clock valuations and transitions are edge-labeled; and dependently-typed functional

Read the complete text