Skip to content

Agent L3 Architecture Review

Current State Analysis

✅ What We Have

  1. Frontend: Complete UI foundation with all major components
  2. CR8 Token & Staking: Fully functional contracts and integration
  3. AgentDeposit.sol: Basic deposit/withdrawal system exists
  4. Architecture Planning: Comprehensive documentation

🔍 Key Observations

1. AgentDeposit Contract Analysis

Current Implementation:

  • Uses ERC20 token for deposits (depositToken)
  • Simple deposit/withdrawal mechanism
  • Proportional fee distribution to depositors
  • No ownership token system yet

Gap with Planned Architecture:

  • ❌ No ownership tokens (ERC-20 per agent)
  • ❌ No fractional ownership representation
  • ❌ Deposits tied to ERC20 token, not ETH-native
  • ❌ Liquidity provision doesn't mint ownership tokens

2. Agent Registry Missing

  • ❌ No centralized agent registry yet
  • ❌ No agent metadata storage
  • ❌ No integration management
  • ❌ Agent registration flow incomplete

Architecture Review: Key Components

Component 1: AgentRegistry.sol ⭐ PRIORITY

Status: Not implemented yet

Design Decisions Needed:

  1. Agent ID System

    • ✅ Sequential IDs (1, 2, 3...) - Simple, recommended
    • ❌ Hash-based IDs - More complex
    • Decision: Sequential is simpler and sufficient
  2. Agent Metadata Storage

    Option A: All on-chain (current plan)
    - Pros: Fully decentralized, verifiable
    - Cons: High gas costs for strings, limited size
    
    Option B: Hybrid (recommended)
    - Core data on-chain (ID, wallet, fees, stats)
    - Rich metadata off-chain (IPFS hash)
    - Pros: Lower gas, flexible
    - Cons: Requires IPFS infrastructure

    Recommendation: Hybrid approach

  3. Agent Wallet Management

    Question: How should agent wallets work?
    
    Option A: User-provided wallet address
    - Simple, user controls wallet
    - Can transfer control
    
    Option B: Contract-managed wallet
    - More complex, automated
    - Requires wallet factory pattern
    
    Option C: Agent is a contract itself
    - Most decentralized
    - Complex, requires agent contract deployment

    Recommendation: Start with Option A (user-provided), upgrade later


Component 2: AgentDeposit Extension ⚠️ NEEDS REDESIGN

Current Issues:

  1. Token vs Native ETH

    Current: Uses depositToken (ERC20)
    Planned: ETH-native liquidity provision
    
    Decision Needed:
    - Keep ERC20 approach? (USDC/DAI)
    - Switch to ETH native?
    - Support both?

    Recommendation: Start with ETH-native, add ERC20 support later

  2. Ownership Token System

    Current: Direct deposit tracking
    Needed: ERC-20 ownership tokens per agent
    
    Design:
    - Deploy ERC-20 token per agent
    - Mint tokens when liquidity provided
    - Burn tokens when liquidity withdrawn
    - Ownership % = user_tokens / total_supply
  3. Integration with AgentRegistry

    Current: AgentDeposit has its own agent registration
    Needed: AgentDeposit should reference AgentRegistry
    
    Change:
    - Remove agent registration from AgentDeposit
    - AgentDeposit checks AgentRegistry for agent existence
    - Single source of truth (AgentRegistry)

Component 3: FeeDistributor.sol

Status: Planned but not implemented

Key Design Questions:

  1. Distribution Mechanism

    Option A: Separate contract (current plan)
    - Pros: Separation of concerns
    - Cons: Additional contract, gas for calls
    
    Option B: Built into AgentDeposit
    - Pros: Less gas, simpler
    - Cons: More complex contract

    Recommendation: Option A (separate contract) for modularity

  2. Distribution Timing

    Option A: Batch (daily/weekly)
    - Lower gas costs
    - Delayed rewards
    
    Option B: Real-time (on each fee)
    - Immediate rewards
    - Higher gas costs
    
    Option C: Hybrid (user-triggered)
    - Users claim when ready
    - Lower gas (only when needed)

    Recommendation: Start with Option C (claim-based), add batch option

  3. Distribution Ratio

    Current Plan: 60% owners, 40% stakers
    Fixed vs Configurable?
    
    Option A: Fixed ratio
    - Simple, predictable
    
    Option B: Configurable per agent
    - More flexible
    - Complex
    
    Option C: Global configurable
    - Balance between fixed and per-agent

    Recommendation: Option C (globally configurable by owner)


Component 4: Integration System

Status: Conceptual only

Critical Design Decisions:

  1. Integration Storage

    Option A: On-chain strings only
    - "uniswap", "openai", etc.
    - Simple, verifiable
    - Limited flexibility
    
    Option B: On-chain registry with metadata
    - Full integration data on-chain
    - Higher gas, more flexible
    
    Option C: Hybrid (recommended)
    - IDs on-chain
    - Metadata off-chain (IPFS or API)
    - Best balance
  2. Integration Execution

    Question: How do agents actually USE integrations?
    
    Option A: Agent wallet calls integration APIs
    - Requires API keys stored off-chain
    - Agent wallet needs ETH for gas
    - Complex
    
    Option B: Integration manager contract
    - Contract handles integration calls
    - Centralized execution point
    - Simpler but less decentralized
    
    Option C: Agent contract with integration hooks
    - Most decentralized
    - Requires agent to be a contract
    - Complex implementation

    Recommendation: Phase 1 - Simple registry only, execution later


Revised Architecture Proposal

Phase 1: Simplified MVP

Focus: Get core functionality working

Contracts Needed:

  1. AgentRegistry.sol (New)

    • Simple agent registration
    • Basic metadata (name, wallet, fee rate)
    • Integration IDs as strings
    • Query functions
  2. AgentDeposit.sol (Refactor)

    • Remove: Agent registration logic
    • Add: ETH-native liquidity provision
    • Add: ERC-20 ownership tokens per agent
    • Modify: Integrate with AgentRegistry
    • Keep: Fee/yield distribution logic (refine)
  3. FeeDistributor.sol (New - Simplified)

    • Split fees between owners/stakers
    • Claim-based distribution (not automatic)
    • Configurable global ratio

Data Flow Simplified:

1. Register Agent → AgentRegistry
2. Provide Liquidity → AgentDeposit (mints ownership tokens)
3. Agent Earns Fees → AgentDeposit collects
4. Distribute Fees → FeeDistributor splits
5. Claim Rewards → Users claim from AgentDeposit

Key Architectural Decisions Needed

Decision 1: Ownership Token Implementation

Question: How should ownership tokens work?

Options:

A) ERC-20 per agent
   - One contract per agent
   - Simple, standard
   - More gas for deployment

B) ERC-1155 multi-token
   - Single contract, multiple tokens
   - Lower gas, more complex
   - Better for scalability

Recommendation: Start with ERC-20, plan ERC-1155 migration path


Decision 2: Liquidity Token Pair

Question: What tokens are supported for liquidity?

Options:

A) ETH only
   - Simplest
   - Native support

B) ERC20 tokens (USDC, DAI, etc.)
   - More flexible
   - Requires approval flow

C) Both (multi-token support)
   - Most flexible
   - Most complex

Recommendation: Start with ETH only, add ERC20 later


Decision 3: Agent Wallet Model

Question: How are agent wallets managed?

Current Plan: User provides wallet address

Considerations:

  • Wallet needs ETH for gas
  • Wallet controls agent operations
  • Who controls wallet initially?
  • Can ownership transfer wallet control?

Recommendation:

  • Phase 1: Creator controls wallet
  • Phase 2: Add multi-sig option
  • Phase 3: Agent-as-contract for full autonomy

Decision 4: Fee Collection Mechanism

Question: How do fees actually get to the system?

Options:

A) Agent wallet transfers to AgentDeposit
   - Requires agent wallet to be active
   - Manual/automated transfer

B) Integration contracts collect fees
   - Fees go directly to contracts
   - More automated

C) External service monitors and collects
   - Off-chain monitoring
   - Automated collection
   - Requires trusted service

Recommendation: Start with Option A, explore Option C for automation


1. Simplify AgentRegistry

Keep Simple:

  • Basic agent info (name, wallet, fee rate)
  • Integration IDs as string array
  • Timestamps and status

Defer:

  • Rich metadata (use IPFS later)
  • Complex querying (add indexes later)
  • Advanced features

2. Refactor AgentDeposit

Changes:

  1. Remove registerAgent() - use AgentRegistry instead
  2. Add ownership token deployment (ERC-20 per agent)
  3. Switch from ERC20 deposits to ETH-native
  4. Add provideLiquidity() and withdrawLiquidity()
  5. Mint/burn ownership tokens

Keep:

  • Fee distribution logic
  • Deposit tracking (but via ownership tokens)
  • Integration with CR8Staking

3. Create Minimal FeeDistributor

Features:

  • Split fees (60/40 or configurable)
  • Track pending distributions
  • Claim-based distribution
  • Integration with AgentDeposit and CR8Staking

Defer:

  • Automatic distribution
  • Complex batching
  • Advanced analytics

Component Relationship Diagram (Revised)

┌─────────────────┐
│ AgentRegistry   │ ← Single source of truth for agents
│ - Register      │
│ - Query         │
│ - Metadata      │
└────────┬────────┘

         │ (references agent ID)

┌─────────────────┐
│ AgentDeposit    │ ← Manages liquidity & ownership
│ - Liquidity     │
│ - Ownership     │
│ - Tokens        │
└────────┬────────┘

         │ (sends fees)

┌─────────────────┐
│ FeeDistributor  │ ← Splits fees
│ - Split Logic   │
│ - Distribution  │
└────────┬────────┘

    ┌────┴────┐
    ▼         ▼
┌─────────┐ ┌──────────┐
│Owners   │ │CR8Stakers│
│Rewards  │ │Rewards   │
└─────────┘ └──────────┘

Open Questions to Resolve

Critical (Before Implementation)

  1. Ownership Token Standard: ERC-20 vs ERC-1155?

    • Recommendation: ERC-20 for MVP
  2. Liquidity Token: ETH vs ERC20 vs Both?

    • Recommendation: ETH-native for MVP
  3. Agent Wallet Control: Who controls initially?

    • Recommendation: Creator controls, can transfer
  4. Integration Storage: On-chain strings vs Registry?

    • Recommendation: On-chain strings for MVP, registry later

Important (Phase 2)

  1. Fee Collection: Manual vs Automated?

    • Recommendation: Manual for MVP, automate later
  2. Distribution Frequency: Real-time vs Batch vs Claim?

    • Recommendation: Claim-based for MVP
  3. Metadata Storage: Full on-chain vs IPFS?

    • Recommendation: Core on-chain, rich metadata IPFS later

Future Considerations

  1. Multi-token support
  2. Agent-as-contract pattern
  3. Advanced integration execution
  4. Governance mechanisms
  5. Layer 2 scaling

Next Steps for Review

  1. Review Decisions: Confirm recommended approaches
  2. Refine Contracts: Update specifications based on decisions
  3. Update Architecture Doc: Reflect finalized decisions
  4. Start Implementation: Begin with AgentRegistry.sol

This review highlights key decisions and trade-offs. Let's discuss each to finalize the architecture before implementation.

CR8 Platform Documentation