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

# How It Works (Technical)

Toggle is an operator of Uniswap v4 **DualPool**. One DualPool hook serves many pools. Each pool is a memecoin / USDG pair (or USDG / WETH, TOGGLE, and so on).

The hook is Uniswap’s audited DualPool bytecode, deployed through the AllowlistedFactory. Toggle does not modify swap math.

## Pool Shape

Each pool is a Uniswap v4 pool with DualPool attached.

At `initializePool`:

* **Fee** is static (set once, for example 0.30%). No dynamic fee.
* **Vaults** are bound once. USDG → Morpho ERC-4626 (Steakhouse USDG or another feeless vault whose `asset()` is USDG). Meme → `address(0)` (raw ERC-20).
* **Distribution** is 1–8 weighted tick buckets (weights sum to 10,000 bps). This is concentrated liquidity, not a Uniswap v2 pair.
* **External deposits** can be opened so anyone can LP.

`bootstrap` seeds inventory, mints shares, and sets the pool live. Swaps before bootstrap revert.

{% hint style="warning" %}
Native ETH is not supported. Use WETH. Fee-on-transfer and rebasing memes are not supported (`TransferReceiptShortfall` on deposit).
{% endhint %}

## Rest vs Work

Between swaps the PoolManager holds effectively **zero** liquidity.

| Leg      | Resting Place                                             |
| -------- | --------------------------------------------------------- |
| USDG     | ERC-4626 (`vault.deposit` / vault shares)                 |
| Memecoin | ERC-20 on the hook, or ERC-6909 claims in the PoolManager |

A 4626 is required for any vaulted leg. DualPool’s type is `IERC4626`. The alternative is `address(0)` (no yield). A Morpho Blue **market** is not a vault. Only a feeless 4626 whose `asset()` matches the currency can be bound.

Feeless check at init:

* `previewDeposit(x) == convertToShares(x)`
* `previewRedeem(x) == convertToAssets(x)`

{% hint style="danger" %}
Entry or exit fees fail init. Looping adapters that slip on unwind will fail this check or break JIT accounting. Toggle uses a lending vault, not a leverage loop, on the DualPool path.
{% endhint %}

## JIT Cycle (One Swap Transaction)

```mermaid
sequenceDiagram
    participant Trader
    participant DualPool
    participant Morpho
    participant PM as PoolManager
    Trader->>DualPool: swap
    DualPool->>Morpho: withdraw USDG shortfall
    DualPool->>PM: deploy tick buckets
    PM->>PM: v4 swap + fee
    DualPool->>PM: remove liquidity
    DualPool->>Morpho: deposit leftover USDG
```

**beforeSwap**

1. JIT lock (blocks reentrant LP / distribution changes).
2. Size each bucket from current balances and weights.
3. Compute token amounts via `SqrtPriceMath`.
4. Redeem claims; `withdraw` only the USDG shortfall from the vault.
5. Deploy each bucket as a DualPool LP position (`LP_SALT`).

PoolManager then executes a normal v4 swap against those positions and charges `PoolKey.fee`.

**afterSwap**

1. Remove the temporary positions.
2. Settle deltas with the PoolManager.
3. `deposit` remaining USDG back into the vault.
4. Clear the JIT lock.

No keeper. The swap pays for the round trip. Gas is higher than a vanilla v4 swap because vault I/O lives in the same transaction.

## Accounting

Shares are DualPool internal shares (non-transferable), v2-style `sqrt(amount0 * amount1)` on bootstrap, with virtual-offset inflation defense. LPs own a slice of total assets: vault shares + claims + ERC-20 on the hook.

Operator controls (outside the three invariants of fee, vault binding, and swap math):

* `setDistribution` — reshape tick buckets between swaps
* `setPoolLive` — pause / resume
* `setExternalDeposits`
* `emergencyRevokeVault` — pause, kill deposits, zero vault allowances, try to pull assets out

## Quoting

On-chain pool state between swaps shows a price and almost no liquidity. Routers that read depth only will skip Toggle.

DualPool exposes a quoting surface: an indicative quote against the liquidity the hook **would** deploy, plus total assets vs effective liquidity (what the vault can return right now if capped). Aggregators should quote that surface. A paused pool reverts with a distinct error.

## Protocol Take

Swap fees and harvest are split on-chain. LPs keep the majority. The protocol share buys TOGGLE on the market. See [Tokenomics](/tokenomics.md).

## What Toggle Adds

Uniswap DualPool is the engine. Toggle is the memecoin DualPool operator: factory and registry of meme / USDG pools, Morpho USDG vault binding, quoting for aggregators, and the TOGGLE buyback path.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.toggle.money/how-it-works-technical.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
