# DAIX.fun 开发者接入标准 v2.0

> 📅 **标准生效日期**：2026-06-29
> 🔗 **维护者**：CONVNET 团队
> 📋 **版本**：v2.0

---

## 目录

1. [系统架构概览](#1-系统架构概览)
2. [智能合约一览](#2-智能合约一览)
3. [角色与权限](#3-角色与权限)
4. [开发者注册流程](#4-开发者注册流程)
5. [应用发布标准](#5-应用发布标准)
6. [推广者系统](#6-推广者系统)
7. [用户购买与激活](#7-用户购买与激活)
8. [收益分配机制](#8-收益分配机制)
9. [APP 端集成指南](#9-app-端集成指南)
10. [APK 上传规范](#10-apk-上传规范)
11. [链上数据结构](#11-链上数据结构)
12. [完整 ABI 参考](#12-完整-abi-参考)
13. [安全与合规](#13-安全与合规)

---

## 1. 系统架构概览

```
┌─────────────────────────────────────────────────────────────────┐
│                       DAIX.fun 系统架构                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐                     │
│  │ 开发者    │  │ 推广者    │  │ 终端用户  │                     │
│  │ Developer │  │ Promoter │  │  User    │                     │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘                     │
│       │              │              │                           │
│       ▼              ▼              ▼                           │
│  ┌──────────────────────────────────────────┐                  │
│  │          daix.fun Web 前端               │                  │
│  │  钱包连接 │ 注册 │ 发布 │ 浏览 │ 购买    │                  │
│  └──────────────────┬───────────────────────┘                  │
│                     │ ethers.js                                 │
│                     ▼                                           │
│  ┌──────────────────────────────────────────┐                  │
│  │           Polygon 主网 (Chain ID: 137)   │                  │
│  │                                          │                  │
│  │  ┌────────────────┐ ┌────────────────┐  │                  │
│  │  │DeveloperRegistry│ │ AppRegistry    │  │                  │
│  │  │  开发者注册      │ │  APP注册管理   │  │                  │
│  │  └────────────────┘ └────────────────┘  │                  │
│  │                                          │                  │
│  │  ┌────────────────┐ ┌────────────────┐  │                  │
│  │  │  LicenseNFT    │ │PromoterRegistry│  │                  │
│  │  │  激活码NFT      │ │  推广者注册     │  │                  │
│  │  └────────────────┘ └────────────────┘  │                  │
│  │                                          │                  │
│  │  ┌────────────────┐ ┌────────────────┐  │                  │
│  │  │ LicenseQuery   │ │  RevenueSplit  │  │                  │
│  │  │  查询工具合约    │ │  二级市场版税   │  │                  │
│  │  └────────────────┘ └────────────────┘  │                  │
│  └──────────────────────────────────────────┘                  │
│                     │                                           │
│       ┌─────────────┼─────────────┐                            │
│       ▼             ▼             ▼                             │
│  ┌─────────┐  ┌──────────┐  ┌──────────┐                      │
│  │  USDC   │  │   POL    │  │   IPFS   │                      │
│  │  支付    │  │  Gas费   │  │  APK存储  │                      │
│  └─────────┘  └──────────┘  └──────────┘                      │
└─────────────────────────────────────────────────────────────────┘
```

---

## 2. 智能合约一览

所有合约部署在 **Polygon 主网**（Chain ID: 137）。

| 合约 | 地址 | 职责 |
|------|------|------|
| DeveloperRegistry | `0x8EE775e943C31EA7c4eF2B7bb83e0651c9d04001` | 开发者身份注册 |
| AppRegistry | `0xdFCFA7d871cCc3674d873d00192Ba26a685B2b68` | APP 元数据管理 |
| LicenseNFT | `0x7Ed65226C66b188f66AA0e5483917B1C33a41225` | 激活码 NFT（ERC-721） |
| PromoterRegistry | `0xeed4653f341F810e00A73c6ECD454a1205C0Cabb` | 推广者注册管理 |
| LicenseQuery | `0xb36Fd748026097e0F18A644452E739DECf4d0686` | 链上查询工具 |
| RevenueSplit | `0x698c00CD9e94353C6ef804e670bc558108250f9D` | 二级市场版税 |
| USDC | `0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359` | 支付代币 |

### 合约依赖关系

```
DeveloperRegistry ◄── AppRegistry（验证开发者身份）
        │
        ▼
   AppRegistry ◄── LicenseNFT（验证APP信息、获取价格）
                        │
                        ▼
                  LicenseQuery（查询NFT持有状态）
                  PromoterRegistry（验证推广者身份）
                  RevenueSplit（二级市场版税计算）
```

---

## 3. 角色与权限

DAIX.fun 生态中有三个核心角色：

### 3.1 开发者（Developer）

- **职责**：开发并发布 Android APP
- **权限**：注册开发者身份、发布APP、更新APP信息、查看收益
- **注册**：通过 DeveloperRegistry 合约免费注册
- **收益**：每次购买获得 APP 售价的 **60%**（无推广者时为 **85%**）

### 3.2 推广者（Promoter / Agent）

- **职责**：推广 APP，通过专属链接引导用户购买
- **权限**：注册推广者身份、生成推广链接、查看推广收益
- **注册**：通过 PromoterRegistry 合约免费注册
- **收益**：每次通过推广链接购买获得 APP 售价的 **25%**

### 3.3 终端用户（User）

- **职责**：购买并使用 APP
- **权限**：浏览APP、购买激活码 NFT、在 APP 内激活
- **流程**：连接钱包 → 浏览APP → 支付 USDC → 获得 NFT → 在 APP 内激活

### 角色关系图

```
开发者 ──发布──▶ APP
                  │
推广者 ──推广──▶ 专属链接 (?agent=0x...)
                  │
用户 ──购买──▶ LicenseNFT ──分账──▶ 开发者 60%
                  │                    推广者 25%
                  │                    平台   10%
                  │                    Gas    5%
                  ▼
            APP 内激活（链上验证）
```

---

## 4. 开发者注册流程

### 4.1 前置条件

- ✅ Polygon 兼容钱包（MetaMask / WalletConnect）
- ✅ 钱包内有少量 POL（Gas 费，约 0.01 POL）
- ✅ 准备好开发者名称

### 4.2 通过 daix.fun 网页注册

```
1. 访问 https://daix.fun
2. 点击「🔗 连接钱包」→ 授权连接
3. 点击「👨‍💻 成为创作者」
4. 填写创作者名称（如 "CONVNET"）
5. 点击「注册创作者」→ 钱包弹窗确认交易
6. 等待链上确认（约 10-30 秒）
7. ✅ 注册完成，可立即发布应用
```

### 4.3 通过合约直接调用

```javascript
// ethers.js v6
const devRegistry = new ethers.Contract(
  "0x8EE775e943C31EA7c4eF2B7bb83e0651c9d04001",
  [
    "function register(string name, string metadataURI) external",
    "function isRegistered(address) view returns (bool)",
    "function getDeveloper(address) view returns (string name, string metadataURI, uint256 registeredAt, bool active)",
    "function developerCount() view returns (uint256)"
  ],
  signer
);

// 检查是否已注册
const isReg = await devRegistry.isRegistered(walletAddress);
if (!isReg) {
  const tx = await devRegistry.register("My Studio", "ipfs://QmMetadata...");
  await tx.wait();
}
```

### 4.4 注册后可做的事

| 操作 | 合约 | 说明 |
|------|------|------|
| 发布 APP | AppRegistry | 需先注册开发者 |
| 更新资料 | DeveloperRegistry | 更新名称和元数据 URI |
| 查看我的 APP | LicenseQuery | 查询自己发布的所有 APP |
| 查看收益 | USDC.balanceOf | 查询钱包 USDC 余额 |

---

## 5. 应用发布标准

### 5.1 应用信息规范

| 字段 | 类型 | 必填 | 说明 | 示例 |
|------|------|------|------|------|
| `name` | string | ✅ | 应用展示名称，≤64 字符 | `"VIP迎宾"` |
| `packageName` | string | ✅ | Android 包名，全局唯一 | `"com.storeguard.vipreception"` |
| `description` | string | ✅ | 应用描述，≤256 字符 | `"VIP客户到店自动识别"` |
| `apkURI` | string | ✅ | APK 下载地址（IPFS 或 HTTP） | `"https://daix.fun/apk/..."` |
| `iconURI` | string | ✅ | 应用图标地址 | `"https://daix.fun/icons/..."` |
| `price` | uint256 | ✅ | 价格（USDC，6位小数） | `198000000`（= 198 USDC） |
| `trialDays` | uint256 | ✅ | 免费试用天数（≥1） | `7` |
| `version` | string | ✅ | 版本号 | `"v1.0.0"` |

### 5.2 发布步骤

```javascript
const appRegistry = new ethers.Contract(
  "0xdFCFA7d871cCc3674d873d00192Ba26a685B2b68",
  [
    "function registerApp(string name, string packageName, string description, string apkURI, string iconURI, uint256 price, uint256 trialDays, string version) external returns (uint256)",
    "function updateApp(uint256 appId, string version, string apkURI, uint256 price) external",
    "function deactivateApp(uint256 appId) external",
    "function getDeveloperApps(address dev) view returns (uint256[])"
  ],
  signer
);

// 发布新 APP
const tx = await appRegistry.registerApp(
  "VIP迎宾",                                    // name
  "com.storeguard.vipreception",                // packageName
  "VIP客户到店自动识别，店员第一时间迎接",        // description
  "https://daix.fun/apk/storeguard-v1.apk",     // apkURI
  "https://daix.fun/icons/storeguard.png",       // iconURI
  ethers.parseUnits("198", 6),                  // price = 198 USDC
  7,                                             // trialDays
  "v1.0.0"                                       // version
);
const receipt = await tx.wait();
console.log("发布成功！APP ID:", receipt.logs[0].args.appId);
```

### 5.3 更新已发布的 APP

```javascript
// 更新版本和价格
await appRegistry.updateApp(
  appId,
  "v1.1.0",                                     // 新版本号
  "https://daix.fun/apk/storeguard-v1.1.apk",   // 新 APK 地址
  ethers.parseUnits("168", 6)                    // 新价格 168 USDC
);
```

### 5.4 下架 APP

```javascript
// 下架（不可逆）
await appRegistry.deactivateApp(appId);
```

### 5.5 查询 APP 信息

```javascript
// 查询单个 APP
const app = await appRegistry.getApp(appId);
console.log("APP:", app.name, app.packageName, ethers.formatUnits(app.price, 6), "USDC");

// 查询我的所有 APP
const myApps = await appRegistry.getDeveloperApps(myAddress);
console.log("我的 APP 数量:", myApps.length);

// 查询所有已上架 APP
const activeApps = await appRegistry.getActiveApps();
```

---

## 6. 推广者系统

### 6.1 推广者注册

推广者通过专属推广链接引导用户购买，每次成功购买获得 **25%** 的佣金。

```javascript
const promoterRegistry = new ethers.Contract(
  "0xeed4653f341F810e00A73c6ECD454a1205C0Cabb",
  [
    "function register(string name, string referralCode) external",
    "function isPromoter(address) view returns (bool)",
    "function getPromoter(address) view returns (string name, string referralCode, uint256 registeredAt, bool active)",
    "function getByCode(string code) view returns (address)"
  ],
  signer
);

// 注册推广者
const tx = await promoterRegistry.register("推广达人", "PROMO2026");
await tx.wait();
```

### 6.2 推广链接格式

推广者生成专属链接分享给用户：

```
https://daix.fun/?agent=0x推广者钱包地址
```

**示例：**
```
https://daix.fun/?agent=0x1Bcb3a35B2aD5f83E4382ba5DaB34D00c2037004
```

### 6.3 推广流程

```
推广者分享链接 → 用户点击打开 → 前端解析 ?agent= 参数
        ↓
用户连接钱包 → 浏览APP → 选择购买
        ↓
前端调用 LicenseNFT.mintLicense(appId, agentAddress)
        ↓
合约自动分账：
  开发者: 60% → app.developer
  推广者: 25% → agentAddress
  平台:   10% → platformWallet
  Gas:     5% → gasWallet
```

### 6.4 推广者查询

```javascript
// 检查是否已注册
const isPromoter = await promoterRegistry.isPromoter(myAddress);

// 获取推广者信息
const [name, code, registeredAt, active] = await promoterRegistry.getPromoter(myAddress);

// 通过推广码查地址
const promoterAddr = await promoterRegistry.getByCode("PROMO2026");
```

### 6.5 推广收益计算

```javascript
// 用户通过推广链接购买 198 USDC 的 APP
const price = 198; // USDC
const devShare  = price * 0.60;  // 118.8 USDC → 开发者
const promoShare = price * 0.25; // 49.5 USDC → 推广者
const platformShare = price * 0.10; // 19.8 USDC → 平台
const gasShare  = price * 0.05;  // 9.9 USDC → Gas
```

---

## 7. 用户购买与激活

### 7.1 购买流程（Web 端）

```
1. 用户访问 https://daix.fun
2. 连接钱包（MetaMask / WalletConnect）
3. 浏览 APP 列表（从链上 AppRegistry 读取）
4. 选择要购买的 APP → 点击「购买」
5. 前端自动执行：
   a. 检查 USDC 余额是否足够
   b. 调用 USDC.approve(LicenseNFT, price) 授权
   c. 调用 LicenseNFT.mintLicense(appId, agent)
6. 钱包弹窗确认交易
7. 等待链上确认（约 10-30 秒）
8. ✅ 获得 License NFT（tokenId）
```

### 7.2 购买代码示例

```javascript
// Step 1: 授权 USDC
const usdc = new ethers.Contract(
  "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
  ["function approve(address spender, uint256 amount) returns (bool)",
   "function allowance(address owner, address spender) view returns (uint256)",
   "function balanceOf(address account) view returns (uint256)"],
  signer
);

const price = ethers.parseUnits("198", 6);
const allowance = await usdc.allowance(myAddress, LICENSE_NFT);
if (allowance < price) {
  const approveTx = await usdc.approve(LICENSE_NFT, price);
  await approveTx.wait();
}

// Step 2: 购买 NFT
const licenseNFT = new ethers.Contract(
  "0x7Ed65226C66b188f66AA0e5483917B1C33a41225",
  ["function mintLicense(uint256 appId, address agent) returns (uint256)"],
  signer
);

// 有推广者时传推广者地址，无推广者时传 address(0)
const agentAddress = referrerAddress || "0x0000000000000000000000000000000000000000";
const tx = await licenseNFT.mintLicense(appId, agentAddress);
const receipt = await tx.wait();
console.log("购买成功！Token ID:", receipt.logs[0].args.tokenId);
```

### 7.3 APP 内激活

用户购买 NFT 后，在 APP 内通过钱包验证激活：

```javascript
// Step 1: 导入钱包（APP 内）
const wallet = new Web3LicenseManager(context, "com.storeguard.vipreception");
wallet.importWallet(privateKey);

// Step 2: 验证 NFT
wallet.verifyLicense((verified, message, appId) => {
  if (verified) {
    // ✅ 激活成功，解锁全部功能
    unlockApp();
  } else {
    // ❌ 未持有 NFT，引导购买
    showPurchaseGuide();
  }
});
```

### 7.4 查询我的许可证

```javascript
const query = new ethers.Contract(
  "0xb36Fd748026097e0F18A644452E739DECf4d0686",
  ["function getUserLicenses(address user) view returns (uint256[] tokenIds, uint256[] appIds)",
   "function verifyLicense(address user, uint256 appId) view returns (bool hasLicense, uint256 tokenId)"],
  provider
);

// 查询我拥有的所有许可证
const [tokenIds, appIds] = await query.getUserLicenses(myAddress);
console.log("我拥有", tokenIds.length, "个许可证");

// 验证我对某个 APP 是否有许可证
const [hasLicense, tokenId] = await query.verifyLicense(myAddress, appId);
```

---

## 8. 收益分配机制

### 8.1 一级市场（首次购买）

| 角色 | 比例 | 说明 |
|------|------|------|
| 👨‍💻 开发者 | **60%** | APP 创建者 |
| 📣 推广者 | **25%** | 推荐购买的推广者（无推广者时归开发者） |
| 🌐 平台 | **10%** | DAIX.fun 运营基金 |
| ⚡ Gas | **5%** | 网络结算补贴 |

**关键逻辑：**
- 若 `agent = address(0)`（无推广者），则推广者份额归开发者 → 开发者获得 **85%**
- 分账在 `mintLicense` 交易中自动执行，无需手动操作

### 8.2 二级市场（NFT 转让）

当 License NFT 在二级市场转让时，原开发者获得 **5%** 版税（由 RevenueSplit 合约处理）。

### 8.3 批量购买（代理商专用）

```javascript
// 代理商批量购买 10 个激活码
const tx = await licenseNFT.batchMint(appId, 10);
const receipt = await tx.wait();

// 返回所有 tokenId
const tokenIds = receipt.logs.map(log => log.args.tokenId);
console.log("批量购买", tokenIds.length, "个激活码");
```

批量购买的分账逻辑与单次购买相同，代理商保留推广者份额（25%）。

### 8.4 收益查询

```javascript
// 查询钱包 USDC 余额（即总收益）
const balance = await usdc.balanceOf(developerAddress);
console.log("总收益:", ethers.formatUnits(balance, 6), "USDC");

// 查询某个 NFT 的铸造价格
const license = await licenseNFT.getLicense(tokenId);
console.log("铸造价格:", ethers.formatUnits(license.mintPrice, 6), "USDC");
```

---

## 9. APP 端集成指南

### 9.1 Web3LicenseManager 概述

每个 DAIX.fun 上架的 Android APP 都需要集成 `Web3LicenseManager`，它负责：

1. **钱包管理**：导入/管理用户私钥
2. **NFT 验证**：通过 Polygon 链验证用户是否持有对应 APP 的 License NFT
3. **试用期管理**：7 天免费试用
4. **离线激活码**：无网络时的 fallback

### 9.2 集成步骤

#### Step 1: 复制 Web3LicenseManager.java

将标准模块复制到你的 Android 项目：

```
app/src/main/java/你的包名/data/Web3LicenseManager.java
```

#### Step 2: 配置包名

在 `Web3LicenseManager` 中，确保 `RPC_URL` 和合约地址正确：

```java
private static final String RPC_URL = "https://polygon-bor-rpc.publicnode.com";
private static final String LICENSE_QUERY = "0xb36Fd748026097e0F18A644452E739DECf4d0686";
private static final String LICENSE_NFT = "0x7Ed65226C66b188f66AA0e5483917B1C33a41225";
private static final long CHAIN_ID = 137;
```

#### Step 3: 初始化

```java
// 在 Activity 中初始化
Web3LicenseManager licenseManager = new Web3LicenseManager(
    context,
    getPackageName() // 自动获取当前 APP 的包名
);
```

#### Step 4: 检查激活状态

```java
// 启动时检查
if (licenseManager.isActivated()) {
    // ✅ 已激活，正常使用
    showMainContent();
} else if (!licenseManager.isTrialExpired()) {
    // ⏳ 试用期内，显示剩余时间
    long remaining = licenseManager.getTrialRemaining();
    showTrialNotice(remaining);
} else {
    // 🔒 试用已过期，引导购买
    showActivationDialog();
}
```

#### Step 5: 验证 NFT

```java
// 验证钱包中的 NFT
licenseManager.verifyLicense((verified, message, appId) -> {
    runOnUiThread(() -> {
        if (verified) {
            // ✅ NFT 验证通过
            showActivated();
        } else {
            // ❌ 未持有 NFT
            showPurchaseGuide(appId);
        }
    });
});
```

#### Step 6: 离线激活码（Fallback）

```java
// 用户输入离线激活码
boolean success = licenseManager.activateOffline("ABCD-1234-EFGH-5678");
if (success) {
    showActivated();
} else {
    showError("激活码无效");
}
```

### 9.3 完整集成示例

```java
public class MainActivity extends AppCompatActivity {
    private Web3LicenseManager licenseManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        licenseManager = new Web3LicenseManager(this, getPackageName());

        checkLicense();
    }

    private void checkLicense() {
        // 1. 已激活
        if (licenseManager.isActivated()) {
            showMainContent();
            return;
        }

        // 2. 试用期内
        if (!licenseManager.isTrialExpired()) {
            showTrialNotice();
            return;
        }

        // 3. 试用过期，显示激活对话框
        showActivationDialog();
    }

    private void showActivationDialog() {
        // 显示两个选项：
        // A) 连接钱包验证 NFT
        // B) 输入离线激活码

        // 选项 A: 验证 NFT
        licenseManager.verifyLicense((verified, message, appId) -> {
            runOnUiThread(() -> {
                if (verified) {
                    dismissDialog();
                    showMainContent();
                } else {
                    showError(message);
                }
            });
        });

        // 选项 B: 离线激活
        boolean ok = licenseManager.activateOffline(code);
        if (ok) {
            dismissDialog();
            showMainContent();
        }
    }
}
```

### 9.4 状态查询 API

| 方法 | 返回 | 说明 |
|------|------|------|
| `hasWallet()` | boolean | 是否已导入钱包 |
| `getAddress()` | String | 钱包地址 |
| `isVerified()` | boolean | NFT 是否已验证 |
| `isActivated()` | boolean | 是否已激活（NFT 或离线码） |
| `isTrialExpired()` | boolean | 试用期是否已过期 |
| `getTrialRemaining()` | long | 试用剩余毫秒数 |
| `getStatusText()` | String | 状态描述文字 |
| `getCachedAppId()` | long | 缓存的链上 APP ID |

---

## 10. APK 上传规范

### 10.1 当前可用方式

#### 方式一：上传到 ClawClaw 服务器（推荐）

```http
POST https://43.166.240.93:3030/api/upload-public
Content-Type: multipart/form-data

Body:
  file: (APK 文件，≤10MB)
```

**响应：**
```json
{
  "success": true,
  "url": "/apk/storeguard-v1.apk"
}
```

下载地址：`https://43.166.240.93:3030/apk/storeguard-v1.apk`

#### 方式二：上传到 IPFS（Pinata）

```bash
curl -X POST "https://api.pinata.cloud/pinning/pinFileToIPFS" \
  -H "Authorization: Bearer $PINATA_JWT" \
  -F file=@"app-release.apk"

# 返回 IPFS Hash
# ipfs://QmStoreGuardAPK...
```

#### 方式三：DAIX.fun APK 服务器（规划中）

```http
POST https://daix.fun/api/upload-apk
Content-Type: multipart/form-data

Body:
  file: (APK 文件，≤100MB)
  packageName: com.storeguard.vipreception
  version: v1.0.0
```

> 🚧 **开发中** — 预计 2026-07 上线

### 10.2 发布流程

```
1. 编译 Release APK
2. 上传 APK 获取下载地址
3. 上传图标获取图标地址
4. 调用 AppRegistry.registerApp() 注册到链上
5. 用户通过 daix.fun 浏览并购买
```

---

## 11. 链上数据结构

### 11.1 DeveloperRegistry

```solidity
struct Developer {
    address wallet;         // 钱包地址
    string name;           // 开发者名称
    string metadataURI;    // 元数据 URI（IPFS）
    uint256 registeredAt;  // 注册时间戳
    bool active;           // 是否活跃
}

mapping(address => Developer) public developers;
uint256 public developerCount;
```

### 11.2 AppRegistry

```solidity
struct App {
    uint256 appId;          // APP 唯一 ID
    address developer;      // 开发者地址
    string name;            // 展示名称
    string packageName;     // Android 包名
    string description;     // 描述
    string apkURI;          // APK 下载地址
    string iconURI;         // 图标地址
    uint256 price;          // 价格（USDC, 6位小数）
    uint256 trialDays;      // 试用天数
    string version;         // 版本号
    uint256 createdAt;      // 创建时间
    uint256 updatedAt;      // 更新时间
    bool active;            // 是否上架
}

uint256 public nextAppId;   // 下一个 APP ID（从 1 开始）
mapping(uint256 => App) public apps;
mapping(address => uint256[]) public developerApps;
uint256[] public activeAppIds;
```

### 11.3 LicenseNFT

```solidity
struct License {
    uint256 appId;          // 关联的 APP ID
    address developer;      // 开发者地址
    uint256 mintPrice;      // 铸造时价格
    uint256 mintedAt;       // 铸造时间
    bool activated;         // 是否已激活
    address holder;         // 当前持有者
}

// 分账比例（基点，10000 = 100%）
uint256 constant DEV_SHARE = 6000;       // 60%
uint256 constant AGENT_SHARE = 2500;     // 25%
uint256 constant PLATFORM_SHARE = 1000;  // 10%
uint256 constant GAS_SHARE = 500;        // 5%

mapping(uint256 => License) public licenses;
mapping(uint256 => uint256) public appLicenseCount;
```

### 11.4 PromoterRegistry

```solidity
struct Promoter {
    string name;            // 推广者名称
    string referralCode;    // 推广码
    uint256 registeredAt;   // 注册时间
    bool active;            // 是否活跃
}

mapping(address => Promoter) private _promoters;
mapping(string => address) private _codeToAddress;
```

---

## 12. 完整 ABI 参考

### 12.1 DeveloperRegistry ABI

```json
[
  {
    "inputs": [{"name":"name","type":"string"},{"name":"metadataURI","type":"string"}],
    "name": "register",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"","type":"address"}],
    "name": "isRegistered",
    "outputs": [{"name":"","type":"bool"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "developerCount",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"_wallet","type":"address"}],
    "name": "getDeveloper",
    "outputs": [
      {"name":"name","type":"string"},
      {"name":"metadataURI","type":"string"},
      {"name":"registeredAt","type":"uint256"},
      {"name":"active","type":"bool"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"name","type":"string"},{"name":"metadataURI","type":"string"}],
    "name": "updateProfile",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getAllDevelopers",
    "outputs": [{"name":"","type":"address[]"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

### 12.2 AppRegistry ABI

```json
[
  {
    "inputs": [
      {"name":"name","type":"string"},
      {"name":"packageName","type":"string"},
      {"name":"description","type":"string"},
      {"name":"apkURI","type":"string"},
      {"name":"iconURI","type":"string"},
      {"name":"price","type":"uint256"},
      {"name":"trialDays","type":"uint256"},
      {"name":"version","type":"string"}
    ],
    "name": "registerApp",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {"name":"appId","type":"uint256"},
      {"name":"version","type":"string"},
      {"name":"apkURI","type":"string"},
      {"name":"price","type":"uint256"}
    ],
    "name": "updateApp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"appId","type":"uint256"}],
    "name": "deactivateApp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"_appId","type":"uint256"}],
    "name": "getApp",
    "outputs": [
      {"name":"appId","type":"uint256"},
      {"name":"developer","type":"address"},
      {"name":"name","type":"string"},
      {"name":"packageName","type":"string"},
      {"name":"description","type":"string"},
      {"name":"apkURI","type":"string"},
      {"name":"iconURI","type":"string"},
      {"name":"price","type":"uint256"},
      {"name":"trialDays","type":"uint256"},
      {"name":"version","type":"string"},
      {"name":"createdAt","type":"uint256"},
      {"name":"updatedAt","type":"uint256"},
      {"name":"active","type":"bool"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"_developer","type":"address"}],
    "name": "getDeveloperApps",
    "outputs": [{"name":"","type":"uint256[]"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getActiveApps",
    "outputs": [{"name":"","type":"uint256[]"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "nextAppId",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

### 12.3 LicenseNFT ABI

```json
[
  {
    "inputs": [
      {"name":"_appId","type":"uint256"},
      {"name":"_agent","type":"address"}
    ],
    "name": "mintLicense",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {"name":"_appId","type":"uint256"},
      {"name":"_quantity","type":"uint256"}
    ],
    "name": "batchMint",
    "outputs": [{"name":"","type":"uint256[]"}],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {"name":"_tokenId","type":"uint256"},
      {"name":"_deviceFingerprint","type":"string"}
    ],
    "name": "activateLicense",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"_tokenId","type":"uint256"}],
    "name": "getLicense",
    "outputs": [
      {"name":"appId","type":"uint256"},
      {"name":"developer","type":"address"},
      {"name":"mintPrice","type":"uint256"},
      {"name":"mintedAt","type":"uint256"},
      {"name":"activated","type":"bool"},
      {"name":"holder","type":"address"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalSupply",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"owner","type":"address"}],
    "name": "balanceOf",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"owner","type":"address"},{"name":"index","type":"uint256"}],
    "name": "tokenOfOwnerByIndex",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"tokenId","type":"uint256"}],
    "name": "ownerOf",
    "outputs": [{"name":"","type":"address"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

### 12.4 PromoterRegistry ABI

```json
[
  {
    "inputs": [{"name":"name","type":"string"},{"name":"referralCode","type":"string"}],
    "name": "register",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"","type":"address"}],
    "name": "isPromoter",
    "outputs": [{"name":"","type":"bool"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"addr","type":"address"}],
    "name": "getPromoter",
    "outputs": [
      {"name":"name","type":"string"},
      {"name":"referralCode","type":"string"},
      {"name":"registeredAt","type":"uint256"},
      {"name":"active","type":"bool"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"code","type":"string"}],
    "name": "getByCode",
    "outputs": [{"name":"","type":"address"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

### 12.5 LicenseQuery ABI

```json
[
  {
    "inputs": [{"name":"user","type":"address"},{"name":"appId","type":"uint256"}],
    "name": "verifyLicense",
    "outputs": [
      {"name":"hasLicense","type":"bool"},
      {"name":"tokenId","type":"uint256"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"user","type":"address"}],
    "name": "getUserLicenses",
    "outputs": [
      {"name":"tokenIds","type":"uint256[]"},
      {"name":"appIds","type":"uint256[]"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"packageName","type":"string"}],
    "name": "getAppByPackageName",
    "outputs": [
      {"name":"appId","type":"uint256"},
      {"name":"found","type":"bool"}
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"dev","type":"address"}],
    "name": "getAppsByDeveloper",
    "outputs": [{"name":"appIds","type":"uint256[]"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

### 12.6 USDC (ERC-20) ABI

```json
[
  {
    "inputs": [{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],
    "name": "approve",
    "outputs": [{"name":"","type":"bool"}],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [{"name":"owner","type":"address"},{"name":"spender","type":"address"}],
    "name": "allowance",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [{"name":"account","type":"address"}],
    "name": "balanceOf",
    "outputs": [{"name":"","type":"uint256"}],
    "stateMutability": "view",
    "type": "function"
  }
]
```

---

## 13. 安全与合规

### 13.1 智能合约安全

- ✅ 基于 OpenZeppelin 标准库（ERC-721、Ownable、ERC721URIStorage）
- ✅ 收益分配逻辑在链上执行，不可篡改
- ✅ 所有合约代码可在 Polygonscan 公开验证
- ✅ 分账在单笔交易中原子执行，不存在中间状态

### 13.2 APP 端安全

- **私钥存储**：APP 使用 `SharedPreferences` 存储私钥，仅本地使用
- **RPC 调用**：仅读取链上数据，不涉及私钥传输
- **离线激活码**：格式校验 + 本地验证，不依赖网络

### 13.3 合规要求

- 📋 **应用审核**：DAIX.fun 采用社区共识机制，无中心化审核
- 🚫 **禁止内容**：恶意软件、钓鱼应用、侵权内容将被社区举报并下架
- 📃 **KYC**：注册无需 KYC，建议提供真实元数据以建立信任
- 💰 **支付**：仅接受 Polygon USDC，确保交易可追溯

---

## 附录：快速参考

### 合约地址速查

```
DeveloperRegistry : 0x8EE775e943C31EA7c4eF2B7bb83e0651c9d04001
AppRegistry       : 0xdFCFA7d871cCc3674d873d00192Ba26a685B2b68
LicenseNFT        : 0x7Ed65226C66b188f66AA0e5483917B1C33a41225
PromoterRegistry  : 0xeed4653f341F810e00A73c6ECD454a1205C0Cabb
LicenseQuery      : 0xb36Fd748026097e0F18A644452E739DECf4d0686
RevenueSplit      : 0x698c00CD9e94353C6ef804e670bc558108250f9D
USDC              : 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
```

### 函数选择器速查

```
DeveloperRegistry.register(string,string)     → 0x91b7f579
DeveloperRegistry.isRegistered(address)        → 0xa1665669
AppRegistry.registerApp(...)                   → 0xf2c89d1d
AppRegistry.getApp(uint256)                    → 0x8da5cb5b
AppRegistry.getActiveApps()                    → 0x22064bfc
LicenseNFT.mintLicense(uint256,address)        → 0x4d28d8aa
LicenseNFT.batchMint(uint256,uint256)          → 0x5e597d90
LicenseNFT.activateLicense(uint256,string)     → 0x2e1a7d4d
LicenseQuery.verifyLicense(address,uint256)    → 0xae0226b3
LicenseQuery.getUserLicenses(address)          → 0xc7a3bc00
LicenseQuery.getAppByPackageName(string)       → 0x58e30592
PromoterRegistry.register(string,string)       → 0xf2c89d1d
```

### 网络配置

```
Chain ID    : 137 (Polygon Mainnet)
RPC URL     : https://polygon-bor-rpc.publicnode.com
Explorer    : https://polygonscan.com
USDC Token  : 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
```

---

*最后更新：2026-06-29 by CONVNET Team*
*完整技术文档：https://daix.fun/docs.html*
*GitHub：https://github.com/zhulianxing/daix-fun*

---

## 附录 B：FTP 上传接口

### B.1 FTP 服务器信息

| 项目 | 值 |
|------|-----|
| 服务器 | 43.166.240.93 |
| 端口 | 21 |
| 用户名 | hackathon |
| 密码 | hackathon2026 |
| 模式 | **主动模式**（Active Mode） |
| 软件 | Pure-FTPd [TLS] |

### B.2 目录结构

```
/
├── apk/       ← APK 文件存放
├── icons/     ← 应用图标存放
├── docs/      ← 文档存放
└── test_folder/
```

### B.3 命令行上传（curl）

```bash
# 上传 APK
curl -T app-release.apk ftp://43.166.240.93/apk/ --user hackathon:hackathon2026 --ftp-pasv -P -

# 上传图标
curl -T icon.png ftp://43.166.240.93/icons/ --user hackathon:hackathon2026 --ftp-pasv -P -
```

### B.4 Python 上传工具

```bash
# 上传 APK（自动重命名）
python3 daix-upload.py apk ./app-release.apk --pkg com.example.app --ver v1.0.0

# 上传图标
python3 daix-upload.py icon ./icon.png --pkg com.example.app

# 上传文档
python3 daix-upload.py doc ./README.md

# 查看目录
python3 daix-upload.py list /apk
```

### B.5 FTP 连接注意事项

- ⚠️ 必须使用**主动模式**（Active Mode），被动模式因服务器返回内网 IP 会超时
- Python: `ftp.set_pasv(False)`
- curl: 使用 `--ftp-pasv` 参数（curl 默认被动，需注意）

### B.6 文件命名规范

| 类型 | 命名格式 | 示例 |
|------|----------|------|
| APK | {pkg}-{ver}.apk | com.storeguard.vipreception-v1.0.0.apk
| 图标 | {pkg}.png | com.storeguard.vipreception.png
| 文档 | 任意 |  |
