-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new place_and_take_perp_order flag #1211
Comments
yes please! |
May I ask if the fulfill_perp_order_ with amm function means to fill everything? Do I need to rewrite a function to implement this feature? |
One question I have is assuming that in the case of a partial order that can be fulfilled, the program is in the stage of filling the order and the data of the order and position has actually changed. If I subsequently cancel this order. Will the data that has been changed before be restored? In other words is this whole program atomic? |
When I tried to implement this new functionality in the handle_place_and_take_perp_order function, my thought process was to run a simulation of the fill_perp_order function first to get the number of underlying assets that were expected to be completed. But I ran into a problem where running the real fill_perp_order function after a successful simulation run reported a stack overflow.
|
Here is the code I tried. Feel free to discuss.
|
i dont think you need to run You probably also want to use an enum instead of bool to allow for the ix to allow user to choose when to revert (partial fill, no fill, or dont revert) |
If there is a partial fill and the order is canceled, the user state does not revert if the transaction is successful (aka. immediate-or-cancel). This feature will allow the transaction to error in the event of partial or no fill - which will result in no change to user account (also known as fill-or-kill) |
I'll say what I understand, because I looked at the code, and I found that it cancels the order if it is partially filled successfully, but the successful part is not withdrawn, or returned to the state it was in before it all started. So, my understanding is to simulate walking through the process first, and if it doesn't fill completely it doesn't perform the later steps. |
So, what do you think are the steps to correctly implement this feature? |
You don't need to simulate because if you throw an error in the tx, the whole state is reverted. So you can just check if there is a full or partial fill after the fill perp order is called |
prototyped this here: https://github.com/drift-labs/protocol-v2/pull/1218/files |
Currently place_and_take_perp_order tx will succeed whether or not there is a fill.
I suggest retro'ing the unused _maker_order_id into a flag that specifies when the tx should fail:
With these new flags, it will be easier for devs to write client code and may lead to less tx actually needed to land onchain (you can skip sending the tx if it fails sim).
The text was updated successfully, but these errors were encountered: