serum-dex
serum-dex copied to clipboard
Add CloseMarket function to redeem rent from permissioned markets
Currently a placeholder pull request for adding a close market function.
Still TODO
Questions for @armaniferrante
- [x] How to check that the events, bid and asks queues are empty before removing rent from them?
- [x] Do we need a
market closed
flag to markets so that it's clear the market is shutdown?
Things I will add
- [x] ~~Add CloseMarkets to the permissioned markets proxy example~~
- [x] ~~Add a test to the permissioned markets javascript tests~~
Plus any other code review and additional checks that need to be added to the function.
The pull request is mainly based on existing examples from how CloseOpenOrders
and Prune
functions were implemented.
Added an anchor test directory that initializes a market and shuts it down again, then checks that the sol is retrieved.
It's not ready for merging yet though. There needs to be more discussion of what checks are needed before the rent is retrieved. Right now though the core functions are there and there's a working test. So fitting in any requested changes ought to be straightforward. We will see though!
Next up
- [x] Investigate what variables are available on the queue structs to tell whether they are truly empty, similar to the
free_slot_bits
variable on the open orders struct
Ok, it looks like it's possible to load up request queue and event queue then check their headers to ensure count = 0
. For bid and ask queue it might be possible to access their SlabHeaders to check the leaf count, although not sure yet.
Update: Added checks that load the headers for all four queue structs and checks that their counts are empty.
How to check that the events, bid and asks queues are empty before removing rent from them?
What the code currently does is correct. The event queue can check the header count and the bid/asks slabs can check the leaf_count.
Ok, added the disabled flag. Going to start adding more comprehensive testing. It looks like the permissioned markets set of tests are failing because they're not using solana 1.9.0
@armaniferrante Ran a full set of tests on the new close market functionality.
close_markets doesn't allow markets to be closed while
- orders are in the bid or ask queue
- there are uncranked events
And even more importantly
- Open orders accounts can be settled and closed after the markets has been closed
Travis CI tests added.
Arguably we still haven't come to a good conclusion on the use of disabled
. Serum was already design such that markets could be disabled
by some authority in extreme scenarios so we make use of that existing functionality. Only the new_order_v3
function has an explicit market_enabled()
check, all the other functions can still be called but will fail if they rely on the existence of any of the queue
accounts.
I wanted to keep the actual changes made to the dex as minimal as possible. However, if it's necessary we can re-use the market_enabled
check in any of the functions that shouldn't be possible to call post-disabling, e.g. cancel_order
, consume events
. Any functions involving open orders accounts, e.g. close open orders
or settle
, should be still be allowed to be called post-disabling, so we wouldn't have to make any changes to them.
bump sers @Henry-E @armaniferrante pls help 🥏
up @Henry-E @armaniferrante I think this legit solution
bump
what's the status of this? Any forthcoming plans to try to include this feature soon?
bump