← Contract Hero · WorkLearnPlugins
acc-deepbook-course
All lessons Lesson 4 · DeepBook track

Market-Maker Bot

Run a two-sided maker on DeepBook v3. Stand up one BalanceManager to hold inventory for both sides, compute a bid and ask grid around mid price, rest it with POST_ONLY orders so it never crosses, stake DEEP for fee rebates, and unwind with cancel-all-and-refresh.

placeLimitOrder OrderType.POST_ONLY governance.stake cancelAllOrders
What you'll learn

Quoting both sides at once

  • ›Two-sided quoting from a single BalanceManager that holds inventory for both the bid and ask side.
  • ›POST_ONLY orders so the maker always makes and never accidentally crosses the book to take.
  • ›Staking DEEP through governance to qualify for maker fee rebates.
Walkthrough

Five sections, end to end

  1. One BalanceManager

    Create a single shared account that holds the inventory backing every leg of the grid.

    src/sandbox.ts
  2. Compute the grid

    Build a symmetric ladder of bids and asks around the current mid price, snapped to the pool tick.

    src/marketMaker.ts
  3. Rest the grid

    Place every level with POST_ONLY in one transaction, so the engine rejects any leg that would cross.

    src/marketMaker.ts
  4. Stake DEEP

    Deposit and stake DEEP through governance so the maker qualifies for fee rebates next epoch.

    src/marketMaker.ts
  5. Unwind & re-quote

    Cancel the whole grid atomically, wire the smoke UI, and pass the live gate.

    src/App.tsx · src/main.tsx
Run it

Start this lesson

claude code
/acc-deepbook-course:start
# then pick "Market-Maker Bot"

Already installed? Run the start command and choose this lesson from the catalog.

New here? Follow the install steps first. The course brings up a local sandbox and gates each section with pnpm vitest run.