> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hex-api.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Pay out a receiver's pending withdrawals

> Queues paying out **every** pending withdrawal of `receiver` on `chain_id` and answers the job. Poll it with `GET /relay/jobs/{chain}/{id}`.

One job per receiver drains omni's `get_withdrawals_by_receiver` oldest first, one withdrawal at a time: an unpaid one is signed and sent to the chain's bridge (`withdraw`) from the relay's account, which pays the fees; a paid one is cleared on omni (`clear_completed_withdrawal`). It is done when omni lists none. A signing refusal fails the job with its detail; RPC and node failures are retried with backoff. A withdrawal to the token contract itself or to the zero address is never paid out, nor a Stellar one older than the bridge's 60-day nonce lifetime (it can only be refunded).

Chains the relay pays out on: EVM chains except Ethereum (1), Base (8453), Linea (59144), Mantle (5000) and Abstract (2741); Gonka (4444119), Stellar (1100) and TON (1117). A chain is also refused (400) while omni's removal key for it is neither the MPC key nor the one this service holds, since a payout it could not clear would block the receiver's next withdrawals.

Only a receiver omni holds a withdrawal for is queued: otherwise `404`, and nothing is queued. A receiver with a queued or running job answers that job (`reused: "active"`) instead of a new one; within 2 minutes of a job of the receiver that failed, or that already went past the withdrawal asked for (or found nothing), that job is answered too (`reused: "cooldown"`). A chain's payout queue holds at most 500 jobs per shard: past it, `429` with `Retry-After`.



## OpenAPI

````yaml https://mpc.hex-api.app/openapi.json post /relay/withdraw
openapi: 3.1.0
info:
  title: HEX MPC API
  version: 1.0.0
  summary: HOT bridge signatures and relay, the bridge registry and monitor.
  description: >
    The public API of `hex-mpc`, a Cloudflare Worker in front of the HOT MPC
    nodes. It replaces the old HOT backend's bridge endpoints

    (`api0.herewallet.app`: `process_bridge_deposit`, `auto_deposit_register`,
    ...) and HOR (`rpc1.hotdao.ai`, `rpc2.hotdao.ai`).


    ## Which routes to use


    - **Credit a deposit to NEAR Intents**: `POST /relay/deposit` with the
    source tx (or the deposit's fields). The service reads the deposit on its
    chain, signs it and sends `mt_deposit_call` on NEAR, paying the gas. This is
    what `process_bridge_deposit` did.

    - **Pay out withdrawals**: `POST /relay/withdraw` with the chain and the
    receiver; poll `GET /relay/jobs/{chain}/{id}`.

    - **Clear a paid withdrawal**: `POST /relay/clear`.

    - **Submit transactions yourself**: the `Signatures` routes return the MPC
    signatures only.

    - **Record what your users do** (optional, for support and recovery): `POST
    /bridge/register`, `/bridge/deposits`, `/bridge/withdrawals`.


    Every relay call sends only what holds on chain (a deposit that happened,
    the payout of a withdrawal omni holds, the clear of a paid one), and each at
    most once, so retrying a call is safe.


    ## Conventions


    - **Bodies** are JSON objects, at most 32 KiB (`/intents/solver`: 128 KiB).
    A body that is not a JSON object is a `422`, a larger one a `413`.

    - **Big integers.** Nonces and amounts are answered as decimal strings. In
    requests they may be decimal strings or JSON integers: integers above 2^53
    are read exactly (the bridge's nonces are about 1.8e21), but a decimal
    string is the safer choice for clients whose JSON encoder uses doubles.

    - **Nonces** are omni's: `unix seconds * 10^12 + n`.

    - **Encodings.** omni's token ids, receivers and the bridge signatures are
    base58; NEAR tx hashes are base58.

    - **Chain ids.** Chain ids are omni's (`v2_1.omni.hot.tg`), not always the
    chain's own: EVM chains use their EIP-155 id (Ethereum 1, Optimism 10, BNB
    56, Polygon 137, Monad 143, X Layer 196, Base 8453, Arbitrum 42161,
    Avalanche 43114, ...); the others have omni's numbers: Solana 1001, NEAR
    1010, Stellar 1100, TON 1117 (TON v1, 1111, is dead), Juno 4444118, Gonka
    4444119.

    - **Errors** are `{ "detail": "..." }` with an HTTP status (FastAPI's
    format, kept from HOR), the router's own `404`, `405` and `429` included.
    Clients should branch on the status and show or log the `detail`. A `5xx`
    (and a `502`/`503` in particular) is worth retrying with backoff; a `4xx`
    will answer the same until something changes on chain.

    - **CORS.** Any origin; the request's `Origin` is echoed with
    `access-control-allow-credentials: true`, and preflights allow `GET, POST,
    OPTIONS` with any header.

    - **Times** in answers are milliseconds since the epoch unless named `*_s`
    (seconds).


    ## Rate limits


    Per client IP (an IPv6 client by its /64), over 60 seconds, counted per
    Cloudflare location:


    | Class | Limit | Routes |

    | --- | --- | --- |

    | `bridge` | 300 / 60 s | `/withdraw/sign`, `/deposit/sign`, `/clear/sign`,
    `/relay/*`, `/bridge/*` |

    | `solver` | 120 / 60 s | `/intents/solver` |


    `/v1/health`, `/v1/time` and `/openapi.json` are not limited. Over the limit
    the answer is `429` `{ "detail": "Too many requests" }` with `Retry-After:
    60`.


    ## Load protection


    The MPC nodes are a fixed quorum: every signature is a round on each of
    them. So on top of the per-IP limits, every call that reaches the nodes (the
    `Signatures` routes, and the relay's own signing) is admitted globally,
    whoever asks:


    - **Rate per kind of signing**, by default 300 a minute each for
    withdrawals, deposits and clears: over it, `429` with `Retry-After`.

    - **Signings at once**, 60 in all, each kind its own share: over it, `503`
    `MPC nodes are busy, try again shortly` with `Retry-After`. Also `503` with
    `Retry-After` when the nodes answer `429` or too few of them are up.

    - **One signing per message.** A signature is kept for a day and answered
    again (a retry, another client, the relay), and while it is being made a
    second request waits for it (or gets `503` `This signature is being made,
    try again shortly` after 45 s). A refusal of the bridge (`400`) is answered
    again for 5 seconds.

    - **Refusals before the nodes**: a deposit omni already credited (`400`
    `Deposit … is already credited`), a withdrawal no payout can land (`400`
    `Withdrawal … : it can only be refunded`: it pays the token contract itself,
    the zero address, or a Stellar nonce past its 60 days).


    Retry a `429` or `503` after its `Retry-After`.
servers:
  - url: https://mpc.hex-api.app
    description: Production
security: []
tags:
  - name: Relay
    description: >-
      The recommended integration: the service sends the bridge's transactions
      and pays for them. Deposits are credited to NEAR Intents; withdrawals are
      paid out on their chain and cleared on omni.
  - name: Signatures
    description: >-
      The bridge's MPC signatures, for callers that submit the transactions
      themselves (HOR-compatible: same bodies, answers and errors). Each
      signature needs omni's word, and a deposit or clear also its AuthCall on
      chain, so a caller cannot forge or redirect one.
  - name: Registry
    description: >-
      The bridge registry: what users do on the bridge, as clients report it and
      as the relay sees it on chain. A post only records a claim: nothing is
      signed or sent for it, and what the relay reads on chain overrides it.
      Lookups answer 503 while the registry's database is not configured.
  - name: Monitor
    description: Health of every bridge HEX moves funds through, over 24 hours.
  - name: Intents
    description: >-
      NEAR Intents solver relay passthrough, used by HEX/HOT kit to publish
      signed intents.
  - name: Service
    description: Health, time and this document.
paths:
  /relay/withdraw:
    post:
      tags:
        - Relay
      summary: Pay out a receiver's pending withdrawals
      description: >-
        Queues paying out **every** pending withdrawal of `receiver` on
        `chain_id` and answers the job. Poll it with `GET
        /relay/jobs/{chain}/{id}`.


        One job per receiver drains omni's `get_withdrawals_by_receiver` oldest
        first, one withdrawal at a time: an unpaid one is signed and sent to the
        chain's bridge (`withdraw`) from the relay's account, which pays the
        fees; a paid one is cleared on omni (`clear_completed_withdrawal`). It
        is done when omni lists none. A signing refusal fails the job with its
        detail; RPC and node failures are retried with backoff. A withdrawal to
        the token contract itself or to the zero address is never paid out, nor
        a Stellar one older than the bridge's 60-day nonce lifetime (it can only
        be refunded).


        Chains the relay pays out on: EVM chains except Ethereum (1), Base
        (8453), Linea (59144), Mantle (5000) and Abstract (2741); Gonka
        (4444119), Stellar (1100) and TON (1117). A chain is also refused (400)
        while omni's removal key for it is neither the MPC key nor the one this
        service holds, since a payout it could not clear would block the
        receiver's next withdrawals.


        Only a receiver omni holds a withdrawal for is queued: otherwise `404`,
        and nothing is queued. A receiver with a queued or running job answers
        that job (`reused: "active"`) instead of a new one; within 2 minutes of
        a job of the receiver that failed, or that already went past the
        withdrawal asked for (or found nothing), that job is answered too
        (`reused: "cooldown"`). A chain's payout queue holds at most 500 jobs
        per shard: past it, `429` with `Retry-After`.
      operationId: relayWithdraw
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RelayWithdrawRequest'
            examples:
              polygon:
                summary: An EVM receiver
                value:
                  chain_id: 137
                  receiver: '0xe4df1d74122c2a7b14481cbdde704fbd0a4f11a2'
              stellar:
                summary: A Stellar receiver, in omni's base58
                value:
                  chain_id: 1100
                  receiver: 1114wxgAxsZMgcitQaVJLFGp4U8ZgJTtC6wgFMt2pu4tEXU1bzbfMaiEDiw
      responses:
        '200':
          description: 'The receiver''s job: new, or the active one.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnqueueAnswer'
              examples:
                queued:
                  summary: A new job
                  value:
                    id: 3.b55dd9d2-a1bd-48fb-b8d6-6e91aa21433b
                    origin: api
                    chain_id: 137
                    receiver: 4BwLMDn4SNyrgHHgU9x5tAudyGZ7
                    status: queued
                    steps: []
                    created_at: 1792944180000
                    updated_at: 1792944180000
                active:
                  summary: The receiver already has one
                  value:
                    id: 3.b55dd9d2-a1bd-48fb-b8d6-6e91aa21433b
                    origin: api
                    chain_id: 137
                    receiver: 4BwLMDn4SNyrgHHgU9x5tAudyGZ7
                    status: running
                    pending: 2
                    steps: []
                    detail: >-
                      withdraw
                      0xdfd90cb908815115b944a21f71a015cccfe668ff8752e49d440beb9da7769df4
                      of 1792107257000001836156 is pending
                    created_at: 1792944180000
                    updated_at: 1792944184000
                    reused: active
        '400':
          description: The chain is not relayed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                unrelayed:
                  value:
                    detail: >-
                      Chain 8453 withdrawals are not relayed: not served by the
                      relay
                clears:
                  value:
                    detail: >-
                      Chain 56 withdrawals are not relayed: its clears cannot be
                      signed here
                notRelayed:
                  value:
                    detail: Chain 1001 withdrawals are not relayed
        '404':
          description: omni holds no withdrawal to the receiver on the chain.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                none:
                  value:
                    detail: >-
                      No pending withdrawal to
                      0xe4df1d74122c2a7b14481cbdde704fbd0a4f11a2 on chain 137
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '422':
          description: A malformed field.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                chain:
                  value:
                    detail: chain_id must be a chain id
                evm:
                  value:
                    detail: receiver must be an EVM address
                other:
                  value:
                    detail: receiver is not an address of chain 1100
        '429':
          description: Over the per-IP rate limit, or the chain's payout queue is full.
          headers:
            Retry-After:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                limited:
                  value:
                    detail: Too many requests
                full:
                  value:
                    detail: The withdraw relay of chain 137 is full, try again later
        '500':
          $ref: '#/components/responses/InternalError'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    RelayWithdrawRequest:
      type: object
      required:
        - chain_id
        - receiver
      properties:
        chain_id:
          $ref: '#/components/schemas/ChainId'
          description: >-
            The target chain. Chains the relay pays out on: EVM chains except
            Ethereum (1), Base (8453), Linea (59144), Mantle (5000) and Abstract
            (2741); Gonka (4444119), Stellar (1100) and TON (1117). A chain is
            also refused (400) while omni's removal key for it is neither the
            MPC key nor the one this service holds, since a payout it could not
            clear would block the receiver's next withdrawals.
        receiver:
          type: string
          description: >-
            The withdrawals' receiver: on EVM a `0x` address or omni's base58 of
            its 20 bytes; on Gonka a bech32 address or omni's base58; on Stellar
            and TON omni's base58 (as `get_withdrawals_by_receiver` names it).
          examples:
            - '0xe4df1d74122c2a7b14481cbdde704fbd0a4f11a2'
    EnqueueAnswer:
      allOf:
        - $ref: '#/components/schemas/DrainJob'
        - type: object
          properties:
            reused:
              type: string
              enum:
                - active
                - cooldown
              description: >-
                Set when no new job was made: `active`, the receiver's queued or
                running job; `cooldown`, its last job, finished within 2 minutes
                (failed, or already past the withdrawal asked for), or for the
                refuel sweep within its longer cooldown.
    Error:
      type: object
      description: 'Every error: FastAPI''s `{ detail }` with the HTTP status.'
      required:
        - detail
      properties:
        detail:
          type: string
          description: What went wrong, readable.
      examples:
        - detail: Nonce was not used on target chain
    ChainId:
      type: integer
      minimum: 1
      description: >-
        Chain ids are omni's (`v2_1.omni.hot.tg`), not always the chain's own:
        EVM chains use their EIP-155 id (Ethereum 1, Optimism 10, BNB 56,
        Polygon 137, Monad 143, X Layer 196, Base 8453, Arbitrum 42161,
        Avalanche 43114, ...); the others have omni's numbers: Solana 1001, NEAR
        1010, Stellar 1100, TON 1117 (TON v1, 1111, is dead), Juno 4444118,
        Gonka 4444119.
      examples:
        - 1100
        - 1117
        - 137
        - 4444119
    DrainJob:
      type: object
      required:
        - id
        - origin
        - chain_id
        - receiver
        - status
        - steps
        - created_at
        - updated_at
      properties:
        id:
          type: string
          description: '`<shard>.<uuid>`, or a bare uuid.'
        origin:
          type: string
          enum:
            - api
            - refuel
          description: >-
            `api`: `POST /relay/withdraw`. `refuel`: the service's own sweep of
            stuck withdrawals.
        chain_id:
          $ref: '#/components/schemas/ChainId'
        receiver:
          $ref: '#/components/schemas/Base58'
          description: The receiver as omni keeps it (base58 of its bytes).
        status:
          type: string
          enum:
            - queued
            - running
            - done
            - failed
        pending:
          type: integer
          minimum: 0
          description: >-
            The receiver's pending withdrawals at the last step. Absent before
            the first.
        steps:
          type: array
          items:
            $ref: '#/components/schemas/DrainStep'
        detail:
          type: string
          description: Why it failed, or what it is waiting for.
        created_at:
          type: integer
          description: ms.
        updated_at:
          type: integer
          description: ms.
    Base58:
      type: string
      pattern: ^[1-9A-HJ-NP-Za-km-z]+$
      description: Base58 (Bitcoin alphabet).
    DrainStep:
      type: object
      required:
        - nonce
        - action
        - tx
        - at
      properties:
        nonce:
          $ref: '#/components/schemas/NonceString'
        action:
          type: string
          enum:
            - withdraw
            - clear
          description: >-
            `withdraw`: the payout sent on the target chain. `clear`:
            `clear_completed_withdrawal` on NEAR.
        tx:
          type: string
          description: >-
            The tx (or, on EVM through the smart wallet, the call id) of the
            step.
        at:
          type: integer
          description: When, ms.
    NonceString:
      type: string
      pattern: ^\d{1,39}$
      description: omni's nonce (`unix seconds * 10^12 + n`), decimal.
      examples:
        - '1792944123000000004211'
  responses:
    PayloadTooLarge:
      description: 'The body exceeds 32 KiB (`/intents/solver`: 128 KiB).'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            tooLarge:
              value:
                detail: Body exceeds 32768 bytes
    InternalError:
      description: An unexpected error. Its message is not exposed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            internal:
              value:
                detail: Internal Server Error
    BadGateway:
      description: >-
        A chain or NEAR RPC is unavailable, or an answer could not be read.
        Retry with backoff.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            near:
              value:
                detail: NEAR RPC is unavailable, try again
            chain:
              value:
                detail: Stellar RPC of chain 1100 is unavailable, try again
    ServiceUnavailable:
      description: Something the route needs is not configured on the service.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            nodes:
              value:
                detail: MPC nodes are not configured
            relay:
              value:
                detail: The relay's NEAR keys are not configured
  headers:
    RetryAfter:
      description: Seconds to wait.
      schema:
        type: integer
      example: 60

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.