From sui-dev-agents
Integrates DeepBook V3 on SUI — canonical CLOB DEX, margin engine, and prediction-market substrate. Use for on-chain trading, order books, perpetuals, leverage, or building DEXes.
How this skill is triggered — by the user, by Claude, or both
Slash command
/sui-dev-agents:sui-deepbookThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Canonical CLOB DEX, margin engine, and prediction-market substrate on SUI.**
Canonical CLOB DEX, margin engine, and prediction-market substrate on SUI.
Targets: @mysten/deepbook-v3 1.4.1 (^1.3), @mysten/sui 2.17.0 (^2.16). Tested: 2026-06-03.
Compatibility notes: Use @mysten/deepbook-v3 (V3 — current). The legacy @mysten/deepbook / clob_v2 packages are deprecated and not what you want.
V3 is a clean break from V2. If you've used V2 (deepbook::clob_v2, AccountCap, custodian), forget the mental model:
| Concern | V2 (legacy) | V3 (current) |
|---|---|---|
| Account model | AccountCap per pool, custodian-owned funds | BalanceManager — one shared object holds all your funds, scoped via TradeCap / DepositCap / WithdrawCap |
| Fees | Paid in base/quote | Paid in DEEP (or whitelisted alternative via payWithDeep: false on supported pools) |
| Pool creation | Permissioned | Permissionless (createPermissionlessPool) — burn DEEP as creation fee |
| Margin / leverage | n/a | First-class: MarginManager, MarginPool, liquidations, Pyth oracles |
| Order primitives | place_limit_order only | Limit + Market + IOC + FOK + Post-Only + Self-matching policies + TPSL conditional orders |
| Move modules | deepbook::clob_v2 | deepbook::pool, deepbook::balance_manager, margin::* |
Do not mix V2 and V3 examples in the same codebase. The Move modules, object types, and SDK packages are entirely separate.
┌─────────────────┐ ┌──────────────┐
│ BalanceManager │◄────────┤ TradeCap │ (delegate trading without giving up funds)
│ (shared obj) │ └──────────────┘
│ • Base coins │
│ • Quote coins │ ┌──────────────┐
│ • DEEP │◄────────┤ TradeProof │ (per-tx capability, generated from cap)
└────────┬────────┘ └──────────────┘
│
│ attached to every order via TradeProof
▼
┌─────────────────┐
│ Pool │ baseCoin / quoteCoin, tick_size, lot_size, min_size
│ (shared obj) │ CLOB matching engine, DEEP fee escrow
└─────────────────┘
Mental model: BalanceManager is your wallet; Pool is the order book. Every order references a BalanceManager via a TradeProof. You can grant TradeCap to a market-making bot (up to ~1,000 authorized traders per BM) without exposing withdrawal rights.
Fee economics: Paying with DEEP gives a fee discount (canonically ~20% — verify current rate); DEEP stakers earn maker rebates and vote on per-pool fee parameters.
Pool internals: A Pool is split into Book (matching), State (governance/fee params), and Vault (settlement). PoolRegistry enforces a single pool per (Base, Quote) pair — no fragmented liquidity.
Client choice (read this — do not skip): @mysten/sui v2 removed SuiClient and getFullnodeUrl. Use SuiGrpcClient from @mysten/sui/grpc. JSON-RPC is deprecated (full removal April 2026). Any code you write using new SuiClient(...) or getFullnodeUrl(...) is wrong on the current SDK and will not type-check.
import { SuiGrpcClient } from '@mysten/sui/grpc';
import { DeepBookClient } from '@mysten/deepbook-v3';
import { Transaction } from '@mysten/sui/transactions';
const suiClient = new SuiGrpcClient({
network: 'mainnet',
baseUrl: 'https://fullnode.mainnet.sui.io:443',
});
const dbClient = new DeepBookClient({
client: suiClient,
address: '0xYOUR_ADDRESS',
network: 'mainnet',
// Optional: register your own BalanceManager so SDK helpers resolve by key
balanceManagers: {
MY_BM: { address: '0xYOUR_BALANCE_MANAGER_ID' },
},
});
The SDK ships mainnet/testnet pool maps (SUI_USDC, DEEP_USDC, DEEP_SUI, …) and package IDs — you don't hard-code them.
// @check:skip — fragment, continues from Quick Start §1
const tx = new Transaction();
tx.add(dbClient.balanceManager.createAndShareBalanceManager());
// Sign + execute, then grab the new shared object ID from object changes
// and feed it back into DeepBookClient as `balanceManagers.MY_BM.address`.
If you want to delegate trading: use createBalanceManagerWithOwner(owner) and mint a TradeCap separately (balanceManager.mintTradeCap).
// @check:skip — fragment, continues from Quick Start §1
const tx = new Transaction();
tx.add(dbClient.balanceManager.depositIntoManager('MY_BM', 'SUI', 1.5));
tx.add(dbClient.balanceManager.depositIntoManager('MY_BM', 'DEEP', 10)); // fee fuel
Quantities are human-readable (1.5 SUI, not 1_500_000_000 MIST). The SDK applies coin scalar from its CoinMap.
// @check:skip — fragment, continues from Quick Start §1
import { OrderType, SelfMatchingOptions } from '@mysten/deepbook-v3';
const tx = new Transaction();
tx.add(
dbClient.deepBook.placeLimitOrder({
poolKey: 'SUI_USDC',
balanceManagerKey: 'MY_BM',
clientOrderId: '1001', // your tracking ID
price: 2.15, // quote per base, human units
quantity: 10, // base units, human
isBid: true, // true = buy SUI
orderType: OrderType.POST_ONLY, // maker-only; cancels if it would cross
selfMatchingOption: SelfMatchingOptions.CANCEL_TAKER,
payWithDeep: true, // DEEP fee path (cheapest on supported pools)
}),
);
PlaceLimitOrderParams (from @mysten/deepbook-v3):
poolKey, balanceManagerKey — string keys into your configured mapsclientOrderId — string; surfaces in events for your reconciliationprice, quantity — number | bigint, human units (SDK rescales)isBid — true buy base / false sell baseexpiration? — epoch ms; defaults to MAX_TIMESTAMPorderType? — NO_RESTRICTION | IMMEDIATE_OR_CANCEL | FILL_OR_KILL | POST_ONLYselfMatchingOption? — SELF_MATCHING_ALLOWED | CANCEL_TAKER | CANCEL_MAKERpayWithDeep? — true (default) uses DEEP fee path// @check:skip — fragment, continues from §4
tx.add(
dbClient.deepBook.placeMarketOrder({
poolKey: 'SUI_USDC',
balanceManagerKey: 'MY_BM',
clientOrderId: '2001',
quantity: 5,
isBid: true,
payWithDeep: true,
}),
);
// @check:skip — fragment, continues from §4
tx.add(dbClient.deepBook.cancelOrder('SUI_USDC', 'MY_BM', orderId));
tx.add(dbClient.deepBook.cancelAllOrders('SUI_USDC', 'MY_BM'));
tx.add(dbClient.deepBook.modifyOrder('SUI_USDC', 'MY_BM', orderId, newQuantity));
// @check:skip — fragment, continues from Quick Start §1
// Top-of-book + depth
const mid = await dbClient.midPrice('SUI_USDC');
const { bids, asks } = await dbClient.getLevel2Range('SUI_USDC', 2.0, 2.30, true);
// Account view
const balances = await dbClient.checkManagerBalance('MY_BM', 'SUI');
const openOrders = await dbClient.accountOpenOrders('SUI_USDC', 'MY_BM');
// Quote a hypothetical fill
const out = await dbClient.getQuoteQuantityOut('SUI_USDC', 10);
All read methods are on the DeepBookClient instance and are async (Promise<...>). They route through devInspect / RPC — no signing needed.
Since SUI v1.47, DeepBook is not an implicit dependency. Pin it explicitly:
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
DeepBook = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/deepbook", rev = "main" }
Token = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-system", rev = "framework/mainnet" }
Minimal Move call (most teams should use the SDK instead — direct Move integration is for protocol composability):
use deepbook::pool::Pool;
use deepbook::balance_manager::{BalanceManager, TradeProof};
use token::deep::DEEP;
use sui::clock::Clock;
public fun place_bid<Base, Quote>(
pool: &mut Pool<Base, Quote>,
manager: &mut BalanceManager,
proof: &TradeProof,
client_order_id: u64,
price: u64, // scaled, see FLOAT_SCALAR
quantity: u64, // scaled to base coin decimals
expire_timestamp: u64,
clock: &Clock,
ctx: &mut TxContext,
) {
deepbook::pool::place_limit_order<Base, Quote>(
pool,
manager,
proof,
client_order_id,
0, // NO_RESTRICTION
0, // SELF_MATCHING_ALLOWED
price,
quantity,
true, // is_bid
true, // pay_with_deep
expire_timestamp,
clock,
ctx,
);
}
DeepBook Margin adds leverage on top of any CLOB pool via separate objects
(MarginManager, MarginPool, PoolProxy, Pyth oracles, MarginTPSL). For the
full setup → borrow → place-margin-order → TPSL flow, health/liquidation reads,
and margin pitfalls, see references/margin.md.
Off-chain REST service for historical / aggregate data (OHLCV, volume, trade history, orderbook snapshots) that you can't cheaply derive from live RPC. Live state (current depth, your open orders) → SDK; historical / aggregates → indexer. For endpoints and the full indexer-vs-SDK guidance, see references/indexer.md.
Expiry-based prediction markets — a separate deepbook_predict Move package,
NOT the CLOB (no Pool / BalanceManager / order book; trades price against an LP
vault via OracleSVI). Testnet-only/experimental as of 2026-05. For the object
model, on-chain entry points, oracle lifecycle, data-read paths, and pitfalls,
see references/predict.md.
clientOrderId as your reconciliation key. It echoes back in events and order objects; the on-chain orderId is generated and not predictable.getQuoteQuantityOut / getBaseQuantityOut to compute expected slippage; show the user the worst-case fill.OrderType.POST_ONLY for market-making strategies to avoid accidentally crossing the spread and paying taker fees.tx.add(...) composition pattern is built for this.CANCEL_TAKER (default-allowed self-matches waste fees).❌ Using SuiClient / getFullnodeUrl (v1 SDK)
@mysten/sui v2 (current); imports fail at type-check, RPC client is wrong shape.import { SuiGrpcClient } from '@mysten/sui/grpc'; construct with { network, baseUrl }. The DeepBook SDK is built against the gRPC client, not the legacy JSON-RPC one.❌ Mixing V2 (clob_v2) examples with V3 imports
clob_v2::place_limit_order doesn't exist on the V3 deployment; LLMs hallucinate this constantly.deepbook::pool::place_limit_order + BalanceManager + TradeProof. No AccountCap, no custodian_v2.❌ Forgetting DEEP for fees
checkManagerBalance(bm, 'DEEP') before placing; or set payWithDeep: false on pools that support whitelisted fee tokens.❌ Hard-coding pool / package IDs
mainnetPools / testnetPools / mainnetPackageIds from the SDK; if you must override, do it via DeepBookClient constructor options.❌ Confusing human vs. scaled units
1_500_000_000 to the SDK when it expects 1.5.coin.scalar internally. Move modules take scaled units. Know which layer you're at.❌ Treating BalanceManager like a per-pool AccountCap
Need current contract addresses, indexer endpoints, or Predict launch status? Use the sui-docs-query skill (Context7 MCP) — e.g. "v3 mainnet contract-information balance manager package id".
Reference URLs (canonical, check for updates):
One BalanceManager, many pools, DEEP fuels the engine.
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
npx claudepluginhub first-mover-tw/sui-dev-agents --plugin sui-dev-agents