# FXD Smart Contract Architecture

<figure><img src="https://2441370967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu8CvMeTMwSaHYwChGoRz%2Fuploads%2FNuUY41hBtiP77Auz1ox2%2FScreenshot%202024-06-02%20at%201.48.53%20PM.png?alt=media&#x26;token=e4c9d5e9-84bc-4b98-b872-6774a1b75bdc" alt=""><figcaption><p>FXD Stablecoin Smart Contract System Design</p></figcaption></figure>

<figure><img src="https://2441370967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu8CvMeTMwSaHYwChGoRz%2Fuploads%2FnTz4JtEaZxV0yWISLk5E%2FFXD_Architecture.drawio.png?alt=media&#x26;token=b8584bb0-38b8-4db5-84d0-7fc4be008f84" alt=""><figcaption><p>FXD Stablecoin Smart Contract Architecture</p></figcaption></figure>

#### Fathom Protocol Smart Contract Architecture

The structure comprises distinct modules, each responsible for a set of defined operations.

**Core Components**

1. **Proxy Module**: Interfaces for the core contracts of the protocol.
   * **ProxyWallet**: Calls functions within the FathomProxyActions contract for user interactions.
   * **ProxyActionsStorage**: Stores the address of the FathomProxyActions contract.
   * **ProxyWalletRegistry**: Oversees the creation of proxy wallets owned by users.
2. **Position Module**: Handles the creation and tracking of user positions.
   * **PositionManager**: Initiates user positions and maintains a record of them.
3. **Stablecoin Core Module**: Central to the management of the FXD stablecoin's lifecycle.
   * **BookKeeper**: Monitors and manages each position's locked collateral and debt share.
   * **CollateralPoolConfig**: Manages configurations for collateral pools.
   * **StablecoinAdapter**: Oversees the minting and burning functions of the FathomStablecoin contract.
4. **StableSwapModule**: Supports the provision of liquidity and the execution of FXD<->xUSDT 1:1 swaps.
   * **StableSwapModuleWrapper**: Integrates and administers the protocol's liquidity pools.
5. **Price Module**: Delivers accurate price information for assets.
   * **PriceFeed**: Gathers price data from price source and feeds it into the protocol.
   * **PriceOracle**: Transforms raw price from PriceFeed to include a safety margin, using the LTV ratio.
6. **Liquidation Module**: Maintains the protocol's financial health by managing under-collateralized positions.
   * **LiquidationEngine**: Carries out the liquidation process according to predefined rules.
   * **FixedSpreadLiquidationStrategy**: Directs liquidation activities, ensuring consistency through a fixed spread.
7. **Emergency Module**: Pause or Terminate the protocol.
   * **ShowStopper**: Stops and terminates the whole protocol and executes the emergency shutdown process to return collateral
   * **AdminControls**: Pauses the protocol at once.
