Repository navigation
Conversation
Quote-priced dust bid, Several dust bids, Order below the minimum size, Treasury reserves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_outreturns 0 DEEP whenever the base it managed to match is above 0 and below the poolmin_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 passesvalidate_fees_against_maxand settlement then aborts when the balance manager holds no DEEP.Approach
calculate_market_order_paramskeeps the ask quote in every case except this one. When the quote reports nothing filled (base_left == order_amount), the order is at leastmin_size, and a live best bid exists, the matched base can only be dust: an empty book has no live bid, and an order belowmin_sizeis excluded becausecreate_orderrejects it before any fee is charged. The quoted 0 is replaced withget_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_sizein total and no better than the best bid, so the taker fee formin_sizeat 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 bothestimate_full_fee_marketfunctions all read this helper, so the on-chain check and the on-chain estimate move together. Bids are unchanged: they already quoted 0 belowmin_sizeand they submit the quoted base rather than the original amount. Limit orders never callget_quantity_out.The dependency pins move from DeepBook
v4.0.0and tokenmaintov9.0.0for both, and the commented test pins move tov9-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:
estimated_deep_requiredfrom DeepBook's owngetQuantityOutsends 0 for this case and aborts withEDeepRequiredExceedsMax. The client has to useestimate_full_fee_market.move_test.ymlonly swaps thedeepbookandpythpins. The new commentedtokenpin is unused, and CI keeps token atv9.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.ymlstill requests1.62.1, and DeepBook v9 itself was built with1.82.2.How to verify
deepbook,token, andpythpins, uncomment thev9-tag-fork-test-methodsand Pyth test-fork pins, and runsui move test --path packages/deeptrade-core --gas-limit 100000000000 calculate_market_order_params_tests.sui move test --path packages/deeptrade-core --gas-limit 100000000000 create_market_order_tests.ask_quote_priced_dust_bid_quotes_notional_boundcovers 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_pricecovers three dust bids at 1, 2, and 3 SUI summing to less thanmin_size, and expects the ceiling at the best price (30).ask_below_min_size_quotes_zero_deepcovers a sell belowmin_sizewith a live bid, and expects 0.ask_dust_fill_borrows_bound_from_reservescovers 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.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_paramsand in the test comments.docs/deepbook-v9-upgrade-notes.mdis still untracked, and it describes the DeepBook behavior rather than this ceiling; it should be updated before it is committed.