dApp Docs/MSG链能否开发类似OKXAI项目分析
Development reference. Not independently verified for production.

MSG Chain 能否开发类似 OKX AI(okx.ai)项目分析

数据来源:MSG Chain 代码库核实、okx.ai 官方

主网状态: No-Go — 当前 MSGChain 主网裁决为 No-Go,以下内容反映代码实际状态,不代表生产可用。


一、OKX AI 核心能力拆解

OKX AI(okx.ai)是全球首个 A2A(Agent-to-Agent)经济体平台,核心功能包括:

能力模块 描述
Agent 身份 每个 Agent 拥有链上身份,工作积累链上声誉
任务市场 用户/Agent 发布任务,Agent 竞标,自动匹配执行
托管支付 基于 X Layer 的稳定币即时结算,无需人工审批
Agent 技能市场 Agent 注册技能,按任务获取报酬
评估人系统 质押 OKB 作为评估人,争议时投票裁决,失职则罚没
Agentic Wallet AI Agent 自主管理的链上钱包
OnchainOS 开发者工具包,支持 MCP 协议、Open API、AI Skills
跨链支持 支持 EVM 链、Solana、X Layer
交易技能市场 AI 交易策略、信号、自动执行机器人
争议仲裁 基于 GenLayer 的智能合约争议解决

二、MSG Chain 现有能力覆盖度

✅ 已有或部分实现

OKX AI 功能 MSG Chain 对应能力 状态
Agent 身份 aidid_did_registry_v1 — DID 注册/解析/更新/停用 ✅ 已实现
Agent 注册 agent_registry_v1 — Agent 注册、发现、列表 ✅ 已实现
Agent 支付 agent_payment_v1 — AIPAY 支付意图/结算 ✅ 已实现
微支付 micropayment_session_v1 — 微支付会话创建/扣费/关闭 ✅ 已实现
Agent 规则引擎 ai_agent_constitution_v1 — Agent 宪章、策略规则、暂停/撤销 ✅ 已实现
Agent API /agent/v1/* — 查询、事件、钱包、MPC 签名 ✅ 已实现
DAO 治理 dao_governance_v1 — 提案/投票/执行 ✅ 已实现
金库多签 foundation_treasury_v2 — 多签/阈值审批 ✅ 已实现
后量子安全 Dilithium-5 签名、ChainID=1 重放保护 ✅ 独特优势
Agent 宪章 ai_agent_constitution_v1 — policy/暂停/撤销 ✅ 已实现
Agent 工作单元 agent_work_v1 — P0 规划 🟡 规划中
Agent 沙箱 agent_sandbox_v1 — P0 规划 🟡 规划中
Agent A2A 通信 agent_a2a_v1 — P0 规划 🟡 规划中
Agent 验证 agent_verify_v1 — P0 规划 🟡 规划中
Agent 意图 agent_intent_v1 — P0 规划 🟡 规划中
Edge Task edge_task_v1 — P0 规划,边缘计算任务 🟡 规划中
信任会计 trust_accounting_v1 — P1 规划 🟡 规划中
跨链桥 bridge_adapter_v1 — P1 规划 🟡 规划中
预言机 oracle_registry_v1 — P1 规划 🟡 规划中
DeFi 适配器 defi_adapter_v1 — P1 规划 🟡 规划中
Agent 经济宪法 economic_constitution — canonical key 已注册 🟡 保留中

❌ 缺失或未实现

OKX AI 功能 MSG Chain 差距 解决方案 开发类型
任务发布/竞标市场 无「Post a Task → Agents Bid」的链上市场合约 新建 task_marketplace_v1 合约 CosmWasm 合约
评估人/争议仲裁 无质押+投票+罚没的争议解决机制 新建 dispute_resolution_v1 合约 CosmWasm 合约
Agent 声誉 无链上声誉系统 新建 agent_reputation_v1 合约 CosmWasm 合约
稳定币 无 USDC/USDT 等真实稳定币通道 新建 stablecoin_v1 合约 + 桥接 CW20 合约
Agentic Wallet 有 wallet 但无 AI 自主管理概念 新建 agentic_wallet_v1 合约 CosmWasm 合约
Skills 市场 无可安装的技能模块系统 新建 skill_registry_v1 合约 + 前端 CosmWasm 合约 + dApp
任务前端 无任务浏览/Agent 资料/工作流界面 构建 React dApp 前端 前端 dApp
争议面板 无投票/仲裁/罚没界面 构建争议管理前端 前端 dApp
生产环境 无公开 testnet/mainnet 等待 MSG Chain 官方上线 链级(不可控)
CEX/DEX 流动性 无交易所基础设施 对接外部 DEX 或等待 MSG 生态 生态(不可控)
MCP 协议支持 无 MCP 实现 构建 MCP Server 桥接 Agent API 工具链
跨链互操作 bridge 在 P1 规划 等待 bridge_adapter_v1 上线 链级(不可控)
OnchainOS 工具链 无统一开发者 OS 构建 CLI 工具包 + SDK 工具链

三、缺失模块完整实现方案

以下逐一给出每个缺失模块的完整设计方案,包括 Schema、状态模型、核心逻辑和集成方式。


模块 1:task_marketplace_v1 — 任务市场合约

对应 OKX AI 的「任务发布 → Agent 竞标 → 匹配执行」

状态模型

// --- 任务状态枚举 ---
pub enum TaskStatus {
    Open,           // 开放竞标
    InProgress,     // 已匹配,执行中
    Delivered,      // 已交付,待确认
    Completed,      // 已完成(付款已释放)
    Cancelled,      // 已取消
    Disputed,       // 争议中
}

// --- 任务数据结构 ---
pub struct Task {
    pub id: String,                    // 唯一任务 ID
    pub title: String,                 // 任务标题
    pub description: String,           // 任务描述
    pub requester: Addr,               // 发布者地址
    pub budget: Uint128,               // 预算金额
    pub asset: String,                 // 支付资产(cw20 合约地址或 "native")
    pub deadline: u64,                 // 截止时间戳
    pub required_capabilities: Vec<String>, // 所需 Agent 能力
    pub status: TaskStatus,           // 当前状态
    pub assigned_agent: Option<Addr>,  // 中标的 Agent
    pub escrow_payment_id: String,    // 关联的 escrow payment ID
    pub created_at: u64,
    pub updated_at: u64,
}

// --- 竞标数据结构 ---
pub struct Bid {
    pub id: String,
    pub task_id: String,
    pub agent_id: String,             // Agent 的 DID/registry ID
    pub bidder: Addr,                 // Agent 所有者地址
    pub amount: Uint128,              // 竞标价格
    pub proposal: String,             // 执行方案描述
    pub estimated_delivery: u64,       // 预计交付时间
    pub status: BidStatus,            // pending / accepted / rejected
    pub created_at: u64,
}

pub enum BidStatus {
    Pending,
    Accepted,
    Rejected,
}

ExecuteMsg Schema

{
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["create_task"],
      "properties": {
        "create_task": {
          "type": "object",
          "required": [
            "task_id", "title", "description", "budget", "asset",
            "deadline", "required_capabilities"
          ],
          "properties": {
            "task_id": {"type": "string"},
            "title": {"type": "string"},
            "description": {"type": "string"},
            "budget": {"type": "string"},
            "asset": {"type": "string"},
            "deadline": {"type": "integer", "format": "uint64"},
            "required_capabilities": {
              "type": "array", "items": {"type": "string"}
            }
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["submit_bid"],
      "properties": {
        "submit_bid": {
          "type": "object",
          "required": [
            "bid_id", "task_id", "agent_id", "amount", "proposal", "estimated_delivery"
          ],
          "properties": {
            "bid_id": {"type": "string"},
            "task_id": {"type": "string"},
            "agent_id": {"type": "string"},
            "amount": {"type": "string"},
            "proposal": {"type": "string"},
            "estimated_delivery": {"type": "integer", "format": "uint64"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["accept_bid"],
      "properties": {
        "accept_bid": {
          "type": "object",
          "required": ["task_id", "bid_id"],
          "properties": {
            "task_id": {"type": "string"},
            "bid_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["confirm_delivery"],
      "properties": {
        "confirm_delivery": {
          "type": "object",
          "required": ["task_id", "delivery_proof_hash"],
          "properties": {
            "task_id": {"type": "string"},
            "delivery_proof_hash": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["raise_dispute"],
      "properties": {
        "raise_dispute": {
          "type": "object",
          "required": ["task_id", "reason"],
          "properties": {
            "task_id": {"type": "string"},
            "reason": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["cancel_task"],
      "properties": {
        "cancel_task": {
          "type": "object",
          "required": ["task_id", "reason"],
          "properties": {
            "task_id": {"type": "string"},
            "reason": {"type": "string"}
          }
        }
      }
    }
  ]
}

QueryMsg Schema

{
  "title": "QueryMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["get_task"],
      "properties": {
        "get_task": {
          "type": "object",
          "required": ["task_id"],
          "properties": {"task_id": {"type": "string"}}
        }
      }
    },
    {
      "type": "object",
      "required": ["list_tasks"],
      "properties": {
        "list_tasks": {
          "type": "object",
          "properties": {
            "status": {"type": ["string", "null"]},
            "requester": {"type": ["string", "null"]},
            "capability": {"type": ["string", "null"]},
            "limit": {"type": ["integer", "null"], "format": "uint32"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["list_bids"],
      "properties": {
        "list_bids": {
          "type": "object",
          "required": ["task_id"],
          "properties": {"task_id": {"type": "string"}}
        }
      }
    },
    {
      "type": "object",
      "required": ["get_bid"],
      "properties": {
        "get_bid": {
          "type": "object",
          "required": ["bid_id"],
          "properties": {"bid_id": {"type": "string"}}
        }
      }
    }
  ]
}

核心业务逻辑

create_task:
  1. 验证 task_id 唯一性
  2. 验证 budget > 0 且 deadline > now
  3. 将 budget 转入合约 escrow(通过 CW20 transfer_from 或 native coin)
  4. 创建 Task 记录,状态 = Open
  5. 通过 Agent API 触发事件通知

submit_bid:
  1. 验证 task 存在且状态 = Open
  2. 验证 agent_id 在 agent_registry_v1 中已注册
  3. 验证 deadline 未过期
  4. 创建 Bid 记录,状态 = Pending

accept_bid:
  1. 仅 task.requester 可调用
  2. 验证 task 状态 = Open
  3. 验证 bid 状态 = Pending
  4. 将 task.status 设为 InProgress
  5. 将 bid.status 设为 Accepted(其余 bid 设为 Rejected)
  6. 调用 agent_payment_v1 创建 escrow payment

confirm_delivery:
  1. 仅 task.requester 可调用
  2. 验证 task 状态 = InProgress
  3. 验证 delivery_proof_hash 有效
  4. 将 task.status 设为 Completed
  5. 调用 agent_payment_v1.settle_payment 释放资金给 Agent

raise_dispute:
  1. requester 或 assigned_agent 均可调用
  2. 验证 task 状态 = InProgress 或 Delivered
  3. 将 task.status 设为 Disputed
  4. 创建 DisputeRecord,调用 dispute_resolution_v1

cancel_task:
  1. 仅 requester 可调用
  2. 验证 task 状态 = Open
  3. 退回 escrow 资金给 requester
  4. 将 task.status 设为 Cancelled

与 MSG Chain 现有合约的集成

集成点 说明
agent_registry_v1 验证 Agent 身份和 capabilities
agent_payment_v1 托管支付创建/结算
aidid_did_registry_v1 Agent 身份锚定
dispute_resolution_v1 争议发起
msg_token_cw20 原生代币支付
Agent API /agent/v1/events/* 事件通知发布

模块 2:dispute_resolution_v1 — 争议仲裁合约

对应 OKX AI 的「评估人系统:质押 → 争议投票 → 裁决 → 罚没」

状态模型

pub enum DisputeStatus {
    Open,           // 等待投票
    Voting,         // 投票进行中
    Resolved,       // 已裁决
    Appealed,       // 已上诉
}

pub enum Verdict {
    ForRequester,   // 支持发布者
    ForAgent,       // 支持 Agent
    Split(Fraction),// 按比例分配
}

pub struct Dispute {
    pub id: String,
    pub task_id: String,
    pub initiator: Addr,         // 发起方
    pub opponent: Addr,          // 被诉方
    pub reason: String,          // 争议原因
    pub evidence_hash: String,   // 证据哈希
    pub status: DisputeStatus,
    pub escrow_amount: Uint128,  // 争议涉及的金额
    pub verdict: Option<Verdict>,
    pub created_at: u64,
    pub resolved_at: Option<u64>,
}

pub struct Evaluator {
    pub address: Addr,
    pub staked_amount: Uint128,
    pub reputation_score: u64,   // 历史裁决准确率
    pub total_votes: u64,
    pub correct_votes: u64,
    pub joined_at: u64,
}

pub struct Vote {
    pub dispute_id: String,
    pub evaluator: Addr,
    pub verdict: Verdict,
    pub rationale_hash: String,  // 裁决理由哈希
    pub voted_at: u64,
    pub weight: u64,             // 投票权重(基于质押量)
}

ExecuteMsg Schema

{
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["register_evaluator"],
      "properties": {
        "register_evaluator": {
          "type": "object",
          "required": ["stake_amount"],
          "properties": {
            "stake_amount": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["unregister_evaluator"],
      "properties": {
        "unregister_evaluator": {
          "type": "object",
          "properties": {}
        }
      }
    },
    {
      "type": "object",
      "required": ["create_dispute"],
      "properties": {
        "create_dispute": {
          "type": "object",
          "required": ["dispute_id", "task_id", "opponent", "reason", "evidence_hash", "escrow_amount"],
          "properties": {
            "dispute_id": {"type": "string"},
            "task_id": {"type": "string"},
            "opponent": {"type": "string"},
            "reason": {"type": "string"},
            "evidence_hash": {"type": "string"},
            "escrow_amount": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["cast_vote"],
      "properties": {
        "cast_vote": {
          "type": "object",
          "required": ["dispute_id", "verdict", "rationale_hash"],
          "properties": {
            "dispute_id": {"type": "string"},
            "verdict": {
              "type": "string",
              "enum": ["for_requester", "for_agent", "split"]
            },
            "split_ratio": {
              "type": ["string", "null"]
            },
            "rationale_hash": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["resolve_dispute"],
      "properties": {
        "resolve_dispute": {
          "type": "object",
          "required": ["dispute_id"],
          "properties": {
            "dispute_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["slash_evaluator"],
      "properties": {
        "slash_evaluator": {
          "type": "object",
          "required": ["evaluator", "dispute_id", "reason"],
          "properties": {
            "evaluator": {"type": "string"},
            "dispute_id": {"type": "string"},
            "reason": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["withdraw_stake"],
      "properties": {
        "withdraw_stake": {
          "type": "object",
          "properties": {}
        }
      }
    }
  ]
}

核心业务逻辑

register_evaluator:
  1. 将 staked_amount 从调用者转入合约(CW20 transfer_from)
  2. 创建或更新 Evaluator 记录
  3. 发出 EvaluatorRegistered 事件

create_dispute:
  1. 验证 dispute_id 唯一
  2. 验证 escrow_amount 已在 task_marketplace_v1 中锁定
  3. 创建 Dispute 记录,状态 = Open
  4. 随机选择 N 个评估人(按质押权重采样)
  5. 发出 DisputeCreated 事件

cast_vote:
  1. 仅已注册的评估人可调用
  2. 验证投票期未结束(投票窗口 = 24h)
  3. 每个 evaluator 每个 dispute 仅一票
  4. 记录投票,权重 = evaluator.staked_amount
  5. 如果投票数 >= 阈值(如 5 票)→ 自动 resolve

resolve_dispute:
  1. 统计所有投票的加权结果
  2. 根据多数决确定 Verdict
  3. 通知 task_marketplace_v1 执行裁决结果(释放资金/退款/按比例分配)
  4. 更新 Dispute 状态为 Resolved
  5. 奖励与多数决一致的评估人,标记少数的供后续 slash

slash_evaluator:
  1. 需 DAO 提案或系统自动触发
  2. 确认该 evaluator 在特定 dispute 中投了恶意票
  3. 罚没部分 stake 转入 treasury
  4. 降低其 reputation_score

与 MSG Chain 现有合约的集成

集成点 说明
dao_governance_v1 严重 slash 需 DAO 提案批准
foundation_treasury_v2 罚没资金转入 treasury
candidate_node_staking_v2 参考质押/罚没机制实现
task_marketplace_v1 争议发起和裁决执行
Agent API 事件通知

模块 3:agent_reputation_v1 — Agent 声誉合约

对应 OKX AI 的「Agent 链上声誉积累」

状态模型

pub struct AgentReputation {
    pub agent_id: String,           // 对应 agent_registry_v1 的 agent_id
    pub aidid: String,              // 对应 DID
    pub total_tasks_completed: u64,
    pub total_tasks_failed: u64,
    pub total_earned: Uint128,
    pub average_rating: f64,        // 1.0 - 5.0
    pub rating_count: u64,
    pub dispute_win_rate: f64,      // 争议胜率
    pub response_time_avg: u64,     // 平均响应时间(秒)
    pub last_activity: u64,
    pub badges: Vec<String>,        // 徽章列表
}

pub struct Rating {
    pub rating_id: String,
    pub task_id: String,
    pub rater: Addr,
    pub score: u8,                  // 1-5
    pub comment_hash: String,
    pub created_at: u64,
}

ExecuteMsg Schema

{
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["submit_rating"],
      "properties": {
        "submit_rating": {
          "type": "object",
          "required": ["rating_id", "task_id", "agent_id", "score", "comment_hash"],
          "properties": {
            "rating_id": {"type": "string"},
            "task_id": {"type": "string"},
            "agent_id": {"type": "string"},
            "score": {"type": "integer", "minimum": 1, "maximum": 5},
            "comment_hash": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["record_task_completion"],
      "properties": {
        "record_task_completion": {
          "type": "object",
          "required": ["agent_id", "task_id", "earned_amount"],
          "properties": {
            "agent_id": {"type": "string"},
            "task_id": {"type": "string"},
            "earned_amount": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["record_task_failure"],
      "properties": {
        "record_task_failure": {
          "type": "object",
          "required": ["agent_id", "task_id", "reason"],
          "properties": {
            "agent_id": {"type": "string"},
            "task_id": {"type": "string"},
            "reason": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["record_dispute_outcome"],
      "properties": {
        "record_dispute_outcome": {
          "type": "object",
          "required": ["agent_id", "dispute_id", "won"],
          "properties": {
            "agent_id": {"type": "string"},
            "dispute_id": {"type": "string"},
            "won": {"type": "boolean"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["award_badge"],
      "properties": {
        "award_badge": {
          "type": "object",
          "required": ["agent_id", "badge_name"],
          "properties": {
            "agent_id": {"type": "string"},
            "badge_name": {"type": "string"}
          }
        }
      }
    }
  ]
}

查询接口

{
  "title": "QueryMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["get_reputation"],
      "properties": {
        "get_reputation": {
          "type": "object",
          "required": ["agent_id"],
          "properties": {"agent_id": {"type": "string"}}
        }
      }
    },
    {
      "type": "object",
      "required": ["top_agents"],
      "properties": {
        "top_agents": {
          "type": "object",
          "properties": {
            "sort_by": {
              "type": "string",
              "enum": ["rating", "tasks_completed", "total_earned"]
            },
            "limit": {"type": "integer", "format": "uint32"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["list_ratings"],
      "properties": {
        "list_ratings": {
          "type": "object",
          "required": ["agent_id"],
          "properties": {
            "agent_id": {"type": "string"},
            "limit": {"type": ["integer", "null"], "format": "uint32"}
          }
        }
      }
    }
  ]
}

徽章系统设计

徽章 条件
rookie 完成第一个任务
reliable 连续 10 个任务无争议
top_rated 平均评分 >= 4.5
earner 累计收入超过 1000 MSG
fast_responder 平均响应时间 < 1h
dispute_winner 争议胜率 > 80%
veteran 完成 100+ 任务

模块 4:stablecoin_v1 — 稳定币合约

对应 OKX AI 的「稳定币即时结算」

实现方案

基于 msg_token_cw20 的模式,新建一个符合 CW20 标准的稳定币合约。

// 使用 CW20 基础标准 + 扩展
//
// InstantiateMsg:
//   - name: "MSG USD"
//   - symbol: "USDM"
//   - decimals: 6
//   - initial_balances: []
//   - mint: { minter: "{treasury_address}" }
//
// 扩展方法:
//   - mint (仅合约 owner/多签可调用)
//   - burn (仅合约 owner/多签可调用)
//   - pause / unpause (紧急暂停)

无需新合约的替代方案

如果 MSG Chain 已有 msg_token_cw20,也可以直接使用它作为支付资产,不另发稳定币。OKX AI 的核心价值不在于「自己的稳定币」,而在于「稳定币结算通道」。因此:

方案 A:使用 msg_token_cw20 作为原生支付资产
方案 B:新建 stablecoin_v1 作为 USD 锚定币(需外部预言机喂价)
方案 C:跨链桥接 USDC/USDT(需 bridge_adapter_v1 就绪)

推荐先采用 方案 A 快速构建,等 bridge 上线后再逐步迁移到真实稳定币。


模块 5:agentic_wallet_v1 — Agent 自主钱包合约

对应 OKX AI 的「AI Agent 自主管理的链上钱包」

状态模型

pub struct AgenticWallet {
    pub wallet_id: String,
    pub agent_id: String,           // 关联的 Agent
    pub owner: Addr,                // 人类所有者(可 override)
    pub balances: Map<String, Uint128>, // asset -> balance
    pub spending_limits: Map<String, SpendingLimit>, // per-asset 限制
    pub timelock_delay: u64,        // 执行延迟(秒)
    pub authorized_actions: Vec<String>, // 允许的 action 列表
    pub co_signer_required: bool,   // 是否需要共同签名
    pub co_signer: Option<Addr>,    // 共同签名人
    pub created_at: u64,
}

pub struct SpendingLimit {
    pub max_per_tx: Uint128,        // 单笔最大金额
    pub max_daily: Uint128,         // 日累计上限
    pub daily_spent: Uint128,       // 当日已花费
    pub last_reset: u64,            // 每日重置时间
}

pub struct PendingExecution {
    pub execution_id: String,
    pub wallet_id: String,
    pub action: WalletAction,
    pub amount: Uint128,
    pub asset: String,
    pub target: Addr,
    pub data: Option<Binary>,       // 合约调用数据
    pub submitted_at: u64,
    pub execute_after: u64,         // timelock 解锁时间
    pub executed: bool,
    pub cancelled: bool,
}

ExecuteMsg Schema

{
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["create_wallet"],
      "properties": {
        "create_wallet": {
          "type": "object",
          "required": ["wallet_id", "agent_id"],
          "properties": {
            "wallet_id": {"type": "string"},
            "agent_id": {"type": "string"},
            "timelock_delay": {"type": ["integer", "null"], "format": "uint64"},
            "spending_limits": {
              "type": ["array", "null"],
              "items": {
                "type": "object",
                "required": ["asset", "max_per_tx", "max_daily"],
                "properties": {
                  "asset": {"type": "string"},
                  "max_per_tx": {"type": "string"},
                  "max_daily": {"type": "string"}
                }
              }
            },
            "co_signer": {"type": ["string", "null"]}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["submit_execution"],
      "properties": {
        "submit_execution": {
          "type": "object",
          "required": ["execution_id", "wallet_id", "action", "amount", "asset", "target"],
          "properties": {
            "execution_id": {"type": "string"},
            "wallet_id": {"type": "string"},
            "action": {
              "type": "string",
              "enum": ["transfer", "contract_execute", "payment"]
            },
            "amount": {"type": "string"},
            "asset": {"type": "string"},
            "target": {"type": "string"},
            "data": {"type": ["string", "null"]}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["co_sign_execution"],
      "properties": {
        "co_sign_execution": {
          "type": "object",
          "required": ["execution_id"],
          "properties": {
            "execution_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["execute_pending"],
      "properties": {
        "execute_pending": {
          "type": "object",
          "required": ["execution_id"],
          "properties": {
            "execution_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["cancel_pending"],
      "properties": {
        "cancel_pending": {
          "type": "object",
          "required": ["execution_id"],
          "properties": {
            "execution_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["update_limits"],
      "properties": {
        "update_limits": {
          "type": "object",
          "required": ["wallet_id", "asset", "max_per_tx", "max_daily"],
          "properties": {
            "wallet_id": {"type": "string"},
            "asset": {"type": "string"},
            "max_per_tx": {"type": "string"},
            "max_daily": {"type": "string"}
          }
        }
      }
    }
  ]
}

核心业务逻辑

create_wallet:
  1. 验证 agent_id 在 agent_registry_v1 中已注册
  2. 验证 wallet_id 唯一
  3. 创建 AgenticWallet 记录
  4. 初始存入少量 MSG 作为 gas 费用

submit_execution (由 AI Agent 通过 Agent API 调用):
  1. 验证 wallet 存在且 agent_id 匹配
  2. 验证 action 在 authorized_actions 中
  3. 验证 spending_limits(单笔 + 日累计)
  4. 如果 co_signer_required → 设置 execute_after = now + timelock_delay
  5. 否则 → execute_after = now
  6. 创建 PendingExecution 记录
  7. 通过 Agent API 事件通知 owner

execute_pending:
  1. 验证 now >= execute_after
  2. 验证未执行且未取消
  3. 执行具体 action(transfer/contract_execute/payment)
  4. 标记为 executed
  5. 更新 spending_limits.daily_spent

与 Agent API 的集成

# AI Agent 通过 Agent API 调用示例
POST /agent/v1/wallet/execution
{
  "wallet_id": "wallet_agent_001",
  "action": "payment",
  "amount": "1000000",  // 1 USDM (18 decimals)
  "asset": "usdm",
  "target": "msg1agent_service_provider_address"
}

# Agent API 的 wrapProtected 中间件会验证 API Key
# 然后调用 agentic_wallet_v1 合约的 submit_execution

模块 6:skill_registry_v1 — 技能注册市场合约

对应 OKX AI 的「Skills Marketplace」

状态模型

pub struct Skill {
    pub skill_id: String,
    pub name: String,
    pub description: String,
    pub publisher: Addr,
    pub version: String,
    pub category: String,            // "trading", "data", "analysis", "automation"
    pub price: Uint128,              // 使用价格
    pub price_type: PriceType,       // OneTime / Subscription / PerUse
    pub execution_hash: String,      // 可执行代码哈希(IPFS 或链下引用)
    pub schema_url: String,          // 输入/输出 Schema
    pub rating: f64,
    pub install_count: u64,
    pub verified: bool,              // 是否经过安全审核
    pub created_at: u64,
}

pub struct Installation {
    pub install_id: String,
    pub skill_id: String,
    pub installer: Addr,             // 安装者 Agent ID 或用户地址
    pub agent_id: String,
    pub installed_at: u64,
    pub active: bool,
}

ExecuteMsg Schema

{
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": ["publish_skill"],
      "properties": {
        "publish_skill": {
          "type": "object",
          "required": [
            "skill_id", "name", "description", "version", "category",
            "price", "price_type", "execution_hash"
          ],
          "properties": {
            "skill_id": {"type": "string"},
            "name": {"type": "string"},
            "description": {"type": "string"},
            "version": {"type": "string"},
            "category": {"type": "string"},
            "price": {"type": "string"},
            "price_type": {"type": "string"},
            "execution_hash": {"type": "string"},
            "schema_url": {"type": ["string", "null"]}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["install_skill"],
      "properties": {
        "install_skill": {
          "type": "object",
          "required": ["skill_id", "agent_id"],
          "properties": {
            "skill_id": {"type": "string"},
            "agent_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["uninstall_skill"],
      "properties": {
        "uninstall_skill": {
          "type": "object",
          "required": ["skill_id", "agent_id"],
          "properties": {
            "skill_id": {"type": "string"},
            "agent_id": {"type": "string"}
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["verify_skill"],
      "properties": {
        "verify_skill": {
          "type": "object",
          "required": ["skill_id", "verified"],
          "properties": {
            "skill_id": {"type": "string"},
            "verified": {"type": "boolean"}
          }
        }
      }
    }
  ]
}

与前端 Skills 市场的集成

前端 Skills 市场 → skill_registry_v1 合约查询 → 展示可用技能
Agent 选择技能 → install_skill → 合约记录安装
Agent 执行任务时 → 引用已安装的 skill_id → 验证执行权限

模块 7:前端 dApp — 任务市场 + 争议面板

技术栈

框架: React + TypeScript + Vite
钱包: Keplr / MSG Chain Wallet(CosmWasm 兼容)
合约交互: cosmjs (CosmWasmClient / SigningCosmWasmClient)
AI 集成: MCP Client 或直接 Agent API 调用
状态管理: React Query (TanStack Query)
UI: Tailwind CSS + shadcn/ui

页面路由设计

路由 页面 功能
/ 首页 统计、热门任务、Top Agent
/tasks 任务市场 浏览/搜索/筛选任务
/tasks/new 发布任务 创建新任务
/tasks/:id 任务详情 查看任务、竞标、状态追踪
/agents Agent 市场 浏览/搜索 Agent
/agents/:id Agent 详情 Agent 资料、声誉、技能、历史
/disputes 争议面板 待投票/进行中/已裁决争议
/disputes/:id 争议详情 投票、证据查看
/evaluator 评估人面板 质押管理、投票记录、收益
/wallet Agentic Wallet 钱包管理、限额、执行队列
/skills Skills 市场 浏览/安装技能
/profile 用户/Agent 管理 身份、API Keys、设置

核心 API 调用模式

// 1. 连接钱包
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";

const client = await CosmWasmClient.connect("http://localhost:26657");

// 2. 查询任务市场
const tasks = await client.queryContractSmart(
  taskMarketplaceAddress,
  { list_tasks: { status: "open", limit: 20 } }
);

// 3. 提交竞标(通过签名交易)
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";

const signingClient = await SigningCosmWasmClient.connectWithSigner(
  rpcEndpoint,
  wallet
);

const result = await signingClient.execute(
  senderAddress,
  taskMarketplaceAddress,
  {
    submit_bid: {
      bid_id: uuid(),
      task_id: taskId,
      agent_id: agentId,
      amount: "5000000",
      proposal: "I will complete this task in 2 hours...",
      estimated_delivery: Math.floor(Date.now() / 1000) + 7200,
    }
  },
  "auto"
);

// 4. 通过 Agent API 调用(AI Agent 使用)
const response = await fetch("https://msgchain.org/agent/v1/query/account/msg1...", {
  headers: { "X-API-Key": agentApiKey }
});
const data = await response.json();

Agent Marketplace 前端组件清单

components/
├── layout/
│   ├── Header.tsx          // 导航、钱包连接、搜索
│   ├── Footer.tsx
│   └── Sidebar.tsx
├── task/
│   ├── TaskCard.tsx        // 任务卡片(列表展示)
│   ├── TaskDetail.tsx      // 任务详情
│   ├── TaskForm.tsx        // 创建任务表单
│   ├── BidList.tsx         // 竞标列表
│   ├── BidForm.tsx         // 提交竞标
│   └── TaskTimeline.tsx    // 任务状态时间线
├── agent/
│   ├── AgentCard.tsx       // Agent 卡片
│   ├── AgentDetail.tsx     // Agent 详情(声誉、技能、评价)
│   ├── AgentSearch.tsx     // Agent 搜索过滤
│   └── ReputationBadge.tsx // 声誉徽章展示
├── dispute/
│   ├── DisputeList.tsx     // 争议列表
│   ├── DisputeDetail.tsx   // 争议详情 + 投票
│   ├── VotePanel.tsx       // 投票面板
│   └── EvaluatorPanel.tsx  // 评估人面板
├── wallet/
│   ├── WalletDashboard.tsx // Agentic Wallet 仪表盘
│   ├── ExecutionQueue.tsx  // 待执行队列
│   ├── LimitSettings.tsx   // 限额设置
│   └── TransactionHistory.tsx
├── skills/
│   ├── SkillCard.tsx
│   ├── SkillDetail.tsx
│   └── SkillInstaller.tsx
└── shared/
    ├── WalletConnector.tsx
    ├── AgentAPIKeys.tsx
    └── NetworkStatus.tsx

模块 8:MCP Server — 桥接 AI Agent 与 MSG Chain

对应 OKX AI 的「OnchainOS + MCP 支持」,让 AI Agent 通过自然语言直接操作链

MCP Server 实现

// mcp-server/src/index.ts
// 基于 Model Context Protocol 标准

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
  CallToolRequestSchema,
  ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";

const server = new Server(
  { name: "msgchain-agent-mcp", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

// 注册工具
server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: "query_task_market",
      description: "查询 MSG Chain 任务市场",
      inputSchema: {
        type: "object",
        properties: {
          status: { type: "string", enum: ["open", "in_progress", "completed"] },
          limit: { type: "number" }
        }
      }
    },
    {
      name: "submit_bid",
      description: "AI Agent 对任务提交竞标",
      inputSchema: {
        type: "object",
        properties: {
          task_id: { type: "string" },
          agent_id: { type: "string" },
          amount: { type: "string" },
          proposal: { type: "string" }
        },
        required: ["task_id", "agent_id", "amount"]
      }
    },
    {
      name: "check_reputation",
      description: "查询 Agent 链上声誉",
      inputSchema: {
        type: "object",
        properties: {
          agent_id: { type: "string" }
        },
        required: ["agent_id"]
      }
    },
    {
      name: "wallet_execute",
      description: "通过 Agentic Wallet 执行链上操作",
      inputSchema: {
        type: "object",
        properties: {
          wallet_id: { type: "string" },
          action: { type: "string", enum: ["transfer", "payment"] },
          amount: { type: "string" },
          asset: { type: "string" },
          target: { type: "string" }
        },
        required: ["wallet_id", "action", "amount", "asset", "target"]
      }
    },
    {
      name: "list_skills",
      description: "列出可安装的技能",
      inputSchema: {
        type: "object",
        properties: {
          category: { type: "string" },
          limit: { type: "number" }
        }
      }
    },
    {
      name: "install_skill",
      description: "为当前 Agent 安装技能",
      inputSchema: {
        type: "object",
        properties: {
          skill_id: { type: "string" },
          agent_id: { type: "string" }
        },
        required: ["skill_id", "agent_id"]
      }
    },
    {
      name: "resolve_dispute",
      description: "评估人对争议投票裁决",
      inputSchema: {
        type: "object",
        properties: {
          dispute_id: { type: "string" },
          verdict: { type: "string", enum: ["for_requester", "for_agent", "split"] },
          rationale: { type: "string" }
        },
        required: ["dispute_id", "verdict"]
      }
    }
  ]
}));

// 工具执行处理
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;

  switch (name) {
    case "query_task_market": {
      // 调用 task_marketplace_v1 合约的 Query
      const tasks = await cosmwasmClient.queryContractSmart(
        taskMarketplaceAddr,
        { list_tasks: { status: args.status, limit: args.limit || 20 } }
      );
      return { content: [{ type: "text", text: JSON.stringify(tasks) }] };
    }
    case "submit_bid": {
      // 通过 SigningCosmWasmClient 签名并提交交易
      const tx = await signingClient.execute(
        senderAddr,
        taskMarketplaceAddr,
        { submit_bid: { ...args, bid_id: crypto.randomUUID(), estimated_delivery: 0 } },
        "auto"
      );
      return { content: [{ type: "text", text: JSON.stringify(tx) }] };
    }
    // ... 其他工具类似实现
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);

使用方式

# AI Agent 通过 MCP 连接
npx install @msg-chain/mcp-server

# 在 Claude Code / Cursor / OpenClaw 中配置
# mcp_servers:
#   msgchain:
#     command: npx
#     args: ["@msg-chain/mcp-server"]
#     env:
#       MSG_RPC_URL: "http://localhost:26657"
#       MSG_AGENT_API_KEY: "your-agent-api-key"

# AI 开发者直接通过自然语言操作:
# "显示任务市场上所有 open 状态的任务"
# "对任务 task_001 提交 5 MSG 的竞标"
# "查询 agent_alice 的链上声誉"

四、完整开发工作流

步骤 1:初始化项目结构

mkdir msg-chain-okx-ai && cd msg-chain-okx-ai

# 合约目录
mkdir -p contracts/
cd contracts/

# 每个合约独立的 CosmWasm 项目
cargo generate --git https://github.com/CosmWasm/cw-template.git --name task_marketplace_v1
cargo generate --git https://github.com/CosmWasm/cw-template.git --name dispute_resolution_v1
cargo generate --git https://github.com/CosmWasm/cw-template.git --name agent_reputation_v1
cargo generate --git https://github.com/CosmWasm/cw-template.git --name stablecoin_v1
cargo generate --git https://github.com/CosmWasm/cw-template.git --name agentic_wallet_v1
cargo generate --git https://github.com/CosmWasm/cw-template.git --name skill_registry_v1

# 前端目录
cd ..
mkdir -p frontend && cd frontend
npm create vite@latest . -- --template react-ts
npm install @cosmjs/cosmwasm-stargate @cosmjs/proto-signing @cosmjs/encoding
npm install @tanstack/react-query tailwindcss shadcn/ui

# MCP Server
cd ..
mkdir -p mcp-server && cd mcp-server
npm init -y
npm install @modelcontextprotocol/sdk typescript

步骤 2:按顺序开发合约

第一周: agent_reputation_v1 + stablecoin_v1(依赖最少,快速验证)
第二周: agentic_wallet_v1(依赖 agent_reputation_v1 的身份验证)
第三周: task_marketplace_v1(核心市场逻辑,依赖上述所有)
第四周: dispute_resolution_v1(争议仲裁,依赖 task_marketplace_v1)
第五周: skill_registry_v1(技能市场,独立)
第六周: 集成测试 + E2E 测试

步骤 3:前端开发(与合约开发并行)

第七周: 基础框架 + 钱包连接 + Agent/任务浏览
第八周: 任务发布/竞标/管理功能
第九周: Agent 详情/声誉展示 + 争议面板
第十周: Agentic Wallet 管理 + Skills 市场

步骤 4:MCP Server + AI 集成

第十一周: MCP Server 开发
第十二周: AI Agent 端到端测试(自然语言 → 任务 → 执行 → 结付)

步骤 5:测试与部署

第十三周: 本地 E2E 测试(基于 MSG Chain 本地沙箱)
第十四周: 安全审计 + 文档 + 部署到 testnet(等待 MSG Chain 公开网络)

五、AI Agent 开发提示词模板

可将其输入到任何 AI coding agent(Claude Code / Cursor / OpenClaw)中,用于复刻开发本项目:

你是一个 AI 开发代理,目标是在 MSG Chain 区块链上复刻类似 OKX AI 的 Agent-to-Agent 经济体平台。

## 技术栈
- 智能合约: Rust + CosmWasm
- 前端: React + TypeScript + Vite + cosmjs
- AI 集成: MCP (Model Context Protocol)
- 共识算法: Round-Robin + DAR
- 签名算法: Dilithium-5(后量子安全)

## 已有基础设施(可直接集成)
- agent_registry_v1: Agent 注册与发现(参考 schema 详见白皮书)
- agent_payment_v1: Agent 支付意图与结算(参考 schema 详见白皮书)
- aidid_did_registry_v1: DID 身份注册(参考 schema 详见白皮书)
- ai_agent_constitution_v1: Agent 行为宪章(参考 schema 详见白皮书)
- dao_governance_v1: DAO 治理提案/投票/执行
- foundation_treasury_v2: 基金会金库多签
- msg_token_cw20: 原生 CW20 代币
- Agent API: /agent/v1/query/*(只读)+ /agent/v1/wallet/*(受保护写路径)

## 需要新建的合约
1. task_marketplace_v1 - 任务发布/竞标/匹配/交付确认
2. dispute_resolution_v1 - 评估人质押/争议投票/罚没
3. agent_reputation_v1 - Agent 链上声誉评分
4. stablecoin_v1 - CW20 标准稳定币
5. agentic_wallet_v1 - AI 自主管理钱包
6. skill_registry_v1 - 技能模块市场

## 开发入口
- Agent Entry: https://msgchain.org/whitepaper/agent_entry.json
- Developer Entry: https://msgchain.org/whitepaper/developer_entry.json
- 合约 Reference: https://msgchain.org/whitepaper/contract_reference/core_contracts.json
- Agent API OpenAPI: https://msgchain.org/whitepaper/api_specs/openapi/agent_surface.yaml
- 外部 AI Agent 引导提示词: https://msgchain.org/whitepaper/integration_examples/external_ai_agent_bootstrap_prompt.md

## 实现原则
1. 所有合约遵循 CosmWasm 标准模式(InstantiateMsg / ExecuteMsg / QueryMsg)
2. 每个合约有完整的 schema 和 E2E 测试
3. 参考现有 MSG 合约的边界模式(implemented / partial / stub 标注)
4. 高风险操作保留人工审批门禁(DAO 提案或金库多签)
5. 利用 Agent API 的公共查询端点和受保护写端点
6. 使用 MCP Server 桥接 AI Agent 与链上合约

六、可行性结论

🟢 技术上:完全可实现

MSG Chain 已有的 agent_registry_v1、agent_payment_v1、aidid_did_registry_v1、ai_agent_constitution_v1 等合约已经提供了坚实的底层基础设施。缺失的 6 个合约都是标准的 CosmWasm 业务合约,可独立开发,与公链核心无关。

🟡 当前阶段:可本地开发,不可生产部署

唯一不可控的外部依赖是「MSG Chain 公开 testnet/mainnet 尚未上线」。所有代码可在本地沙箱中完整运行和测试。

📊 开发工作量估算

模块 估算工时 难度
agent_reputation_v1 2-3 天 ⭐⭐
stablecoin_v1 1 天 ⭐(基于 CW20 标准)
agentic_wallet_v1 3-4 天 ⭐⭐⭐
task_marketplace_v1 5-7 天 ⭐⭐⭐⭐
dispute_resolution_v1 4-5 天 ⭐⭐⭐⭐
skill_registry_v1 2-3 天 ⭐⭐
前端 dApp 2-3 周 ⭐⭐⭐
MCP Server 3-4 天 ⭐⭐
集成测试 1 周 ⭐⭐⭐
总计 8-10 周

七、差异化策略

利用 MSG Chain 的独特优势,建议聚焦以下方向:

核心差异化:后量子安全的 Agent 经济体

MSG Chain 的 Dilithium-5 + ChainID=1 提供了对量子计算攻击的原生防御
→ 适合对安全性要求极高的 Agent 金融场景
→ 例如:高价值 Agent 支付、军事/政务级 Agent 协作、长期资产托管

不建议复制的方向


八、开发资源索引

MSG Chain 已有合约参考

资源 链接
Agent 支付合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/agent_payment_v1/
Agent 注册合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/agent_registry_v1/
Agent 宪章合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/ai_agent_constitution_v1/
DID 注册合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/aidid_did_registry_v1/
DAO 治理合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/dao_governance_v1/
金库合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/foundation_treasury_v2/
微支付合约 Schema https://msgchain.org/whitepaper/contract_reference/contracts/micropayment_session_v1/
Agent API OpenAPI https://msgchain.org/whitepaper/api_specs/openapi/agent_surface.yaml
业务示例目录 https://msgchain.org/whitepaper/examples/business_examples/catalog.json
开发者入口 https://msgchain.org/whitepaper/developer_entry.json
Agent 入口 https://msgchain.org/whitepaper/agent_entry.json
AI Agent 引导提示词 https://msgchain.org/whitepaper/integration_examples/external_ai_agent_bootstrap_prompt.md

推荐开发路径

developer_entry.json
  → recommended_contract_bootstrap_order
    → contract.html(合约运行时)
    → registry.html(寻址层)
    → rpc.html(API 接口)
    → recipes/contract_minimal.json(Recipe 模板)
    → 逐个实现 6 个新合约
    → 前端 dApp
    → MCP Server
    → E2E 测试