fix: keep AMM ephemeral position throughout entire auction uncrossing #11615
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.
closes #11583
During auction uncrossing when trades are matched with an AMM, the AMM's actual position is only updated after we've left the matching engine and the trades are confirmed. This causes problems since as the uncrossing is happening and we are shooting orders from one side of the book at the other, the AMM's fair-price won't change as we go along and each incoming uncrossing order will just keep taking the same volume from the same region of the same AMM.
Code exists that handles this where the AMM engine keeps track of an AMM's not-quite-confirmed position, and then clears it when uncrossing has finished so we can return to reading its position from the position's engine.
The bug here is that we were actually clearing the AMM's "ephemeral position" too soon, and not at the end of uncrossing like we were supposed to.