# Rebalance Mechanism

Rebalance is the core mechanism of Mooncake. After each rebalance, both Funding Positions and Leveraged Positions are **reset** into new positions. This ensures that the **Effective Leverage** of Leveraged Positions return to the **Target Leverage**.

## Rebalance Process

1. **Conversion to Underlying Value**
   * All Leveraged Positions and Funding Positions in the Leveraged Vault, Funding Vault, and LP Vault are converted into the equivalent value of the underlying token.
   * Conversion uses either:
     * Oracle Price (for **Scheduled Rebalances**), or
     * Price Cap/Floor (for **Price-Driven Rebalances**).<br>
2. **Re-splitting**

   The total underlying tokens are then re-split into new Funding Positions and Leveraged Positions, according to the target leverage.<br>
3. **Vault Adjustment**

   Funding Vault and Leveraged Vault are swapped against the LP Vault as needed, so that each vault ends up holding only its designated type of position. If mismatched positions remain, the system will keep retrying swaps until cleared.

<figure><img src="https://406199118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJU0ljCKdTl5gS8qv2O56%2Fuploads%2F0DvRUTIrh3yf1CDygWih%2Fimage.png?alt=media&#x26;token=8b110727-154b-4659-8d06-ae1c13db31b0" alt=""><figcaption></figcaption></figure>

### Rebalance Triggers

**Scheduled Rebalance**

To ensure the effective leverage does not drift too far from the initial target, Mooncake performs periodic rebalances for each market.<br>

**Price-Driven Rebalance**

When leverage deviation is caused by price movements, Mooncake applies a cap/floor mechanism. If the TWAP oracle price moves outside the cap or floor range, a rebalance is triggered at the cap/floor price.
