> For the complete documentation index, see [llms.txt](https://gremlix.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gremlix.gitbook.io/docs/getting-started/how-it-works.md).

# How it Works

## Step-by-Step Flow

### 1. User Deposits

You deposit an asset (USDC or BTC etc.) into a Gremlix vault. In return, you receive **ERC4626 vault shares** — fungible tokens representing your proportional ownership of the vault.

```
Deposit 1000 USDC → Receive 1000 gUSDC shares (at 1:1 initial ratio)
```

Over time, as the vault earns yield, the exchange rate of shares to assets increases:

```
Later: 1000 gUSDC shares → Redeem for 1080 USDC (8% gain)
```

### 2. Capital Allocation

The vault allocates deposited capital to one or more **Strategy contracts**. Each strategy executes a specific [grid trading](/docs/getting-started/grid-trading.md) approach on a Perpetual DEX.

The allocation happens via the **Keeper** — an authorized on-chain operator that calls `allocate()` to move capital from the vault into the strategy.

### 3. Grid Trading Execution

The strategy deploys capital on a Perpetual DEX (HyENA, Ethereal etc.) and runs automated grid orders:

* **Grid orders** are placed at regular price intervals above and below the current price
* When price moves up → sell orders execute, capturing spread profit
* When price moves down → buy orders execute, accumulating position at lower prices
* The cycle repeats continuously, generating income from price oscillations

Meanwhile, every executed trade earns **DEX protocol points** — a bonus yield layer from exchange's early-stage incentive program.

### 4. Yield Harvesting

Periodically, the Keeper calls `reconcileAndHarvest()`:

1. **Reconcile** — updates the on-chain strategy value to reflect actual off-chain/cross-chain PnL
2. **Harvest** — triggers vault accounting: new yield is recognized, performance fees are accrued, share price increases

This keeps the vault's share price up-to-date with real strategy performance.

### 5. User Redeems

At any time(check Vaults details), you can redeem your shares for the underlying asset at the current exchange rate. Your yield is the difference between your deposit value and redemption value.

```
Deposited:  1000 USDC
Shares:     1000 gUSDC
Redeemed:   1,083 USDC  (after fees)
Net yield:  +8.3%
```

## Value Flow Diagram

<figure><img src="https://3603376872-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlgA9ZMNVOvkQvQDUuKgk%2Fuploads%2FytHtj1QF5Jw5nSyMzNH1%2Fimage.png?alt=media&amp;token=5076822b-f026-438d-926e-3e7e55335f90" alt=""><figcaption></figcaption></figure>

## Two Yield Sources

| Source              | Description                                         | Frequency  |
| ------------------- | --------------------------------------------------- | ---------- |
| Grid trading spread | Buy low / sell high profits from price oscillations | Continuous |
| DEX Points          | Protocol points from trading volume on partner DEXs | Continuous |

All sources are harvested together and reflected in the rising share price.
