openapi: 3.0.3
info:
  title: "Raydium トランザクション API (Route V2)"
  version: 1.0.0
  description: |
    Solana のサーバーサイド・スワップ・トランザクション・ビルダー。このAPI は、クライアントが RPC コネクションまたはフル Raydium SDK を実行することなく、シリアライズされたスワップ・トランザクションを生成します。

    レスポンスは標準的なエンベロープ形式に従います：
    - **成功**: `{ id: string, success: true, data: {...} }`
    - **エラー**: `{ id: string, success: false, msg: string }`
  contact:
    name: Raydium
    url: https://raydium.io

servers:
  - url: https://transaction-v1.raydium.io
    description: Mainnet
  - url: https://transaction-v1-devnet.raydium.io
    description: Devnet

tags:
  - name: Compute
    description: "スワップ・クオート計算用の読み取り専用エンドポイント（トランザクション・ビルディングなし）。"
  - name: Transaction
    description: "署名・ブロードキャスト可能なシリアライズされたスワップ・トランザクションを生成します。"

paths:
  /compute/swap-base-in:
    get:
      summary: "スワップ・クオート計算（基本入力）"
      description: |
        固定入力額をスワップする際の予想出力額を計算します。
        トランザクション・ビルディング前のプレビュー表示に便利です。
      operationId: computeSwapBaseIn
      tags:
        - Compute
      parameters:
        - name: inputMint
          in: query
          required: true
          schema:
            type: string
          description: "入力トークンのミント・アドレス（base58 エンコード公開鍵）。"
          example: EPjFWdd5Au5WrWSNY8jk5oHE3TkM3TvhEhBNj9xtJzwQ
        - name: outputMint
          in: query
          required: true
          schema:
            type: string
          description: "出力トークンのミント・アドレス（base58 エンコード公開鍵）。"
          example: So11111111111111111111111111111111111111112
        - name: amount
          in: query
          required: true
          schema:
            type: string
          description: "入力額（ラムポート、SPL トークンの最小単位）。負でない整数文字列である必要があります。"
          example: "1000000"
        - name: slippageBps
          in: query
          required: true
          schema:
            type: string
          description: "最大スリッページ・トレランス（ベーシス・ポイント、0～10000）。1 bps = 0.01%。"
          example: "50"
        - name: referrerBps
          in: query
          required: false
          schema:
            type: string
          description: "オプションのリファラー・フィー（ベーシス・ポイント、0～10000）。リファラー・オーソリティがある場合のみ使用。"
          example: "100"
        - name: txVersion
          in: query
          required: true
          schema:
            type: string
            enum: [V0, LEGACY]
          description: "Solana トランザクション・バージョン。V0 はアドレス・ルックアップ・テーブルを使用、LEGACY は従来の形式です。"
          example: V0
      responses:
        "200":
          description: "スワップ・クオートが正常に計算されました。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ComputeSwapResponse"
        "400":
          description: "無効な入力パラメータです。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /compute/swap-base-out:
    get:
      summary: "スワップ・クオート計算（基本出力）"
      description: |
        目的の出力額を達成するのに必要な入力額を計算します。
        目標出力額がわかっているスワップに便利です。
      operationId: computeSwapBaseOut
      tags:
        - Compute
      parameters:
        - name: inputMint
          in: query
          required: true
          schema:
            type: string
          description: "入力トークンのミント・アドレス。"
          example: EPjFWdd5Au5WrWSNY8jk5oHE3TkM3TvhEhBNj9xtJzwQ
        - name: outputMint
          in: query
          required: true
          schema:
            type: string
          description: "出力トークンのミント・アドレス。"
          example: So11111111111111111111111111111111111111112
        - name: amount
          in: query
          required: true
          schema:
            type: string
          description: "目的の出力額（最小単位、ラムポート）。"
          example: "5000000"
        - name: slippageBps
          in: query
          required: true
          schema:
            type: string
          description: "最大スリッページ・トレランス（ベーシス・ポイント、0～10000）。"
          example: "50"
        - name: txVersion
          in: query
          required: true
          schema:
            type: string
            enum: [V0, LEGACY]
          description: "Solana トランザクション・バージョン。"
          example: V0
      responses:
        "200":
          description: "スワップ・クオートが正常に計算されました。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ComputeSwapResponse"
        "400":
          description: "無効な入力パラメータです。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /transaction/swap-base-in:
    post:
      summary: "スワップ・トランザクション生成（基本入力）"
      description: |
        固定入力額のシリアライズされたスワップ・トランザクションを生成します。
        `/compute/swap-base-in` からの成功したcompute レスポンスが必要です。
      operationId: buildSwapTransactionBaseIn
      tags:
        - Transaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BuildTransactionRequest"
      responses:
        "200":
          description: "シリアライズされたトランザクションが正常に生成されました。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TransactionResponse"
        "400":
          description: "無効なリクエスト・ボディまたはcompute状態です。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /transaction/swap-base-out:
    post:
      summary: "スワップ・トランザクション生成（基本出力）"
      description: |
        目的の出力額のシリアライズされたスワップ・トランザクションを生成します。
        `/compute/swap-base-out` からの成功したcompute レスポンスが必要です。
      operationId: buildSwapTransactionBaseOut
      tags:
        - Transaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BuildTransactionRequest"
      responses:
        "200":
          description: "シリアライズされたトランザクションが正常に生成されました。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TransactionResponse"
        "400":
          description: "無効なリクエスト・ボディまたはcompute状態です。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

components:
  schemas:
    ComputeSwapResponse:
      type: object
      properties:
        id:
          type: string
          description: "一意のリクエスト識別子（UUID）。"
          example: "550e8400-e29b-41d4-a716-446655440000"
        success:
          type: boolean
          description: "compute が成功したかどうか。"
          example: true
        version:
          type: string
          description: "API レスポンス・バージョン。"
          example: "V1"
        data:
          type: object
          description: "スワップ計算結果。"
          properties:
            inputAmount:
              type: string
              description: "入力額（最小単位）。"
            outputAmount:
              type: string
              description: "予想出力額（スリッページを考慮）。"
            priceImpact:
              type: string
              description: "価格インパクト・パーセンテージ（例：0.5 は 0.5%）。"
            routes:
              type: array
              description: "使用されたスワップ・ルートとプールの配列。"
              items:
                type: object

    TransactionResponse:
      type: object
      properties:
        id:
          type: string
          description: "一意のリクエスト識別子。"
          example: "550e8400-e29b-41d4-a716-446655440000"
        success:
          type: boolean
          description: "トランザクション構築が成功したかどうかです。"
          example: true
        version:
          type: string
          example: "V1"
        data:
          type: object
          description: "トランザクションデータです。"
          properties:
            transaction:
              type: string
              description: "署名可能な状態のBase64エンコード済みバージョン付きトランザクションです。"
            addressLookupTableAddresses:
              type: array
              description: "アドレスルックアップテーブルのアドレス（txVersion=V0の場合）です。"
              items:
                type: string

    BuildTransactionRequest:
      type: object
      required:
        - wallet
        - swapResponse
        - txVersion
        - computeUnitPriceMicroLamports
      properties:
        wallet:
          type: string
          description: "署名者ウォレットアドレス（base58形式）です。"
          example: "11111111111111111111111111111111"
        swapResponse:
          type: object
          description: "コンピュートエンドポイントからの完全なレスポンスオブジェクトです。"
          properties:
            id:
              type: string
            success:
              type: boolean
            version:
              type: string
            data:
              type: object
        txVersion:
          type: string
          enum: [V0, LEGACY]
          description: "Solanaトランザクションのバージョンです。"
          example: V0
        computeUnitPriceMicroLamports:
          type: string
          description: "マイクロラムポート単位のコンピュートユニット価格（優先フィー用）です。"
          example: "1000"
        wrapSol:
          type: boolean
          description: "入力がネイティブSOLの場合、SOLをラップするかどうかです。"
          example: false
        unwrapSol:
          type: boolean
          description: "出力でWSolをSOLにアンラップするかどうかです。"
          example: false
        inputAccount:
          type: string
          description: "入力用のオプショナルトークンアカウントアドレスです。SOLをラップしない場合は必須です。"
          example: "TokenAccount1111111111111111111111111111111111"
        outputAccount:
          type: string
          description: "出力用のオプショナルトークンアカウントアドレスです。"
          example: "TokenAccount2222222222222222222222222222222222"
        jitoInfo:
          type: object
          description: "MEV対策用のオプショナルJitoバンドルパラメータです。"
          properties:
            address:
              type: string
              description: "Jitoバンドル送信アドレスです。"
            amount:
              type: string
              description: "ラムポート単位のバンドルチップ額です。"
        referrerWallet:
          type: string
          description: "フィー回収用のオプショナルリファラーウォレットアドレスです。"
          example: "ReferrerWallet1111111111111111111111111111111111"

    ErrorResponse:
      type: object
      properties:
        id:
          type: string
          description: "一意のリクエスト識別子です。"
        success:
          type: boolean
          example: false
        version:
          type: string
          example: "V1"
        msg:
          type: string
          description: "エラーメッセージコード（例：REQ_SLIPPAGE_BPS_ERROR、REQ_WALLET_ERROR）です。"
