Skip to content

Feature/upgrade deepbook to v9 - #147

Open
bathord wants to merge 4 commits into
feature/upgrade-deepbook-to-v4from
feature/upgrade-deepbook-to-v9
Open

bathord wants to merge 4 commits into
feature/upgrade-deepbook-to-v4from
feature/upgrade-deepbook-to-v9

Conversation

@bathord

@bathord bathord commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Problem / goal

DeepBook v4 and every earlier package version are being disabled, so the spot contract has to depend on DeepBook v9. v9 changes the ask quote: get_quantity_out returns 0 DEEP whenever the base it managed to match is above 0 and below the pool min_size, regardless of how large the sell itself is. A 10 SUI sell against a single 0.2 SUI bid quotes 0 DEEP, but the immediate-or-cancel order still fills that 0.2 and DeepBook charges the taker fee on it. We plan DEEP from that quote, so the quote of 0 passes validate_fees_against_max and settlement then aborts when the balance manager holds no DEEP.

Approach

calculate_market_order_params keeps the ask quote in every case except this one. When the quote reports nothing filled (base_left == order_amount), the order is at least min_size, and a live best bid exists, the matched base can only be dust: an empty book has no live bid, and an order below min_size is excluded because create_order rejects it before any fee is charged. The quoted 0 is replaced with get_order_deep_required(min_size, best_bid_price).

That is a ceiling, not a reconstruction of the fill. DeepBook has already thrown away the matched amount, and no read returns it. Every matched bid is strictly below min_size in total and no better than the best bid, so the taker fee for min_size at the best bid is always at least the fee the fill charges. For a DEEP-per-base pool the price does not enter the fee; for a DEEP-per-quote pool it does, and using the best price is what keeps the ceiling above the cheaper dust behind it.

create_market_order, create_market_order_v2, and both estimate_full_fee_market functions all read this helper, so the on-chain check and the on-chain estimate move together. Bids are unchanged: they already quoted 0 below min_size and they submit the quoted base rather than the original amount. Limit orders never call get_quantity_out.

The dependency pins move from DeepBook v4.0.0 and token main to v9.0.0 for both, and the commented test pins move to v9-tag-fork-test-methods. Across the rest of the v4 to v9 diff, nothing else on the spot call surface changes behavior. The other v9 work is new entry points (place_post_only_limit_order, cancel_live_order), the per-pool referral types, the app-authorization witness, and the registry pause cap.

Caveats:

  • The user deposits, and pays the coverage fee on, the ceiling rather than the fill. Unused DEEP stays in the balance manager. A wallet that holds exactly the real fee and nothing more now fails the estimate check, where v4 would have passed.
  • Anything that still estimates estimated_deep_required from DeepBook's own getQuantityOut sends 0 for this case and aborts with EDeepRequiredExceedsMax. The client has to use estimate_full_fee_market.
  • move_test.yml only swaps the deepbook and pyth pins. The new commented token pin is unused, and CI keeps token at v9.0.0. Token sources did not change between these tags, so that is the right resolution.

Risk & blast radius

The behavior change is limited to DEEP planning for market asks on non-whitelisted pools, and to the SUI coverage fee when that DEEP comes from treasury reserves. Market bids, limit orders, input-coin-fee orders, and swaps do not use this number. Input-coin-fee orders and whitelisted pools call the helper but discard its DEEP result.

The dependency bump is the wider change: every pool, balance-manager, and swap call now executes DeepBook v9. Rollback is a package upgrade that leaves v9 disabled in our own version gate. Publishing needs a Sui toolchain that can read the new pinned Move.lock; publish_package.yml still requests 1.62.1, and DeepBook v9 itself was built with 1.82.2.

How to verify

  • Comment the production deepbook, token, and pyth pins, uncomment the v9-tag-fork-test-methods and Pyth test-fork pins, and run sui move test --path packages/deeptrade-core --gas-limit 100000000000 calculate_market_order_params_tests.
  • With the same pins, run sui move test --path packages/deeptrade-core --gas-limit 100000000000 create_market_order_tests.
  • ask_quote_priced_dust_bid_quotes_notional_bound covers a DEEP-per-quote pool, where the ceiling depends on the best bid price (20, against 10 for the same size on a base-priced pool).
  • ask_several_dust_bids_bound_uses_best_price covers three dust bids at 1, 2, and 3 SUI summing to less than min_size, and expects the ceiling at the best price (30).
  • ask_below_min_size_quotes_zero_deep covers a sell below min_size with a live bid, and expects 0.
  • ask_dust_fill_borrows_bound_from_reserves covers no DEEP anywhere: reserves lend 10, the fill charges 5, 5 remains in the balance manager, and the coverage fee is 3000 SUI, the value of 10 rather than of 5.
  • The earlier tests cover the single dust bid (quote 10, DeepBook quote 0), the empty book (0), a bid at or above min_size (the quote's own fee, 20), and a wallet holding exactly 10 DEEP (fill completes, 5 left).

Docs

No doc update is in this diff. The rule and the arithmetic are in the comment on calculate_market_order_params and in the test comments. docs/deepbook-v9-upgrade-notes.md is still untracked, and it describes the DeepBook behavior rather than this ceiling; it should be updated before it is committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant