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

feat: Fix market price checker for market orders #2312

Closed
sunce86 opened this issue Jan 22, 2024 · 5 comments · Fixed by #2315
Closed

feat: Fix market price checker for market orders #2312

sunce86 opened this issue Jan 22, 2024 · 5 comments · Fixed by #2315

Comments

@sunce86
Copy link
Contributor

sunce86 commented Jan 22, 2024

Problem

As a consequence of #2304, market orders
contain a bug, because their sell_amount doesn't contain the fee. This leads to market orders being classified as liquidity orders. https://github.com/cowprotocol/services/blob/main/crates/shared/src/order_validation.rs#L682

An order being classified as liquidity order might lead to order being less likely to be picked up by solvers? (Haris confirmed that only quasilabs can solve them as part of COW).

Example order: https://dev.explorer.cow.fi/orders/0xa1b886011c8d077187bead0e7d0ba1077f68de6bc0d6423b9ac643ead2153e33dd9eb88c5c6d2a85a08a96c7f0cccce27cb843cb65ae7f5a?tab=overview

@fleupold
Copy link
Contributor

Can you explain orders are more often considered as out-of-market due to @2304. This is not intuitive to me (and makes it hard to understand if #2312 is the right fix)

@sunce86
Copy link
Contributor Author

sunce86 commented Jan 22, 2024

Before #2304, out of market order would require:

sell_amount/buy_amount < quote_sell/quote_buy.

So, if we increase quote_sell by adding fee_amount to it (as we did with #2304, making it quote_sell+quote_fee, then, right part of the equation is higher, which means more orders satisfy the equation and get marked as out of market.

@fleupold
Copy link
Contributor

Wouldn't the right fix in this case be to compare

(sell_amount+fee_amount)/buy_amount < (quote_sell+quote_fee)/quote_buy

?

@sunce86
Copy link
Contributor Author

sunce86 commented Jan 22, 2024

sell_amount is a signed sell amount from order so it contains the fee already (it's a sell_amount_before_fee value).

@fleupold
Copy link
Contributor

sell_amount is a signed sell amount from order so it contains the fee already (it's a sell_amount_before_fee value).

At least here (see below) we are using the raw orders sell amount, which (at least for market orders) doesn't contain the fee amount:

if boundary::is_order_outside_market_price(
&order.data.sell_amount,
&order.data.buy_amount,
&quote.buy_amount,
&quote.sell_amount,
&quote.fee,
) {

@sunce86 sunce86 changed the title feat: Remove liquidity orders feat: Fix market price checker for market orders Jan 22, 2024
sunce86 added a commit that referenced this issue Jan 23, 2024
# Description
#2304 fixed the checker for
limit orders. However, for market orders, which signed `sell_amount`
doesn't contain the signed `fee_amount` (so it's basically
`sell_amount_after_fee`), we need to take this fee into acount.

For limit orders nothing changes, since those have `fee_amount` = 0.

Fixes #2312
sunce86 added a commit that referenced this issue Jan 23, 2024
# Description
#2304 fixed the checker for
limit orders. However, for market orders, which signed `sell_amount`
doesn't contain the signed `fee_amount` (so it's basically
`sell_amount_after_fee`), we need to take this fee into acount.

For limit orders nothing changes, since those have `fee_amount` = 0.

Fixes #2312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants