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

Remove re-classification to Liquidity order #2313

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions crates/shared/src/order_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,25 +665,6 @@ impl OrderValidating for OrderValidator {
},
}

// Check if we need to re-classify the market order if it is outside the market
// price. We consider out-of-price orders as liquidity orders. See
// <https://github.com/cowprotocol/services/pull/301>.
let class = match (class, &quote) {
(OrderClass::Market, Some(quote))
if is_order_outside_market_price(
&quote_parameters.sell_amount,
&quote_parameters.buy_amount,
&quote.sell_amount,
&quote.buy_amount,
&quote.fee_amount,
) =>
{
tracing::debug!(%uid, ?owner, ?class, "order being flagged as outside market price");
OrderClass::Liquidity
}
(_, _) => class,
};

self.check_max_limit_orders(owner, &class).await?;

let order = Order {
Expand Down Expand Up @@ -1509,67 +1490,6 @@ mod tests {
assert!(matches!(result, Err(ValidationError::ZeroAmount)));
}

#[tokio::test]
async fn post_out_of_market_orders_when_limit_orders_disabled() {
let expected_buy_amount = U256::from(100);

let mut order_quoter = MockOrderQuoting::new();
let mut bad_token_detector = MockBadTokenDetecting::new();
let mut balance_fetcher = MockBalanceFetching::new();
order_quoter.expect_find_quote().returning(move |_, _| {
Ok(Quote {
buy_amount: expected_buy_amount,
sell_amount: U256::from(1),
fee_amount: U256::from(1),
..Default::default()
})
});
bad_token_detector
.expect_detect()
.returning(|_| Ok(TokenQuality::Good));
balance_fetcher
.expect_can_transfer()
.returning(|_, _| Ok(()));
let mut limit_order_counter = MockLimitOrderCounting::new();
limit_order_counter.expect_count().returning(|_| Ok(0u64));
let validator = OrderValidator::new(
dummy_contract!(WETH9, [0xef; 20]),
hashset!(),
hashset!(),
OrderValidPeriodConfiguration::any(),
false,
Arc::new(bad_token_detector),
dummy_contract!(HooksTrampoline, [0xcf; 20]),
Arc::new(order_quoter),
Arc::new(balance_fetcher),
Arc::new(MockSignatureValidating::new()),
Arc::new(limit_order_counter),
0,
Arc::new(MockCodeFetching::new()),
Default::default(),
);
let order = OrderCreation {
valid_to: time::now_in_epoch_seconds() + 2,
sell_token: H160::from_low_u64_be(1),
buy_token: H160::from_low_u64_be(2),
buy_amount: expected_buy_amount + 1, // buy more than expected
sell_amount: U256::from(1),
fee_amount: U256::from(1),
kind: OrderKind::Sell,
signature: Signature::Eip712(EcdsaSignature::non_zero()),
..Default::default()
};
let (order, quote) = validator
.validate_and_construct_order(order, &Default::default(), Default::default(), None)
.await
.unwrap();

// Out-of-price orders are intentionally marked as liquidity
// orders!
assert_eq!(order.metadata.class, OrderClass::Liquidity);
assert!(quote.is_some());
}

#[tokio::test]
async fn post_validate_err_wrong_owner() {
let mut order_quoter = MockOrderQuoting::new();
Expand Down
Loading