-
Notifications
You must be signed in to change notification settings - Fork 93
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
[ON HOLD] Don't take protocol fee for in-market limit orders #2188
Conversation
72f4210
to
31aef39
Compare
31aef39
to
05181dd
Compare
crates/autopilot/src/shadow.rs
Outdated
@@ -201,6 +201,7 @@ impl RunLoop { | |||
self.score_cap, | |||
self.solve_deadline, | |||
self.fee_policy.clone(), | |||
HashMap::new(), |
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.
Would be cool if we could get the correct fee policies as part of the shadow competition as well but that is probably not straight forward since we don't have a DB connection in this case.
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.
correct
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.
@MartinquaXD do you maybe know why we don't have the access to db? for security reasons so we don't end up changing something?
I am worried that onboarding new solvers and checking the protocol fee mechanism will be imposible without db connection. OTOH, we do have staging if necesarry.
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 when the shadow
autopilot was written there was no need to store anything in the DB.
And over all I like that we don't need any DB connection for it to run.
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.
so do you think is it worth to modify the code of the shadow to be able to read the order and compute the fee policies or maybe is not worth the investment ?
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 for testing fee policies we might have to add the original quote to the order (or some other indicator that fees should be applied) in /auction
. However, if we decide to go that route we should do it in a separate PR.
With that taken care of the only reason the shadow
autopilot would need a DB is to store the data we need before calling /settle
which I think is outside of the scope of what the shadow
environment was initially envisioned to do. Originally it was only supposed to be a test bed to onboard new solvers without risk.
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.
We are adding a lot of logic and dependencies to the autopilot runloop due to fees (we are using the run_loops db access to fetch quotes which we pass down into the solve request, we instantiate the run_loop with the fee policies that need to be applied, we have a specific function to compute the fee policies all inside the run_loop).
I wonder how good this will scale. What are the trade-offs of having some fee component which knows about its dependencies (ie a database to look up quotes, the fee policy arguments) and can apply
the required fee policy logic to an order?
How do we build this in a way that scales for the other types of fees we want to take eventually? How do we prevent the run-loop from becoming our next "SettlementEncoder" or "SolutionSubmissionStrategy" (ie pieces of code no-one wants to touch anymore because they are so brittle )?
#2157 has some attempt and more context on this discussion I believe.
The other alternative I see could be to reuse |
Yes, we should first merge #2157.
With regards to network fees, it is too early to do this because we would have |
What's the issue with this? I remember the frontend team asking us to provide the labels. Are we depending on the assumption |
Wouldn't we end up charging 0 fee in that case? |
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.
Logic lgtm. Let's just reorganize the code according to code review comments so it's more aligned with the ddd approach. Also, it needs to rebase after #2157 is merged.
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.
Concern about the failability of the fee application and that it's part of the critical path of sending the auction rather than building the auction.
@@ -350,6 +350,11 @@ impl OrderData { | |||
self.valid_to, | |||
) | |||
} | |||
|
|||
/// Checks if the order is a market order. | |||
pub fn within_market(&self, quote_sell_amount: &U256, quote_buy_amount: &U256) -> bool { |
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: you can extend OrderData inside the order_quoting.rs
module to allow using the quote type as an argument here which makes this nicer to read.
pub trait OrderPricing {
fn within_market(&self, quote: &Quote) -> bool;
}
impl OrderPricing for OrderData {
/// Checks if the order is a market order.
fn within_market(&self, quote: &Quote) -> bool {
self.sell_amount.full_mul(quote.buy_amount) >= quote.sell_amount.full_mul(self.buy_amount)
}
}
This reverts commit b96f18d.
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 this is a great step in the right direction! Could you please create a separate PR for the refactoring that changes SolvableOrdersCache.current_auction
to return the domain model (without any logic changes)?
And then add the fee policy and application logic to the domain model in a separate PR?
Moving driver_model
into the new structure should also be a separate PR imo.
@@ -0,0 +1,4 @@ | |||
pub mod quote; |
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.
Why are all these new files? Can't they be moved from existing dtos? Can we maybe leave that to a different PR (to keep the size of this one manageable)?
crate::domain::{self}, | ||
}; | ||
|
||
pub mod postgres; |
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 the module structure should be infra::persistence::postgres::dto::{auction, order, fee, quote}
# Description Subset of changes from #2188 Orderbook's `get_auction()` now returns a new Auction type (let's call it `dto::Auction`). `dto::Auction` is a struct that contains the orders in a format that is used between `autopilot` and `drivers`. Note that it is allowed for `dto::Auction` to contain fields which type belongs to `model`. This is to make sure no bugs were introduced due to serialization/deserialization and to reuse the code. If we want to decouple these dependencies we can do it in a separate PR for easier review. Other than that, I introduced a `domain::Auction` that is built from `dto::Auction` and used within autopilot's `RunLoop`. The idea is to gradually eliminate all type dependencies from `RunLoop` so that it works only with `domain` types, which would make it trivial to move it to domain at the end. ## How to test Existing tests. #TODO Update e2e tests.
# Description A subset of changes from #2188 (part 2) # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Move fee policies to `domain` - [ ] No fee policies for in-market limit orders ## How to test Existing tests.
# Description A subset of changes from #2188 (part 2) # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Move fee policies to `domain` - [ ] No fee policies for in-market limit orders ## How to test Existing tests.
Closing as the last 4th part of this PR is tracked here: #2286 |
ON HOLD - will be split into several PRs:
infra
#2278Description
We don't want to take protocol fees for limit orders with in-market price.
Changes
We read the quote from the db and compare the order price with the quote price.
Fixes
#2092