# Vault Design

**Vault Architecture**

Each vault (GLP++, GM, etc.) is a standalone unit made up of two key components: the *Vault*, and the *Trader*. The Vault is an ERC-4626 compatible single staking vault, which handles all deposit, withdrawal, and share accounting functions. The Trader is tasked to deploy the vault’s funds according to the vault’s designated trading strategy.

In V0 whitelisted proof-of-concept vaults, this address has been an EOA controlled by BWS Labs. For production vaults, the Trader will be a smart contract which provides an interface for executing the strategy safely.

**Vault Process**&#x20;

The vault works in cycles called “epochs”. Each epoch has a *funding* phase, a *trading* phase, and a *withdrawal* phase. When the vault opens in the funding phase, users can deposit the vault’s underlying currency, or withdraw their assets if they have a balance from previous epochs. During the trading phase, users may not deposit or withdraw, and the trader may take custody of the vault’s funds. When the trader returns the vault’s funds, the epoch ends, and the vault enters a withdrawal-only state until another epoch and its associated funding window is started.

Each vault follows the same steps for each epoch:

1. Vault opens;
2. The user deposits the vault’s underlying token, ex. USDC, and receives share tokens representing an equivalent percentage of total vault funds;
3. The vault closes and the trader takes custody of the funds;
4. Strategies are executed by the experienced Investment Team through the Trader Smart Contract. Only designated traders from the BWS trading team can interact with the trader contract
5. The Trader Smart Contract restricts the traders to a specific set of actions, only for whitelisted DeFi protocols;
6. BWS Trading Engine uses the locked funds to execute trades;
7. The Trader unwinds all positions and returns the vault funds and profits/losses, less fees, to the vault;
8. The vault is in a withdrawal only state until the next funding window opens.

<figure><img src="/files/7QHr08KVag1jZmoOY4zY" alt=""><figcaption><p>Process flow of D-Squared vaults</p></figcaption></figure>

**Vault Contract Structure**

D-Squared has designed its trader smart contracts on a modular basis. The strategy’s modules are selected when it is built, and cannot be changed once deployed, providing assurance to the user that their funds can only be used as originally stated.

Initially, the strategies will have a limited selection of modules to choose from. Over time as more modules are developed and audited, more complex strategies will be possible, and the protocol will be well-positioned to take advantage of any emerging market opportunities by deploying a new Vault and Strategy with the appropriate mix of modules.

<br>


---

# 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.d2.finance/docs/vault-design.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.
