DeepBook V3 Dart SDK

Dart/Flutter SDK for DeepBook V3 — the decentralized central limit order book (CLOB) on Sui. A faithful port of the official @mysten/deepbook-v3 TypeScript SDK (v2.6.8), running on the gRPC(-web) transport of package:sui ≥ 0.5.0.

History: 0.1.0 was a complete rewrite — the 0.0.x releases targeted DeepBook V2 (0xdee9), decommissioned on-chain, over the now-sunset JSON-RPC API, and nothing from them survives. 0.2.0 moves margin onto Pyth's upgraded Core and adds Predict, sessions and the account primitive. See CHANGELOG.

Coverage

Full parity with the official TS SDK surface:

  • Spot CLOB — BalanceManager (deposits/withdrawals/trade caps/proofs), order placement & cancellation, swaps, flash loans, governance (stake/vote/proposals), referrals.
  • Queries — all devInspect-style reads: order book (level2), pool parameters, account state, quantity quotes, registry, margin state.
  • Margin trading — margin managers, margin pools, leveraged orders via pool proxy, TP/SL conditional orders, liquidations, maintainer/admin ops. Targets Pyth's upgraded Core (the only deployment the official SDK supports); price updates need a Hermes credential via pythAccessToken.
  • Pyth — Hermes (v2) price service client, wormhole VAA verification and on-chain price feed updates.
  • Predict (package:deepbook/predict.dart) — prediction markets: market discovery, quotes, mint/redeem/claim, PLP, typed receipts, and client-side all-in cost previews that are an exact integer port of the on-chain fee path.
  • Account & sessions (package:deepbook/account.dart, package:deepbook/sessions.dart) — the shared on-chain account primitive and time-limited trading sessions over it, mirroring the official SDK's /account and /sessions subpaths. Like the official package root, package:deepbook/deepbook.dart is unchanged — the new surfaces are separate entry points.
  • Admin — pool creation/tuning, version management, stablecoin whitelist (requires the DeepbookAdminCap).

Install

dependencies:
  deepbook: ^0.2.0
  sui: ^0.5.0

Quick start

import 'package:sui/sui.dart' hide Coin; // `Coin` also exists in deepbook
import 'package:deepbook/deepbook.dart';

final grpc = SuiGrpcClient(network: SuiNetwork.mainnet);
final client = DeepBookClient(
  client: grpc.core as GrpcCoreClient,
  network: 'mainnet',
  address: '0x...your address',
  balanceManagers: {
    'MAIN': BalanceManager(address: '0x...your balance manager'),
  },
);

// Read the book.
final mid = await client.midPrice('SUI_USDC');
final book = await client.getLevel2TicksFromMid('SUI_USDC', 10);

// Trade: compose a transaction with the contract builders, then sign+execute
// with the sui package.
final tx = Transaction();
client.deepBook.placeLimitOrder(PlaceLimitOrderParams(
  poolKey: 'SUI_USDC',
  balanceManagerKey: 'MAIN',
  clientOrderId: '1',
  price: 3.05,
  quantity: 10,
  isBid: true,
))(tx);

final account = SuiAccount.fromPrivateKey('suiprivkey...');
final executed = await (grpc.core as GrpcCoreClient)
    .signAndExecuteTransaction(account, tx);

Every transaction-builder method returns a closure to apply to a Transaction — contract.method(...)(tx) — mirroring the official SDK's tx.add(contract.method(...)) composition, so multiple calls compose into one programmable transaction block.

Quantity/price inputs accept either a num (human units, scaled by the coin scalar) or a BigInt (raw on-chain u64).

Networks

Built-in constants cover mainnet and testnet (package ids, coins, pools, margin pools, Pyth state). For localnet or custom deployments pass packageIds:/coins:/pools: explicitly (see tool/localnet/setup.sh for a self-deployed localnet used by the tests).

Regenerating the contract bindings

lib/src/contracts/ is generated from the official SDK's codegen output:

dart tool/codegen/generate.dart <ts-sdks>/packages/deepbook-v3/src/contracts
dart format lib/src/contracts

Testing

  • flutter test test/config_test.dart test/byte_compare_test.dart test/account_sessions_byte_compare_test.dart test/predict_byte_compare_test.dart test/predict_cost_test.dart test/pyth_offline_test.dart — offline. The byte-compare suites verify builder output against fixtures produced by the official TS SDK (tool/byte_compare/gen_fixtures*.mjs regenerates them), and the Predict cost suite asserts bit-exact parity with the official fee engine. The fixtures live in the repository but are not shipped in the published package; the suites skip themselves when they are absent.
  • flutter test test/balance_manager_live_test.dart test/queries_live_test.dart test/predict_live_test.dart test/pyth_live_test.dart — live against public testnet.
  • test/*_localnet_test.dart — full REAL-EXECUTION integration against a self-deployed localnet: matched trades, market/IOC/FOK/post-only orders, swaps in both directions, flash loans, cap-based permissions, governance, and the complete margin stack (borrow/repay, leveraged orders via pool proxy, TP/SL conditional orders, and liquidation driven by a crashed oracle price). Prepare the chain once with tool/localnet/vendor.sh, then tool/localnet/setup.sh per regenesis. These skip automatically when no localnet is configured. The margin suite currently requires a re-vendored deployment carrying the _upgraded modules (the SDK's oracle entrypoints target Pyth's upgraded Core since 0.2.0); until then the margin write path is covered by the byte-compare suites.

Web platform

flutter test test/web_transport_test.dart test/config_test.dart --platform chrome covers the browser path: the gRPC-web transport, dio, config / constants / conversion, and BCS (including the u128 BigInt path).

The network layer is verified end-to-end in a real browser: tool/webcheck/run.sh builds a minimal Flutter Web app against this package, serves it, and loads it in headless Chrome, asserting that live gRPC-web reads against a mainnet fullnode succeed (chain id, mid price, pool params). flutter build web --release takes ~25s.

Note: flutter test --platform chrome cannot compile a suite that constructs GrpcCoreClient — the test runner's compiler stalls on the generated sui.rpc.v2 protobuf set (124 files, ~18k lines). That is a test-runner limitation only; release web builds are unaffected, which is why browser coverage of the network layer lives in tool/webcheck/ rather than in a --platform chrome test.

The byte-compare suite is VM-only (@TestOn('vm')) because it reads fixtures from disk.

Libraries

account
The shared on-chain account primitive — package:deepbook/account.dart.
account/account
Full generated bindings for the account Move module (account): every move-call builder and BCS struct, including symbols the flat package:deepbook/account.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/account/account.dart' as account;
account/account_events
Full generated bindings for the account_events Move module (account): every move-call builder and BCS struct, including symbols the flat package:deepbook/account.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/account/account_events.dart' as account_events;
account/account_registry
Full generated bindings for the account_registry Move module (account): every move-call builder and BCS struct, including symbols the flat package:deepbook/account.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/account/account_registry.dart' as account_registry;
deepbook
Dart SDK for DeepBook V3 — the decentralized central limit order book on Sui. Aligned with the official @mysten/deepbook-v3 TypeScript SDK (v1.6.2). Transport is the gRPC(-web) stack from package:sui 0.5.0.
predict
DeepBook Predict — package:deepbook/predict.dart.
predict/admin
Full generated bindings for the admin Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/admin.dart' as admin;
predict/builder_code
Full generated bindings for the builder_code Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/builder_code.dart' as builder_code;
predict/builder_code_events
Full generated bindings for the builder_code_events Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/builder_code_events.dart' as builder_code_events;
predict/config_events
Full generated bindings for the config_events Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/config_events.dart' as config_events;
predict/ewma
Full generated bindings for the ewma Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/ewma.dart' as ewma;
predict/ewma_config
Full generated bindings for the ewma_config Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/ewma_config.dart' as ewma_config;
predict/expiry_cash
Full generated bindings for the expiry_cash Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/expiry_cash.dart' as expiry_cash;
predict/expiry_market
Full generated bindings for the expiry_market Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/expiry_market.dart' as expiry_market;
predict/lp_book
Full generated bindings for the lp_book Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/lp_book.dart' as lp_book;
predict/market_lifecycle_cap
Full generated bindings for the market_lifecycle_cap Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/market_lifecycle_cap.dart' as market_lifecycle_cap;
predict/market_manager
Full generated bindings for the market_manager Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/market_manager.dart' as market_manager;
predict/order
Full generated bindings for the order Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/order.dart' as order;
predict/order_events
Full generated bindings for the order_events Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/order_events.dart' as order_events;
predict/pause_cap
Full generated bindings for the pause_cap Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/pause_cap.dart' as pause_cap;
predict/plp
Full generated bindings for the plp Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/plp.dart' as plp;
predict/pool_accounting
Full generated bindings for the pool_accounting Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/pool_accounting.dart' as pool_accounting;
predict/pool_valuation_cap
Full generated bindings for the pool_valuation_cap Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/pool_valuation_cap.dart' as pool_valuation_cap;
predict/predict_account
Full generated bindings for the predict_account Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/predict_account.dart' as predict_account;
predict/pricing
Full generated bindings for the pricing Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/pricing.dart' as pricing;
predict/pricing_config
Full generated bindings for the pricing_config Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/pricing_config.dart' as pricing_config;
predict/propbook/block_scholes_store
Full generated bindings for the block_scholes_store Move module (propbook): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/propbook/block_scholes_store.dart' as block_scholes_store;
predict/propbook/oracle_lane
Full generated bindings for the oracle_lane Move module (propbook): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/propbook/oracle_lane.dart' as oracle_lane;
predict/propbook/pyth_feed
Full generated bindings for the pyth_feed Move module (propbook): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/propbook/pyth_feed.dart' as pyth_feed;
predict/propbook/registry
Full generated bindings for the registry Move module (propbook): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/propbook/registry.dart' as registry;
predict/protocol_config
Full generated bindings for the protocol_config Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/protocol_config.dart' as protocol_config;
predict/range_codec
Full generated bindings for the range_codec Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/range_codec.dart' as range_codec;
predict/registry
Full generated bindings for the registry Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/registry.dart' as registry;
predict/strike_exposure
Full generated bindings for the strike_exposure Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/strike_exposure.dart' as strike_exposure;
predict/strike_exposure_config
Full generated bindings for the strike_exposure_config Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/strike_exposure_config.dart' as strike_exposure_config;
predict/strike_payout_tree
Full generated bindings for the strike_payout_tree Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/strike_payout_tree.dart' as strike_payout_tree;
predict/vault_events
Full generated bindings for the vault_events Move module (deepbook_predict): every move-call builder and BCS struct, including symbols the flat package:deepbook/predict.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/predict/vault_events.dart' as vault_events;
sessions
Time-limited trading sessions — package:deepbook/sessions.dart.
sessions/session_config
Full generated bindings for the session_config Move module (deepbook_sessions): every move-call builder and BCS struct, including symbols the flat package:deepbook/sessions.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/sessions/session_config.dart' as session_config;
sessions/sessions
Full generated bindings for the sessions Move module (deepbook_sessions): every move-call builder and BCS struct, including symbols the flat package:deepbook/sessions.dart surface hides to avoid name collisions. Import with a prefix: import 'package:deepbook/sessions/sessions.dart' as sessions;