# Conditional market

Conditional markets are markets which based on the outcome of an existing market.

Let's take an example to follow up on the question from the previous section. We could have a market asking **If the war in Ukraine ends in 2024, will Russia withdraw all its troops from Ukrainian territory by the end of 2025?** This market will be conditional to the market [**Will war in Ukraine stop in 2024?**](https://seer-3.gitbook.io/seer-documentation/developers/interact-with-seer/market-example) resolving to **Yes.**

### Create a conditional market

To create a conditional market, you must have an address of the parent market and the parent outcome:

{% code overflow="wrap" %}

```javascript
await marketFactory.createCategoricalMarket({
  marketName: `If the war in Ukraine ends in 2024, will Russia withdraw all its troops from Ukrainian territory by the end of 2025?`,
  category: "misc",
  lang: "en_US",
  parentOutcome: 0 // 0 is Yes in parent market,
  parentMarket: parentMarketAddress,
  questionStart: "", // only used in multi-scalar
  questionEnd: "", // only used in multi-scalar
  outcomeType: "", // only used in multi-scalar
  outcomes: ["Yes", "No"],
  lowerBound: 0, // only used in scalar
  upperBound: 0, // only used in scalar
  minBond: "1000",
  openingTime: 1767139200, //2025-12-31T00:00:00.000Z
  tokenNames: ["YES", "NO"],
})
```

{% endcode %}

### Split, merge and redeem a conditional market

To interact with conditional outcome tokens, we have to use <mark style="color:red;">`Router`</mark> instead of <mark style="color:red;">`GnosisRouter`</mark>.

#### Splitting

Before splitting a conditional market, you must have enough parent outcome tokens first (by splitting or trading):

{% code overflow="wrap" %}

```typescript
await parentToken.approve(router, "1000"); // allow the router to spend your parent outcome tokens
await router.splitPosition(
    collateralToken,
    market, // the conditional market
    "1000", // split amount
);
```

{% endcode %}

As you can see, the process is quite similar to splitting a simple market. Under the hood, we used a specific **parentCollectionId** instead of the default bytes32(0). The market contract has already saved this variable, and can be accessed with:

```typescript
await market.parentCollectionId()
```

If you want to know how a **parentCollectionId** is generated in detail, you can check out the [Conditional Tokens GitHub site](https://github.com/gnosis/conditional-tokens-contracts). In short, it requires the **parentCollectionId** of the parent market, the **conditionId** of the parent market and the **indexSet** of the parent outcome.

```typescript
await conditionalTokens.getCollectionId(
    await parentMarket.parentCollectionId(),
    await parentMarket.conditionId(),
    "0b001",
)
```

After splitting, you will notice that your parent tokens are no longer present. Instead, you will have multiple sets of conditional outcome tokens at your disposal.

#### Merging

The process is the exact opposite of splitting. Here, the contract will burn your conditional outcome tokens and return the corresponding parent tokens to you.

**Redeeming**

The contract will burn the specified conditional outcome tokens. If you are redeeming a winning outcome, it will return the corresponding parent tokens to you in proportion to the payouts.

```typescript
await router.redeemPositions(
    collateralToken,
    market,
    [0], // array of outcome indexes
    [1000n], // array of redeem amounts
);
```

#### Nested conditional markets

In theory, the conditional tokens framework supports infinite nesting levels. You can create a conditional market based on another conditional market and interact with it as you would with any market.&#x20;

However, conditional markets are dependent on their parent market's outcome. If the parent market resolves to an outcome different from the one assumed by the child market, then the child market and all markets nested under it become obsolete.
