# Technical Architecture

## Diamond Pattern Implementation

The protocol leverages the **EIP-2535 Diamond Pattern** to achieve modularity, upgradeability, and well-organized shared storage management.

#### Core Components

1. **Diamond Contract**

   Acts as the main entry point, delegating function calls to the appropriate facets.
2. **Facets**

   Modular contracts that implement specific areas of functionality.
3. **Shared Storage**

   Structured storage layout that is accessible across all facets, ensuring consistency and upgrade safety.

## Storage Architecture

| **Storage Contract**     | **Purpose**                | **Key Data Structures**                                                        |
| ------------------------ | -------------------------- | ------------------------------------------------------------------------------ |
| **AppStorage**           | Global configuration       | System version, collateral whitelist, limits, timeouts, Party B configurations |
| **AccountStorage**       | User balances and accounts | Scheduled releases, withdrawal records, nonces                                 |
| **SymbolStorage**        | Trading instruments        | Symbol definitions, oracle references, instrument configurations               |
| **TradeStorage**         | Active positions           | Open intents, close intents, active trades                                     |
| **StateControlStorage**  | System state management    | Pause states, emergency flags, suspended addresses                             |
| **AccessControlStorage** | Permission management      | User roles, access rights                                                      |

## Facet Organization

**1. Account Management**

* **Account Facet**

  Manages user deposits, withdrawals, balances, and collateral allocation.

2. **Trading Operations**

* **Party A Open Facet** & **Party A Close Facet**

  Handle Party A’s position opening and closing intents.
* **Party B Open Facet** & **Party B Close Facet**

  Manage Party B’s intent locking, unlocking, and filling intents.
* **Trade Facet**

  Manage trade execution and cancelation.
