dApp Docs/代币经济模型
Development reference. Not independently verified for production.

MSG 代币经济模型完整白皮书

版本: v1.0.0
目标链: msg-chain-1
主网状态: No-Go
代币: MSG (umsg)
精度: 18 位小数
签名: Dilithium-5 (后量子密码学)
共识: Round-Robin + DAR


目录

  1. MSG代币总览
  2. 发行机制 (emission_schedule_v2)
  3. 质押经济学
  4. Gas费市场
  5. 收益分配模型
  6. 代币分配
  7. 流通量分析
  8. AI Agent经济
  9. 治理经济
  10. 经济安全
  11. 代币操作指南
  12. 附录:数学公式与代码

1. MSG代币总览

1.1 基本参数

参数 值
代币名称 MSG Token
符号 MSG
精度 (Decimals) 18
最小单位 umsg (1 MSG = 10^18 umsg)
Chain ID msg-chain-1
Bech32 前缀 msg
Coin Type (BIP44) 118
总供应量 (创世) 1,000,000,000 MSG (10亿)
最终供应量 通胀模型,无硬顶

1.2 单位换算

1 MSG           = 1,000,000,000,000,000,000 umsg (10^18)
0.001 MSG       = 1,000,000,000,000,000 umsg
0.000001 MSG    = 1,000,000,000,000 umsg
0.000000001 MSG = 1,000,000,000 umsg

示例:

1.3 与其他 L1 代币对比

特性 MSG (MSG Chain) ATOM (Cosmos Hub) OSMO (Osmosis) ETH (Ethereum)
精度 18 6 18 18
最小单位 umsg uatom uosmo wei
代币标准 CW20 (原生) 原生 Cosmos 原生 Cosmos ERC-20
通胀模型 动态通胀 动态通胀 (7-20%) 动态减半 固定 (EIP-1559 燃烧)
通胀参数 每年递减 0.5% 目标质押率 67% 目标质押率 50% 年增 ~0.5%
出块时间 5 秒 ~7 秒 ~6 秒 ~12 秒
年出块数 6,307,200 ~4,505,143 ~5,256,000 ~2,628,000
最大验证者 100 180 100 ~1,000,000 (PoS)
Gas 机制 固定费率 固定费率 固定费率 EIP-1559
签名算法 Dilithium-5 Secp256k1 Secp256k1 Secp256k1
后量子安全 ✅ ❌ ❌ ❌

1.4 代币用途矩阵

用途 描述 是否需要 MSG 消耗 or 质押
交易费用 支付所有链上操作 ✅ 必须 消耗 (Gas)
质押 (Staking) 网络安全与验证者选择 ✅ 必须 质押 (锁定)
治理投票 提案投票 (1 MSG = 1 票) ✅ 必须 质押 (投票时锁定)
AI Agent 支付 调用 Agent 服务 ✅ 必须 消耗 (AIPAY)
微支付通道 实时按秒计费 ✅ 必须 锁定 (通道)
Agent 注册费 注册 AI Agent ✅ 必须 消耗
DAO 参与 金库治理与提案 ✅ 推荐 质押 or 持有
DeFi 抵押品 未来借贷抵押 可选 锁定
验证者注册 创建验证者节点 ✅ 必须 质押 (500 MSG 起)

1.5 创世供应量分配概览

总供应量: 1,000,000,000 MSG (100%)
     │
     ├── 生态系统基金: 300,000,000 MSG (30%)
     │   └── 用于生态建设、Grant、合作
     │
     ├── 社区销售/IDO: 200,000,000 MSG (20%)
     │   └── 公开发售
     │
     ├── 团队与核心贡献者: 150,000,000 MSG (15%)
     │   └── 锁仓 2 年,线性释放
     │
     ├── 基金会储备: 150,000,000 MSG (15%)
     │   └── 运营、市场、流动性
     │
     ├── 验证者奖励储备: 100,000,000 MSG (10%)
     │   └── 区块奖励初始储备
     │
     └── 社区空投: 100,000,000 MSG (10%)
         └── 早期采用者、测试网参与者

2. 发行机制 (emission_schedule_v2)

2.1 概述

emission_schedule_v2 是 MSG Chain 的代币发行计划管理合约,通过 canonical key emission_schedule 在 genesis_registry 中注册。它控制区块奖励的发行速率和总供应量增长。

类似 Cosmos Hub 的通货膨胀模型,MSG Chain 使用动态通胀机制,但增加了一层 AI Agent 经济驱动的排放调节。

2.2 合约接口

// emission_schedule_v2 核心查询接口
#[cw_serde]
pub enum QueryMsg {
    /// 获取当前区块排放速率
    GetCurrentEmission {},
    /// 获取完整排放计划
    GetEmissionSchedule {},
    /// 查询已排放总量
    GetTotalEmitted {},
    /// 查询剩余可排放量
    GetRemainingEmission {},
    /// 获取指定高度的排放参数
    GetEmissionAtHeight { height: u64 },
}

// 响应类型
#[cw_serde]
pub struct CurrentEmissionResponse {
    pub blocks_per_year: u64,           // 每年区块数 (~6,307,200)
    pub emission_per_block: Uint128,    // 每区块排放量 (umsg)
    pub inflation_rate: Decimal,        // 当前年通胀率
    pub last_update_height: u64,        // 上次更新时间
}

#[cw_serde]
pub struct EmissionScheduleResponse {
    pub params: EmissionParams,
    pub phases: Vec<EmissionPhase>,
}

#[cw_serde]
pub struct EmissionParams {
    pub genesis_supply: Uint128,        // 创世供应量
    pub max_supply: Option<Uint128>,    // 最大供应量 (None = 无上限)
    pub inflation_rate_change: Decimal, // 年通胀率变化量
    pub min_inflation_rate: Decimal,    // 最低通胀率
    pub max_inflation_rate: Decimal,    // 最高通胀率
    pub target_staking_ratio: Decimal,  // 目标质押率
}

#[cw_serde]
pub struct EmissionPhase {
    pub start_height: u64,
    pub end_height: u64,
    pub inflation_rate: Decimal,
    pub emission_per_block: Uint128,
}

2.3 通胀模型公式

MSG Chain 采用 动态通胀模型,类似 Cosmos Hub 的 x/mint 模块,但参数经过优化:

年通胀率公式:

  if 实际质押率 >= 目标质押率:
      通胀率 = max(最低通胀率, 前一年通胀率 - 通胀率变化量)
  else:
      通胀率 = min(最高通胀率, 前一年通胀率 + 通胀率变化量)

每区块排放量:

  排放量_每区块 = (当前总供应量 × 年通胀率) / 年区块数

MSG Chain 具体参数:

参数 值
初始年通胀率 10.00%
最低年通胀率 3.00%
最高年通胀率 20.00%
通胀率年变化量 0.50%
目标质押率 66.67% (2/3)
年区块数 6,307,200

2.4 每区块排放计算

计算示例 (第1年, 总供应量 1,000,000,000 MSG):

年通胀率 = 10.00%
总供应量 = 1,000,000,000 MSG = 1,000,000,000 × 10^18 umsg = 10^27 umsg

每区块排放 = (10^27 × 10%) / 6,307,200
           = 10^26 / 6,307,200
           = 15,854,994,935,561,943 umsg/block
           ≈ 15.85 MSG/block

每年总排放 = 15.85 MSG × 6,307,200 blocks
           = 100,000,000 MSG (10% of genesis supply)

2.5 逐年排放时间表

假设目标质押率始终达到 (通胀率逐年递减 0.5%):

年份 区块高度范围 年通胀率 每区块排放 (MSG) 年排放量 (MSG) 累计供应量
0 (创世) 0 - - - 1,000,000,000
1 1 - 6,307,200 10.00% 15.8550 100,000,000 1,100,000,000
2 6,307,201 - 12,614,400 9.50% 16.5732 104,500,001 1,204,500,001
3 12,614,401 - 18,921,600 9.00% 17.1937 108,405,000 1,312,905,001
4 18,921,601 - 25,228,800 8.50% 17.6977 111,596,925 1,424,501,926
5 25,228,801 - 31,536,000 8.00% 18.0749 113,960,154 1,538,462,080
6 31,536,001 - 37,843,200 7.50% 18.3040 115,436,406 1,653,898,486
7 37,843,201 - 44,150,400 7.00% 18.3609 115,782,894 1,769,681,380
8 44,150,401 - 50,457,600 6.50% 18.2412 115,028,290 1,884,709,670
9 50,457,601 - 56,764,800 6.00% 17.9314 113,074,580 1,997,784,250
10 56,764,801 - 63,072,000 5.50% 17.4330 109,931,134 2,107,715,384
11 63,072,001 - 69,379,200 5.00% 16.7126 105,378,769 2,213,094,153
12 69,379,201 - 75,686,400 4.50% 15.7923 99,582,937 2,312,677,090
13 75,686,401 - 81,993,600 4.00% 14.6730 92,521,084 2,405,198,174
14 81,993,601 - 88,300,800 3.50% 13.3416 84,130,936 2,489,329,110
15 88,300,801 - 94,608,000 3.00% 11.8466 74,696,673 2,564,025,783
16+ 94,608,001+ 3.00% (稳定) 渐增 渐增 持续增长

2.6 排放曲线可视化 (ASCII)

年排放量 (MSG)    年通胀率 (%)
    ^                ^
    |                |
120M|              12%|
    | \              | \
100M|  \             |10%\
    |   \            |   \
 80M|    \           |    \
    |     \          |8%   \
 60M|      \         |     \
    |       \        |      \
 40M|        \       |6%    \
    |         \      |       \
 20M|          \__   |4%    __\
    |             \_ |3% __/
    +--+--+--+--+--+--+--+--+--+--+--> 年份
    0  1  2  3  4  5  6  7  8  9  10

2.7 累计供应量增长

总供应量 (十亿 MSG)
    ^
3.0 |                    ~~~~~ (稳态 ~3% 通胀)
    |                  /
2.5 |                /
    |              /
2.0 |            /
    |          /
1.5 |        /
    |      / 
1.0 |----/
    |
    +--+--+--+--+--+--+--+--+--+--+--> 年份
    0  1  2  3  4  5  6  7  8  9  10

第0年: 1.00B MSG
第1年: 1.10B MSG (+10.0%)
第2年: 1.20B MSG (+9.5%)
第3年: 1.31B MSG (+9.0%)
第5年: 1.54B MSG (+8.0%)
第10年: 2.11B MSG (+5.5%)

2.8 查询排放数据

CLI 查询:

# 查询当前排放速率
./build/msgd query wasm contract-state smart \
  $(./build/msgd query registry resolve emission_schedule -o json | jq -r '.address') \
  '{"get_current_emission":{}}' \
  --node tcp://localhost:26657 -o json

# 输出示例:
# {"data":{"blocks_per_year":"6307200","emission_per_block":"15854994935561943000","inflation_rate":"0.1","last_update_height":"100000"}}

# 查询总排放量
./build/msgd query wasm contract-state smart \
  $(./build/msgd query registry resolve emission_schedule -o json | jq -r '.address') \
  '{"get_total_emitted":{}}' \
  --node tcp://localhost:26657 -o json

# 查询剩余排放
./build/msgd query wasm contract-state smart \
  $(./build/msgd query registry resolve emission_schedule -o json | jq -r '.address') \
  '{"get_remaining_emission":{}}' \
  --node tcp://localhost:26657 -o json

JavaScript (CosmJS) 查询:

import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";

async function queryEmission(client: CosmWasmClient, contractAddr: string) {
  // 查询当前排放
  const current = await client.queryContractSmart(contractAddr, {
    get_current_emission: {}
  });
  console.log(`当前通胀率: ${Number(current.inflation_rate) * 100}%`);
  console.log(`每区块排放: ${current.emission_per_block / 1e18} MSG`);
  console.log(`年区块数: ${current.blocks_per_year}`);

  // 查询已排放总量
  const emitted = await client.queryContractSmart(contractAddr, {
    get_total_emitted: {}
  });
  console.log(`已排放: ${emitted.total_emitted / 1e18} MSG`);

  return { current, emitted };
}

2.9 Rust 排放计算

use cosmwasm_std::{Decimal, Uint128};

const BLOCKS_PER_YEAR: u64 = 6_307_200;
const DECIMAL_FACTOR: Uint128 = Uint128::new(1_000_000_000_000_000_000); // 10^18

/// 计算每区块排放量
fn calculate_emission_per_block(
    total_supply: Uint128,
    inflation_rate: Decimal,
) -> Uint128 {
    // 年排放 = 总供应量 × 通胀率
    let annual_emission = total_supply * inflation_rate;
    // 每区块排放 = 年排放 / 年区块数
    annual_emission / Uint128::from(BLOCKS_PER_YEAR)
}

/// 计算动态通胀率
fn calculate_inflation_rate(
    current_rate: Decimal,
    actual_staking_ratio: Decimal,
    target_staking_ratio: Decimal,
    rate_change: Decimal,
    min_rate: Decimal,
    max_rate: Decimal,
) -> Decimal {
    if actual_staking_ratio >= target_staking_ratio {
        // 质押充足,降低通胀
        let new_rate = current_rate - rate_change;
        if new_rate < min_rate { min_rate } else { new_rate }
    } else {
        // 质押不足,提高通胀以激励质押
        let new_rate = current_rate + rate_change;
        if new_rate > max_rate { max_rate } else { new_rate }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use cosmwasm_std::Decimal;

    #[test]
    fn test_emission_calculation() {
        let total_supply = Uint128::new(1_000_000_000) * DECIMAL_FACTOR; // 1B MSG
        let inflation = Decimal::percent(10); // 10%

        let per_block = calculate_emission_per_block(total_supply, inflation);
        // 预期: 15.85 MSG/block
        assert!(per_block.u128() > 15_000_000_000_000_000_000u128); // >15 MSG
        assert!(per_block.u128() < 16_000_000_000_000_000_000u128); // <16 MSG
    }

    #[test]
    fn test_inflation_dynamics() {
        let current = Decimal::percent(10);
        let target = Decimal::from_ratio(2u64, 3u64); // 66.67%
        let change = Decimal::from_ratio(5u64, 1000u64); // 0.5%
        let min_rate = Decimal::percent(3);
        let max_rate = Decimal::percent(20);

        // 质押充足 → 降低通胀
        let new_rate = calculate_inflation_rate(
            current, Decimal::percent(70), target, change, min_rate, max_rate
        );
        assert_eq!(new_rate, Decimal::percent(9)); // 10% - 0.5% = 9.5%... 嗯 Decimal::percent 是整数百分比
        // 实际上 Decimal::percent(10) = 0.1, 所以 0.1 - 0.005 = 0.095 = 9.5%
        assert_eq!(new_rate, Decimal::from_ratio(95u64, 1000u64));
    }

    #[test]
    fn test_annual_emission() {
        let supply = Uint128::new(1_000_000_000) * DECIMAL_FACTOR;
        let inflation = Decimal::percent(10);
        let per_block = calculate_emission_per_block(supply, inflation);
        let annual = per_block * Uint128::from(BLOCKS_PER_YEAR);
        // 年排放应 ≈ 1亿 MSG (10% of 10亿)
        let expected = Uint128::new(100_000_000) * DECIMAL_FACTOR;
        assert_eq!(annual, expected);
    }
}

2.10 TypeScript 代币计算工具

// token-math.ts — MSG 代币数学工具函数

const DECIMALS = 18;
const BLOCKS_PER_YEAR = 6_307_200;
const ONE_MSG = BigInt(10) ** BigInt(DECIMALS); // 10^18

/** umsg 转 MSG (显示用) */
export function umsgToMsg(umsg: bigint | string, precision = 4): string {
  const value = typeof umsg === 'string' ? BigInt(umsg) : umsg;
  const divisor = BigInt(10) ** BigInt(DECIMALS - precision);
  const display = value / divisor;
  const whole = display / BigInt(10 ** precision);
  const frac = display % BigInt(10 ** precision);
  return `${whole}.${frac.toString().padStart(precision, '0')}`;
}

/** MSG 转 umsg (链上格式) */
export function msgToUmsg(msg: string): string {
  const [whole, frac = ''] = msg.split('.');
  const padded = frac.padEnd(DECIMALS, '0').slice(0, DECIMALS);
  return (BigInt(whole || '0') * ONE_MSG + BigInt(padded)).toString();
}

/** 计算每区块排放量 */
export function calcEmissionPerBlock(
  totalSupply: bigint,
  inflationRate: number, // 例如 0.10 = 10%
): bigint {
  const annualEmission = BigInt(Math.floor(Number(totalSupply) * inflationRate));
  return annualEmission / BigInt(BLOCKS_PER_YEAR);
}

/** 计算质押年化收益率 */
export function calcStakingAPR(
  annualEmission: bigint,
  totalStaked: bigint,
  validatorCommission: number, // 例如 0.10 = 10%
): number {
  const rewardPool = annualEmission;
  const delegatorShare = rewardPool * BigInt(Math.floor((1 - validatorCommission) * 1000)) / BigInt(1000);
  return Number(delegatorShare) / Number(totalStaked);
}

/** 推算当年通胀率 */
export function calcInflationRate(
  currentRate: number,
  actualStakingRatio: number,
  targetStakingRatio: number = 0.6667,
  rateChange: number = 0.005,
  minRate: number = 0.03,
  maxRate: number = 0.20,
): number {
  if (actualStakingRatio >= targetStakingRatio) {
    return Math.max(minRate, currentRate - rateChange);
  } else {
    return Math.min(maxRate, currentRate + rateChange);
  }
}

// 使用示例
const supply = BigInt(1_000_000_000) * ONE_MSG; // 10亿 MSG
const inflation = 0.10; // 10%
const perBlock = calcEmissionPerBlock(supply, inflation);
console.log(`每区块排放: ${umsgToMsg(perBlock, 2)} MSG`); // "15.85 MSG"

const staked = BigInt(650_000_000) * ONE_MSG; // 6.5亿 MSG 质押
const apr = calcStakingAPR(
  BigInt(100_000_000) * ONE_MSG, // 年排放 1亿 MSG
  staked,
  0.10, // 10% 佣金
);
console.log(`质押 APR: ${(apr * 100).toFixed(2)}%`); // "13.85%"

// 通胀率推演
const newRate = calcInflationRate(0.10, 0.70, 0.6667);
console.log(`新年通胀率: ${(newRate * 100).toFixed(2)}%`); // "9.50%"

3. 质押经济学

3.1 质押参数

参数 值
最小自委托量 1 MSG (1000000000000000000umsg)
最小总委托量 (创建验证者) 500 MSG
解绑期 (Unbonding Period) 21 天
再委托周期限制 7 天
最大验证者数 100
验证者佣金上限 20%
佣金日变更上限 1%

3.2 质押 APR 计算

质押年化收益率取决于三个核心变量:

  1. 年通胀率(决定区块奖励总额)
  2. 总质押比例(决定奖励分配)
  3. 验证者佣金率(决定委托者实得)
基础 APR = 年区块奖励总额 / 总质押量
委托者 APR = 基础 APR × (1 - 佣金率)

计算示例 (第1年, 总质押率 65%):

总供应量 = 1,000,000,000 MSG
年通胀率 = 10%
年排放量 = 100,000,000 MSG
总质押量 = 650,000,000 MSG (65% of supply)
验证者佣金 = 10%

基础 APR = 100,000,000 / 650,000,000 = 15.38%
委托者 APR = 15.38% × (1 - 0.10) = 13.85%
验证者 APR (佣金) = 15.38% × 0.10 + 13.85% = 15.38%

不同质押率下的 APR (第1年, 10% 佣金):

总质押率 总质押量 (MSG) 基础 APR 委托者 APR 验证者 APR
30% 300,000,000 33.33% 30.00% 33.33%
40% 400,000,000 25.00% 22.50% 25.00%
50% 500,000,000 20.00% 18.00% 20.00%
66.67% (目标) 666,700,000 15.00% 13.50% 15.00%
75% 750,000,000 13.33% 12.00% 13.33%
90% 900,000,000 11.11% 10.00% 11.11%

3.3 多年 APR 预测 (假设质押率稳定在 66.67%)

年份 通胀率 年排放 (MSG) 预期质押量 基础 APR 委托者 APR (10%佣)
1 10.00% 100,000,000 666,700,000 15.00% 13.50%
2 9.50% 104,500,001 803,000,000 13.01% 11.71%
3 9.00% 108,405,000 875,270,000 12.39% 11.15%
4 8.50% 111,596,925 949,667,950 11.75% 10.58%
5 8.00% 113,960,154 1,025,641,387 11.11% 10.00%
10 5.50% 109,931,134 1,405,143,590 7.82% 7.04%

3.4 复利 vs 领取对比

场景: 委托 10,000 MSG, APR 13.50%, 10% 佣金, 运行 1 年

每日领取 (不复利):
  日收益 = 10,000 × 13.50% / 365 = 3.70 MSG
  年收益 = 10,000 × 13.50% = 1,350 MSG
  最终余额 = 10,000 + 1,350 = 11,350 MSG

每日复利 (领取后立即再委托):
  复利公式: A = P × (1 + r/n)^(n×t)
  其中:
    P = 初始委托 (10,000 MSG)
    r = APR (13.50% = 0.135)
    n = 复利频率 (每日 = 365)
    t = 时间 (1 年)
  
  A = 10,000 × (1 + 0.135/365)^(365×1)
  A = 10,000 × (1.0003699)^365
  A = 10,000 × 1.1443
  A = 11,443 MSG

  复利超额收益 = 11,443 - 11,350 = 93 MSG
  复利提升 = (1.1443 - 1.1350) / 0.1350 = 6.89%

不同复利频率对比:

频率 年化收益率 10,000 MSG 年收益 超额收益
不操作 13.50% 1,350 MSG 0
每周复利 14.43% 1,443 MSG +93 MSG
每日复利 14.44% 1,444 MSG +94 MSG
每区块复利 14.45% 1,445 MSG +95 MSG

结论: 每日复利和每周复利差异极小。建议每周或每月批量操作一次复利,以节省 Gas 费。

3.5 实际收益计算器

/**
 * 计算质押预期收益
 */
function calculateStakingReturns(
  stakeAmount: bigint,           // 委托数量 (umsg)
  annualEmission: bigint,        // 年排放量 (umsg)
  totalStaked: bigint,           // 总质押量 (umsg)
  commissionRate: number,        // 验证者佣金率 (0.10 = 10%)
  compoundingFrequency: number,  // 复利频率 (每年次数, 365=每日)
  years: number,                 // 持有年限
): {
  annualReward: string,
  effectiveAPR: string,
  finalAmount: string,
  compoundingBonus: string,
} {
  const baseAPR = Number(annualEmission) / Number(totalStaked);
  const delegatorAPR = baseAPR * (1 - commissionRate);

  const annualReward = Number(stakeAmount) * delegatorAPR;
  const effectiveAPR = delegatorAPR;

  // 复利计算
  const r = delegatorAPR;
  const n = compoundingFrequency;
  const t = years;
  const finalAmount = Number(stakeAmount) * Math.pow(1 + r / n, n * t);
  const compoundingBonus = finalAmount - Number(stakeAmount) * (1 + r * t);

  return {
    annualReward: umsgToMsg(BigInt(Math.floor(annualReward))),
    effectiveAPR: `${(effectiveAPR * 100).toFixed(2)}%`,
    finalAmount: umsgToMsg(BigInt(Math.floor(finalAmount))),
    compoundingBonus: umsgToMsg(BigInt(Math.floor(compoundingBonus))),
  };
}

// 使用示例
const result = calculateStakingReturns(
  msgToUmsg("10000"),     // 10,000 MSG
  msgToUmsg("100000000"), // 年排放 1亿 MSG
  msgToUmsg("666700000"), // 总质押 6.667亿 MSG
  0.10,                   // 10% 佣金
  365,                    // 每日复利
  1,                      // 1 年
);
console.log(result);
// { annualReward: "1350.00", effectiveAPR: "13.50%", finalAmount: "11443.74", compoundingBonus: "93.74" }

3.6 质押操作示例

# 查询质押池状态
./build/msgd query staking pool --node tcp://localhost:26657 -o json

# 输出:
# {
#   "not_bonded_tokens": "50000000000000000000000000",    # 未质押 (5,000 MSG)
#   "bonded_tokens": "650000000000000000000000000000"     # 已质押 (650,000,000 MSG)
# }

# 计算质押率
# 质押率 = bonded / (bonded + not_bonded)
# = 650,000,000 / (650,000,000 + 5,000) = 99.999%

# 委托操作
./build/msgd tx staking delegate \
  msgvaloper1qypqxpq9kcrn2c9afea5lq35ef37c5x7xyzabc \
  1000000000000000000000umsg \  # 1,000 MSG
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --gas-adjustment 1.3 \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 解委托 (21天等待)
./build/msgd tx staking unbond \
  msgvaloper1qypqxpq9kcrn2c9afea5lq35ef37c5x7xyzabc \
  500000000000000000000umsg \    # 500 MSG
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 重新委托 (立即生效,7天冷却)
./build/msgd tx staking redelegate \
  msgvaloper1old123... \
  msgvaloper1new456... \
  300000000000000000000umsg \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

3.7 验证者佣金策略

验证者可设置 0-20% 的佣金率,每日最多变更 1%:

佣金率 验证者行为 典型场景
0-5% 低佣金,吸引更多委托 新验证者、社区节点
5-10% 中等佣金 多数验证者
10-15% 高佣金 品牌验证者、机构节点
15-20% 极高佣金 仅限于高信誉验证者

委托者选择验证者的经济考量:

净收益 = 委托量 × (基础 APR × (1 - 佣金率))

示例:
  验证者 A: 佣金 5%, 基础 APR 15%
  委托者净 APR = 15% × (1 - 0.05) = 14.25%

  验证者 B: 佣金 10%, 基础 APR 16% (更高 DAR 评分)
  委托者净 APR = 16% × (1 - 0.10) = 14.40%

结论: 即使佣金较高,如果验证者 DAR 评分高带来更多出块机会,
基础 APR 更高,委托者净收益可能反而更高。

4. Gas费市场

4.1 Gas 计算模型

MSG Chain 使用固定费率 Gas 模型(非 EIP-1559),交易费用由用户指定的 Gas 价格和 Gas 消耗量决定。

交易费 (umsg) = Gas 消耗量 × Gas 价格 (umsg/Gas)

Gas 消耗量 ≈ 固定 Gas + 存储 Gas + 计算 Gas

各操作 Gas 消耗参考:

操作 预估 Gas 平均费用 (1,000,000,000 attoMSG/Gas)
转账 (Bank Send) ~100,000 0.0001 MSG
委托 (Delegate) ~200,000 0.0002 MSG
领取奖励 (Withdraw) ~250,000 0.00025 MSG
解委托 (Unbond) ~200,000 0.0002 MSG
合约调用 (Execute) ~300,000 - 1,000,000 0.0003 - 0.001 MSG
合约部署 (Store Code) ~2,000,000 0.002 MSG
跨链 IBC 转账 ~300,000 0.0003 MSG
AI Agent 调用 ~500,000 - 5,000,000 0.0005 - 0.005 MSG

以上为估算值。实际 Gas 消耗会因合约复杂度、参数大小和链状态而有所不同。

4.2 Gas 价格

等级 价格 (attoMSG) 价格 (MSG) 使用场景
固定费率 1,000,000,000 attoMSG 0.000000001 MSG 所有链上操作

费用对比示例 (转账 100 MSG):

固定费率: 100,000 Gas × 1,000,000,000 attoMSG = 100,000,000,000,000 attoMSG = 0.0001 MSG

与以太坊对比:

指标 MSG Chain Ethereum (EIP-1559)
Gas 计算 固定 Gas × 固定价格 Base Fee + Priority Tip
价格波动 无 (用户自选三档) Base Fee 每块动态调整
费用消耗 40/30/20/10 分配 Base Fee 销毁,Tip 给验证者
每笔平均费 ~0.0001 MSG ~0.001-0.01 ETH
费用波动性 极低 (稳定可预测) 高 (拥堵时暴涨)
可预测性 ✅ 完全可预测 ❌ 拥堵时不可预测

4.3 Fee 分配机制 (gas_fee_distribution_v2)

MSG Chain 的 Gas 费用按以下比例分配:

                             Gas Fee Pool
                                  │
                    ┌─────────────┼─────────────┐
                    │             │             │
                    ▼             ▼             ▼
              40% 给区块     30% 给基     20% 给开发   10% 销毁
              提议者验证者   金库          者基金
                
每个区块: Σ(Gas_i × GasPrice_i) → 自动分配至四个地址

分配公式:

区块 Gas 总收入 = Σ(每笔交易 Gas × Gas 价格)

验证者收益 = 区块 Gas 总收入 × 40%
金库收入   = 区块 Gas 总收入 × 30%
开发者基金 = 区块 Gas 总收入 × 20%
销毁       = 区块 Gas 总收入 × 10%

年 Gas 收入预估 (假设每天 1,000,000 笔交易, 平均每笔 100,000 Gas):

日均交易量 = 1,000,000 笔
日均 Gas 消耗 = 1,000,000 × 100,000 = 100,000,000,000 Gas
日均 gas 收入 = 100,000,000,000 × 1,000,000,000 attoMSG = 100,000,000,000,000,000,000 attoMSG = 0.1 MSG

日均费用总收入 = 0.1 MSG
每笔平均 Gas = 100,000
每笔平均费用 = 100,000 × 1,000,000,000 attoMSG = 100,000,000,000,000 attoMSG = 0.0001 MSG

日均交易量 = 1,000,000 笔
日均费用总收入 = 1,000,000 × 0.0001 MSG = 100 MSG

换算为 attoMSG: 100 × 10^18 = 100,000,000,000,000,000,000 attoMSG

年费用总收入 = 0.0000000025 × 365 = 0.0000000009125 MSG

各分配接收方年收入:
  验证者 (40%): 0.000000000365 MSG
  金库 (30%):  0.000000000274 MSG
  开发者 (20%): 0.000000000183 MSG
  销毁 (10%):  0.0000000000913 MSG

实际上 Gas 费用在链早期主要为 umsg 级别的微小额。随着 MSG 价值上升和交易量增长,Gas 费用重要性会增加。

4.4 Gas 价格选择策略

/**
 * 根据交易紧急程度选择推荐 Gas 价格
 */
type Priority = "low" | "average" | "high";

function getGasPrice(): string {
  return "1000000000attoMSG";
}

/**
 * 估算交易费用
 */
function estimateTxFee(
  estimatedGas: bigint,
  priority: Priority = "average",
): string {
  const gasPrice = BigInt(getGasPrice(priority).replace("umsg", ""));
  const fee = estimatedGas * gasPrice;
  return `${fee} umsg (${umsgToMsg(fee, 6)} MSG)`;
}

// 使用示例
console.log(estimateTxFee(BigInt(100000), "average"));
// "2500000 umsg (0.0000025 MSG)"
console.log(estimateTxFee(BigInt(500000), "high"));
// "通用维护记录 umsg (0.00002 MSG)"

4.5 CLI 中的 Gas 配置

# 自动预估 Gas (推荐)
./build/msgd tx bank send ... \
  --gas auto \
  --gas-prices 1000000000attoMSG \
  --gas-adjustment 1.3

# 手动指定 Gas
./build/msgd tx bank send ... \
  --gas 250000 \
  --gas-prices 1000000000attoMSG

# 使用不同优先级
# Low
--gas-prices 1000000000attoMSG

# Average (默认)
--gas-prices 1000000000attoMSG

# High
--gas-prices 1000000000attoMSG

# 查询 Gas 费用分配参数
curl -X POST http://localhost:26657/cosmwasm.wasm.v1.Query/SmartContractState \
  -H "Content-Type: application/json" \
  -d '{
    "address": "msg1...gas_fee_distribution",
    "query_data": "'$(echo -n '{"get_distribution_params":{}}' | base64 -w0)'"
  }' | jq

4.6 Gas 费用优化建议

  1. 批量操作: 使用 --generate-only 构建多笔交易,减少重复费用
  2. 低峰期交易: 低优先级 Gas 在网络空闲时也能快速打包
  3. 合约优化: 编写高效 CosmWasm 合约,减少存储操作
  4. 复用连接: 使用 WebSocket 持久连接减少握手费用

5. 收益分配模型

5.1 区块奖励结构

每个 MSG Chain 区块包含两部分奖励:

  1. 区块排放奖励 (来自 emission_schedule_v2)
  2. Gas 费收入 (来自 gas_fee_distribution_v2)
每个区块的收入:
  区块奖励 = 排放奖励 + Gas 费收入

  排放奖励 → 100% 给验证者和委托者 (通过 staking 模块分配)
  Gas 费收入 → 40% 验证者 + 30% 金库 + 20% 开发者 + 10% 销毁

5.2 验证者奖励分配

区块奖励分配流程:

1. 区块被提议者生产
2. 全体验证者 (包括提议者) 参与签名
3. 奖励汇集至 distribution 模块
4. 按验证者投票权重分配
5. 每个验证者内部按佣金率分割:

   验证者总收入 = 应得区块奖励
        │
        ├── 佣金部分 = 总收入 × 佣金率 (归验证者运营者)
        │
        └── 委托者部分 = 总收入 × (1 - 佣金率)
                │
                └── 按各委托者质押比例分配

分配示例 (十年后第1个区块):

参数:
  当前总供应量: 1,100,000,000 MSG
  年通胀率: 9.50%
  年排放量: 104,500,000 MSG
  每区块排放: 16.5732 MSG
  区块 Gas 费收入: ~0.0000025 MSG (初期较低)
  
  总区块奖励 = 16.5732 + 0.0000025 ≈ 16.5732 MSG

验证者 A (质押权重 15%, 佣金率 10%):
  应得 = 16.5732 × 15% = 2.486 MSG
  佣金 = 2.486 × 10% = 0.2486 MSG (归验证者运营者)
  委托者分配 = 2.486 - 0.2486 = 2.2374 MSG

委托者 X (在验证者 A 质押 10,000 MSG, 验证者 A 总质押量 100,000,000 MSG):
  应得 = 2.2374 × (10,000 / 100,000,000) = 0.00022374 MSG/区块
  日收益 = 0.00022374 × (86400 / 5) = 3.866 MSG/天

5.3 Auto-compounding 策略

/**
 * 自动复利策略计算
 */
function autoCompoundStrategy(
  stakeAmount: bigint,      // 初始委托
  apr: number,              // 年化收益率
  commission: number,       // 佣金率
  compoundEvery: number,    // 复利间隔 (秒)
  gasCostPerAction: bigint, // 每次操作的 Gas 费
  days: number,             // 运行天数
) {
  const blocksPerDay = 24 * 3600 / 5; // 17,280
  const rewardPerBlockPerMsg = (apr / blocksPerDay / 365) * (1 - commission);
  
  let currentStake = Number(stakeAmount);
  let totalGasCost = BigInt(0);
  let actions = 0;

  const blocksPerAction = compoundEvery / 5;
  const totalBlocks = days * blocksPerDay;

  for (let block = 0; block < totalBlocks; block++) {
    if (block > 0 && block % blocksPerAction === 0) {
      // 领取并复利
      totalGasCost += gasCostPerAction;
      actions++;
    }
    // 累积奖励
    const blockReward = currentStake * rewardPerBlockPerMsg;
    currentStake += blockReward;
  }

  return {
    finalStake: currentStake,
    totalGasCost: Number(totalGasCost),
    actions,
    netReturn: currentStake - Number(stakeAmount) - Number(totalGasCost),
  };
}

5.4 查询奖励命令

# 查询委托者未领取奖励
./build/msgd query distribution rewards \
  $(./build/msgd keys show mywallet -a --keyring-backend os) \
  --node tcp://localhost:26657 -o json

# 输出示例:
# {
#   "rewards": [
#     {
#       "validator_address": "msgvaloper1...",
#       "reward": [
#         {"denom": "umsg", "amount": "1500000000000000000"}
#       ]
#     }
#   ],
#   "total": [
#     {"denom": "umsg", "amount": "1500000000000000000"}
#   ]
# }
# 说明: 待领取 1.5 MSG

# 查询验证者待发放的未领取奖励总和
VALOPER=$(./build/msgd keys show validator --bech val -a --keyring-backend os)
./build/msgd query distribution validator-outstanding-rewards "$VALOPER" \
  --node tcp://localhost:26657 -o json

# 领取所有奖励
./build/msgd tx distribution withdraw-all-rewards \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 领取特定验证者奖励
./build/msgd tx distribution withdraw-rewards \
  msgvaloper1qypqxpq9kcrn2c9afea5lq35ef37c5x7xyzabc \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 验证者领取佣金 (添加 --commission 标志)
./build/msgd tx distribution withdraw-rewards \
  "$VALOPER" \
  --from validator --commission \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 设置自动提现地址
./build/msgd tx distribution set-withdraw-addr \
  msg1destination_address... \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

5.5 收益计算总结

角色 收入来源 分配方式 获取频率
验证者 区块排放奖励 + Gas 费 佣金 + 委托者分配后剩余 每区块自动累积
委托者 区块排放奖励 (扣除佣金) 按质押比例分配 手动领取 (建议定期)
金库 Gas 费 (30%) 自动分配 每区块自动累积
开发者基金 Gas 费 (20%) 自动分配 每区块自动累积
燃烧地址 Gas 费 (10%) 自动销毁 每区块自动销毁

6. 代币分配

6.1 创世分配详情

                         MSG 创世分配
                   总供应量: 1,000,000,000 MSG
┌──────────────────────────────────────────────────────────┐
│  生态系统基金    │  300,000,000 MSG  │  30%              │
│  社区销售/IDO    │  200,000,000 MSG  │  20%              │
│  团队与贡献者    │  150,000,000 MSG  │  15%              │
│  基金会储备      │  150,000,000 MSG  │  15%              │
│  验证者奖励储备  │  100,000,000 MSG  │  10%              │
│  社区空投        │  100,000,000 MSG  │  10%              │
└──────────────────────────────────────────────────────────┘

创世时初始供应量: 1,000,000,000 MSG
总供应量 (含排放通货膨胀): 逐步增长至 21 亿+ MSG (15 年内)

6.2 各分配细则

6.2.1 生态系统基金 (30% — 300,000,000 MSG)

子项 比例 数量 锁仓
生态 Grant 40% 120,000,000 MSG 线性释放 4 年,无 cliff
合作伙伴基金 25% 75,000,000 MSG 线性释放 3 年,6个月 cliff
市场与流动性 20% 60,000,000 MSG 10% 立即可用,其余 2 年线性
黑客松与活动 15% 45,000,000 MSG 按活动计划释放

解锁曲线 (生态系统基金):

释放比例
 100% ┤                                ────
  80% ┤                          ────
  60% ┤                    ────
  40% ┤              ────
  20% ┤        ────
   0% ┤─── ────
       +--+--+--+--+--+--+--+--+--+--+--> 时间 (年)
       0  1  2  3  4  5  6  7  8  9  10

6.2.2 社区销售/IDO (20% — 200,000,000 MSG)

子项 比例 数量 锁仓
公募 (Public Sale) 60% 120,000,000 MSG 25% TGE 解锁,剩余 6 个月线性
私募 (Private Sale) 30% 60,000,000 MSG 12 个月 cliff,之后 18 个月线性
战略轮 (Strategic) 10% 20,000,000 MSG 24 个月 cliff,之后 24 个月线性

IDO 解锁时间线:

     公募                     私募                     战略轮
TGE: 25% 解锁          0%                     0%
M1:  ~37.5% (线性)      0%                     0%
M3:  ~62.5%             0%                     0%
M6:  100%              0%                     0%
M12: 100%              Cliff 结束 → 开始释放   0%
M18: 100%              50%                    0%
M24: 100%              100%                   Cliff 结束 → 开始释放
M36: 100%              100%                   50%
M48: 100%              100%                   100%

6.2.3 团队与贡献者 (15% — 150,000,000 MSG)

子项 比例 数量 锁仓
核心团队 60% 90,000,000 MSG 12 个月 cliff,36 个月线性
早期贡献者 25% 37,500,000 MSG 6 个月 cliff,24 个月线性
顾问 15% 22,500,000 MSG 6 个月 cliff,18 个月线性

核心团队解锁示例:

释放量/月
  2.5M ┤
       │      ┌────────────────────────────────
   2M ┤      /
       │     /
 1.5M ┤    /
       │   /
   1M ┤  /
       │ /
 0.5M ┤/
       │
   0M ┤─────────────────────────────────────> 时间
       └──+──+──+──+──+──+──+──+──+──+──+──
       M0  M6 M12 M18 M24 M30 M36 M42 M48
       ↑
    Cliff (0 释放)

月释放量 = 总配额 / 线性释放月数 = 90,000,000 / 36 = 2,500,000 MSG/月 (在 cliff 后)

6.2.4 基金会储备 (15% — 150,000,000 MSG)

子项 比例 数量 锁仓
运营资金 50% 75,000,000 MSG 20% TGE,剩余 3 年线性
安全基金 25% 37,500,000 MSG 100% 锁仓,仅用于安全事件
战略投资 25% 37,500,000 MSG 无锁仓,按需使用

6.2.5 验证者奖励储备 (10% — 100,000,000 MSG)

此部分资金用于补充早期的区块奖励,确保在链启动初期通胀排放不足时有足够的奖励分发:

奖励储备释放策略:
  第1年: 使用 40,000,000 MSG (补充至 100M 年排放目标)
  第2年: 使用 30,000,000 MSG
  第3年: 使用 20,000,000 MSG
  第4年: 使用 10,000,000 MSG
  第5年: 剩余 0 MSG (完全依赖通胀排放)

6.2.6 社区空投 (10% — 100,000,000 MSG)

子项 比例 数量 条件
测试网参与者 30% 30,000,000 MSG 完成测试任务
MSG 社区成员 25% 25,000,000 MSG Discord/Twitter 活跃
Cosmos 生态持有者 25% 25,000,000 MSG ATOM/OSMO 持有者快照
开发者空投 20% 20,000,000 MSG 部署合约或提交代码

6.3 线性释放与 Cliff 公式

/**
 * 线性释放计算器
 */
interface VestingSchedule {
  totalAmount: bigint;        // 总释放量 (umsg)
  cliffMonths: number;        // Cliff 月数 (0 = 无 cliff)
  vestingMonths: number;      // 线性释放总月数
  tgePercentage: number;      // TGE 解锁百分比 (0-100)
  startTimestamp: number;     // 开始时间戳 (秒)
}

function calculateVestedAmount(
  schedule: VestingSchedule,
  currentTimestamp: number,
): {
  unlocked: bigint;           // 已解锁数量
  locked: bigint;             // 仍锁仓数量
  availableToClaim: bigint;   // 可领取 (含 TGE)
  nextUnlockAmount: bigint;   // 下次解锁数量
} {
  const elapsedMonths = (currentTimestamp - schedule.startTimestamp) 
    / (30.44 * 24 * 3600); // 月平均秒数
  const totalMonths = schedule.cliffMonths + schedule.vestingMonths;

  if (elapsedMonths < schedule.cliffMonths) {
    // 仍在 Cliff 期内
    const tgeAmount = schedule.totalAmount 
      * BigInt(schedule.tgePercentage) / BigInt(100);
    return {
      unlocked: tgeAmount,
      locked: schedule.totalAmount - tgeAmount,
      availableToClaim: tgeAmount,
      nextUnlockAmount: BigInt(0),
    };
  }

  const vestingElapsed = Math.min(
    elapsedMonths - schedule.cliffMonths,
    schedule.vestingMonths,
  );
  const vestingProgress = vestingElapsed / schedule.vestingMonths;
  const tgeAmount = schedule.totalAmount 
    * BigInt(schedule.tgePercentage) / BigInt(100);
  const vestingUnlocked = BigInt(
    Math.floor(Number(schedule.totalAmount - tgeAmount) * vestingProgress),
  );

  return {
    unlocked: tgeAmount + vestingUnlocked,
    locked: schedule.totalAmount - tgeAmount - vestingUnlocked,
    availableToClaim: tgeAmount + vestingUnlocked,
    nextUnlockAmount: schedule.vestingMonths > 0
      ? (schedule.totalAmount - tgeAmount) / BigInt(schedule.vestingMonths)
      : BigInt(0),
  };
}

// 验证 (核心团队示例)
const teamVesting: VestingSchedule = {
  totalAmount: msgToUmsg("90000000"), // 90,000,000 MSG
  cliffMonths: 12,
  vestingMonths: 36,
  tgePercentage: 0,
  startTimestamp: 1700000000, // 假设 2023-11-14
};

console.log(calculateVestedAmount(teamVesting, Math.floor(Date.now() / 1000)));
// 输出 { unlocked: "0", locked: "90000000", availableToClaim: "0", ... }
// (12个月 cliff 内, 仍完全锁仓)

6.4 创世分配饼图 (ASCII)

      ┌──────────────────────────────────────┐
      │          MSG 创世分配                 │
      │                                      │
      │    ┌─────────────┐                   │
      │    │ 生态系统基金 │  30%              │
      │    │  300M MSG   │ ████████████████  │
      │    └─────────────┘                   │
      │    ┌─────────────┐                   │
      │    │ 社区销售    │  20%              │
      │    │  200M MSG   │ ████████████      │
      │    └─────────────┘                   │
      │    ┌─────────────┐                   │
      │    │ 团队/贡献者 │  15%              │
      │    │  150M MSG   │ █████████         │
      │    └─────────────┘                   │
      │    ┌─────────────┐                   │
      │    │ 基金会储备  │  15%              │
      │    │  150M MSG   │ █████████         │
      │    └─────────────┘                   │
      │    ┌─────────────┐                   │
      │    │ 奖励储备    │  10%              │
      │    │  100M MSG   │ ██████            │
      │    └─────────────┘                   │
      │    ┌─────────────┐                   │
      │    │ 社区空投    │  10%              │
      │    │  100M MSG   │ ██████            │
      │    └─────────────┘                   │
      └──────────────────────────────────────┘

7. 流通量分析

7.1 流通量分类

MSG 代币的流通状态可分为以下类别:

总供应量 (Total Supply)
    │
    ├── 已流通 (Circulating Supply)
    │       ├── 交易所可用余额
    │       ├── 钱包可用余额
    │       └── DeFi 协议中流动性
    │
    ├── 已质押 (Staked / Bonded)
    │       ├── 验证者自委托
    │       └── 委托者委托
    │
    ├── 锁仓 (Locked / Vesting)
    │       ├── 团队锁仓
    │       ├── 投资人锁仓
    │       └── 基金会锁仓
    │
    └── 未发放 (未分配的排放奖励)

7.2 创世后流通量分析

创世时刻 (TGE):

类别 数量 比例
立即流通 ~380,000,000 MSG 38%
已质押 (初始验证者) ~200,000,000 MSG (20%) 隐含在流通中
锁仓 ~500,000,000 MSG 50%
奖励储备 (未发放) ~100,000,000 MSG 10%
销毁 ~20,000,000 MSG (暂估) 2%

第1年末: (加入通胀 100M MSG, 一部分锁仓释放)

类别 数量 比例
总供应量 1,100,000,000 MSG 100%
已流通 ~550,000,000 MSG 50%
已质押 ~500,000,000 MSG 45% (质押率)
锁仓 ~400,000,000 MSG 36%
奖励储备 (剩余) ~60,000,000 MSG 5%

第5年末: (通胀累积, 大部分锁仓已释放)

类别 数量 比例
总供应量 1,538,462,080 MSG 100%
已流通 ~800,000,000 MSG 52%
已质押 ~700,000,000 MSG 45% (质押率)
锁仓 ~50,000,000 MSG 3%
排放储备 0 0%

7.3 月流通量增加预估

月度流通量增加 = 月通胀排放 + 月锁仓释放 - 月质押增加

月通胀排放 (第1年): 100,000,000 / 12 = 8,333,333 MSG
月锁仓释放 (第1年平均): ~(500M - 400M) / 12 ≈ 8,333,333 MSG
月质押增加: 取决于市场需求

净月流通增加: ~8-16 MSG/月 (第1年)

7.4 质押率与流通速度

质押率直接影响代币的流通速度和市场价格:

流通速度 (Velocity) 公式:
  V = (交易总量 × 平均 MSG 价格) / (流通供应量 × MSG 价格)
    = 交易总量 / 流通供应量

高质押率 → 低流通量 → 低流通速度 → 潜在价格上涨压力
低质押率 → 高流通量 → 高流通速度 → 潜在价格下跌压力

质押率对市场价格的影响路径:

质押率 ↑ → 流通供应 ↓ → 稀缺性 ↑ → 价格 ↑ → 通胀排放价值 ↑ → 更多质押 → 循环
质押率 ↓ → 流通供应 ↑ → 抛压 ↑ → 价格 ↓ → APR ↑ → 吸引更多质押 → 稳定

7.5 交易所储备预估

链上可监控的交易所地址:
  大型交易所 (Binance/Coinbase/OKX): ~50-100M MSG
  中型交易所 (Kucoin/Gate/Bitget): ~20-50M MSG
  DEX (Osmosis/Astroport): ~10-30M MSG
  做市商: ~10-20M MSG

总交易所储备: ~90-200M MSG
占总流通量: ~15-35%

8. AI Agent经济

8.1 AI Agent 经济体量预估

MSG Chain 的核心差异化在于 AI Agent 经济。Agent 之间的微交易、服务调用和支付通道构成了独特的代币需求场景。

8.2 Agent 注册费

AI Agent 需要在 agent_registry_v1 合约中注册,注册过程消耗 MSG:

// agent_registry_v1 注册费逻辑
pub fn execute_register_agent(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    agent_id: String,
    did_id: String,
    owner: String,
    name: String,
    description: Option<String>,
    endpoint: Option<String>,
    metadata: Option<Binary>,
    agent_type: String,
    capabilities: Vec<String>,
) -> Result<Response, ContractError> {
    // 检查注册费
    let registration_fee = Uint128::from(100_000_000_000_000_000_000u128); // 100 MSG
    if info.funds.iter().find(|c| c.denom == "umsg").map(|c| c.amount) < Some(registration_fee) {
        return Err(ContractError::InsufficientRegistrationFee {});
    }
    // ... 注册逻辑
}
Agent 类型 注册费 年维护费 说明
基础 Agent 100 MSG 10 MSG 简单自动化、信息查询
专业 Agent 500 MSG 50 MSG 数据分析、内容生成
企业 Agent 2,000 MSG 200 MSG 高频交易、大规模处理
Agent DAO 10,000 MSG 1,000 MSG 自治 Agent 组织

8.3 支付会话经济

agent_payment_v1 合约实现里程碑式支付 (AIPAY 标准):

// 支付会话数据结构
#[cw_serde]
pub struct PaymentSession {
    pub session_id: String,
    pub agent_id: String,
    pub client: String,
    pub total_amount: Uint128,       // 总金额 (umsg)
    pub released_amount: Uint128,    // 已释放金额
    pub milestones: Vec<Milestone>,  // 里程碑列表
    pub status: SessionStatus,       // 进行中/完成/争议
    pub created_at: u64,
    pub expires_at: u64,
}

#[cw_serde]
pub struct Milestone {
    pub id: String,
    pub description: String,
    pub amount: Uint128,             // 此里程碑金额
    pub proof_hash: Option<String>,  // 完成证明
    pub status: MilestoneStatus,     // 待处理/已批准/争议中
}

支付会话经济模型:

会话费用 = 服务费 + 协议费

服务费 → Agent 运营者 (90%)
协议费 → 网络/质押者 (10%)
    ├── 验证者 (5%)
    ├── 金库 (3%)
    └── 销毁 (2%)

各参与方收入分配 (100 MSG 支付会话):

总支付: 100 MSG
    │
    ├── Agent 运营者: 90 MSG (90%)  ← Agent 提供服务的收入
    │
    └── 网络费用: 10 MSG (10%)
            ├── 验证者: 5 MSG (5%)
            ├── 金库: 3 MSG (3%)
            └── 销毁: 2 MSG (2%)

8.4 微支付通道经济

micropayment_session_v1 实现按秒计费的微支付通道,类似闪电网络的链下支付:

微支付通道生命周期:

1. 开户 (Client 锁定资金)
   Client → 通道合约: 锁定 1,000 MSG
   通道状态: 开启, 余额 0

2. 服务使用 (Agent 按秒计费)
   Agent 每秒签名更新状态: 余额 += 0.001 MSG/秒
   仅在链上提交最终结算

3. 结算 (链上关闭)
   Client 或 Agent 提交最终状态
   Agent 收到 累计费用
   Client 收到 剩余退款
   通道状态: 关闭

经济参数:

参数 值
最低通道保证金 10 MSG
最高通道金额 100,000 MSG
通道有效期 最长 30 天
结算费 0.5 MSG (固定, 关闭时支付)
按秒计费最低单位 0.000001 MSG/秒 (1e-6)
争议期 24 小时

微支付按秒计费示例:

场景: Client 使用 AI 翻译 Agent 服务
费率: 0.001 MSG/秒
使用时长: 5 分钟 (300 秒)

总费用 = 300 × 0.001 = 0.3 MSG
结算费 = 0.5 MSG

Agent 实收 = 0.3 - 0.5 × 90% = 0.3 - 0.45 = ??? (结算费高于服务费!!)

解决方案: 对于小额微支付,协议补贴结算费或允许批量结算

批量结算: 10 次使用后一次结算
  总费用 = 300 × 0.001 × 10 = 3 MSG
  结算费 = 0.5 MSG (一次)
  Agent 实收 = 3 × 90% - 0.5 = 2.7 - 0.5 = 2.2 MSG
  协议收入 = 3 × 10% = 0.3 MSG

8.5 Agent 服务定价模型

服务类型 典型定价 使用场景
文本生成 0.001 MSG/千token ChatGPT 类
图像生成 0.01 MSG/张 DALL-E, Stable Diffusion
数据分析 0.005 - 0.1 MSG/任务 数据清洗、报告生成
代码生成 0.01 MSG/千token Codex, Copilot
交易策略 0.1 - 1 MSG/策略 DeFi 策略、MEV
实时翻译 0.0005 MSG/秒 语音/文本翻译
视频处理 0.1 - 1 MSG/分钟 视频生成、编辑
Agent 编排 0.05 MSG/任务 多 Agent 协作

8.6 AI Agent 交易量预估

假设第1年:
  注册 Agent 数量: 10,000
  日均活跃 Agent: 1,000
  日均交易笔数: 100,000 (包括支付和微支付)
  平均交易额: 0.5 MSG

日均 Agent 经济交易量: 50,000 MSG
年化 Agent 经济交易量: 18,250,000 MSG
占年排放量比例: 18.25% (18.25M / 100M)

8.7 Agent 运营者收入计算

/**
 * AI Agent 运营者收益计算
 */
interface AgentEconomics {
  dailyCalls: number;          // 日调用次数
  avgPricePerCall: number;     // 平均单次价格 (MSG)
  successRate: number;         // 成功率 (0-1)
  protocolFeeRate: number;     // 协议费率 (0.10 = 10%)
  operatingCost: number;       // 日运营成本 (MSG, 算力+存储)
  registrationFee: number;     // 注册费 (MSG)
  amortizationDays: number;    // 注册费摊销天数
}

function calculateAgentProfit(config: AgentEconomics): {
  dailyRevenue: number;
  dailyProtocolFee: number;
  dailyNetRevenue: number;
  dailyCost: number;
  dailyProfit: number;
  monthlyProfit: number;
  annualProfit: number;
  roi: string;
} {
  const dailyRevenue = config.dailyCalls * config.avgPricePerCall * config.successRate;
  const dailyProtocolFee = dailyRevenue * config.protocolFeeRate;
  const dailyNetRevenue = dailyRevenue - dailyProtocolFee;
  const dailyRegAmort = config.registrationFee / config.amortizationDays;
  const dailyCost = config.operatingCost + dailyRegAmort;
  const dailyProfit = dailyNetRevenue - dailyCost;

  return {
    dailyRevenue,
    dailyProtocolFee,
    dailyNetRevenue,
    dailyCost,
    dailyProfit,
    monthlyProfit: dailyProfit * 30,
    annualProfit: dailyProfit * 365,
    roi: `${((dailyProfit / dailyCost) * 100).toFixed(2)}%`,
  };
}

// 典型 Agent 运营者财务模型
const agentConfig: AgentEconomics = {
  dailyCalls: 1000,
  avgPricePerCall: 0.01,    // 0.01 MSG/调用
  successRate: 0.95,
  protocolFeeRate: 0.10,
  operatingCost: 2.0,       // 2 MSG/天 (GPU 算力)
  registrationFee: 100,     // 100 MSG 注册费
  amortizationDays: 365,
};

console.log(calculateAgentProfit(agentConfig));
// 输出:
// dailyRevenue: 9.5 MSG (1000 × 0.01 × 0.95)
// dailyProtocolFee: 0.95 MSG (10%)
// dailyNetRevenue: 8.55 MSG
// dailyCost: 2.274 MSG (2.0 + 100/365)
// dailyProfit: 6.276 MSG
// monthlyProfit: 188.28 MSG
// annualProfit: 2290.74 MSG
// roi: "275.9%"

8.8 AI Agent 经济对 MSG 价值的乘数效应

传统 L1 代币价值 = 交易费 + 质押收益 + 治理溢价

MSG 代币价值 = 传统 L1 价值 + AI Agent 经济溢价

AI Agent 经济溢价来源:
  1. Agent 注册费 (每年新增 Agent 的 MSG 消耗)
  2. 微支付通道保证金 (锁定 MSG)
  3. Agent 服务费 (交易量中的 MSG 流转)
  4. 争议保证金 (解决 Agent 纠纷时锁定)

预估 AI 经济溢价: 传统估值的 1.5x - 3x

9. 治理经济

9.1 双层治理架构

MSG Chain 采用双层治理:

层级 模块 投票权重 管辖范围
第一层 Cosmos SDK x/gov 质押权重 (1 MSG = 1 票) 链参数、软件升级、社区池
第二层 dao_governance_v1 合约 可自定义 DAO 内部决策、金库管理

9.2 治理参数

第一层 (Cosmos SDK gov):

参数 值 说明
最小保证金 (MinDeposit) 1,000 MSG 提交提案需锁仓
保证金存入期 (MaxDepositPeriod) 14 天 筹集保证金的时间
投票期 (VotingPeriod) 7 天 投票窗口
法定人数 (Quorum) 33.4% 需至少 33.4% 质押量参与
通过阈值 (Threshold) 50% 赞成票 > 50% 非弃权票
否决阈值 (VetoThreshold) 33.4% 否决票占 > 33.4% 则提案失败

第二层 (dao_governance_v1):

参数 默认值 说明
最小提案保证金 100 MSG 提交 DAO 提案需锁仓
投票期 3-7 天 可配置
法定人数 20% 可配置
通过阈值 60% 可配置
时间锁 (Timelock) 48 小时 通过后等待执行

9.3 投票权集中度分析

假设:
  前 10 大验证者占总质押: ~40%
  前 50 大验证者占总质押: ~80%
  个人委托者: ~20%

投票权分布:
  ┌─────────────────────────────────────┐
  │ Top 10 验证者:  40%                 │
  │ Top 11-50 验证者: 40%               │
  │ 散户委托者:      20%                │
  └─────────────────────────────────────┘

治理安全性评估:
  - 3 大验证者合谋: ~15-20% (不足 33.4% 否决)
  - 5 大验证者合谋: ~25-30% (接近但不足否决)
  - 10 大验证者合谋: ~40% (可否决任意提案)
  - 单一实体控制 33.4% 质押: 极困难 (需要约 ~333M MSG)

9.4 保证金经济学

提案需要一定量的 MSG 作为保证金:

保证金锁定期间的经济成本:
  
  oppotunity_cost = 保证金 × APR × 锁定天数 / 365

示例 (1,000 MSG 保证金, APR 13.5%, 锁定 10 天):
  机会成本 = 1,000 × 13.5% × 10 / 365 = 3.70 MSG

与 Gas 费一起构成了提案的总成本:
  总提案成本 = 保证金机会成本 + Gas 费
              = 3.70 + ~0.005 = ~3.705 MSG

9.5 金库支出效率

/**
 * 金库支出效率分析
 */
interface TreasuryMetrics {
  totalInflow: bigint;        // 总收入 (MSG)
  totalOutflow: bigint;       // 总支出 (MSG)
  grantProposals: number;     // Grant 提案数
  grantApproved: number;      // 批准的 Grant 数
  totalGrantAmount: bigint;   // Grant 总金额
  operationalCost: bigint;    // 运营支出
}

function calculateTreasuryEfficiency(metrics: TreasuryMetrics): {
  netFlow: string;
  burnRate: string;
  grantApprovalRate: string;
  grantEfficiency: string;
  operationalRatio: string;
  runwayMonths: number;
} {
  const netFlow = Number(metrics.totalInflow - metrics.totalOutflow);
  const grantApprovalRate = metrics.grantApproved / metrics.grantProposals;
  const operationalRatio = Number(metrics.operationalCost) / Number(metrics.totalOutflow);
  const grantEfficiency = Number(metrics.totalGrantAmount) / Number(metrics.totalOutflow);

  // 假设金库余额
  const TREASURY_BALANCE = BigInt(150_000_000) * ONE_MSG; // 150M MSG
  const monthlyOutflow = Number(metrics.totalOutflow) / 12;
  const runwayMonths = monthlyOutflow > 0 
    ? Math.floor(Number(TREASURY_BALANCE) / monthlyOutflow) 
    : 999;

  return {
    netFlow: `${netFlow >= 0 ? '+' : '-'}${umsgToMsg(BigInt(Math.abs(netFlow)))} MSG`,
    burnRate: `${(operationalRatio * 100).toFixed(1)}%`,
    grantApprovalRate: `${(grantApprovalRate * 100).toFixed(1)}%`,
    grantEfficiency: `${(grantEfficiency * 100).toFixed(1)}%`,
    operationalRatio: `${(operationalRatio * 100).toFixed(1)}%`,
    runwayMonths,
  };
}

9.6 二次方投票可能性

dao_governance_v1 合约支持可配置的投票策略,二次方投票 (Quadratic Voting) 是一个可能的升级方向:

二次方投票公式:
  投票权重 = (持有 MSG 数量)^0.5

示例:
  持有 1 MSG → 1 票
  持有 100 MSG → 10 票
  持有 10,000 MSG → 100 票
  持有 1,000,000 MSG → 1,000 票

传统投票:
  持有 1 MSG → 1 票
  持有 1,000,000 MSG → 1,000,000 票

二次方投票的优势:
  - 减少大户投票权过大的问题
  - 增加小户参与治理的激励
  - 更准确地反映社区意愿

10. 经济安全

10.1 攻击成本分析

33% 攻击成本

在 PoS 网络中,控制 33%+ 的质押量可以中断网络 (阻止最终性)。

攻击成本公式:
  AttackCost = 质押量 × 市场价格 + 机会成本

假设:
  流通量: 550,000,000 MSG (第1年末)
  质押率: 45% = 247,500,000 MSG 质押
  33% 攻击阈值: 247,500,000 × 33% = 81,675,000 MSG
  MSG 价格: $0.10 (假设)

直接成本:
  购买 81,675,000 MSG = $8,167,500
  通过 DEX 购买会产生滑点和价格冲击 (估计 +20%)
  实际成本: ~$9,801,000

机会成本:
  被攻击期间无法获得质押奖励
  预期 APR: 13.5%
  每天机会成本: 81,675,000 × 13.5% / 365 × $0.10 = $3,020/天
  攻击持续 7 天: $21,140

总攻击成本: ~$9,822,140

与其他 L1 对比

指标 MSG Chain Cosmos Hub Ethereum Solana
攻击阈值质押量 81.7M MSG ~90M ATOM ~18M ETH ~110M SOL
预估攻击成本 ~$9.8M ~$90M ~$45B ~$15B
Slashing 惩罚 5-10% (规划中) 5% 最高 100% 最高 100%
攻击后恢复 经济惩罚 + 社交共识 社交共识 Social Slashing 社交共识
后量子安全 ✅ Dilithium-5 ❌ Secp256k1 ❌ Secp256k1 ❌ Ed25519

10.2 Slashing 条件

Slashing 模块当前处于规划阶段,预期设计如下:

违规行为 惩罚比例 说明
双签 (Double Sign) 5% 质押量 + 监禁 同一高度签名两个不同区块
长时间离线 0.01% + 监禁 连续 24 小时不出块
DAR 评分过低 0.1% + 降低出块权 评分低于阈值
恶意治理行为 社区投票决定 如提案攻击

Slashing 对 APR 的影响:

验证者被 Slash 后的 APR 变化:

假设:
  验证者 A 总质押: 100,000,000 MSG
  Slashing 惩罚: 5%
  惩罚金额: 5,000,000 MSG

首次 Slashing:
  委托者损失: 5% × 每个委托者余额
  影响: 严重的信誉损失 → 委托人重新委托

预防措施:
  - TMKMS 远程签名 (防止双签)
  - 哨兵节点架构 (防止 DDoS 离线)
  - 多验证者实例 (分散风险)

10.3 DAR 评分经济激励

DAR (Dilithium-AR) 评分系统影响出块概率:

出块概率 = (质押权重 × DAR 评分系数) / Σ(所有验证者质押权重 × DAR 评分系数)

DAR 评分因子:
  - 出块参与率 (40%): 实际出块 / 应出块
  - 签名及时性 (25%): 预投票/预提交延迟中位数
  - 网络质量 (20%): 对等节点数量与连接稳定性
  - 历史表现 (15%): 评分趋势与改进

经济激励示例:

验证者 A (高评分, DAR=1.0):
  质押: 100,000,000 MSG (10% 权重)
  有效权重: 100,000,000 × 1.0 = 100,000,000
  出块概率: ~10% (按质押比例)
  年预期收入: 100M × 13.5% × 10% = 1,350,000 MSG (实际可能会更高)

验证者 B (低评分, DAR=0.7):
  质押: 100,000,000 MSG (10% 权重)
  有效权重: 100,000,000 × 0.7 = 70,000,000
  出块概率: ~7%
  年预期收入: 100M × 13.5% × 7% = 945,000 MSG

差异: 高评分验证者收入多 42.8%!

10.4 保险基金

保险基金用于覆盖 Slashing 事故造成的委托者损失:

保险基金来源:
  - Gas 费分配的 10% 销毁 → 可部分转为保险基金
  - 验证者自愿存入保费
  - 基金会初始拨款

保险运作方式:
  委托者可选支付 0.1% 保费 → 获得 Slashing 保障
  被 Slash 时基金赔付 80% 损失
  基金余额不足时按比例赔付

保险基金预估规模:
  第1年: 2,000,000 MSG (从 Gas 费和 grant 中拨付)
  第2年: 5,000,000 MSG
  第3年: 10,000,000 MSG

10.5 经济安全总结

MSG Chain 经济安全依赖于:

1. 质押规模
   ├── 总质押价值越大, 攻击成本越高
   └── 目标质押率: 66.67%

2. DAR 评分
   ├── 激励验证者保持高质量服务
   └── 提高网络整体可靠性

3. Dilithium-5 后量子签名
   ├── 抵抗量子计算攻击
   └── 长期安全性保障

4. 未来 Slashing 机制
   └── 惩罚恶意行为, 保护委托者

5. 治理保障
   ├── 社区监督
   └── 参数可通过治理调整

11. 代币操作指南

11.1 查询余额

# CLI 查询
./build/msgd query bank balances $(./build/msgd keys show mywallet -a --keyring-backend os) \
  --node tcp://localhost:26657 -o json

# 输出:
# {
#   "balances": [
#     {
#       "denom": "umsg",
#       "amount": "10000000000000000000"
#     }
#   ],
#   "pagination": {"total": "1"}
# }
# 说明: 余额 10 MSG

# REST API
curl -s http://localhost:1317/cosmos/bank/v1beta1/balances/msg1... | jq

# Tendermint RPC
curl -s http://localhost:26657/abci_query \
  --data-urlencode "path=\"/cosmos.bank.v1beta1.Query/Balance\"" \
  --data-urlencode 'data={"address":"msg1...","denom":"umsg"}' | jq

11.2 转账

# 基本转账
./build/msgd tx bank send \
  mywallet \
  msg1destination_address... \
  500000000000000000umsg \ # 0.5 MSG
  --gas auto \
  --gas-prices 1000000000attoMSG \
  --gas-adjustment 1.3 \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 使用不同 Gas 优先级
# Low:
--gas-prices 1000000000attoMSG

# Average (默认):
--gas-prices 1000000000attoMSG

# High:
--gas-prices 1000000000attoMSG

# 离线签名 (安全环境)
./build/msgd tx bank send \
  mywallet msg1destination... 500000000000000000umsg \
  --generate-only \
  --chain-id msg-chain-1 \
  > unsigned_tx.json

# 签名
./build/msgd tx sign unsigned_tx.json \
  --from mywallet \
  --keyring-backend os \
  --chain-id msg-chain-1 \
  > signed_tx.json

# 广播
./build/msgd tx broadcast signed_tx.json \
  --node tcp://localhost:26657

11.3 代币操作 (JavaScript)

import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import { fromBase64, toBase64 } from "@cosmjs/encoding";

const RPC_ENDPOINT = "http://localhost:26657";
const CHAIN_ID = "msg-chain-1";
const GAS_PRICE = GasPrice.fromString("1000000000attoMSG");

/**
 * 创建签名客户端
 */
async function createClient(mnemonic: string) {
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
    prefix: "msg",
    hdPaths: [makeCosmsPath(118, 0, 0, 0)], // CoinType 118
  });
  return SigningCosmWasmClient.connectWithSigner(RPC_ENDPOINT, wallet, {
    gasPrice: GAS_PRICE,
  });
}

/**
 * 查询余额
 */
async function getBalance(client: SigningCosmWasmClient, address: string) {
  const balance = await client.getBalance(address, "umsg");
  return {
    umsg: balance.amount,
    msg: umsgToMsg(BigInt(balance.amount), 6),
  };
}

/**
 * 转账 MSG
 */
async function sendTokens(
  client: SigningCosmWasmClient,
  sender: string,
  recipient: string,
  amountMsg: string, // 例如 "10.5"
) {
  const amountUmsg = msgToUmsg(amountMsg);
  const result = await client.sendTokens(
    sender,
    recipient,
    [{ denom: "umsg", amount: amountUmsg }],
    "auto",
  );
  return result.transactionHash;
}

/**
 * 查询排放数据 (通过 emission_schedule_v2)
 */
async function queryEmissionSchedule(
  client: CosmWasmClient,
  contractAddr: string,
) {
  const current = await client.queryContractSmart(contractAddr, {
    get_current_emission: {},
  });
  return {
    blocksPerYear: Number(current.blocks_per_year),
    emissionPerBlock: current.emission_per_block.toString(),
    inflationRate: Number(current.inflation_rate),
    lastUpdateHeight: Number(current.last_update_height),
  };
}

/**
 * 查询质押奖励
 */
async function queryStakingRewards(
  client: CosmWasmClient,
  delegatorAddr: string,
) {
  const rewards = await client.queryContractSmart(
    "msg1...candidate_node_staking", // staking 合约地址
    {
      get_delegator_rewards: {
        delegator: delegatorAddr,
      },
    },
  );
  return rewards;
}

// 使用示例
async function main() {
  const mnemonic = "word1 word2 ... word24"; // 24 个助记词
  const client = await createClient(mnemonic);
  const [account] = await client.getAccounts();

  // 查询余额
  const balance = await getBalance(client, account.address);
  console.log(`余额: ${balance.msg} MSG`);

  // 转账
  const txHash = await sendTokens(client, account.address, "msg1dest...", "1.5");
  console.log(`转账完成: ${txHash}`);

  // 查询排放
  const emissionContract = "msg1...emission_schedule_contract_address...";
  const emission = await queryEmissionSchedule(client as any, emissionContract);
  console.log(`当前通胀率: ${(emission.inflationRate * 100).toFixed(2)}%`);
}

11.4 质押与委托操作

# 查询验证者列表
./build/msgd query staking validators --node tcp://localhost:26657 -o json \
  | jq '.validators[] | {moniker: .description.moniker, tokens: .tokens, commission: .commission.commission_rates.rate}'

# 委托给验证者
./build/msgd tx staking delegate \
  msgvaloper1qypqxpq9kcrn2c9afea5lq35ef37c5x7xyzabc \
  1000000000000000000000umsg \  # 1,000 MSG
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --gas-adjustment 1.3 \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 查询我的所有委托
./build/msgd query staking delegations \
  $(./build/msgd keys show mywallet -a --keyring-backend os) \
  --node tcp://localhost:26657 -o json

# 解委托 (21天等待)
./build/msgd tx staking unbond \
  msgvaloper1qypqxpq9kcrn2c9afea5lq35ef37c5x7xyzabc \
  500000000000000000000umsg \  # 500 MSG
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 重新委托 (立即转移,无等待期)
./build/msgd tx staking redelegate \
  msgvaloper1old_validator... \
  msgvaloper1new_validator... \
  300000000000000000000umsg \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 领取奖励
./build/msgd tx distribution withdraw-all-rewards \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 查询历史奖励
./build/msgd query distribution rewards \
  $(./build/msgd keys show mywallet -a --keyring-backend os) \
  --node tcp://localhost:26657 -o json

# 设置提现地址 (奖励自动转至该地址)
./build/msgd tx distribution set-withdraw-addr \
  msg1new_withdraw_address... \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

11.5 治理操作

# 查询治理提案列表
./build/msgd query gov proposals --node tcp://localhost:26657 -o json

# 查询单个提案
./build/msgd query gov proposal 1 --node tcp://localhost:26657 -o json

# 投票 (Yes / No / Abstain / NoWithVeto)
./build/msgd tx gov vote 1 Yes \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 提交文本提案 (需要 1,000 MSG 保证金)
./build/msgd tx gov submit-proposal \
  --title "示例提案" \
  --description "这是提案描述" \
  --type Text \
  --deposit 1000000000000000000000umsg \  # 1,000 MSG
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

# 查询我的投票
./build/msgd query gov vote 1 \
  $(./build/msgd keys show mywallet -a --keyring-backend os) \
  --node tcp://localhost:26657 -o json

# 查询投票结果统计
./build/msgd query gov tally 1 --node tcp://localhost:26657 -o json

11.6 CW20 代币操作 (msg_token_cw20)

# 查询 CW20 代币信息
curl -X POST http://localhost:26657/cosmwasm.wasm.v1.Query/SmartContractState \
  -H "Content-Type: application/json" \
  -d '{
    "address": "msg1...cw20_contract",
    "query_data": "'$(echo -n '{"token_info":{}}' | base64 -w0)'"
  }' | jq

# 查询 CW20 余额
curl -X POST http://localhost:26657/cosmwasm.wasm.v1.Query/SmartContractState \
  -H "Content-Type: application/json" \
  -d '{
    "address": "msg1...cw20_contract",
    "query_data": "'$(echo -n '{"balance":{"address":"msg1..."}}' | base64 -w0)'"
  }' | jq

# 转账 CW20 (通过 CosmWasm execute)
./build/msgd tx wasm execute \
  msg1...cw20_contract \
  '{"transfer":{"recipient":"msg1dest...","amount":"1000000000000000000"}}' \
  --from mywallet \
  --gas auto --gas-prices 1000000000attoMSG \
  --chain-id msg-chain-1 \
  --keyring-backend os -y

11.7 查询排放与供应量

# 解析 emission_schedule 合约地址
EMISSION_ADDR=$(./build/msgd query registry resolve emission_schedule \
  --node tcp://localhost:26657 -o json | jq -r '.address')

# 查询当前排放
./build/msgd query wasm contract-state smart "$EMISSION_ADDR" \
  '{"get_current_emission":{}}' \
  --node tcp://localhost:26657 -o json

# 输出:
# {"data":{
#   "blocks_per_year":"6307200",
#   "emission_per_block":"15854994935561943000",
#   "inflation_rate":"0.1",
#   "last_update_height":"100000"
# }}

# 查询排放计划
./build/msgd query wasm contract-state smart "$EMISSION_ADDR" \
  '{"get_emission_schedule":{}}' \
  --node tcp://localhost:26657 -o json

# 查询总排放量
./build/msgd query wasm contract-state smart "$EMISSION_ADDR" \
  '{"get_total_emitted":{}}' \
  --node tcp://localhost:26657 -o json

# 查询剩余排放
./build/msgd query wasm contract-state smart "$EMISSION_ADDR" \
  '{"get_remaining_emission":{}}' \
  --node tcp://localhost:26657 -o json

# 查询 staking pool (总质押量)
./build/msgd query staking pool --node tcp://localhost:26657 -o json

# 查询总供应量 (银行模块)
./build/msgd query bank total --node tcp://localhost:26657 -o json

# 通过 REST API
curl -s http://localhost:1317/cosmos/bank/v1beta1/supply/umsg | jq
curl -s http://localhost:1317/api/v1/emission/rate | jq

11.8 一键收益复利脚本

#!/bin/bash
# auto_compound.sh — 自动化领取奖励并重新委托
# 建议每 7 天运行一次 (crontab)

set -e

KEY_NAME=${1:-"mywallet"}
VALIDATOR=${2:-"msgvaloper1..."}  # 目标验证者地址
CHAIN_ID="msg-chain-1"
NODE="tcp://localhost:26657"
GAS_PRICES="1000000000attoMSG"
GAS_ADJUSTMENT="1.5"

DELEGATOR_ADDR=$(./build/msgd keys show "$KEY_NAME" -a --keyring-backend os)
echo "委托者地址: $DELEGATOR_ADDR"
echo "目标验证者: $VALIDATOR"

# 1. 查询待领取奖励
echo "--- 查询奖励 ---"
REWARDS=$(./build/msgd query distribution rewards "$DELEGATOR_ADDR" \
  --node "$NODE" -o json | jq -r '.total[] | select(.denom=="umsg") | .amount')
echo "待领取奖励: $(echo "scale=6; $REWARDS / 10^18" | bc) MSG"

# 2. 领取所有奖励
echo "--- 领取奖励 ---"
./build/msgd tx distribution withdraw-all-rewards \
  --from "$KEY_NAME" \
  --gas auto --gas-prices "$GAS_PRICES" \
  --gas-adjustment "$GAS_ADJUSTMENT" \
  --chain-id "$CHAIN_ID" \
  --keyring-backend os \
  --node "$NODE" -y | jq '.txhash'

# 等待交易确认
sleep 5

# 3. 查询领取后的余额
BALANCE=$(./build/msgd query bank balances "$DELEGATOR_ADDR" \
  --node "$NODE" -o json | jq -r '.balances[] | select(.denom=="umsg") | .amount')
echo "当前余额: $(echo "scale=6; $BALANCE / 10^18" | bc) MSG"

# 4. 将余额重新委托 (预留少许作为 Gas 费)
DELEGATE_AMOUNT=$(echo "$BALANCE - 1000000000000000000" | bc)  # 留 1 MSG 作 Gas
if [ "$(echo "$DELEGATE_AMOUNT > 0" | bc)" -eq 1 ]; then
  echo "--- 重新委托 $DELEGATE_AMOUNT umsg ---"
  ./build/msgd tx staking delegate \
    "$VALIDATOR" \
    "${DELEGATE_AMOUNT}umsg" \
    --from "$KEY_NAME" \
    --gas auto --gas-prices "$GAS_PRICES" \
    --gas-adjustment "$GAS_ADJUSTMENT" \
    --chain-id "$CHAIN_ID" \
    --keyring-backend os \
    --node "$NODE" -y | jq '.txhash'
fi

echo "--- 复利完成 ---"

# crontab 每周运行:
# 0 9 * * 1 /bin/bash /home/user/auto_compound.sh mywallet msgvaloper1...

11.9 批量代币发送工具

// batch_send.ts — 批量 MSG 发送
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";

interface Transfer {
  recipient: string;
  amount: string; // MSG 数量
}

async function batchSend(
  mnemonic: string,
  transfers: Transfer[],
): Promise<string[]> {
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
    prefix: "msg",
  });
  const client = await SigningCosmWasmClient.connectWithSigner(
    "http://localhost:26657",
    wallet,
    { gasPrice: { denom: "umsg", amount: "1000000000" } },
  );
  const [account] = await client.getAccounts();
  const txHashes: string[] = [];

  for (const { recipient, amount } of transfers) {
    const umsgAmount = msgToUmsg(amount);
    const result = await client.sendTokens(
      account.address,
      recipient,
      [{ denom: "umsg", amount: umsgAmount }],
      "auto",
    );
    txHashes.push(result.transactionHash);
    console.log(`发送 ${amount} MSG → ${recipient}: ${result.transactionHash}`);
  }

  return txHashes;
}

// 使用示例
batchSend("your mnemonic phrase here", [
  { recipient: "msg1addr1...", amount: "10" },
  { recipient: "msg1addr2...", amount: "25.5" },
  { recipient: "msg1addr3...", amount: "100" },
]);

12. 附录:数学公式与代码

12.1 核心公式总结

1. 每区块排放:
   E_block = (S_total × I_annual) / B_year
   其中: S_total = 总供应量, I_annual = 年通胀率, B_year = 年区块数 (6,307,200)

2. 动态通胀率:
   if R_actual >= R_target:
       I_new = max(I_min, I_old - ΔI)
   else:
       I_new = min(I_max, I_old + ΔI)
   其中: R_target = 66.67%, ΔI = 0.5%, I_min = 3%, I_max = 20%

3. 质押 APR:
   APR_staking = E_annual / S_staked × (1 - C_rate)
   其中: E_annual = 年排放量, S_staked = 总质押量, C_rate = 佣金率

4. 复利终值:
   A = P × (1 + r/n)^(n×t)
   其中: P = 本金, r = APR, n = 复利频率, t = 年数

5. Gas 费:
   Fee = Gas_limit × Gas_price
   分配: 40% 验证者 + 30% 金库 + 20% 开发者 + 10% 销毁

6. 出块概率 (DAR 加权):
   P(i) = (W_i × D_i) / Σ(W_j × D_j)
   其中: W_i = 质押权重, D_i = DAR 评分

12.2 单位换算速查

数量 umsg MSG
1 umsg 1 0.000000000000000001
1,000 umsg 10^3 0.000000000000001
1,000,000 umsg 10^6 0.000000000001
1 Gumsg 10^9 0.000000001
1 Tumsg 10^12 0.000001
1 Pumsg 10^15 0.001
1 MSG 10^18 1
1,000 MSG 10^21 1,000
1,000,000 MSG 10^24 1,000,000

12.3 年化排放计算器

/// 完整年化排放表生成器
fn generate_emission_table(
    genesis_supply: Uint128,
    initial_inflation: Decimal,
    inflation_change: Decimal,
    min_inflation: Decimal,
    max_inflation: Decimal,
    years: u32,
) -> Vec<YearData> {
    let mut supply = genesis_supply;
    let mut inflation = initial_inflation;
    let mut table = Vec::new();

    table.push(YearData {
        year: 0,
        supply,
        inflation: Decimal::zero(),
        emission: Uint128::zero(),
        note: "Genesis".to_string(),
    });

    for year in 1..=years {
        let emission = supply * inflation;
        supply += emission;
        
        // 计算下一年通胀率
        if inflation > min_inflation {
            inflation = inflation - inflation_change;
            if inflation < min_inflation {
                inflation = min_inflation;
            }
        }

        table.push(YearData {
            year,
            supply,
            inflation,
            emission,
            note: format!("Year {}", year),
        });
    }

    table
}

#[derive(Debug)]
struct YearData {
    year: u32,
    supply: Uint128,
    inflation: Decimal,
    emission: Uint128,
    note: String,
}

12.4 区块时间与出块数据

年区块数计算:
  365.25 天 × 24 小时 × 3600 秒 / 5 秒 = 6,307,200 blocks/year

日区块数:
  24 × 3600 / 5 = 17,280 blocks/day

时区块数:
  3600 / 5 = 720 blocks/hour

月区块数 (平均):
  6,307,200 / 12 = 525,600 blocks/month

每区块排放 (第1年, 10% 通胀):
  100,000,000 MSG / 6,307,200 blocks = 15.8550 MSG/block

每秒排放:
  15.8550 / 5 = 3.171 MSG/second

12.5 术语表

术语 英文 定义
MSG MSG Token MSG Chain 原生代币,18位精度
umsg Micro MSG MSG 的最小单位,1 MSG = 10^18 umsg
Staking Staking 质押 MSG 以保护网络并获得奖励
APR Annual Percentage Rate 年化收益率
Unbonding Period Unbonding Period 解委托后的等待时间 (21天)
Emission Token Emission 通过区块奖励发行新代币
Inflation Inflation Rate 年通胀率 (3-20%)
DAR Dilithium-AR 基于 Dilithium 的共识评分系统
Slashing Slashing 对违规验证者的质押惩罚
Validator Validator 负责生产区块的节点
Delegator Delegator 委托 MSG 给验证者的用户
Commission Commission 验证者从奖励中抽取的比例
AIPAY AI Payment 专为 AI Agent 设计的支付标准
Micropayment Micropayment Channel 链下微支付通道,按秒计费
Genesis Genesis 链的初始状态(创世区块)
Cliff Cliff Period 锁仓后首次释放的等待期
Vesting Vesting 代币线性释放过程
Quorum Quorum 治理投票的法定参与率
Threshold Threshold 治理投票的通过阈值

版本历史

版本 日期 变更内容
v1.0.0 2026-07-05 初版发布,涵盖完整代币经济模型

本文档基于 MSG Chain 代码库核实的技术事实。
白皮书系统: https://msgchain.org/whitepaper/