Agentic swarm router for Uniswap v4: optimizes trades, internalizes MEV, gates agents via ERC-8004
SwarmRep is a fully on-chain, agentic MEV-protection protocol built on Uniswap v4. Autonomous agents perform the core work of analyzing swaps, proposing routes, detecting opportunities, and executing recovery flows in real time. Instead of relying on opaque MEV bots or off-chain trust assumptions, SwarmRep makes execution logic explicit through on-chain agent roles coordinated by AgentExecutor and SwarmCoordinator.
SwarmRep is centered on ERC-8004. Every core agent is registered through SwarmAgentRegistry with an ERC-8004 identity, agent metadata, and on-chain reputation hooks. Agents are therefore not anonymous scripts; they are verifiable entities with persistent identities, scoreable behavior, and programmable access controls. Identity and reputation can be used to gate who is allowed to propose or execute actions, and outcomes from successful executions are written back on-chain, creating a closed accountability loop.
The protocol’s agentic architecture spans two layers. Hook agents (e.g., ArbitrageAgent, DynamicFeeAgent, BackrunAgent) run inside Uniswap v4 swap callbacks. Route/executor agents (e.g., SimpleRouteAgent, FlashBackrunExecutorAgent) automate intent proposal and backrun execution. This makes “agent intelligence” both composable and measurable: agents can be swapped, ranked, gated, and rewarded without changing the user experience.
Captured value is redistributed rather than privately extracted. Backrun profits flow to LPs through LPFeeAccumulator, with explicit keeper incentives, aligning users, LPs, and agents. SwarmRep is implemented against real Sepolia integrations—including Uniswap v4, Chainlink, Aave, and ERC-8004—making it a practical demonstration of agent-native DeFi infrastructure with ERC-8004 serving as the trust and reputation backbone.
We built SwarmRep as a modular, agentic DeFi protocol in Solidity (0.8.24) + Foundry, centered around a Uniswap v4 hook architecture and ERC-8004 identity/reputation rails.
At the core is SwarmHook, attached to a v4 pool. In beforeSwap, it invokes AgentExecutor, which coordinates specialized agents by type: ArbitrageAgent (value-capture decision from oracle/pool divergence), DynamicFeeAgent (fee override recommendation), and BackrunAgent (opportunity detection). In afterSwap, the system logs backrun opportunities and routes captured value into LPFeeAccumulator. We used Uniswap v4’s native patterns (PoolManager, hook callbacks, pool keys/IDs, router action bundles) rather than wrapping them behind off-chain services.
For the intent flow, we built SwarmCoordinator + SimpleRouteAgent. Users submit intents (createIntent) with token pair, size, slippage, fee splits, and candidate paths. Route agents propose/submit paths and execute the winner on-chain. This enables “intent routing + execution” without centralized route servers. Hook payload data (MEV fee, LP share, treasury share, agent metadata) is encoded directly into the swap path hookData, so every execution remains verifiable on-chain.
For MEV backruns, we built FlashLoanBackrunner + FlashBackrunExecutorAgent. Backruns support two modes: keeper-capital or Aave v3 flashloan. Execution is permissionless via the executor agent, with configurable maxFlashloanAmount and minProfit, and profits are split (LP-first) through LPFeeAccumulator. A repay pool is configured for round-trip settlement. We removed reliance on off-chain keeper infrastructure by making the execution agent itself on-chain and directly callable from the UI.
ERC-8004 is treated as a first-class primitive in the design: all major agents are registered through SwarmAgentRegistry, linked to ERC-8004 identity IDs, and wired to reputation updates. The coordinator and executor can enforce identity/reputation policies. Agent execution outcomes can be recorded as on-chain feedback, enabling measurable, persistent agent performance over time instead of anonymous bot behavior.
Partner tech and benefits:
Uniswap v4: native hooks + programmable execution surface.
Chainlink (via OracleRegistry): trusted price anchor for divergence detection.
Aave v3: capital-efficient flashloan backrun execution.
ERC-8004: standardized identity + reputation for agent accountability.
Frontend stack is React + TypeScript + Vite + ethers v6. We surface wallet state, agent IDs/reputation, intent lifecycle, LP donation state, and backrun controls. We specifically cleaned token decimal handling and backrun display logic so operational values reflect real on-chain units.
We validated with Foundry unit/integration tests and Sepolia-fork E2E runs, then deployed the live contract set to Sepolia with full wiring (agents, hook, coordinator, registry, flash backrunner, executor).

