# Codebase

Perennial V2 has been designed to be as modular as possible, allowing for horizontal scaling to many markets, oracles & vaults.&#x20;

### Ownership Hierarchy&#x20;

In terms of structure, the protocol owns three factories covering Markets, Oracles & Vaults. The protocol owner can use these factories to spawn new markets, exotic oracles & vaults to direct liquidity. \
\
Additionally, the protocol owns the Multi Invoker (an Operator contract for the UI)

<figure><img src="/files/eGcgIEkA3W4ammwgsq6d" alt=""><figcaption><p>A hierarchical ownership tree for the perennial protocol.</p></figcaption></figure>

### Standard Market Flow w/ MultiInvoker

When a user interacts with a market using the MultiInvoker they are able to bundle a number of steps required to modify their position.

<figure><img src="/files/92ACkPale3TJtO7WPuva" alt=""><figcaption><p>A user takes a 1 unit position in a market.</p></figcaption></figure>

### Standard Vault flow w/ MultiInvoker

When a user interacts with a Vault they generally follow this flow to adjust the vault balances between markets.

<figure><img src="/files/X7J0mP987uae7TwR4aEn" alt=""><figcaption></figcaption></figure>


---

# 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.perennial.finance/protocol/codebase.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.
