aegis-defi
Safety layer for autonomous DeFi agents. Scans contracts for exploit patterns, simulates transactions, blocks honeypots.
README
Aegis
Safety layer for autonomous DeFi agents. | Website | Docs
AI agents trading on-chain have no way to tell a legitimate token from a honeypot. Aegis fixes that. It's an MCP server that any agent can plug into, backed by on-chain contracts that enforce the safety checks.
Before an agent swaps, Aegis scans the target contract, simulates the transaction, and returns a simple go/no-go. If the contract has a 99% sell tax or a hidden pause function, the agent never touches it.
Why this exists
We watched an agent lose its entire wallet to a honeypot token in under 30 seconds. The token looked fine on the surface - verified contract, decent liquidity, active trading. But buried in the code was a 99% sell tax and a hidden owner behind a fake renounceOwnership().
No agent framework had a way to catch this. So we built one.
How it works
Agent -> Aegis (scan + simulate + decide) -> Chain
- Agent connects to Aegis via MCP (one line of config)
- Before any swap/approve/transfer, agent calls
assess_risk - Aegis scans the contract source, simulates the tx, checks for honeypot patterns
- Returns ALLOW, WARN, or BLOCK with a risk score (0-100)
- On-chain: the AegisGateway contract enforces attestations and collects a 5 bps fee
Quick Start
# Add to Claude Code
claude mcp add aegis npx aegis-defi
# Or clone and try the demo
git clone https://github.com/StanleytheGoat/aegis
cd aegis && npm install
npx tsx demo/catch-honeypot.ts
The demo deploys a deliberately malicious token (99% sell tax, fake ownership renounce, hidden admin) and watches Aegis catch every red flag:
Aegis Risk Assessment
Risk Score: 100/100
Findings:
[CRITICAL] Fake Ownership Renounce
[CRITICAL] Asymmetric Buy/Sell Tax (99% sell)
[CRITICAL] Sell Pause Mechanism
[HIGH] Hidden Max Sell Amount
[HIGH] Hidden Admin Functions
Decision: BLOCK
What's in the box
MCP Server (TypeScript)
scan_contract- pattern matching against 12 known exploit typessimulate_transaction- dry-run on a forked chaincheck_token- anti-honeypot checks (sellability, concentrated holdings)assess_risk- all of the above combined into one call. Returns a signed attestation for ALLOW/WARN decisions (falls back to MCP-only mode if no attester key configured)
Smart Contracts (Solidity)
AegisGateway- safety wrapper for any DeFi interaction. Verifies attestations, checks risk scores, collects fees. Fees go to a Safe multisig that can never be changed, even by the contract owner. Signatures include chain ID + contract address to prevent cross-chain replay. ecrecover validates against address(0), EIP-2 s-value malleability check enforced, andwithdrawFeesis protected bynonReentrant. IncludesrescueStuckEth()for ETH sent directly toreceive().AegisSafetyHook- Uniswap v4beforeSwaphook. Blocks swaps that don't have a valid safety attestation. Inline attestation verification extracts agent, risk score, and expiry from the signed message - no hardcoded defaults. Hook owner is immutable. EmitsRiskThresholdUpdated,PermissiveModeUpdated, andAttestationRecordedevents. Signatures include chain ID + hook address to prevent cross-chain replay.MockHoneypot- a deliberately evil token for testing. Aegis scores it 100/100.
Paperclip Integration
- Aegis works as a safety skill in Paperclip zero-human companies. Any company doing DeFi operations can plug Aegis in as a mandatory pre-transaction check. See paperclip/ for the skill definition.
Deployed on Base Mainnet:
- AegisGateway:
0x62c64c063ddbcd438f924184c03d8dad45230fa3 - AegisSafetyHook:
0xaEE532d9707b056f4d0939b91D4031298F7340C0
What it catches
| Pattern | Severity |
|---|---|
| Asymmetric sell tax (50-99%) | Critical |
| Sell pause mechanism | Critical |
| Fake ownership renounce | Critical |
| Reentrancy | Critical |
| Hidden admin functions | High |
| Unrestricted minting | High |
| Hidden max sell amount | High |
| Flash loan / oracle manipulation | High |
| Permit/approval phishing | High |
| Blacklist mechanism | Medium |
| Upgradeable proxy | Medium |
| Unlimited approval | Medium |
What it does NOT catch: novel zero-days, social engineering, MEV/sandwich attacks, governance attacks.
Tests
# TypeScript unit tests
npm test
# Contract tests
npm run test:contracts
# Demo (honeypot detection)
npm run demo
106 tests total (30 contract + 64 TypeScript + 12 Base mainnet fork tests):
- 12 risk engine unit tests (pattern matching)
- MCP server tests (tool execution, error handling)
- Simulator unit tests (transaction simulation, token checks)
- 30 contract tests (AegisGateway attestations/fees/admin, MockHoneypot, AegisSafetyHook)
- 12 Base mainnet fork tests (run against real Base mainnet state)
- Full fee flow test (fees verified landing in Safe multisig)
Revenue model
5 bps (0.05%) on every transaction that goes through the gateway. The fee recipient is a Safe multisig set at deploy time. No one can change where fees go, not even the contract owner. withdrawFees is protected by nonReentrant. This was a deliberate security decision.
At scale, if 5% of agent transaction volume on Base flows through Aegis, that's roughly $25K/month at current volumes.
Docs
- Agent Integration Guide - how to connect your agent (for both AI agents and human developers)
- Project Integration Guide - how to integrate Aegis into a product
- Paperclip Skill - how to add Aegis to a Paperclip zero-human company
- llms.txt - machine-readable description for agentic search
Security practices
Built following ethskills Ethereum production best practices:
- Gas: Base L2 gas is ~0.1-0.5 gwei (not 10-30). Deploy costs under $1.
- Signatures: Chain ID + contract address in all signed messages (no cross-chain replay). EIP-2 s-value malleability check. ecrecover validated against address(0).
- Fee math: Multiply before divide. Explicit overflow guards. Basis points (not percentages).
- Access control: OZ Ownable + ReentrancyGuard on Gateway. Immutable owner on Hook.
- Deployment: Safe Singleton Factory CREATE2 deployer. Source verified on Basescan. Ownership transferred to Safe multisig post-deploy.
- Base-specific: Uses
block.timestamp(notblock.number). Correct chain ID 8453. - Testing: Fork tests against real Base mainnet state. Fuzz-compatible fee math.
Challenges we ran into
- Uniswap v4 hooks need to be deployed at addresses with specific permission bits set. You can't just deploy normally. We wrote a CREATE2 salt miner that finds addresses with the correct
beforeSwap+afterSwapbits. Hook deployed via CREATE2 at a vanity address. - The v4 API changed between versions.
SwapParamsmoved fromIPoolManagerto its ownPoolOperation.solfile. Had to dig through the npm package to find the right imports. - The inline attestation verification in the v4 hook originally returned hardcoded values instead of extracting from the signature. We refactored to pass
(attestationId, agent, riskScore, expiresAt, signature)in hookData and verify the full signed message on-chain. Signatures now include chain ID + contract/hook address to prevent cross-chain replay. - Stack-too-deep in the hook's
beforeSwaprequired extracting token checks and attestation processing into separate internal functions. - Fee flow testing on testnet required deploying a helper contract (EthReceiver) because
executeProtectedforwards calls to the target. - Added comprehensive security hardening: ecrecover address(0) checks, EIP-2 s-value malleability enforcement, zero-address validation on attester, nonReentrant on withdrawFees, immutable hook owner, and rescueStuckEth() for ETH recovery.
Built for
The Synthesis - Ethereum Foundation Hackathon, March 2026
Tracks: Agents that trust, Agents that pay
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.