# 创建平台

创建并配置您的 LaunchLab 平台，以启用代币发行。

在用户可以在您的平台上发行代币之前，您需要先创建平台配置。每个钱包只能创建一个平台。

***

## 创建平台

使用 `createPlatformConfig()` 来使用手续费结构、LP 分配设置和元数据初始化您的平台。

```typescript
import {
  TxVersion,
  LAUNCHPAD_PROGRAM,
  DEVNET_PROGRAM_ID,
} from '@raydium-io/raydium-sdk-v2'
import { initSdk } from './config'
import { PublicKey } from '@solana/web3.js'
import BN from 'bn.js'

const createPlatform = async () => {
  const raydium = await initSdk()
  const owner = raydium.ownerPubKey

  const { execute, extInfo } = await raydium.launchpad.createPlatformConfig({
    programId: LAUNCHPAD_PROGRAM, // Use DEVNET_PROGRAM_ID.LAUNCHPAD_PROGRAM for devnet

    // Wallet configuration
    platformAdmin: owner,
    platformClaimFeeWallet: owner,
    platformLockNftWallet: owner,
    platformVestingWallet: owner,

    // CPMM pool fee tier for migrated pools
    cpConfigId: new PublicKey('DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8'),

    // Token-2022 transfer fee authority (receives fee authorities post-migration)
    transferFeeExtensionAuth: owner,

    // Fee configuration
    feeRate: new BN(10000),        // 1% platform fee on bonding curve trades
    creatorFeeRate: new BN(5000),  // 0.5% creator fee on bonding curve trades

    // LP distribution at migration (must sum to 1,000,000)
    migrateCpLockNftScale: {
      platformScale: new BN(100000),  // 10% to platform (locked)
      creatorScale: new BN(100000),   // 10% to creator (locked)
      burnScale: new BN(800000),      // 80% burned
    },

    // Platform metadata
    name: 'My LaunchLab',
    web: 'https://mylaunchlab.io',
    img: 'https://mylaunchlab.io/logo.png',

    txVersion: TxVersion.V0,
  })

  const { txId } = await execute({ sendAndConfirm: true })
  console.log('Platform created:', extInfo.platformId.toBase58())
}
```

***

## 配置参数

### 钱包配置

| 参数                       | 类型        | 描述                                              |
| ------------------------ | --------- | ----------------------------------------------- |
| `platformAdmin`          | PublicKey | 控制平台的管理员钱包。可以更新设置。                              |
| `platformClaimFeeWallet` | PublicKey | 接收来自 bonding curve 的平台交易手续费的钱包。                 |
| `platformLockNftWallet`  | PublicKey | 在迁移后接收平台 Fee Key NFT 的钱包。                       |
| `platformVestingWallet`  | PublicKey | 平台 vesting 分配的钱包。若不需要，请使用 `PublicKey.default` 。 |

### 手续费配置

| 参数               | 类型 | 描述                                                                           |
| ---------------- | -- | ---------------------------------------------------------------------------- |
| `feeRate`        | BN | 平台在 bonding curve 交易手续费中的占比。单位为 bps × 100（`10000 = 1%`).                     |
| `creatorFeeRate` | BN | 创作者在 bonding curve 交易手续费中的占比。单位为 bps × 100（`5000 = 0.5%`）。最大 `50000` (`5%`). |

手续费以 quote token 计价（例如 SOL）。每笔交易的总手续费 = `protocolFeeRate` + `platformFeeRate` + `creatorFeeRate` + `shareFeeRate`。各方按比例获得其份额。

### 迁移时的 LP 分配

| 参数              | 类型 | 描述                                                 |
| --------------- | -- | -------------------------------------------------- |
| `platformScale` | BN | 平台的 LP 代币份额，通过 Burn & Earn 锁定。平台会收到 Fee Key NFT。   |
| `creatorScale`  | BN | 创作者的 LP 代币份额，通过 Burn & Earn 锁定。创作者会收到 Fee Key NFT。 |
| `burnScale`     | BN | LP 代币将永久销毁，不会产生手续费。                                |

这三个值的总和必须等于 `1,000,000` (100%).

### 示例分配

```typescript
// 80% 销毁，10% 创作者，10% 平台
{ burnScale: 800000, creatorScale: 100000, platformScale: 100000 }

// 90% 销毁，10% 创作者（无平台份额）
{ burnScale: 900000, creatorScale: 100000, platformScale: 0 }

// 100% 销毁（无持续手续费）
{ burnScale: 1000000, creatorScale: 0, platformScale: 0 }
```

### 池配置

| 参数                         | 类型        | 描述                                              |
| -------------------------- | --------- | ----------------------------------------------- |
| `cpConfigId`               | PublicKey | 迁移后 CPMM 池的手续费等级。可从 API 获取可用配置。                 |
| `transferFeeExtensionAuth` | PublicKey | 在迁移后接收 Token-2022 发行业务的 transfer fee authority。 |

### 可用的 CPMM 配置

* 主网： [api-v3.raydium.io/main/cpmm-config](https://api-v3.raydium.io/main/cpmm-config)
* Devnet： [api-v3-devnet.raydium.io/main/cpmm-config](https://api-v3-devnet.raydium.io/main/cpmm-config)

### 元数据

| 参数     | 类型     | 描述           |
| ------ | ------ | ------------ |
| `name` | string | 平台名称（存储在链上）。 |
| `web`  | string | 平台网站 URL。    |
| `img`  | string | 平台 logo URL。 |

***

## 更新平台配置

平台设置每个 epoch 可更新一次。使用 `updatePlatformConfig()` 来修改设置。

```typescript
const updatePlatform = async () => {
  const raydium = await initSdk()

  const { execute } = await raydium.launchpad.updatePlatformConfig({
    platformAdmin: raydium.ownerPubKey,

    // Update a single setting
    updateInfo: { type: 'updateFeeRate', value: new BN(15000) }, // Change to 1.5%

    txVersion: TxVersion.V0,
  })

  await execute({ sendAndConfirm: true })
}
```

### 可用的更新类型

| 类型                           | 值         | 描述                                                 |
| ---------------------------- | --------- | -------------------------------------------------- |
| `updateFeeRate`              | BN        | 更新平台交易手续费率                                         |
| `updateClaimFeeWallet`       | PublicKey | 更改手续费收款钱包                                          |
| `updateLockNftWallet`        | PublicKey | 更改 Fee Key NFT 接收者                                 |
| `updateVestingWallet`        | PublicKey | 更改 vesting 钱包                                      |
| `updateCpConfigId`           | PublicKey | 更改迁移时的 CPMM 手续费等级                                  |
| `updateName`                 | string    | 更新平台名称                                             |
| `updateWeb`                  | string    | 更新网站 URL                                           |
| `updateImg`                  | string    | 更新 logo URL                                        |
| `migrateCpLockNftScale`      | object    | 更新 LP 分配比例                                         |
| `updatePlatformVestingScale` | BN        | 更新平台 vesting 分配                                    |
| `updatePlatformCpCreator`    | PublicKey | pass a publicKey as fee receipient post graduation |
| `updateAll`                  | object    | 一次更新所有设置                                           |

***

### 强制执行发行参数（可选）

平台可以限制允许哪些代币配置。如果创作者的参数与允许的配置不匹配，交易将失败。

```typescript
import { updatePlatformCurveParamInstruction } from '@raydium-io/raydium-sdk-v2'

// Add an allowed configuration at index 1
const instruction = updatePlatformCurveParamInstruction(
  LAUNCHPAD_PROGRAM,
  platformAdmin,
  platformId,
  1, // index (0-254)
  {
    migrateType: 1,                              // 0 = AMM, 1 = CPMM
    migrateCpmmFeeOn: 0,                         // Creator fee token
    supply: new BN('1000000000000000'),          // 1B tokens (with decimals)
    totalSellA: new BN('793100000000000'),       // ~79.3% sold on curve
    totalFundRaisingB: new BN('85000000000'),    // 85 SOL to raise
    totalLockedAmount: new BN('0'),              // No vesting
    cliffPeriod: new BN('0'),
    unlockPeriod: new BN('0'),
  }
)
```

### 参数强制执行的工作方式

* 最多存储 25 个配置（index 0-254）
* 将某个参数设为 `null` 可跳过该字段的校验
* 创作者必须与至少一个配置完全匹配
* 配置每个 epoch 可更新一次

**示例：** 允许灵活的募资金额，但固定供应量：

```typescript
{
  supply: new BN('1000000000000000'),     // 必须正好是 1B
  totalFundRaisingB: null,                // 允许任意金额
  // ... other params
}
```

***

### 推导您的平台 ID

创建后，您的平台 ID 将根据您的管理员钱包推导：

```typescript
import { getPdaPlatformId, LAUNCHPAD_PROGRAM } from '@raydium-io/raydium-sdk-v2'

const { publicKey: platformId } = getPdaPlatformId(
  LAUNCHPAD_PROGRAM,
  adminWallet
)
```

共享此 `platformId` 给希望在您的平台上发行代币的创作者。
