> ## Documentation Index
> Fetch the complete documentation index at: https://docs.limora.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Protocol Overview

> Technical overview of the Limora protocol architecture

Limora is a decentralized leveraged trading protocol built on Base. This document provides a technical overview of how the protocol works.

***

## Architecture

The Limora protocol consists of several interconnected components:

```mermaid theme={null}
graph TB
    subgraph "User Layer"
        T[Traders]
        M[Matchers]
    end

    subgraph "Application Layer"
        UI[Web Interface]
        API[API Services]
    end

    subgraph "Protocol Layer"
        TC[Trading Contract]
        MC[Matching Contract]
        VC[Vault Contract]
    end

    subgraph "Infrastructure"
        O[Oracle]
        BC[Base Chain]
    end

    T --> UI
    M --> UI
    UI --> API
    API --> TC
    API --> MC
    TC --> VC
    MC --> VC
    TC --> O
    VC --> BC
```

***

## Core Components

### Trading Contract

The Trading Contract handles all trade-related operations:

* Opening new positions (long/short)
* Closing existing positions
* Liquidating undercollateralized positions
* Processing stop-loss and take-profit orders

### Matching Contract

The Matching Contract manages liquidity provision:

* Depositing collateral from matchers
* Matching pending trades with available liquidity
* Tracking matched positions and interest accrual
* Processing withdrawal requests

### Vault Contract

The Vault Contract serves as the secure storage layer:

* Holds all deposited collateral
* Manages fund transfers between traders and matchers
* Enforces access controls and security policies

***

## Trade Lifecycle

A typical trade follows this lifecycle:

<Steps>
  <Step title="Trade Request">
    Trader submits a trade request with: - Trading pair - Direction (long/short)

    * Collateral amount - Leverage - Optional stop-loss/take-profit
  </Step>

  <Step title="Pending State">
    Trade enters pending state, waiting for a matcher to provide liquidity.
  </Step>

  <Step title="Matching">
    A matcher deposits funds to match the trade, locking both parties'
    collateral.
  </Step>

  <Step title="Active Position">
    Position is now active: - P\&L calculated against oracle price - Interest
    accrues to the matcher - Stop-loss/take-profit monitored
  </Step>

  <Step title="Closure">
    Position closes via: - Manual close by trader - Stop-loss/take-profit
    trigger - Liquidation if margin insufficient
  </Step>

  <Step title="Settlement">
    Final settlement: - P\&L calculated at closing price - Funds distributed to
    both parties - Interest paid to matcher
  </Step>
</Steps>

***

## Position Mechanics

### Long Positions

When a trader opens a long position:

* Trader profits if the asset price increases
* Matcher profits if the asset price decreases
* Liquidation occurs if price drops below the liquidation threshold

**Example:**

```
Collateral: 100 USDC
Leverage: 10x
Position Size: 1,000 USDC
Entry Price: $50,000 BTC

If BTC rises to $55,000 (+10%):
  Profit = 1,000 USDC × 10% = 100 USDC (100% return on collateral)

If BTC falls to $45,000 (-10%):
  Loss = 1,000 USDC × 10% = 100 USDC (100% loss, near liquidation)
```

### Short Positions

When a trader opens a short position:

* Trader profits if the asset price decreases
* Matcher profits if the asset price increases
* Liquidation occurs if price rises above the liquidation threshold

***

## Collateral and Margin

### Initial Margin

Initial margin is the collateral required to open a position:

```
Initial Margin = Position Size / Leverage
```

### Maintenance Margin

Positions must maintain a minimum margin level to avoid liquidation:

```
Maintenance Margin = Position Size × Maintenance Margin Rate
```

### Liquidation

When a position's margin falls below the maintenance margin:

1. Position is flagged for liquidation
2. Liquidation bot executes the close
3. Remaining collateral distributed:
   * Liquidation penalty to protocol
   * Remaining to appropriate party

***

## Interest Model

Interest accrues continuously on open positions:

```
Hourly Interest = Position Size × Hourly Interest Rate
```

The interest rate is determined by:

* Utilization rate of the matching pool
* Market conditions
* Protocol parameters

Interest is paid from the trader to the matcher for the duration of the position.

***

## Security Model

### Smart Contract Security

* All contracts are audited by reputable security firms
* Upgradability follows strict governance procedures
* Emergency pause functionality for critical situations

### Oracle Security

* Multi-source price aggregation
* Deviation checks against historical data
* Staleness protection to reject outdated prices

### Access Control

* Role-based permissions for administrative functions
* Time-locks on critical parameter changes
* Multi-sig requirements for sensitive operations

***

## Protocol Parameters

Key configurable parameters:

| Parameter             | Description                         | Default |
| --------------------- | ----------------------------------- | ------- |
| Max Leverage          | Maximum allowed leverage            | 50x     |
| Liquidation Threshold | Margin level triggering liquidation | 80%     |
| Opening Fee           | Fee charged on position opening     | 0.1%    |
| Closing Fee           | Fee charged on position closing     | 0.1%    |
| Base Interest Rate    | Minimum hourly interest rate        | 0.001%  |

***

## Network Details

Limora is deployed on the Base network:

| Property     | Value        |
| ------------ | ------------ |
| Network      | Base Mainnet |
| Chain ID     | 8453         |
| Native Token | ETH          |
| Block Time   | \~2 seconds  |

***

## Further Reading

<CardGroup cols={2}>
  <Card title="Memo Strings" icon="code" href="/protocol/memo-strings">
    Learn about transaction memo format.
  </Card>

  <Card title="Oracle System" icon="broadcast-tower" href="/protocol/oracle">
    Understand the price oracle mechanism.
  </Card>

  <Card title="Contract Addresses" icon="file-contract" href="/protocol/addresses">
    Find deployed contract addresses.
  </Card>

  <Card title="API Reference" icon="book" href="/api/reference">
    Explore the API documentation.
  </Card>
</CardGroup>
