> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testnet.dev.adipredictstreet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get backend co-signature for vault.mergePositions

> Inverse of split. Returns the backend co-signature needed to call `vault.mergePositions(...)` on-chain — burns equal units of every outcome ERC-1155 inside the vault and credits the corresponding USDC amount. The flow: (1) POST this endpoint with `{marketId, amount}` → server signs the MergePositions typed-data and returns the cosig + salt + deadline. (2) Sign the same struct yourself with your EOA against the vault's EIP-712 domain. (3) Submit `vault.mergePositions(kind, collateralToken, conditionId, partition, amount, salt, deadline, ownerSig, backendSig)` on-chain. After it confirms, the platform debits ERC-1155 holdings and credits USDC `available` for the vault. Use cases: closing a hedged position before resolution, freeing locked outcome tokens back into spendable USDC, exiting a market early.



## OpenAPI

````yaml /api-reference/openapi.json post /api/vault/merge-signature
openapi: 3.1.0
info:
  title: PredictStreet core-api
  description: >-
    Client-facing HTTP gateway for the PredictStreet prediction-market platform.
    This spec is hand-written against the NestJS controllers and DTOs in
    core-api/src/modules/. For the source-of-truth live spec, run
    `./scripts/pull-openapi.sh` against a running core-api (NestJS exposes it at
    /api/docs-json). **Partner kinds.** Every authenticated endpoint resolves a
    request's *effective wallet* from the partner row. `single_wallet` partners
    bind to one `associatedWallet` set at creation. `multi_wallet` partners
    declare the actor on every request via an `X-User-Wallet: 0x<40-hex>`
    header. See the [Partner kinds](/auth/api-keys#partner-kinds) doc for the
    full contract.
  version: '2026-06-16'
  contact:
    name: PredictStreet partners
    email: partners@predictstreet.com
servers:
  - url: https://core.api.dev.predictstreet.sde.adifoundation.ai
    description: Testnet (partner integrator API — final domain TBD)
security: []
tags:
  - name: Deposits
    description: >-
      Gasless USDC deposit relay - submit a signed EIP-2612 permit and the
      platform broadcasts the on-chain deposit for you (no gas).
  - name: Events
    description: >-
      Polymarket-style event grouping with football metadata (group, stage,
      teams, tags).
  - name: Tags
    description: Curated tag taxonomy used to filter events.
  - name: Markets
    description: 'Public market data: list, detail, orderbook, trades, OHLC.'
  - name: Orders
    description: >-
      Signed-order place / cancel / read. Requires `X-Api-Key` with
      `orders:read` / `orders:write` scope; every write additionally requires an
      EIP-712 signature over the order.
  - name: Portfolio
    description: >-
      Balances, positions, trades, fees, vault info for the key's
      `associatedWallet`. Requires `X-Api-Key` with `portfolio:read` scope.
  - name: Matches
    description: >-
      admin.matches aggregate — groups several events into one fixture/card (1X2
      + first-scorer + over-under under one matchup).
  - name: Vault
    description: >-
      Backend co-signatures for ERC-1155 split / merge, and recovery for
      off-chain locks when the corresponding chain tx never confirmed. Requires
      `X-Api-Key` with `vault:write` scope plus an EIP-712 signature over the
      operation.
  - name: Leaderboard
    description: Public ranked leaderboard across PnL / volume buckets.
  - name: Search
    description: Global search across users, events, and matches.
  - name: Withdrawal Security
    description: >-
      Self-service withdrawal 2FA (TOTP) and withdrawal-address whitelist. Same
      endpoints serve the frontend (Privy JWT) and API-key integrators.
      Mutations need `vault:write`, reads `portfolio:read`. Both are opt-in per
      wallet and only gate withdrawals once the platform enables
      withdrawal-security enforcement.
paths:
  /api/vault/merge-signature:
    post:
      tags:
        - Vault
      summary: Get backend co-signature for vault.mergePositions
      description: >-
        Inverse of split. Returns the backend co-signature needed to call
        `vault.mergePositions(...)` on-chain — burns equal units of every
        outcome ERC-1155 inside the vault and credits the corresponding USDC
        amount. The flow: (1) POST this endpoint with `{marketId, amount}` →
        server signs the MergePositions typed-data and returns the cosig + salt
        + deadline. (2) Sign the same struct yourself with your EOA against the
        vault's EIP-712 domain. (3) Submit `vault.mergePositions(kind,
        collateralToken, conditionId, partition, amount, salt, deadline,
        ownerSig, backendSig)` on-chain. After it confirms, the platform debits
        ERC-1155 holdings and credits USDC `available` for the vault. Use cases:
        closing a hedged position before resolution, freeing locked outcome
        tokens back into spendable USDC, exiting a market early.
      operationId: VaultController_requestMergeSignature
      parameters:
        - $ref: '#/components/parameters/UserWalletHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MergeSignatureRequest'
      responses:
        '200':
          description: Backend co-signature ready
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MergeSignatureResponse'
        '400':
          description: Validation error or unsupported market (binary only in MVP)
        '401':
          description: Missing or invalid X-Api-Key
        '404':
          description: Market not found
        '409':
          description: Market not in tradable status
        '429':
          description: Rate-limited. See per-endpoint limits in the auth overview.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      security:
        - ApiKeyAuth:
            - vault:write
components:
  parameters:
    UserWalletHeader:
      name: X-User-Wallet
      in: header
      required: false
      description: >-
        **Required for `multi_wallet` partners on every authenticated request;
        ignored for `single_wallet`.** Declares the acting end-user wallet for
        this request — drives KYC checks, balances/positions/orders attribution,
        rate-limit buckets, and audit. Lower-cased server-side. Missing on a
        multi_wallet key → 401 `api_key_user_wallet_required`; malformed → 401
        `api_key_user_wallet_invalid`. The on-chain `CTFExchange`/`Vault`
        contracts still verify EIP-712 signer ↔ vault binding, so loosening
        API-layer attribution is safe by construction.
      schema:
        $ref: '#/components/schemas/EthereumAddress'
      example: '0x1234567890abcdef1234567890abcdef12345678'
  schemas:
    MergeSignatureRequest:
      type: object
      required:
        - marketId
        - amount
      properties:
        marketId:
          type: string
          example: NC26-BIN-83479265
        amount:
          $ref: '#/components/schemas/DecimalString'
          example: '30'
          description: >-
            Decimal USDC amount the merge unwraps. Burns equal units of YES + NO
            inside the vault and credits this much USDC.
    MergeSignatureResponse:
      type: object
      required:
        - pendingMergeId
        - kind
        - collateralToken
        - conditionId
        - partition
        - backendSig
        - salt
        - deadline
        - vaultAddress
      properties:
        pendingMergeId:
          type: string
          description: >-
            Stable audit id derived from (wallet, marketId, amountWei, salt).
            Idempotent for retries.
        kind:
          type: integer
          description: 0 = binary, 1 = neg-risk.
        collateralToken:
          $ref: '#/components/schemas/EthereumAddress'
        conditionId:
          type: string
          pattern: ^0x[0-9a-fA-F]{64}$
        partition:
          type: array
          items:
            type: string
          example:
            - '1'
            - '2'
        amount:
          type: string
          description: USDC wei (6-decimal).
        salt:
          type: string
        deadline:
          type: integer
        vaultAddress:
          $ref: '#/components/schemas/EthereumAddress'
          description: >-
            EIP-712 verifyingContract for the MergePositions struct (the vault,
            not the factory).
        backendSig:
          $ref: '#/components/schemas/HexSignature'
          description: >-
            Backend co-signature; pair with the owner's EIP-712 signature in
            vault.mergePositions(...).
    ErrorEnvelope:
      type: object
      required:
        - error
      properties:
        status:
          type: integer
          example: 400
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              example: bad_request
            message:
              type: string
            details:
              type: object
              additionalProperties: true
            trace_id:
              type: string
    EthereumAddress:
      type: string
      pattern: ^0x[a-fA-F0-9]{40}$
      example: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb3'
    DecimalString:
      type: string
      description: >-
        Decimal number encoded as a string to preserve precision (e.g.
        `'100.5'`).
    HexSignature:
      type: string
      pattern: ^0x[a-fA-F0-9]+$
      description: 0x-prefixed hex-encoded ECDSA signature (usually 65 bytes).
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Partner / integrator key — format `ps_live_<keyId>_<secret>`. Issued by
        PredictStreet ops via the admin panel; never self-service. Never ship to
        a browser. `multi_wallet` partners must additionally send
        `X-User-Wallet: 0x<40-hex>` on every authenticated request to declare
        the acting wallet. See the [API keys guide](/auth/api-keys) for scope
        taxonomy, partner kinds, rate limits, and rotation procedure.

````