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

# Merging positions

> Hold YES and NO of the same market? Merge the pairs back into USDC in your Safe before the market resolves, with one relayed signature.

A YES share and a NO share of the same market always pay **1.00 USDC between them**,
whatever the result. If you hold both, you do not have to wait for resolution: a
**merge** burns N YES + N NO from your Safe and pays **N USDC** back into it at once.

* Your YES and NO positions each go down by N.
* N USDC is added to your spendable [`balance_safe`](https://docs.calibri.io/non-custodial/balances).
* There is no fee. The difference between the 1.00 per pair and what you paid for the two
  shares is booked as realized P\&L on the positions.

Merging is `mergePositions` on the ConditionalTokens contract, signed by your Safe and
relayed gaslessly, the same way as [redeeming winnings](https://docs.calibri.io/non-custodial/redeeming-winnings.md).

> [!NOTE]
>
> Merges through the relay are being switched on gradually. Where they are not on yet, the
> relay refuses a merge with `422 relay.call_not_allowed`.

## When you can merge

While the market is `active`, `closed`, `resolving`, `proposed` or `escalated`. Once the
result is determined, [redeem](https://docs.calibri.io/non-custodial/redeeming-winnings.md) instead: the winning side
pays 1.00 and the losing side 0, which is the same total.

## How many pairs

At most your **free pairs**: the smaller of your YES and NO `sellable_volume`
(`GET /api/v2/atlas/account/positions`), less the pairs of your merges that are still
pending. Shares reserved by a resting sell, and shares from a buy that has not settled
on-chain yet, are not free. Cancel a resting sell first if you want to merge those shares.

Your own merges that are not `booked` or `failed` yet still count against your shares.
Subtract them from what you offer to sell, or the sale is voided when the merge lands.

## Merge, step by step

**1. Look up the market's condition**

`GET /api/v2/atlas/account/wallet/markets/{id}` gives the market's `condition_id`, with
the `usdc_address` and `conditional_tokens_address` you need below.

**2. Read the nonce**

`GET /api/v2/atlas/account/wallet/nonce` returns `{ "safe": "0x…", "nonce": "…" }`, the
nonce your next Safe transaction must sign. Read it just before signing.

**3. Build the mergePositions call**

Encode
`mergePositions(address collateralToken, bytes32 parentCollectionId, bytes32 conditionId, uint256[] partition, uint256 amount)`
with:

* `collateralToken` = `usdc_address`
* `parentCollectionId` = `0x0000…0000` (32 zero bytes)
* `conditionId` = `condition_id`
* `partition` = `[1, 2]` (YES and NO)
* `amount` = the number of pairs in USDC base units (6 decimals: 10 pairs = `10000000`)

**4. Sign it as a SafeTx**

`to` = `conditional_tokens_address`, `value` = 0, `operation` = 0 (a plain call). Send
the merge as a **single call**: a merge inside a MultiSend batch is refused. Sign with
your Safe's owner, as for any [relayed call](https://docs.calibri.io/non-custodial/the-safe.md#the-safetx-typed-data).

**5. Relay it**

`POST /api/v2/atlas/account/wallet/relay` with the encoded call, your signature and the
nonce. The operator executes it and pays gas.

**6. Wait for it to be booked**

Poll `GET /api/v2/atlas/account/positions/merges/{id}` with the `merge.id` from the
relay answer until `state` is `booked` (the USDC is in `balance_safe`) or `failed`.

### The relay call

```json theme={null}
{
  "safe": "0x… (your Safe)",
  "to": "0x… (ConditionalTokens address)",
  "value": "0",
  "data": "0x… (encoded mergePositions call)",
  "operation": 0,
  "signature": "0x… (your SafeTx signature)",
  "nonce": "41"
}
```

The answer carries the merge Calibri recorded for it:

```json theme={null}
{
  "tx": "0x…",
  "status": "mined",
  "state": "pending",
  "relay_id": "1907",
  "merge": { "id": 312, "state": "submitted" }
}
```

A `202` answers `{ "data": { "relay_id": "…", "state": "pending", "tx": null, "merge": { "id": 312, "state": "submitted" } } }`:
the transaction may have been sent and its outcome is not known yet. Poll the merge.
The other refusals and answers are the same as for any relay; see
[Relaying a setup call](https://docs.calibri.io/non-custodial/the-safe.md#relaying-a-setup-call).

### Why a merge is refused

Refusals are `422` with a `code`. Nothing is sent and no merge is recorded.

| Code | Meaning |
| - | - |
| `merge.bad_call` | The call could not be read, the partition is not `[1, 2]`, or the amount is 0 |
| `merge.unknown_market` | The condition is not a Calibri market |
| `merge.market_state` | The market is not open for merges. From `determined` on, redeem instead |
| `merge.not_enough_pairs` | More pairs than you have free. `max` gives the most you can merge now |
| `relay.call_not_allowed` | Merges are not switched on, or the merge was sent inside a MultiSend batch, or with a collateral other than USDC or a non-zero parent collection |

```json theme={null}
{
  "errors": ["You can merge at most 4 pairs in this market."],
  "code": "merge.not_enough_pairs",
  "max": "4"
}
```

## Merge states

| `state` | Meaning |
| - | - |
| `submitted` | Relayed; waiting for the chain |
| `confirmed` | The merge is on-chain and final; Calibri is booking it. `waiting_on` says why it is not booked yet, if it is waiting |
| `booked` | Done: positions reduced, USDC in `balance_safe`, `proceeds` and `realized_pnl` set |
| `failed` | Nothing was merged. `failure_reason`: `reverted`, `dropped` (the nonce was used by another transaction), `not_broadcast` or `superseded` (the same signed merge was booked on another record) |

`waiting_on` while `confirmed`:

* `inflight`: one of your trades on this market is still settling on-chain. The merge waits
  for it, which takes as long as that settlement.
* `settling`: the market is being settled. The merge is booked once that finishes.
* `funding`: an earlier transaction of your Safe (the one that brought the shares or the
  USDC) is not booked yet. The merge waits for it.
* `settlement_rows`: the merge landed after the market settled and waits for your
  settlement to be recorded. It then counts against your winnings: you are paid once,
  either way.

A merge or split you send from your Safe without the relay (with another
[signing key](https://docs.calibri.io/non-custodial/signing-keys.md)) is recorded and booked the same way.

## Your merges

**`GET /api/v2/atlas/account/positions/merges`**

Your merges, and any splits of USDC into pairs you sent from your Safe directly, newest
first. Filters: `market_id`, `kind` (`merge` or `split`), `state`. Paginated with `page` and
`limit` (up to 100), totals in the `Page`, `Per-Page` and `Total` headers.

**`GET /api/v2/atlas/account/positions/merges/{id}`**

One record. `404` for an id that is not yours.

```json theme={null}
{
  "id": 312,
  "kind": "merge",
  "state": "booked",
  "market_id": 14738,
  "market": {
    "id": 14738,
    "title": "…",
    "event_slug": "…",
    "event_title": "…",
    "outcome_labels": ["Yes", "No"]
  },
  "pairs": "10",
  "proceeds": "10",
  "realized_pnl": "0.4",
  "tx_id": "0x…",
  "failure_reason": null,
  "waiting_on": null,
  "created_at": "2026-11-30T09:12:03Z",
  "booked_at": "2026-11-30T09:13:41Z"
}
```

`proceeds` is the USDC credited. A booked merge also appears in your activity:
`GET /api/v2/atlas/account/transactions?type=position_merge` (`type` `merge` on the row, or
`split` for a split).

> [!NOTE]
>
> Splitting USDC into YES + NO pairs is not offered through the relay.

## Related

* [Redeeming winnings](https://docs.calibri.io/non-custodial/redeeming-winnings.md): after the result is determined
* [Balances](https://docs.calibri.io/non-custodial/balances.md): where the USDC lands (`balance_safe`)
* [The Safe](https://docs.calibri.io/non-custodial/the-safe.md): the relay endpoint and the SafeTx structure


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