# Perpetual DEX Module

The perpetual side of Amara is forked from GMX and adapted to run natively on Odyssey Chain. It provides leverage trading through a vault-based collateral model, backed by smart contracts that manage deposits, orders, liquidations, and fees.

**Vault**\
At the heart of the perpetual system is the Vault contract. Liquidity providers deposit assets such as USDC, DIONE into this vault. These assets serve as collateral for traders opening long and short positions. The Vault tracks balances, applies profit and loss from open trades, and ensures that withdrawals are only possible when funds are available.

**Router**\
The Router acts as the main entry point for traders. When a user wants to open, adjust, or close a position, they submit the transaction through the Router. The Router validates inputs, interacts with the Vault to lock collateral, and creates an order record. It ensures a standardized workflow so that all positions follow the same lifecycle.

**Position Manager**\
The Position Manager is responsible for maintaining open trades. It handles leverage calculations, applies funding rates, and checks margin requirements. If a position falls below required thresholds, it flags it for liquidation. This module also integrates with the Oracle system to update positions with the latest price data.

**Asynchronous Execution Flow**\
Orders in Amara are executed asynchronously, mirroring GMX’s design. When a trader submits an order, it does not execute instantly. Instead:

1. The order is stored on-chain through the Router.
2. Off-chain keepers monitor pending orders.
3. Once conditions are met (such as price, time, or collateral checks), a keeper executes the order.
4. The Oracle provides the latest price feed at the moment of execution.

This design protects users from frontrunning and ensures fairness, as execution always uses the most recent validated price.

**Fee Logic**\
Fees in the perpetual system are dynamic. Beyond standard swap and funding fees, Amara introduces impact-based adjustments.

* If a trade improves pool balance, it is charged a lower fee.
* If a trade worsens pool balance, it incurs a higher fee.\
  This mechanism discourages imbalances in collateral pools and incentivizes healthier market activity.

**Market Utilities**\
The perpetual module also includes supporting utilities:

* **Liquidation logic**: Automatically closes undercollateralized positions.
* **Funding rate adjustments**: Keeps long and short positions balanced over time.
* **Auto-deleveraging (ADL)**: Protects the protocol in extreme scenarios by partially reducing positions to stabilize the pool.

Together, these components allow Amara to run a secure, capital-efficient perpetual exchange with support for synthetic carbon credits and native Odyssey assets.


---

# 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.amara.exchange/architecture-and-design/perpetual-dex-module.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.
