# Collecting fees

LaunchLab は手数料を 2 段階で生成します：ボンディングカーブ取引中と、流動性プールへの移行後です。プラットフォームとクリエイターはいつでも獲得した手数料を請求できます。

### 手数料の概要

| ステージ             | 手数料の種類         | 誰が得るか    | 請求方法                      |
| ---------------- | -------------- | -------- | ------------------------- |
| ボンディングカーブ        | 取引手数料          | プラットフォーム | `claimVaultPlatformFee()` |
| ボンディングカーブ（従来の方法） | 取引手数料          | プラットフォーム | `claimAllPlatformFee()`   |
| ボンディングカーブ        | 取引手数料          | クリエイター   | `claimCreatorFee()`       |
| 移行後              | LP 取引手数料       | プラットフォーム | `harvestLockLiquidity()`  |
| 移行後              | LP 取引手数料       | クリエイター   | `harvestLockLiquidity()`  |
| 移行後              | CPMM クリエイター手数料 | クリエイター   | `collectCreatorFee()`     |

***

### ボンディングカーブの手数料回収

手数料はボンディングカーブ取引中に蓄積されます。プラットフォームとクリエイターはそれぞれの取り分をいつでも請求できます。

#### プラットフォーム手数料の回収

### プラットフォームボールトからの請求

プラットフォームはホストするボンディングカーブ上の各取引の一部を得ます。手数料はボールトに蓄積され、いつでも請求可能です。

```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)
}
```

### すべてのプールからの請求（従来の方法）

プラットフォーム上のすべてのボンディングカーブプールから一度に手数料を請求します：

```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)
}
```

***

#### クリエイターの手数料回収

### ボンディングカーブ手数料の請求

クリエイターは自分のトークンのボンディングカーブ上の取引から手数料を得ます。手数料はクリエイター専用のボールトに蓄積されます。

```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 クリエイター手数料

もし `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 })
  }
}
```

#### 手数料蓄積のタイムライン

### ボンディングカーブフェーズ

* **プラットフォーム手数料** — で請求 `claimVaultPlatformFee()`
* **クリエイター手数料** — で請求 `claimCreatorFee()`
* **計算単位** — 引用トークン（例：SOL）

### 移行後フェーズ

* **プラットフォーム手数料** — で請求 `harvestLockLp()`
* **クリエイター手数料** — で請求 `harvestLockLp()` および任意で `collectCreatorFee()` （CPMM）
* **計算単位** — ペア内の両トークン

#### ベストプラクティス

1. **定期的に請求する** — 手数料は自動複利化されないため、定期的に請求して利益を確定してください
2. **複数のプールを追跡する** — 複数のローンチを運用している場合、可能な限り請求をバッチ処理してください
3. **Fee Key NFT を安全に保管する** — これらを価値のある資産として扱ってください。紛失すると手数料請求権を失います
4. **両方のソースを監視する** — 移行後は、ボンディングカーブのボールトと LP ポジションの両方から請求することを忘れないでください
