# 收取手续费

LaunchLab 在两个阶段产生费用：在 bonding curve 交易期间以及迁移到流动性池之后。平台和创作者可以随时提取他们获得的费用。

### 费用概述

| 阶段                            | 费用类型              | 谁获得     | 提取方式                      |
| ----------------------------- | ----------------- | ------- | ------------------------- |
| Bonding curve                 | 交易手续费             | 平台      | `claimVaultPlatformFee()` |
| Bonding curve (former method) | 交易手续费             | 平台      | `claimAllPlatformFee()`   |
| Bonding curve                 | 交易手续费             | Creator | `claimCreatorFee()`       |
| Post-migration                | LP 交易手续费          | 平台      | `harvestLockLiquidity()`  |
| Post-migration                | LP 交易手续费          | Creator | `harvestLockLiquidity()`  |
| Post-migration                | CPMM creator fees | Creator | `collectCreatorFee()`     |

***

### Bonding curve 费用提取

费用在 bonding curve 交易期间累积。平台和创作者都可以随时提取他们的份额。

#### 平台费用提取

### 从平台金库提取

平台从其托管的 bonding curve 上的每笔交易中获得一部分收入。费用累积在金库中，可以随时提取。

```typescript
import { TxVersion } from '@raydium-io/raydium-sdk-v2'
import { initSdk } from './config'
import { PublicKey } from '@solana/web3.js'
import { NATIVE_MINT } from '@solana/spl-token'

const claimPlatformFees = async () => {
  const raydium = await initSdk()

  const { execute } = await raydium.launchpad.claimVaultPlatformFee({
    platformId: new PublicKey('your-platform-id'),
    mintB: NATIVE_MINT,
    claimFeeWallet: raydium.ownerPubKey, // optional, defaults to signer
    txVersion: TxVersion.V0,
  })

  const { txId } = await execute({ sendAndConfirm: true })
  console.log('Platform fees claimed:', txId)
}
```

### 从多种计价代币提取

如果您的平台托管了使用不同计价代币的发行：

```typescript
const claimMultipleVaultFees = async () => {
  const raydium = await initSdk()
  const platformId = new PublicKey('your-platform-id')

  const { execute } = await raydium.launchpad.claimMultipleVaultPlatformFee({
    platformList: [
      { id: platformId, mintB: NATIVE_MINT },
      { id: platformId, mintB: new PublicKey('USDC-mint-address') },
    ],
    unwrapSol: true, // unwrap SOL to native balance
    txVersion: TxVersion.V0,
  })

  const { txIds } = await execute({ sendAndConfirm: true, sequentially: true })
  console.log('Fees claimed:', txIds)
}
```

### 从所有池中提取（旧方法）

一次性从您平台上的所有 bonding curve 池提取费用：

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

  const { execute } = await raydium.launchpad.claimAllPlatformFee({
    platformId: new PublicKey('your-platform-id'),
    platformClaimFeeWallet: raydium.ownerPubKey,
    txVersion: TxVersion.V0,
  })

  const { txIds } = await execute({ sendAndConfirm: true, sequentially: true })
  console.log('All platform fees claimed:', txIds)
}
```

***

#### 创作者费用提取

### 提取 bonding curve 费用

创作者从其代币的 bonding curve 上的交易中获得费用。费用累积在创作者专属的金库中。

```typescript
import { TxVersion } from '@raydium-io/raydium-sdk-v2'
import { initSdk } from './config'
import { NATIVE_MINT } from '@solana/spl-token'

const claimCreatorFees = async () => {
  const raydium = await initSdk()

  const { execute } = await raydium.launchpad.claimCreatorFee({
    mintB: NATIVE_MINT,
    txVersion: TxVersion.V0,
  })

  const { txId } = await execute({ sendAndConfirm: true })
  console.log('Creator fees claimed:', txId)
}
```

### 从多种计价代币提取

如果您以不同的计价代币发起了发行：

```typescript
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'

const claimMultipleCreatorFees = async () => {
  const raydium = await initSdk()

  const { execute } = await raydium.launchpad.claimMultipleCreatorFee({
    mintBList: [
      { pubKey: NATIVE_MINT, programId: TOKEN_PROGRAM_ID },
      { pubKey: new PublicKey('USDC-mint-address'), programId: TOKEN_PROGRAM_ID },
    ],
    txVersion: TxVersion.V0,
  })

  const { txIds } = await execute({ sendAndConfirm: true, sequentially: true })
  console.log('Creator fees claimed:', txIds)
}
```

### 迁移后 LP 费用提取

迁移到 CPMM 之后，平台和创作者都可以使用他们收到的 Fee Key NFT 来提取其应得的 LP 交易手续费份额。

### 提取 LP 费用

```typescript
import {
  LOCK_CPMM_PROGRAM,
  LOCK_CPMM_AUTH,
} from '@raydium-io/raydium-sdk-v2'

const claimLpFees = async () => {
  const raydium = await initSdk()

  // 获取锁仓位数据（包含 Fee Key NFT 信息）
  const lockPositions = await raydium.cpmm.getOwnerLockLpInfo({
    owner: raydium.ownerPubKey,
  })

  for (const position of lockPositions) {
    const { execute } = await raydium.cpmm.harvestLockLp({
      programId: LOCK_CPMM_PROGRAM,
      authProgram: LOCK_CPMM_AUTH,

      // 锁仓位数据
      lockData: position,

      txVersion: TxVersion.V0,
    })

    await execute({ sendAndConfirm: true })
    console.log('LP fees harvested for:', position.poolId.toBase58())
  }
}
```

### 理解 Fee Key NFT

| 属性    | 详情                    |
| ----- | --------------------- |
| 它是什么  | 在迁移期间铸造到创作者/平台钱包的 NFT |
| 它代表什么 | 对一部分 LP 交易手续费的提取权利    |
| 是否可转让 | 是，新的所有者继承费用提取权利       |

> **警告：** 不要销毁您的 Fee Key NFT。如果被销毁，费用提取权将永久丧失。

#### CPMM creator fees

如果 `creatorFeeOn` 在发行期间被配置，创作者还可从 CPMM 交易中获得额外费用。这些费用与 LP 手续费份额是分开的。

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

  // 获取您作为创作者的池
  const pools = await raydium.cpmm.getCreatorPools({
    creator: raydium.ownerPubKey,
  })

  for (const pool of pools) {
    const { execute } = await raydium.cpmm.collectCreatorFee({
      poolInfo: pool,
      txVersion: TxVersion.V0,
    })

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

#### 费用累积时间线

### Bonding curve 阶段

* **平台费用** — 使用以下方式提取 `claimVaultPlatformFee()`
* **创作者费用** — 使用以下方式提取 `claimCreatorFee()`
* **计价单位** — 计价代币（例如，SOL）

### 迁移后阶段

* **平台费用** — 使用以下方式提取 `harvestLockLp()`
* **创作者费用** — 使用以下方式提取 `harvestLockLp()` 并可选地 `collectCreatorFee()` (CPMM)
* **计价单位** — 交易对中的两种代币

#### 最佳实践

1. **定期提取** — 费用不会自动复利，请定期提取以实现收益
2. **跟踪多个池** — 如果您运营多个发行，尽可能批量提取
3. **保护 Fee Key NFT** — 将其视为有价值的资产；丢失意味着丧失费用权利
4. **监控两个来源** — 迁移后，记得从 bonding curve 金库和 LP 头寸中都提取
