-
Notifications
You must be signed in to change notification settings - Fork 67
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
Conversation
382527c
to
6de7a26
Compare
let sell_native = order.data.sell_amount * prices.get(&order.data.sell_token).unwrap() | ||
+ order.metadata.surplus_fee; |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
crates/autopilot/src/arguments.rs
Outdated
@@ -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")] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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.
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. |
888260a
to
af9eff2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 🙂