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

Filter limit orders during auction cutting #752

Merged
merged 8 commits into from
Nov 10, 2022
Merged

Conversation

sistemd
Copy link
Contributor

@sistemd sistemd commented Nov 9, 2022

Fixes #740.

When cutting the auction, for each limit order convert the sell and buy price to the native token (ETH) and make sure that sell with the surplus fee is higher than buy with the configurable price factor. If it isn't, filter it out.

I think this approach makes sense but there might be some better idea that I'm missing.

Test Plan

This module is structured as a bunch of freestanding functions that are being tested individually. I think it'd be more natural if these were methods, and in general I don't like this approach to testing, so I didn't want to keep adding to it. Related: #713 (comment).

After #713 is merged which should be soon, we can extend the E2E tests from #746 to cover the full flow. And then we can start advertising and testing this feature in production 🙂

@sistemd sistemd requested a review from a team as a code owner November 9, 2022 10:30
@sistemd sistemd changed the title Filter limit orders during auction cutting [WIP] Filter limit orders during auction cutting Nov 9, 2022
@sistemd sistemd marked this pull request as draft November 9, 2022 10:33
@sistemd sistemd marked this pull request as ready for review November 9, 2022 10:54
@sistemd sistemd changed the title [WIP] Filter limit orders during auction cutting Filter limit orders during auction cutting Nov 9, 2022
Comment on lines 266 to 267
let sell_native = order.data.sell_amount * prices.get(&order.data.sell_token).unwrap()
+ order.metadata.surplus_fee;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it correct that surplus_fee is not multiplied by the price? Is the unit in the sell token or native token? Maybe we should comment that on to OrderMetadata::surplus_fee .

Copy link
Contributor Author

@sistemd sistemd Nov 9, 2022

Choose a reason for hiding this comment

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

I believe surplus_fee is indeed denoted in the native token. But you're correct, I need to double-check this, and a comment would be in order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was indeed a mistake, good catch! d56b238

@sistemd sistemd requested a review from vkgnosis November 9, 2022 16:03
Copy link
Contributor

@MartinquaXD MartinquaXD left a comment

Choose a reason for hiding this comment

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

Code looks good, math looks reasonable.
One additional step we could consider is to have an upper limit on orders in an auction. Then we could take the n most favorably priced orders in case there are too many orders we consider reasonable.

I think this will not be necessary for a long time and should happen in another PR (if we even want that) but I just wanted to put that out there so we don't forget about it.

@@ -130,6 +130,9 @@ pub struct Arguments {
/// in COW base units
#[clap(long, env)]
pub cip_14_reward_cap: Option<f64>,

#[clap(long, env, default_value = "0.97")]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 3% spread might be a little too tight for long-tail tokens. I think something more like 10% may be more reasonable. Maybe @harisang can comment as they have used some heuristics for filtering out mis-prised orders in our optimization solvers in the past.

That being said, I would actually use a default that allows all orders through (so 0.0) and then only manually configure this value in our deployment configuration. My rationale is that when we are doing local testing, I don't want to have to think about what price my limit order needs to be to exercise the quoting code. Don't feel strongly about this point though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess Marco and Tom may have done these nice preprocessing steps, but I am not really familiar with them.

However, 3% definitely sounds low. I would be very liberal with this number (e.g., 10-15%), although I expressed my concern about this altogether here as well, labeling it as order censorship in a way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let buy_native = order.data.buy_amount * prices.get(&order.data.buy_token).unwrap();
let sell_native = u256_to_big_decimal(&sell_native);
let buy_native = u256_to_big_decimal(&buy_native);
sell_native >= buy_native * self.limit_order_price_factor.clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Sometimes its hard to debug why an order wasn't included in a batch. Can you add a log message including the order UID for when it gets filtered out?

Copy link
Contributor Author

@sistemd sistemd Nov 10, 2022

Choose a reason for hiding this comment

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

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

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

Changes look good. Just some small nits.

@nlordell
Copy link
Contributor

One additional step we could consider is to have an upper limit on orders in an auction. Then we could take the n most favorably priced orders in case there are too many orders we consider reasonable.

I think this is another heuristic that we can add to better "choose" what orders to include in an auction. Agree it should be a separate PR though.

Once limit orders is released, we should do some testing on how much we can saturate the orderbook before we start running into performance issues. This will help us pick parameters like this one, as well the maximum number of orders per user.

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

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

LGTM

@sistemd sistemd merged commit 9b11e35 into main Nov 10, 2022
@sistemd sistemd deleted the limit_order_auction_cutting branch November 10, 2022 18:57
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 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.

Heuristically filter orders for batch cutting
5 participants