# Architecture

Fathom DEX relies on a robust and secure smart contract architecture to facilitate its decentralized exchange functionalities.

These smart contracts are the [Uniswap V2 direct fork](https://docs.uniswap.org/contracts/v2/concepts/protocol-overview/smart-contracts). They are battle-tested on various networks and are considered safe.

### **Overview of Smart Contract Architecture**

#### **Factory Contract**

* **Role:** The factory contract is responsible for deploying new liquidity pool contracts. It maintains a registry of all active liquidity pools on the platform.
* **Functions:**
  * CreatePair: Deploys a new pair contract for a given token pair.
  * GetPair: Retrieves the address of an existing pair contract.

#### **Pair Contract**

* **Role:** Each pair contract represents a liquidity pool for a specific token pair. It manages the addition and removal of liquidity, as well as the execution of token swaps.
* **Functions:**
  * AddLiquidity: Allows users to add tokens to the liquidity pool.
  * RemoveLiquidity: Allows users to withdraw their tokens from the liquidity pool.
  * Swap: Facilitates token swaps between the two tokens in the pair.

#### **Router Contract**

* **Role:** The router contract provides the main interface for users to interact with the DEX. It routes transactions to the appropriate pair contracts.
* **Functions:**
  * AddLiquidity: Simplifies the process of adding liquidity by automatically calculating the optimal token amounts.
  * RemoveLiquidity: Manages the removal of liquidity, ensuring users receive the correct token amounts.
  * SwapExactTokensForTokens: Executes a token swap with a specified input amount.
  * SwapTokensForExactTokens: Executes a token swap with a specified output amount.


---

# 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.fathom.fi/dex/architecture.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.
