Smart Contracts

Miko402's autonomous payment system is powered by three core smart contracts that work together to enable secure, transparent, and trustless transactions.

Contract Overview

┌─────────────────────────────────────┐
│          Miko402 Ecosystem          │
├─────────────────────────────────────┤
│  User Interface (Next.js App)       │
├─────────────────────────────────────┤
│  AI Agent (Google Gemini)           │
├─────────────────────────────────────┤
│          Smart Contracts            │
│  ┌───────────────────────────────┐  │
│  │  PaymentGateway.sol           │  │
│  │  - Payment processing         │  │
│  │  - Escrow & release           │  │
│  └───────────────────────────────┘  │
│  ┌───────────────────────────────┐  │
│  │  SpendingLimits.sol           │  │
│  │  - Limit enforcement          │  │
│  │  - Spending tracking          │  │
│  └───────────────────────────────┘  │
│  ┌───────────────────────────────┐  │
│  │  X402Registry.sol             │  │
│  │  - Service discovery          │  │
│  │  - Provider registry          │  │
│  └───────────────────────────────┘  │
├─────────────────────────────────────┤
│  Blockchain (Solana / EVM chains)   │
└─────────────────────────────────────┘

1. PaymentGateway.sol

Purpose

Handles all payment processing, escrow, and fund transfers between users and x402 service providers.

Key Features

  • Native token and ERC-20 support

  • Payment escrow and release

  • Refund mechanism

  • Transaction tracking with full audit trail

Core Functions

Data Structures

Events

2. SpendingLimits.sol

Purpose

Enforces user-defined spending limits to prevent overspending during autonomous payment operations.

Key Features

  • Daily, weekly, and monthly limits

  • Automatic time-based resets

  • Approved spender management

  • Real-time limit checking

Core Functions

Data Structures

Events

3. X402Registry.sol

Purpose

Central on-chain registry for x402-compatible services and their pricing.

Key Features

  • Service registration and discovery

  • Multi-tier pricing

  • Service verification

  • Usage statistics tracking

Core Functions

Data Structures

Contract Interactions

Payment Flow

Limit Enforcement Flow

Security Features

Access Control

  • Ownable — Admin-only functions

  • approvedSpenders — Authorized agent addresses

  • ReentrancyGuard — Reentrancy attack prevention

Input Validation

  • Non-zero address checks

  • Positive amount validation

  • Limit hierarchy enforcement

  • Service existence verification

Gas Optimization

  • Struct packing for efficient storage slots

  • Minimized SLOAD operations

  • Batch payments coming soon

Upgradeability

Contracts are currently non-upgradeable for security. Future plans include a proxy pattern with timelock governance, multi-sig approval, and community voting.

Testing

Each contract has 30+ tests covering normal operations, edge cases, access control, error handling, gas optimization, and integration scenarios.

See /contracts/test/ for the full test suite.

Deployment

Supported Networks

  • Solana (adapted version)

  • Ethereum Mainnet

  • Polygon

  • Base

  • Arbitrum

  • Optimism

Deployment Process

Contract Addresses

Mainnet: Coming soon Testnet (Sepolia): Available in the repository

Audits

Security audits are in progress with professional auditing firms. All contracts are open source and available for community review.

Source Code

All contracts are open source under the MIT License:


Questions? Email [email protected]envelope or open an issue on GitHubarrow-up-right.

Last updated