# Stock pools (PropAMM)

> How the Robinhood Chain PropAMM prices stock-token swaps against USDG with a hook-owned Uniswap v4 pool, a fair-value shield and a daily breaker.

Source: https://docs.degenhive.ai/pools

The PropAMM is DegenHive's market for Stock Tokens on Robinhood Chain (4663). Each stock trades against USDG in one Uniswap v4 pool, `MakerHook` is that pool's only liquidity provider, and every swap fee is set inside the hook.

> [!IMPORTANT]
> The contracts on this page are not deployed yet and not externally audited. Addresses publish at launch on [Network](https://docs.degenhive.ai/network.md).

## How it works

Five contracts run the market on Robinhood Chain:

| Contract | Role |
|---|---|
| `MakerHook` | The v4 hook for every Stock Token/USDG pool, one pool per stock. It alone adds or removes liquidity, blocks `donate`, enforces the `DOMAIN_ENTRY` pause, and computes each swap's dynamic LP fee on both `MakerHook.swap` and router swaps. |
| `MakerQuoter` | Read-only (`eth_call`) quoter (`quoteExactInput` and `quoteExactOutput`) that simulates the real swap fee path and returns exact output, fee paid and post-swap tick. |
| `MakerPilot` | The on-chain engine. Anyone calls `step(poolId)`; it sets fees, layout and auction start fees inside the guard policy bounds. |
| `BookVault` | One per pool. LPs deposit stock and USDG; the book owns everything the hook holds for that pool. See [Provide liquidity](https://docs.degenhive.ai/pools/liquidity.md). |
| `HiveFund` | The protocol's own allocator across books. It deposits like any LP through `allocate()`, once per UTC day. |

An off-chain poster, the `fairValueUpdater`, sends `updateFairTick(poolId, fairTick)` with the stock's reference price. When entry is paused (`DOMAIN_ENTRY`), swaps and deposits revert while withdrawals continue to work.

> **Figure: How MakerHook prices a swap.** MakerHook builds each swap's dynamic LP fee from seven layers on both MakerHook.swap and any v4 router, with inputs from MakerPilot and the fair-value poster, over liquidity only the hook holds.
>
> Center, MakerHook's seven-layer dynamic LP fee stack: 1. engine ask or bid fee; 2. fair-value shield; 3. router discount; 4. inventory skew; 5. size surcharge; 6. calendar floor and reopen auction; 7. a cap of 999,999 pips. The fee builds from rows 1 to 6 and never exceeds row 7. Left: a swapper calls MakerHook.swap or any v4 router, and both paths check the entry pause, apply the same seven-layer fee stack and emit SwapFeeCharged. Right: MakerPilot.step sets fees, layout and auctions inside the guard policy and feeds row 1; fairValueUpdater posts updateFairTick, fresh for maxStaleSecs, and feeds rows 2 and 3, which apply only while the fair tick is fresh. Bottom: BookVault books, one per pool, supply all the liquidity, and only MakerHook can add or remove it.

## The swap fee

Every swap, through `MakerHook.swap` or any v4 router, applies the same dynamic LP fee in pips (1,000,000 pips = 100%) built in this order:

| Part | What it does |
|---|---|
| Engine fee | `askPips` for buyers of the stock, `bidPips` for sellers, set by the engine. |
| Fair-value shield | Arbitrage toward a fresh fair tick pays a surcharge; flow away from it gets `rebDiscountBps` off. |
| Router discount | A per-router discount (up to 8,000 bps), only while the fair tick is fresh and the trade is not arbitrage. It tapers to zero with trade size. |
| Inventory skew | Flow that reduces the pool's drift from its day-start stock/USDG mix gets up to `invRebDiscountBps` off; flow that worsens it pays up to `invWorsenMaxPips` more. |
| Floor | The fee never drops below a quarter of the engine fee. |
| Size surcharge | Trades above `sizeThresholdBps` of pool depth pay up to `maxSizeFeePips` extra. |
| Calendar floor | The fee is at least the closed-hours fee or the running auction fee, whichever is higher. |
| Cap | 999,999 pips. |

The hook emits `SwapFeeCharged(poolId, sender, zeroForOne, amountSpecified, parts)` with each part, so integrators can see what a trade paid.

### Fair-value shield

The shield is fresh while `block.timestamp <= updatedAt + maxStaleSecs`, with `maxStaleSecs` at most 3,600 seconds. Each update moves at most 500 ticks from the last fair tick and lands within 1,000 ticks of the pool's TWAP. When the pool tick is more than `deadbandTicks` from fair, a trade toward fair pays:

`Arbitrage surcharge (pips)`

```math
arb = min( (|tick - fairTick| - deadbandTicks) * 100 * lvrGainBps / 10000, maxArbFeePips )
```

`lvrGainBps` is at most 20,000 and `maxArbFeePips` at most 250,000. With no fresh fair tick, the shield and every router discount switch off and the pool runs on the engine fee and calendar.

### Market hours

The council sets a weekly calendar per pool in minutes after Monday 00:00 UTC: up to 16 trading sessions and 16 auction times. Outside every session the fee is at least `closedFeePips` (at most the guard's `maxFeePips`, 10%). At each auction time the fee floor starts at the armed start fee and falls linearly to zero over `auctionDuration` (1 minute to 1 hour). This is a reopen Dutch auction: the price gap that builds while the stock market is closed is sold to the first trader who accepts the falling fee.

## MakerPilot.step

`MakerPilot.step(bytes32 poolId)` is permissionless and runs at most once per `minStepSecs` (60 seconds to 1 day) per pool. It reads only the pool's own TWAP, holdings and day-start mix. It measures volatility, sets a fee level plus inventory skew, picks a calm or storm layout, and arms the next auction's start fee. The guard policy bounds every action: fees inside `[minFeePips, maxFeePips]`, the average fee moving at most `feeStepPips` per `feePeriod`, and layout changes rate-limited by `layoutInterval` and `layoutsPerDay`.

## The daily breaker

On the first check of each UTC day the hook records the pool's holdings at the TWAP. If the pool later loses more than `dayLossBps` against simply holding those day-start tokens, the breaker trips. The engine is locked for `dayLockSecs`, fees go to `safeFeePips`, and all liquidity moves to full range. Clearing the breaker early (`clearBreaker`) waits the 2-day timelock.

## Why this limits LVR

Loss-versus-rebalancing (LVR) is what an AMM gives away when arbitrageurs trade against its stale price after the real price moves. The PropAMM narrows that loss in four places:

- The shield prices arbitrage by its distance to fair value, so the pool keeps part of each move.
- Closed-hours fees stop cheap trades against a price that cannot be checked.
- Reopen auctions sell the overnight gap through a falling fee.
- The breaker caps one day's loss against holding.

The book's performance fee is charged on gain over holding, so it is paid only when the pool beats holding its tokens.

## The numbers

| Parameter | Bound | Who changes it |
|---|---|---|
| Swap fee cap | 999,999 pips | Fixed |
| `maxFeePips` (engine) | 1 to 100,000 pips | Council, 2-day timelock |
| `maxStaleSecs` | 0 (off) to 3,600 s | Council, 2-day timelock |
| `lvrGainBps` / `maxArbFeePips` | ≤ 20,000 / ≤ 250,000 | Council, 2-day timelock |
| Router discount | ≤ 8,000 bps | Cut at once, raise after 2 days |
| `auctionMaxPips` | ≤ 200,000 | Council, 2-day timelock |
| `dayLossBps` / `dayLockSecs` | 1 to 2,000 bps / 1 hour to 30 days | Council, 2-day timelock |
| Calendar | ≤ 16 sessions, ≤ 16 auctions | Council, immediate |

## Edge cases

- Swaps revert with `EmptyPool` on both routes if the full-range position has no liquidity.
- While `DOMAIN_ENTRY` is paused, every swap reverts with `DomainError` (directly in `MakerHook.swap` and in `beforeSwap` for routers), including the books' own fee sales. Book withdrawals still run.
- `MakerHook.swap` enforces the `DOMAIN_ENTRY` pause directly, computes the same dynamic LP fee stack (fair-value shield, swap guard and calendar floor) with `sender` set to the hook itself, and emits `SwapFeeCharged`. A router discount applies to `MakerHook.swap` only if the hook's own address is listed.

## Related

- [Swap against a pool](https://docs.degenhive.ai/pools/swapping.md) Build the pool key, quote, and swap through the hook or any v4 router.
- [Provide liquidity](https://docs.degenhive.ai/pools/liquidity.md) Deposit into a BookVault and follow the daily roll.
- [Networks & status](https://docs.degenhive.ai/network.md) Robinhood Chain endpoints and deployment status.
- [Revenue](https://docs.degenhive.ai/revenue.md) Where book fees go after the roll.
