Skip to content
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

Scale down in-flight partially fillable orders #152

Merged
merged 6 commits into from
May 4, 2022

Conversation

MartinquaXD
Copy link
Contributor

Fixes #123

The driver currently filters out all solvable orders for which it knows that a trade referring to it is in-flight at the moment.
This is overly pessimistic for partially fillable orders because you could issue many trades using liquidity from that order as long as they don't exceed the executable amount from that order.

The improved approach is to sum up the executed amounts of all in-flight trades for a partially filled order and add that to the last "confirmed" executed amount of that order. "Confirmed" in this case means the executed_(buy|sell|fee)_amount fields from the order metadata. Data within that field gets calculated by our database and should probably be used as the source of truth in case trades for the same order show up across multiple auctions.

If a partially fillable order is actually filled completely the order gets dropped from the Auction.

Test Plan

Update existing unit test and extend it.

@MartinquaXD MartinquaXD requested a review from a team as a code owner April 14, 2022 11:43
Comment on lines +25 to +29
pub fn u256_to_big_uint(input: &U256) -> BigUint {
let mut bytes = [0; 32];
input.to_big_endian(&mut bytes);
BigUint::from_bytes_be(&bytes)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from /orderbook/src/conversions to /shared/src/conversions. At some point we should move everything to the shared version.

@MartinquaXD MartinquaXD force-pushed the scale-down-partially-fillable-orders branch from 451772c to b8961e3 Compare April 14, 2022 11:48
@codecov-commenter
Copy link

codecov-commenter commented Apr 14, 2022

Codecov Report

Merging #152 (a54089b) into main (ad8b329) will increase coverage by 0.15%.
The diff coverage is 97.68%.

@@            Coverage Diff             @@
##             main     #152      +/-   ##
==========================================
+ Coverage   65.10%   65.26%   +0.15%     
==========================================
  Files         183      183              
  Lines       38199    38340     +141     
==========================================
+ Hits        24871    25021     +150     
+ Misses      13328    13319       -9     

Comment on lines 87 to 89
.inspect(|(trade, _)| {
uids.push(trade.order.metadata.uid);
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I slightly prefer doing this in an extra for loop to make it clear that we need this side effect.

@MartinquaXD MartinquaXD force-pushed the scale-down-partially-fillable-orders branch from b8961e3 to a54089b Compare April 14, 2022 13:29
@MartinquaXD MartinquaXD enabled auto-merge (squash) May 4, 2022 12:36
@MartinquaXD MartinquaXD merged commit 7bf0a7c into main May 4, 2022
@MartinquaXD MartinquaXD deleted the scale-down-partially-fillable-orders branch May 4, 2022 12:38
@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More Precise In-Flight Order Filtering for Partially Fillable Orders
4 participants