CoolFace
Apppublic

DIREWOLFE-X/Protocol-Zero

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿ›ก๏ธ Protocol Zero โ€” Autonomous ERC-8004 DeFi Trading Agent

![Python 3.11+](https://www.python.org/downloads/) ![ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) ![License: MIT](LICENSE) ![Amazon Nova](https://aws.amazon.com/bedrock/)

Capital preservation first, profit second.

Protocol Zero is a trust-minimized, autonomous DeFi trading agent built on the ERC-8004 standard for on-chain agent identity, reputation, and validation. It combines AI-driven market reasoning (Amazon Bedrock Nova) with cryptographic accountability (EIP-712 signed intents) and a multi-layered risk management pipeline.


๐ŸŽฌ Demo

๐Ÿ“บ Demo Video โ€” Coming soon before final submission. Run streamlit run streamlit_app.py to see Protocol Zero live: AI-driven market analysis, EIP-712 intent signing, and on-chain ERC-8004 registration โ€” all in one cinematic dashboard.

๐Ÿ“ธ Screenshots

Run streamlit run streamlit_app.py to experience the full cinematic dashboard: cognitive stream, market regime orb, trade DNA, risk heat-map, XAI reasoning panel, and more. Screenshots will be added before final submission.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Fetch    โ”‚ โ”€โ”€โ–บ โ”‚  Brain  โ”‚ โ”€โ”€โ–บ โ”‚ Risk Check   โ”‚ โ”€โ”€โ–บ โ”‚ Validate +    โ”‚
โ”‚ Market   โ”‚     โ”‚ (Nova)  โ”‚     โ”‚ (6 checks)   โ”‚     โ”‚ Sign (EIP712) โ”‚
โ”‚ Data     โ”‚     โ”‚         โ”‚     โ”‚              โ”‚     โ”‚               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                              โ”‚
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
                        โ–ผ                                     โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Validation   โ”‚                 โ”‚ Reputation        โ”‚
                 โ”‚ Artifacts    โ”‚                 โ”‚ (giveFeedback)    โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Modules

ModulePurpose
brain.pyAI reasoning engine โ€” fetches OHLCV data, builds prompts, calls Nova Lite with agentic tool-use
risk_check.py6-layer fail-closed risk gate (position size, daily loss, frequency, concentration, confidence, expiry)
sign_trade.pyEIP-712 trade intent validation & signing โ€” the AI never touches private keys
eip712_signer.pyPure cryptographic EIP-712 module โ€” no RPC required
chain_interactor.pyWeb3 bridge for the three ERC-8004 registries (Identity, Reputation, Validation)
dex_executor.pyLive Uniswap V3 swap execution with slippage protection
dashboard.pyStreamlit cinematic dashboard with cognitive stream, market orb, trade DNA, risk heatmap
config.pyCentralized configuration โ€” loads .env with validation
metadata_handler.pyERC-8004 agent-identity.json generator with keccak256 & IPFS CID hashing
performance_tracker.pySession analytics โ€” Sharpe ratio, win rate, drawdown tracking
validation_artifacts.pyCryptographic audit trail builder for every decision

Nova AI Integrations

ModuleAWS ServicePurposeLive / Fallback
brain.pyBedrock (Nova Lite)Agentic market reasoning with tool-use loopโœ… Real Converse API
nova_sonic_voice.pyBedrock (Nova Lite)Text intelligence for voice commands (browser TTS)โšก Nova Lite text + Web Speech API
nova_act_auditor.pyNova Act (invite-only)Browser-based smart contract auditingโฌ‡๏ธ Simulated (SDK invite-only)
nova_embeddings.pyNova Embed MultimodalScam-pattern detection via cosine similarityโœ… Real embeddings / heuristic fallback

Quick Start

1. Clone & Install

bash
git clone https://github.com/Direwolfe999/Protocol-Zero.git
cd Protocol-Zero
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

2. Configure Environment

bash
cp .env.example .env
# Edit .env with your real keys

Required variables:

  • โ€”RPC_URL โ€” Sepolia or mainnet RPC endpoint (Alchemy / Infura)
  • โ€”PRIVATE_KEY โ€” Bot wallet private key (hex, no 0x prefix)
  • โ€”IDENTITY_REGISTRY_ADDRESS โ€” ERC-8004 Identity Registry contract
  • โ€”REPUTATION_REGISTRY_ADDRESS โ€” ERC-8004 Reputation Registry contract
  • โ€”VALIDATION_REGISTRY_ADDRESS โ€” ERC-8004 Validation Registry contract

Optional (for full AI reasoning):

  • โ€”AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY โ€” Amazon Bedrock credentials
  • โ€”DEX_ENABLED=true โ€” Enable live Uniswap V3 swaps

3. Register Agent (one-time)

bash
python main.py --register

4. Run

bash
# Single decision cycle
python main.py

# Continuous trading loop
python main.py --loop

# Launch the dashboard
streamlit run streamlit_app.py

Risk Management

Protocol Zero enforces a fail-closed risk pipeline โ€” if any check is uncertain, the trade is blocked. Six independent checks run in sequence:

CheckPurposeDefault Limit
check_max_position_sizeSingle-trade USD cap$500
check_daily_loss_limitCumulative daily drawdown-$1,000
check_trade_frequencyMax trades per rolling hour10
check_concentrationMax % of capital in one asset30%
check_confidence_floorMinimum model confidence40%
check_intent_expiryReject stale intents5 min TTL

ERC-8004 Compliance

Protocol Zero implements all three ERC-8004 registries:

  • โ€”Identity Registry โ€” Agent mints an ERC-721 NFT with register(agentURI), stores metadata via setMetadata
  • โ€”Reputation Registry โ€” Every trade result is logged via giveFeedback() with PnL, tags, and content hashes
  • โ€”Validation Registry โ€” Trade intents are submitted via validationRequest() with EIP-712 signatures

Testing

bash
# Run all tests
pytest

# Run with coverage
pytest --cov=. --cov-report=term-missing

# Run a specific module's smoke test
python risk_check.py
python eip712_signer.py
python sign_trade.py --json '{"action":"BUY","asset":"ETH","confidence":0.8,"risk_score":3,"position_size_percent":1.0,"stop_loss_percent":3.0,"take_profit_percent":6.0,"market_regime":"TRENDING"}'

Test Coverage

ModuleTest FileCoverage
brain.pytests/test_brain.pyRule-based engine, response parser
risk_check.pytests/test_risk_check.pyAll 6 risk gates
sign_trade.pytests/test_sign_trade.pyIntent validation & signing
eip712_signer.pytests/test_eip712_signer.pyEIP-712 message builder, signing, nonce persistence
nova_sonic_voice.pytests/test_nova_sonic_voice.pyCommand parser, text fallback, alerts
performance_tracker.pytests/test_performance_tracker.pySharpe, drawdown, win rate
metadata_handler.pytests/test_metadata_handler.pyMetadata generation & hashing
validation_artifacts.pytests/test_validation_artifacts.pyArtifact data structures
exceptions.pytests/test_exceptions.pyException hierarchy

๐Ÿค– Amazon Nova AI Integration

Protocol Zero integrates four Amazon Nova services through Bedrock, with transparent fallback engines for each:

Nova Lite โ€” Agentic Market Reasoning โœ…

The brain uses the Bedrock Converse API with tool-use to make trading decisions. The LLM can request additional data mid-reasoning by calling tools:

  • โ€”rug_pull_scanner โ†’ Check contracts for scam indicators
  • โ€”market_deep_dive โ†’ Fetch real-time order-book depth from CCXT
  • โ€”nova_act_audit โ†’ Browser-based contract verification
  • โ€”embedding_scan โ†’ Scam-pattern detection on token metadata

This is the strongest integration โ€” a real agentic loop with tool orchestration.

Nova Voice Intelligence โšก

Uses Nova Lite Converse API for intelligent text responses to voice commands. Browser-side Web Speech API handles text-to-speech playback. A Nova Sonic bidirectional stream session is initialised for future audio I/O, but audio frame processing is not yet wired. Falls back to rule-based text responses when AWS is unavailable.

Nova Act โ€” Browser-Based Smart Contract Auditing โฌ‡๏ธ

The code implements real Nova Act browser automation for Etherscan/DEXTools auditing. However, the nova-act SDK is invite-only and not publicly available. The system falls back to deterministic heuristic audits that honestly label themselves as "audit_method": "simulated".

Nova Multimodal Embeddings โ€” Scam Detection โœ…

Generates real embeddings via amazon.nova-embed-multimodal-v1:0 and compares them against reference pattern vectors using cosine similarity. Falls back to keyword/hash heuristics when AWS is unavailable.

All Nova services are optional โ€” the system gracefully falls back to rule-based engines and text-mode responses when AWS credentials are not configured. Fallback modes are clearly labeled in the dashboard.

๐Ÿ”ง Troubleshooting

"AWS credentials not ready โ€” using rule-based fallback brain"

This is normal when AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY are not set. The system uses a technical-indicator-driven fallback engine (RSI + SMA crossovers).

"ValidationException: Operation not allowed" (Bedrock Converse)

If your dashboard shows AWS as configured but Bedrock runtime calls fail with:

ValidationException: Operation not allowed

this usually means partial AWS access:

  • โ€”IAM credentials are valid
  • โ€”control-plane checks may work
  • โ€”but runtime model invocation is blocked at account/org/region/model level

In this state, Protocol Zero now:

  • โ€”marks Nova Brain as BLOCKED/FALLBACK in status views
  • โ€”suppresses noisy retry loops
  • โ€”uses the deterministic rule-based decision engine until Bedrock runtime access is enabled

To fix at AWS side:

  • โ€”Verify Bedrock model access approval for amazon.nova-lite-v1:0
  • โ€”Confirm region alignment (AWS_DEFAULT_REGION)
  • โ€”Check org SCP/permission boundaries for bedrock:Converse / bedrock:InvokeModel
  • โ€”Open AWS Support if runtime remains blocked despite IAM allow policies

"Cannot reach RPC" error

Check your RPC_URL in .env. For local testing, start Anvil:

bash
anvil --chain-id 31337

Then set RPC_URL=http://127.0.0.1:8545 in .env.local.

"nova-act" install fails

nova-act is an invite-only SDK. It's commented out of requirements.txt. Install it manually if you have access: pip install nova-act. The system falls back to simulated audits when unavailable.

Dashboard won't start

bash
# Make sure Streamlit is installed
pip install streamlit plotly

# Run from the project root
streamlit run streamlit_app.py --server.port 8502

EIP-712 signature mismatch

Ensure CHAIN_ID and VALIDATION_REGISTRY_ADDRESS in your .env match the values hard-coded in your deployed contract. The EIP-712 domain separator must be identical on both sides.


Project Structure

Protocol-Zero/
โ”œโ”€โ”€ brain.py                  # AI reasoning engine (Nova Lite + tool-use)
โ”œโ”€โ”€ chain_interactor.py       # Web3 bridge for ERC-8004 registries
โ”œโ”€โ”€ config.py                 # Centralized .env loader with validation
โ”œโ”€โ”€ dashboard.py              # Streamlit cinematic dashboard
โ”œโ”€โ”€ streamlit_app.py          # Streamlit Cloud entrypoint (main module)
โ”œโ”€โ”€ dex_executor.py           # Uniswap V3 live swap execution
โ”œโ”€โ”€ eip712_signer.py          # EIP-712 structured data signing
โ”œโ”€โ”€ exceptions.py             # Custom exception hierarchy
โ”œโ”€โ”€ main.py                   # Orchestrator โ€” full agent lifecycle
โ”œโ”€โ”€ metadata_handler.py       # ERC-8004 agent-identity.json generator
โ”œโ”€โ”€ nova_act_auditor.py       # Nova Act browser-based contract auditing
โ”œโ”€โ”€ nova_embeddings.py        # Nova multimodal embedding scam detection
โ”œโ”€โ”€ nova_sonic_voice.py       # Nova Sonic bidirectional voice interface
โ”œโ”€โ”€ performance_tracker.py    # Session analytics (Sharpe, drawdown, etc.)
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ pyproject.toml            # Project metadata & optional dependencies
โ”œโ”€โ”€ risk_check.py             # 6-layer fail-closed risk gate
โ”œโ”€โ”€ sign_trade.py             # Trade intent validator & signer
โ”œโ”€โ”€ validation_artifacts.py   # Cryptographic audit trail builder
โ”œโ”€โ”€ tests/                    # Unit & integration tests
โ”‚   โ”œโ”€โ”€ test_brain.py         # Brain rule-engine + parser tests
โ”‚   โ”œโ”€โ”€ test_eip712_signer.py # EIP-712 signing + nonce persistence
โ”‚   โ”œโ”€โ”€ test_exceptions.py    # Exception hierarchy tests
โ”‚   โ”œโ”€โ”€ test_metadata_handler.py   # Metadata generation & hashing
โ”‚   โ”œโ”€โ”€ test_nova_sonic_voice.py   # Voice command parser & fallback
โ”‚   โ”œโ”€โ”€ test_performance_tracker.py # Performance metrics tests
โ”‚   โ”œโ”€โ”€ test_risk_check.py    # Risk gate tests
โ”‚   โ”œโ”€โ”€ test_sign_trade.py    # Trade intent signing tests
โ”‚   โ””โ”€โ”€ test_validation_artifacts.py # Artifact data structure tests
โ”œโ”€โ”€ .env.example              # Environment variable template (copy to .env)
โ”œโ”€โ”€ .gitignore                # Git exclusions
โ”œโ”€โ”€ LICENSE                   # MIT license
โ””โ”€โ”€ README.md                 # This file

License

MIT โ€” see LICENSE for details.


๐Ÿ† Hackathon

Built for the Amazon Nova AI Hackathon on Devpost.

Protocol Zero demonstrates how autonomous AI agents can operate transparently on-chain using the ERC-8004 standard, with Amazon Nova providing the cognitive backbone:

  • โ€”Nova Lite โ€” Agentic reasoning with tool-use (real Converse API)
  • โ€”Nova Voice โ€” Text intelligence + browser-side Web Speech API
  • โ€”Nova Act โ€” Browser-based contract auditing (simulated; SDK is invite-only)
  • โ€”Nova Embeddings โ€” Cosine-similarity scam detection (real embeddings when AWS available)

Every decision is cryptographically signed (EIP-712), risk-gated (6 independent checks), and logged on-chain (Validation Registry) โ€” creating a complete audit trail that proves the agent's reasoning was sound before execution.

Capital preservation first, profit second. ๐Ÿ›ก๏ธ