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

# Detect a market's generation

> Decide a market's generation from exchangeAddress and the generation-1 addresses in GET /api/platform/contracts, then pick the maker vault from GET /api/me/vault.

## Contract addresses

`GET /api/platform/contracts` (public) lists both generations. Cache it
for a few minutes; never hard-code the values.

```json theme={null}
{
  "chainId": 36900,
  "usdc": "0x…",
  "vaultFactory": "0x…",        "vaultFactoryGen2": "0x…",
  "ctfExchange": "0x…",         "ctfExchangeGen2": "0x…",
  "ctfExchangeNegRisk": "0x…",  "ctfExchangeNegRiskGen2": "0x…",
  "negRiskAdapter": "0x…",      "negRiskAdapterGen2": "0x…",
  "negRiskOracle": "0x…",       "negRiskOracleGen2": "0x…",
  "multicallExecutor": "0x…",
  …
}
```

The `*Gen2` fields are `null` until generation 2 is deployed in that
environment. The other fields are unchanged; see
[Environments](https://docs.adipredictstreet.com/environments.md).

## The rule

Every market (`GET /api/markets/{slug}` and the list endpoints) carries
`contractGeneration` (`1` | `2`) — stored at deploy time — as well as
`exchangeAddress`, the exchange it is pinned to (lower-case, set once),
and `negRiskEligible`.

The primary rule is reading `market.contractGeneration`:

* `contractGeneration === 2` → generation 2 (`Order.maker` = generation-2 vault, `verifyingContract` = `market.exchangeAddress`).
* `contractGeneration === 1` → generation 1 (`Order.maker` = generation-1 vault, `verifyingContract` = `ctfExchangeNegRisk` if `negRiskEligible`, else `ctfExchange`).

For clients that predated `contractGeneration` or when determining generation from `exchangeAddress` directly:

| `exchangeAddress` | Generation | `verifyingContract` |
| - | - | - |
| `null` (not pinned yet) | 1 | `ctfExchangeNegRisk` if `negRiskEligible`, else `ctfExchange` |
| `ctfExchange` or `ctfExchangeNegRisk` | 1 | `exchangeAddress` |
| Any other value | 2 | `exchangeAddress` |

Compare against the generation-1 addresses, which are always
published. Do not compare against the `*Gen2` fields: a bot that cached
them as `null` before the deploy would sign every generation-2 order
with the generation-1 vault and get `409 vault_generation_mismatch`
until it restarts.

```typescript theme={null}
const contracts = await fetch(`${BASE}/api/platform/contracts`).then(r => r.json()); // refresh every few minutes

function marketGeneration(market: { contractGeneration?: 1 | 2; exchangeAddress: string | null }): 1 | 2 {
  if (market.contractGeneration === 1 || market.contractGeneration === 2) return market.contractGeneration;
  const ex = market.exchangeAddress?.toLowerCase();
  if (!ex) return 1;
  const gen1 = [contracts.ctfExchange, contracts.ctfExchangeNegRisk].map((a: string) => a.toLowerCase());
  return gen1.includes(ex) ? 1 : 2;
}

function marketExchange(market: { exchangeAddress: string | null; negRiskEligible: boolean }): string {
  if (market.exchangeAddress) return market.exchangeAddress;
  return market.negRiskEligible ? contracts.ctfExchangeNegRisk : contracts.ctfExchange;
}
```

## Your vaults

`GET /api/me/vault` lists every vault you own:

```json theme={null}
{
  "walletAddress": "0x…",
  "vaultAddress": "0x…gen2",
  "generation": 2,
  "targetGeneration": 2,
  "status": "ready",
  "vaults": [
    { "vaultAddress": "0x…gen2", "generation": 2, "active": true },
    { "vaultAddress": "0x…gen1", "generation": 1, "active": false }
  ],
  "upgrade": { "status": "ready", "vaultAddress": "0x…gen2", … },
  "usdcMove": { "freeUsdc": "…", "transfer": null, … }
}
```

| Field | Meaning |
| - | - |
| `vaultAddress`, `generation` | The active vault. Deposit here |
| `vaults[]` | Every vault you own, with its generation |
| `upgrade` | State of the generation-2 vault deploy. See [Upgrade](https://docs.adipredictstreet.com/concepts/vault-gen2/upgrade.md) |
| `usdcMove` | Free USDC on the generation-1 vault (`freeUsdc`) and the open USDC move, if any. `freeUsdc` is `null` for a key without `portfolio:read` or `vault:write`; omit `amount` on the move to move all of it |

Pick the maker per market:

```typescript theme={null}
const maker = vaults.find(v => v.generation === marketGeneration(market))?.vaultAddress;
// undefined on a generation-2 market before the upgrade: the order would get 409 vault_generation_missing
```

Cache `vaults[]` rather than calling `GET /api/me/vault` before every
order. Refresh it after your upgrade, on the WebSocket's
`vault_activated` frame, or when the cache has no vault of the
generation you need.


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