Bonfida/dex-v4

Question: Can accounts close immediately after sending an IOC take order?

Closed this issue · 1 comments

In the existing dex one cannot close an account in the same transaction as opening + trading. Even IOC take orders mutate some open orders state that needs to be cleared on the consume events crank. Specifically, the free_slot_bits are not cleared and so closing an account hits this line https://github.com/project-serum/serum-dex/blob/master/dex/src/state.rs#L2292.

This is particularly problematic for swaps because it makes fees appear larger than they are, since one has to pay for rent exemption sol for the open orders account.

According to @dr497, for IOC the posted_order_id is always None, so you never add an order to the open orders https://github.com/Bonfida/dex-v4/blob/main/program/src/processor/new_order.rs#L336. So yes. You can immediately close.