Agent L3 Architecture & Design Plan
Executive Summary
Agent L3 is a decentralized agent registry platform enabling:
- Agent Registration: Create and register AI agents with integrations
- Fractional Ownership: Invest in agents via liquidity provision
- Fee Distribution: Agents earn fees and yield, distributed to owners and CR8 stakers
- Agent Wallet: Each agent has its own wallet for autonomous operations
1. System Architecture
1.1 High-Level Architecture
┌─────────────────────────────────────────────────────────────┐
│ Frontend (Next.js UI) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Registry │ │ Portfolio│ │ Staking │ │ Builder │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Blockchain Layer (Smart Contracts) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │AgentRegistry │ │ AgentDeposit │ │ CR8Staking │ │
│ │ │ │ │ │ │ │
│ │- Register │ │- Liquidity │ │- Stake CR8 │ │
│ │- Query │ │- Ownership │ │- Rewards │ │
│ │- Manage │ │- Fees/Yield │ │- Distribution│ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ CR8Token │ │ FeeDistributor│ │
│ │ │ │ │ │
│ │- ERC20 │ │- Collect │ │
│ │- Minting │ │- Distribute │ │
│ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ External Integrations │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ DeFi │ │ AI │ │ NFT │ │ Oracles │ │
│ │ Uniswap │ │ OpenAI │ │ IPFS │ │Chainlink │ │
│ │ Aave │ │ Midjourney│ │ OpenSea │ │ │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘1.2 Core Components
Smart Contracts
AgentRegistry.sol
- Agent registration and metadata storage
- Integration management
- Agent wallet address management
- Query functions for frontend
AgentDeposit.sol (Existing - extend)
- Liquidity provision (fractional ownership)
- Ownership token (ERC-20 or ERC-1155)
- Fee/yield collection from agents
- Distribution to owners
CR8Staking.sol (Existing)
- CR8 token staking
- Reward distribution from agent fees
- Staker management
FeeDistributor.sol (New)
- Collect fees from agents
- Split distribution (owners vs stakers)
- Automated distribution logic
CR8Token.sol (Existing)
- ERC-20 token
- Minting capabilities
- Upgradeable
Frontend Components
Agent Registry
- Browse/search agents
- Filter by integrations, performance
- Agent detail pages
Agent Builder/Registration
- Multi-step registration form
- Integration marketplace
- Configuration management
Portfolio Dashboard
- User's agent holdings
- CR8 staking overview
- Earnings and rewards
Staking Interface
- Stake/unstake CR8
- Claim rewards
- Performance tracking
Agent Detail Pages
- Agent information
- Liquidity provision
- Ownership chart
- Performance metrics
- Action buttons (stake, claim, manage)
2. Data Models & Structures
2.1 Agent Data Structure
struct Agent {
uint256 id; // Unique agent ID
string name; // Agent name
string description; // Agent description
address walletAddress; // Agent's operational wallet
address creator; // Creator address
uint256 userFeeRate; // Fee rate (basis points)
uint256 totalLiquidity; // Total liquidity provided
uint256 feesGenerated; // Lifetime fees
uint256 yieldGenerated; // Lifetime yield
uint256 totalDistributed; // Total distributed to owners
uint256 ownerCount; // Number of fractional owners
string[] integrations; // Integration IDs
bool isActive; // Active status
uint256 createdAt; // Registration timestamp
}2.2 Ownership Structure
struct Ownership {
address owner; // Owner address
uint256 tokens; // Ownership tokens (or shares)
uint256 percentage; // Ownership percentage
uint256 feesEarned; // Cumulative fees earned
uint256 yieldEarned; // Cumulative yield earned
uint256 lastClaimTime; // Last reward claim
}2.3 Integration Structure
interface Integration {
id: string;
name: string;
description: string;
category: 'defi' | 'ai' | 'nft' | 'oracle' | 'other';
icon: string;
contractAddress?: string; // Optional: smart contract address
apiKeyRequired: boolean; // Whether API key needed
configurable: boolean; // Can be configured per agent
}3. Smart Contract Architecture
3.1 AgentRegistry Contract
Functions:
// Registration
function registerAgent(
string memory name,
string memory description,
address agentWallet,
uint256 feeRate, // Basis points (0-1000 = 0-10%)
string[] memory integrations
) external returns (uint256 agentId);
// Query
function getAgent(uint256 agentId) external view returns (Agent memory);
function getAllAgents() external view returns (Agent[] memory);
function getAgentsByIntegration(string memory integration) external view returns (uint256[] memory);
// Management
function updateAgentMetadata(uint256 agentId, string memory description) external;
function addIntegration(uint256 agentId, string memory integrationId) external;
function setAgentWallet(uint256 agentId, address newWallet) external;
function setActiveStatus(uint256 agentId, bool active) external;3.2 AgentDeposit Contract (Extended)
New Functions:
// Liquidity Provision
function provideLiquidity(uint256 agentId) external payable returns (uint256 tokens);
function withdrawLiquidity(uint256 agentId, uint256 tokens) external;
// Fee/Yield Collection
function collectFees(uint256 agentId, uint256 amount) external;
function collectYield(uint256 agentId, uint256 amount) external;
// Distribution
function distributeRewards(uint256 agentId) external;
function claimRewards(uint256 agentId) external;
// Query
function getOwnership(uint256 agentId, address owner) external view returns (Ownership memory);
function getTotalOwnership(uint256 agentId) external view returns (uint256);3.3 FeeDistributor Contract (New)
Functions:
// Distribution Logic
function distributeAgentFees(uint256 agentId, uint256 totalFees) external;
function distributeAgentYield(uint256 agentId, uint256 totalYield) external;
// Configuration
function setDistributionRatio(uint256 ownerShare, uint256 stakerShare) external; // e.g., 60% owners, 40% stakers
function getDistributionRatio() external view returns (uint256, uint256);4. Integration System
4.1 Integration Types
DeFi Integrations:
- Uniswap: Swap functionality
- Aave: Lending/borrowing
- Compound: Yield generation
AI Integrations:
- OpenAI: GPT models, embeddings
- Midjourney: Image generation
- Anthropic: Claude models
NFT Integrations:
- IPFS: Decentralized storage
- OpenSea: NFT marketplace
- Minting contracts: NFT creation
Oracle Integrations:
- Chainlink: Price feeds, randomness
- Band Protocol: Data feeds
4.2 Integration Framework
Integration Interface:
- initialize(agentId, config)
- execute(agentId, action, params)
- getStatus(agentId)
- updateConfig(agentId, config)4.3 Integration Registry
struct IntegrationMetadata {
string id;
string name;
string category;
address implementation; // Optional contract address
bool requiresApproval; // Needs admin approval
bool isActive;
}
mapping(string => IntegrationMetadata) public integrations;5. Economic Model
5.1 Revenue Streams
Agent Fees:
- Users pay fees to use agents
- Fee rate set per agent (0-10%)
- Fees collected by agent wallet
Yield Generation:
- Agents invest liquidity for yield
- Yield sources: DeFi protocols, staking, etc.
- Yield collected by agent wallet
5.2 Distribution Model
Example Distribution (60/40 split):
- 60% to agent owners (proportional to ownership)
- 40% to CR8 stakers (proportional to staked amount)
Distribution Frequency:
- Real-time (on each fee collection)
- Or batch (daily/weekly)
5.3 Ownership Model
Fractional Ownership:
- Users provide liquidity (ETH/USDC)
- Receive ownership tokens (shares)
- Ownership percentage = user_tokens / total_tokens
- Ownership determines share of fees/yield
Ownership Token:
- ERC-20 or ERC-1155
- Transferable
- Represents fractional ownership
6. User Flows
6.1 Agent Creator Flow
Registration
- Fill agent information
- Select integrations
- Set fee rate
- Deploy agent wallet (optional)
Activation
- Agent goes live
- Accepts liquidity from users
- Starts generating fees/yield
Management
- Update integrations
- Monitor performance
- Configure agent settings
6.2 Investor Flow
Browse Agents
- Search/filter agents
- View performance metrics
- Check integrations
Provide Liquidity
- Select agent
- Enter amount
- Receive ownership tokens
Monitor & Claim
- View holdings in portfolio
- Track earnings
- Claim rewards
6.3 CR8 Staker Flow
Stake CR8
- Approve tokens
- Stake amount
- Start earning rewards
Receive Rewards
- Automatic distribution from agent fees
- Claim rewards
- Compound or withdraw
7. Technical Specifications
7.1 Frontend Tech Stack
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- Blockchain: Wagmi v2 + Viem
- Wallet: RainbowKit
- State: React Query (TanStack Query)
7.2 Smart Contract Stack
- Language: Solidity ^0.8.22
- Framework: Hardhat
- Standards: ERC-20, ERC-165, ERC-1967 (UUPS)
- Libraries: OpenZeppelin
7.3 Storage
- On-Chain: Agent metadata, ownership, distributions
- Off-Chain: Integration configs, agent descriptions (IPFS option)
8. Security Considerations
8.1 Smart Contract Security
- Access control (Ownable/Roles)
- Reentrancy guards
- Integer overflow protection (Solidity 0.8+)
- Pausable functionality
- Upgradeability (UUPS pattern)
8.2 Integration Security
- Integration whitelisting
- Rate limiting
- API key management (encrypted)
- Sandboxed execution
8.3 Frontend Security
- Wallet connection validation
- Transaction simulation
- Error handling
- Rate limiting on API calls
9. Roadmap & Phases
Phase 1: Foundation (Weeks 1-2)
- ✅ UI Components (Current state)
- ✅ CR8 Token Integration
- ✅ Staking Interface
- [ ] AgentRegistry Smart Contract
- [ ] Agent Registration Flow
Phase 2: Core Functionality (Weeks 3-4)
- [ ] AgentDeposit Contract Extension
- [ ] Liquidity Provision UI
- [ ] Ownership Token System
- [ ] Basic Integration System
- [ ] Agent Detail Pages
Phase 3: Fee Distribution (Weeks 5-6)
- [ ] FeeDistributor Contract
- [ ] Fee Collection Mechanism
- [ ] Distribution Logic (Owners/Stakers)
- [ ] Reward Claiming Interface
Phase 4: Integrations (Weeks 7-8)
- [ ] DeFi Integrations (Uniswap, Aave)
- [ ] AI Integrations (OpenAI, Midjourney)
- [ ] NFT Integrations (IPFS, OpenSea)
- [ ] Integration Marketplace UI
Phase 5: Advanced Features (Weeks 9-10)
- [ ] Agent Performance Analytics
- [ ] Advanced Search/Filtering
- [ ] Agent Marketplace
- [ ] Governance Features (if needed)
Phase 6: Testing & Audit (Weeks 11-12)
- [ ] Comprehensive Testing
- [ ] Security Audit
- [ ] Bug Fixes
- [ ] Mainnet Deployment Prep
10. Key Decisions & Considerations
10.1 Ownership Token Standard
Option A: ERC-20
- Simple, widely supported
- Each agent has separate token
- More gas-intensive
Option B: ERC-1155
- Batch operations
- Single contract for all agents
- More complex
Recommendation: Start with ERC-20, consider ERC-1155 for optimization
10.2 Fee Distribution Frequency
Option A: Real-time
- Immediate rewards
- Higher gas costs
- Better UX
Option B: Batch (Daily/Weekly)
- Lower gas costs
- Delayed rewards
- Simpler implementation
Recommendation: Start with batch, add real-time option later
10.3 Integration Management
Option A: On-Chain Registry
- Fully decentralized
- Higher gas costs
- Immutable
Option B: Hybrid (On-Chain + Off-Chain)
- Flexibility
- Lower gas costs
- Admin control
Recommendation: Hybrid approach
11. Open Questions
- Agent Wallet Management: Autonomous wallets vs. creator-controlled?
- Integration Approval: Manual approval vs. automated whitelist?
- Liquidity Pairs: ETH only vs. multiple tokens (USDC, DAI)?
- Ownership Limits: Minimum/maximum ownership percentages?
- Fee Limits: Maximum fee rate cap?
- Governance: DAO for platform decisions?
12. Success Metrics
- Number of registered agents
- Total liquidity locked
- Total fees generated
- Active owners/investors
- CR8 staked amount
- Integration usage
- User retention
This architecture document serves as the foundation for building Agent L3. We'll refine specific components and integrations as we progress through development.