# 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="https://2608572446-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FesXIGSYvKcOjqMTCdsjo%2Fuploads%2Fb53tsPq646RXGUcbeSO0%2Fperennial-v2-Protocol%20View.drawio.svg?alt=media&#x26;token=ec8f35ea-02e8-4966-915a-6101b38586e5" 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="https://2608572446-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FesXIGSYvKcOjqMTCdsjo%2Fuploads%2F8hlaGLicChYwQlsayryD%2Fmarket_USER.drawio.png?alt=media&#x26;token=22422cb4-1c3c-4622-940f-cd2b61cfafa4" 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="https://2608572446-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FesXIGSYvKcOjqMTCdsjo%2Fuploads%2Fxn4jvxr17Y5MRCa8uMEs%2Fuser_make.drawio.png?alt=media&#x26;token=619bf715-85e8-4685-84e5-d8decc5fc6f8" alt=""><figcaption></figcaption></figure>
