> For the complete documentation index, see [llms.txt](https://helix-5.gitbook.io/tradelayer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://helix-5.gitbook.io/tradelayer/architecture/data-model.md).

# Data model

Four shapes carry everything.

## Intent

Plaintext. Exists only on the device and inside the enclave.

```json
{
  "v": 1,
  "orderId": "0x…",
  "account": "0x…",
  "orgId": "0x…",
  "side": "BUY",
  "symbol": "TSLA",
  "maxSpend": "5000000",
  "expiry": 1789230185,
  "nonce": 1789222955,
  "userPubKey": "0x02…",
  "sig": "0x…"
}
```

* `sig` is an EIP-712 signature over every other field, domain `TradeLayerIntent`.
* `maxSpend` is in USDC base units (6 dp). Orders are placed **by amount**, not share count.
* `orgId` is **informational only** — H1 re-resolves the real institution from the registry.
* `nonce` must strictly exceed the portfolio's stored nonce, which is the replay guard.

## Sealed envelope

```json
{ "epk": "0x02…", "iv": "…", "ct": "…", "tag": "…" }
```

ECIES over secp256k1 to `INTENT_PUBKEY`, with an AES-256-GCM payload. The ephemeral key is fresh per envelope.

`commit = keccak256(ct)` is written into `OrderEscrow` at `openBuy`, binding the on-chain order to exactly this sealed intent. H1 recomputes it and rejects a mismatch — so the envelope handed to the enclave must be the one the escrow was opened against.

## Portfolio blob

Stored twice in `ConfidentialLedger`, under two different keys, for two different readers.

```json
{
  "cash": "0",
  "positions": { "TSLA": { "qty": "13680452", "locked": "0" } },
  "openOrders": {
    "0x…": { "side": "BUY", "symbol": "TSLA", "notional": "5000000",
             "escrow": "5000000", "brokerOrderId": "…", "placedAt": 1789222955 }
  },
  "nonce": 1789222955,
  "userPubKey": "0x02…"
}
```

* `enclaveBlob` — AES-256-GCM under `k_account = HKDF(LEDGER_MASTER_KEY, accountId)`.
* `userBlob` — ECIES to the employee's own public key, derived from a wallet signature over the fixed string `TradeLayer portfolio key v1`.

Share quantities are **9-decimal base units**, matching the ATS equities' precision, so a fractional position tracks exactly rather than drifting by dust each batch.

## Policy blob

```json
{
  "employees": {
    "0x…": { "canBuy": true, "canSell": true, "restricted": ["VOO"] }
  },
  "maxOrderNotional": "100000000",
  "allowWithdrawShares": false
}
```

Encrypted under `orgKey = HKDF(LEDGER_MASTER_KEY, orgId)`, written only through an admin-signed policy intent processed by H4, which proves authorship against `registry.adminOf` before accepting it.

Because the key derives from the ledger master key, **the admin cannot read their own rulebook back from the chain.** Publishing replaces it wholesale.

## Identifiers

|                   | Derivation                                            |
| ----------------- | ----------------------------------------------------- |
| `accountId`       | `keccak256(abi.encodePacked(address))`                |
| `orderId`         | client-chosen bytes32; must match the on-chain escrow |
| `orgId`           | `bytes32` of the institution's name, ASCII-padded     |
| `client_order_id` | the **first 32 hex characters** of `orderId`          |

That last one is load-bearing for verification: Alpaca caps `client_order_id` at 48 characters, so H1 sends a truncation of the on-chain order id. It is derived identically when placing (H1) and polling (H2), which keeps the broker itself the idempotency barrier against a duplicate buy — and it means an identifier taken from HashScan can be pasted into Alpaca to find the same order.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://helix-5.gitbook.io/tradelayer/architecture/data-model.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
