# Contracts

The Somnia DEX uses a distinct contract for each trading pair. To discover available markets and their contract addresses, query the [`GET /v0/markets`](/ld25g222WKDrLlJMcR41/developers/http-api/market-data.md) endpoint.

## OrderBook API (SpotPool)

* [Types](/ld25g222WKDrLlJMcR41/developers/contracts/types.md) — structs and enums used in function signatures and event payloads.
* [Functions](/ld25g222WKDrLlJMcR41/developers/contracts/functions.md) — place, cancel, reduce, and query orders; deposit and withdraw from the vault; manage builder approvals.
* [Events](/ld25g222WKDrLlJMcR41/developers/contracts/events.md) — on-chain events emitted by the order book contract.

## StopOrderRegistry API (SpotStopOrderRegistry)

Each SpotPool has a corresponding StopOrderRegistry for stop-loss, take-profit, and stop-buy orders. See [Stop Orders](/ld25g222WKDrLlJMcR41/trading/readme-1/stop-orders.md) for how they work.

* [Types](/ld25g222WKDrLlJMcR41/developers/contracts/types.md#stop-order-types) — `PendingOrderType`, `Operator`, `PendingOrder`, `PendingOrderWithTrigger`
* [Functions](/ld25g222WKDrLlJMcR41/developers/contracts/functions.md#stop-orders-spotstoporderregistry) — `createPendingOrder`, `cancelPendingOrder`, `claimSomi`, and view functions
* [Events](/ld25g222WKDrLlJMcR41/developers/contracts/events.md#stop-order-events) — `PendingOrderCreated`, `PendingOrderTriggered`, `PendingOrderCancelled`, `SomiRefundFailed`

## SpotRouter API

A multi-stage swap router that walks ordered SpotPool legs as taker orders in a single transaction. Powers the [Simple Swap](/ld25g222WKDrLlJMcR41/trading/readme-1/simple-swap.md) frontend. The router is a pure orchestrator — pools auto-pull / auto-deliver between the user's wallet and the router never custodies funds across legs.

* [SpotRouter reference](/ld25g222WKDrLlJMcR41/developers/contracts/spot-router.md) — functions (`swapExactIn` / `swapExactOut` / `quoteMarketExactIn` / `quoteExactIn` / `quoteExactOut`), events, errors, caller prerequisites, and the quote → swap recipe.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dreamdex.io/ld25g222WKDrLlJMcR41/developers/contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
