serum-dex icon indicating copy to clipboard operation
serum-dex copied to clipboard

Add CloseMarket function to redeem rent from permissioned markets

Open Henry-E opened this issue 3 years ago • 10 comments

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.

Henry-E avatar Nov 03 '21 11:11 Henry-E

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.

Henry-E avatar Dec 02 '21 11:12 Henry-E

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.

armaniferrante avatar Dec 08 '21 17:12 armaniferrante

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

Henry-E avatar Dec 14 '21 15:12 Henry-E

@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

Henry-E avatar Dec 15 '21 20:12 Henry-E

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.

Henry-E avatar Jan 07 '22 11:01 Henry-E

bump sers @Henry-E @armaniferrante pls help 🥏

0xBooler avatar Feb 08 '22 01:02 0xBooler

up @Henry-E @armaniferrante I think this legit solution

wdstudionft avatar Apr 26 '22 01:04 wdstudionft

bump

wdstudionft avatar May 09 '22 23:05 wdstudionft

what's the status of this? Any forthcoming plans to try to include this feature soon?

bigdefidev avatar Jul 01 '22 05:07 bigdefidev

bump

gaburipeach avatar Sep 21 '22 22:09 gaburipeach