AgentNexus: DeFi yield optimizer with AI agents, ZK safety, and one‑click bridge‑and‑execute.
Title AgentNexus — Autonomous, Explainable, Cross‑Chain DeFi Yield Optimization powered by uAgents, ASI:One, MeTTa, Avail Nexus, and Pyth
What this project is AgentNexus is an autonomous multi‑agent DeFi portfolio manager that discovers yields, reasons about protocol risk, and executes optimal, cross‑chain strategies on behalf of the user. It combines agentic AI (Fetch.ai’s uAgents, Agentverse), Web3‑native reasoning (ASI:One LLM + MeTTa knowledge graphs), verifiable execution (Avail Nexus Bridge & Execute), and real‑time market data (Pyth) into a single, production‑style system.
Unlike dashboards that only surface APYs, AgentNexus:
Continuously scans protocols like Aave V3, Compound V3, and Morpho on Base Sepolia, pulling APY/TVL and price data via Pyth to build a real‑time opportunity set.
Scores risk using a hybrid approach:
ASI:One LLM produces human‑readable risk rationales per protocol and allocation.
MeTTa knowledge graphs encode structured rules (TVL bands, audit tags, protocol tenure) for consistent, explainable scoring.
Allocates funds and submits transactions to deployed adapter smart contracts (verified on Basescan) using Avail Nexus Bridge & Execute for single‑flow bridge + function call when needed.
Exposes a unified, chain‑agnostic portfolio view, with agent reasoning accessible through an ASI:One chat interface for why/how each decision was made.
Core components
Agents (uAgents + Agentverse)
YieldScanner: polls protocol APY/TVL and normalizes signals per chain.
RiskAssessor: calls ASI:One to produce risk narratives, then applies MeTTa rules to produce scores and constraints (e.g., min risk score, allocation caps).
ProtocolExecutor: converts strategy into on‑chain actions, using Avail Nexus’s bridgeAndExecute() when capital must move cross‑chain; otherwise executes locally on Base Sepolia.
Smart contracts (verified)
Protocol Adapters: thin, auditable integration for Aave/Compound/Morpho with a unified interface (supply/withdraw/query), enabling safe, composable execution.
AgentVault: custody and accounting for user deposits, with hooks for proof verification.
Frontend
Unified portfolio balances, per‑protocol positions, and performance.
ASI:One chat wired to agent logs/decisions for “Why X over Y?” explainability.
Pyth price integration via Hermes API for ETH/USD, USDC/USD.
Zero‑knowledge (ZK) component AgentNexus introduces a “Provable Strategy” flow that prepares for privacy‑preserving allocation submissions and verifiable constraints:
Private Strategy Commit: The frontend/agent creates a commitment to the allocation vector without revealing the exact per‑protocol amounts.
ZK Proof of Validity: A circuit enforces constraints such as:
Allocations sum to 100%: ∑i ai = 1, ai ≥ 0.
Risk limit respected: ∑i ai · risk_i ≥ Rmin (or max VaR below threshold).
Liquidity/TVL bounds: ai ≤ cap_i for lower‑liquidity pools.
On‑chain Verification: The StrategyVerifier verifies the proof before the executor calls adapters. This prevents strategy leakage (anti‑copy/MEV) while guaranteeing safety rules, and allows future auditability without compromising proprietary strategy details. The same pattern can be extended to prove “better‑than‑baseline” allocation, time‑locked commitments, or MEV‑resistant batched rebalances.
Why this matters DeFi power users struggle with fragmented liquidity, volatile yields, and opaque risks. AgentNexus turns this into a “self‑driving” experience:
Autonomous: agents scan, reason, and act across chains and protocols.
Explainable: every action is accompanied by a human‑readable rationale (ASI:One) grounded in structured rules (MeTTa).
Verifiable: cross‑chain execution is auditable (Avail Nexus), assets are managed via verified adapters, and strategies can be privacy‑preserving yet provably safe (ZK).
Composable: add new chains, protocols, or scoring rules without rewriting the system.
Track alignment (why it fits)
ASI Alliance: Uses ASI:One for human–agent interaction and decision justification; integrates MeTTa knowledge graphs to structure risk reasoning; uAgents + Agentverse for registration/discoverability.
Avail Nexus: Uses bridgeAndExecute() to move funds and call adapters in a single flow; ready for smart‑balance checks and unified execution patterns.
Pyth: Real‑time price feeds (Hermes REST) drive valuation, risk/health metrics, and allocation thresholds.
Fetch.ai/uAgents: Multi‑agent architecture with real messaging, identity, and orchestration via Agentverse.
What’s implemented now
Deployed, verified adapters for Aave, Compound, Morpho on Base Sepolia; AgentVault and StrategyVerifier live and wired to agents.
3 agents running with inter‑agent messaging: discovery → risk → execution loop.
ASI:One chat integrated in frontend; agents call ASI:One for risk narratives and strategy validation; MeTTa rules incorporated for consistent scoring.
Pyth price integration via Hermes endpoint; unified balances/positions visualized in the dashboard.
ZK flow scaffolded: StrategyVerifier contract, allocation constraints, and proof plumbing prepared; off‑chain prover integration planned (circuit + witness + on‑chain verify).
How it works (flow)
YieldScanner fetches APY/TVL and normalized oracle prices from Pyth; emits opportunities.
RiskAssessor queries ASI:One for qualitative risk reasoning and applies MeTTa rules to emit a numeric score and constraints.
Strategy is formed (e.g., 40% Aave, 35% Compound, 25% Morpho), optionally committed and proven (ZK) for validity/privacy, then handed to ProtocolExecutor.
Executor executes via adapters; if capital relocation is needed, it calls Avail Nexus bridgeAndExecute() to bridge and invoke the target adapter in one step.
Frontend shows updated portfolio, per‑protocol allocations, and the agent’s reasoning; users can ask ASI:One “why” questions for transparency.
What’s next
Full ZK proof pipeline (circuit, prover service, on‑chain verifier integration) for private allocations and constraint proofs.
Additional protocols/networks, and support for dynamic yield/risk regimes (volatility‑adaptive rebalancing).
Agentverse listing and MCP integration for turnkey discoverability/interoperability.
More advanced MeTTa rulebooks (e.g., oracle diversity, liquidity decay, chain‑specific risk).
Tech used
Agents: uAgents, Agentverse (Fetch.ai)
LLM & Chat: ASI:One (LLM + Chat Protocol)
Reasoning: MeTTa Knowledge Graphs
Cross‑chain: Avail Nexus SDK (bridgeAndExecute)
Oracles: Pyth Network (Hermes)
Contracts: Solidity adapters (Aave/Compound/Morpho), AgentVault, StrategyVerifier (ZK‑ready)
Frontend: Next.js, Wagmi/viem, Tailwind
Chain: Base Sepolia (testnet)
This project shows how autonomous agents, explainable AI, zero‑knowledge proofs, and cross‑chain execution can work together to deliver a “self‑driving” DeFi portfolio—auditable, safe, and human‑understandable from end to end
Stack overview Agents: Python 3.12, uagents (Yield Scanner, Risk Assessor, CrossChain Executor, ASI Chat). Smart contracts: Foundry (Solidity), AgentVault + protocol adapters + Groth16 verifier. ZK: Circom + snarkjs (wasm/zkey artifacts, Groth16 on-chain verifier). Frontend: Next.js 15 (Turbopack), wagmi/viem, snarkjs in-browser. Chain: Base Sepolia (RPC), web3.py for execution. Optional: MeTTa knowledge runtime for risk heuristics; falls back if missing. Architecture Message pipeline (uAgents) yield_scanner.py → emits YieldOpportunities based on configured protocols and optional ASI:One guidance. risk_assessor.py → ranks opportunities using ASI:One (JSON extraction with regex fallback) or heuristic; sends RiskAssessments. crosschain_executor.py → validates/normalizes inputs, computes allocations (optionally refined by ASI:One), and executes adapter calls on Base Sepolia. Contracts AgentVault.sol (agUSDC receipt token, 6 decimals): deposits gated by a fresh Groth16 proof of a strategy commitment; redeem/withdraw use ERC4626-like math. StrategyVerifier.sol (snarkjs-generated): minimal Groth16 on-chain verifier used by the vault. adapters/*Adapter.sol: minimal adapters to target Aave/Compound/Morpho supply flows. ZK flow Circom circuit for private strategy signal; Poseidon hash of allocations (+user secret) creates a commitment. test_proof.js uses snarkjs to generate local Groth16 proofs; on-chain verifier checks validity; AgentVault stores commitment and enforces “fresh proof” on deposit. Frontend Next.js app for UX, charts, and potential proof generation/visualization with snarkjs. Partner tech and how it helped ASI:One: compact reasoning to score risks and validate allocations; drastically reduces bespoke rule code and lets us keep agents small and configurable. Agentverse (uAgents Inspector): instant local agent observability and address inspection, speeding dev/testing. Base Sepolia: low-cost, reliable L2 test environment with EIP-1559; fast iteration for on-chain execution. Aave V3 libraries: reference-level interfaces and structure to shape adapter design and testing against real-world semantics. Notable hacky bits Manual ABI-encoding shortcut in the executor for demo function selectors (4-byte selectors + 32-byte args). Clear win for hackathon speed; real deployments should use proper ABI encoding throughout. Fixed agent seeds for deterministic addresses to simplify wiring and logs in a multi-agent setup. Self-send execution in the executor to unify external and internal flow while keeping the message pipeline observable. Retry HTTP microserver on port 8010 for manual re-tries—dead-simple control plane during demos. ASI JSON scraping: robust JSON-or-text parsing with regex fallback to be resilient to LLM drift under time pressure. Chain/protocol normalization: tolerant mapping (e.g., multiple “Sepolia” variants collapse to Base Sepolia) so small env deviations don’t break runs. Nitty-gritty implementation details Risk heuristics: TVL-weighted baseline + brand multipliers (Aave/Compound/Morpho) if ASI:One is unavailable; optional MeTTa knowledge graph layer when present. Web3 execution: EIP-1559 fees with base fee detection, maxPriorityFee fallback, nonce handling + a small retry loop for “already known/replacement” conditions. Allowance and balance checks: pre-flight USDC balance and adapter allowance; on-demand approvals with receipt logging. Env-driven adapter resolution: env keys like AAVE_ADAPTER_BASE_SEPOLIA; normalization of protocol/chain strings to env keys. Vault math: ERC4626-like conversions; deposit/withdraw rounding discipline, and proof freshness check via lastProofBlock. ZK assets included: .wasm, .zkey, verification key; test_proof.js demonstrates end-to-end proof and verification. Trade-offs and constraints Speed over completeness: adapters and selector map kept deliberately thin for hackathon velocity; replace with full ABI + function coverage for production. Optional MeTTa: treated as a “nice to have”—build runs without it to avoid blocking on exotic deps. Pinned Python deps: improves reproducibility under tight timelines but may be strict across platforms. Why this composition works Agents modularize concerns (data → risk → execution) and keep each process testable. ZK constraint is isolated: verifier and vault gate deposits without complicating the execution agent. Using ASI:One provides flexible reasoning where rules would be brittle, without locking us into a single scoring approach. Base Sepolia plus Foundry gives fast on-chain iteration with familiar EVM tooling.

