Skip to content

Smart Contracts Overview

WasiAI's smart contracts form the on-chain backbone of the marketplace. They handle model registration, license sales, agent identity, and revenue distribution.


Contract Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                        WASIAI SMART CONTRACTS                               │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │                      MarketplaceV3                                   │   │
│  │  • Model registration & updates                                      │   │
│  │  • License sales (perpetual & subscription)                          │   │
│  │  • Pricing configuration                                             │   │
│  │  • Agent registration (delegated)                                    │   │
│  │  • Splitter creation (delegated)                                     │   │
│  └──────────────────────────┬──────────────────────────────────────────┘   │
│                             │                                               │
│           ┌─────────────────┼─────────────────┐                            │
│           │                 │                 │                            │
│           ▼                 ▼                 ▼                            │
│  ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐              │
│  │  LicenseNFTV2   │ │ AgentRegistryV2 │ │ SplitterFactory │              │
│  │  (ERC-721)      │ │ (ERC-8004)      │ │ (EIP-1167)      │              │
│  │                 │ │                 │ │                 │              │
│  │  • License mint │ │  • Agent mint   │ │  • Clone deploy │              │
│  │  • Rights mgmt  │ │  • Identity     │ │  • Config init  │              │
│  │  • Revocation   │ │  • Reputation   │ │                 │              │
│  └─────────────────┘ └─────────────────┘ └────────┬────────┘              │
│                                                   │                        │
│                                                   ▼                        │
│                                          ┌─────────────────┐               │
│                                          │  ModelSplitter  │               │
│                                          │  (per model)    │               │
│                                          │                 │               │
│                                          │  • Receive USDC │               │
│                                          │  • Split revenue│               │
│                                          │  • Distribute   │               │
│                                          └─────────────────┘               │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │                    External Contracts                                │   │
│  │  • Circle USDC (0x5425890298aed601595a70AB815c96711a31Bc65)         │   │
│  │  • MockUSDC for testing (0xCDa6E1C8340550aC412Ee9BC59ae4Db46745C53e)│   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Deployed Addresses (Avalanche Fuji)

Contract Address Verified
MarketplaceV3 0xf1eA59d71C67e9E6Ea481Aa26911641a6c97370C
LicenseNFTV2 0xC657F1B26fc56A0AA1481F502BCC6532B93d7426
AgentRegistryV2 0x3421c2cDE342afF48C12Fe345eD81cA1ac4D89A6
SplitterFactory 0xf8d8C220181CAe9A748b8e817BFE337AB5b74731
MockUSDC 0xCDa6E1C8340550aC412Ee9BC59ae4Db46745C53e
Circle USDC 0x5425890298aed601595a70AB815c96711a31Bc65 External

Contract Summaries

MarketplaceV3

The central contract for the WasiAI marketplace. Handles all model-related operations.

Key Functions: - publishModel(): Register a new model - updateModel(): Update model metadata - buyLicense(): Purchase a license NFT - setInferencePrice(): Configure pay-per-use pricing

Security Features: - Ownable2Step (two-step ownership transfer) - ReentrancyGuard (reentrancy protection) - Pausable (emergency stop) - 24-hour timelock for critical changes

Full Reference →

LicenseNFTV2

ERC-721 contract for license tokens. Each token represents access rights to a model.

Key Functions: - mint(): Mint a new license (called by Marketplace) - burn(): Burn an expired/revoked license - tokenURI(): Get license metadata

License Types: - Perpetual (KIND_PERPETUAL = 0) - Subscription (KIND_SUBSCRIPTION = 1)

Rights Bitmask: - API Access (RIGHTS_API = 1) - Download Access (RIGHTS_DOWNLOAD = 2)

Full Reference →

AgentRegistryV2

ERC-8004 compliant identity registry for AI agents. Each agent is an ERC-721 token.

Key Functions: - registerAgent(): Register a new agent - updateEndpoint(): Change inference endpoint - requestWalletChange(): Initiate wallet change (timelocked) - executeWalletChange(): Complete wallet change after timelock

Agent Data: - Model ID reference - Payment wallet - Inference endpoint URL - Registration timestamp - Active status

Full Reference →

SplitterFactory

Factory contract for deploying ModelSplitter clones using EIP-1167 minimal proxies.

Key Functions: - createSplitter(): Deploy a new splitter for a model - getSplitter(): Get splitter address for a model - aliasSplitter(): Link model versions to same splitter

Gas Efficiency: - Uses EIP-1167 minimal proxies - ~$0.10-0.30 per splitter deployment

Full Reference →

ModelSplitter

Individual splitter contract for each model. Receives payments and distributes to stakeholders.

Key Functions: - receive(): Receive USDC payments - distribute(): Split and send to recipients - updateShares(): Modify split percentages (owner only)

Revenue Split:

Recipient Share
Creator 80%
Marketplace 20%

Full Reference →


Security Model

Access Control

Contract Access Pattern
MarketplaceV3 Ownable2Step + model owner checks
LicenseNFTV2 Only Marketplace can mint
AgentRegistryV2 Ownable2Step + agent owner checks
SplitterFactory Authorized addresses only
ModelSplitter Owner (Marketplace) only

Timelocks

Critical operations require a 24-hour delay: - Inference wallet changes - Fee recipient changes - Contract upgrades

Pausability

All main contracts can be paused by the owner in emergencies:

function pause() external onlyOwner {
    _pause();
}

function unpause() external onlyOwner {
    _unpause();
}

Reentrancy Protection

All payment-related functions use nonReentrant modifier:

function buyLicense(...) external nonReentrant whenNotPaused {
    // ...
}


Events

MarketplaceV3 Events

event ModelPublished(uint256 indexed modelId, address indexed owner, string name);
event ModelUpdated(uint256 indexed modelId);
event LicensePurchased(uint256 indexed modelId, uint256 indexed licenseId, address buyer);
event InferencePriceSet(uint256 indexed modelId, uint256 price);

LicenseNFTV2 Events

event LicenseMinted(uint256 indexed tokenId, uint256 indexed modelId, address indexed buyer);
event LicenseRevoked(uint256 indexed tokenId);

AgentRegistryV2 Events

event AgentRegistered(uint256 indexed agentId, address indexed owner, uint256 indexed modelId);
event AgentEndpointUpdated(uint256 indexed agentId, string endpoint);
event AgentWalletChanged(uint256 indexed agentId, address oldWallet, address newWallet);

SplitterFactory Events

event SplitterCreated(uint256 indexed modelId, address indexed splitter, address seller);
event SplitterAliased(uint256 indexed newModelId, uint256 indexed originalModelId);

Integration Guide

Reading Contract Data

import { createPublicClient, http } from 'viem'
import { avalancheFuji } from 'viem/chains'

const client = createPublicClient({
  chain: avalancheFuji,
  transport: http()
})

// Get model info
const model = await client.readContract({
  address: MARKETPLACE_ADDRESS,
  abi: MarketplaceV3ABI,
  functionName: 'models',
  args: [modelId]
})

// Get agent info
const agent = await client.readContract({
  address: AGENT_REGISTRY_ADDRESS,
  abi: AgentRegistryV2ABI,
  functionName: 'agents',
  args: [agentId]
})

Writing to Contracts

import { createWalletClient, custom } from 'viem'

const walletClient = createWalletClient({
  chain: avalancheFuji,
  transport: custom(window.ethereum)
})

// Buy a license
const hash = await walletClient.writeContract({
  address: MARKETPLACE_ADDRESS,
  abi: MarketplaceV3ABI,
  functionName: 'buyLicense',
  args: [modelId, KIND_PERPETUAL, RIGHTS_API]
})

Next Steps