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

Market orders deprecation date remove #2536

Merged
merged 18 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
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
29 changes: 4 additions & 25 deletions crates/autopilot/src/database/onchain_order_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct OnchainOrderParser<EventData: Send + Sync, EventRow: Send + Sync> {
domain_separator: DomainSeparator,
settlement_contract: H160,
metrics: &'static Metrics,
market_orders_deprecation_date: Option<chrono::DateTime<Utc>>,
}

impl<EventData, EventRow> OnchainOrderParser<EventData, EventRow>
Expand All @@ -78,7 +77,6 @@ where
custom_onchain_data_parser: Box<dyn OnchainOrderParsing<EventData, EventRow>>,
domain_separator: DomainSeparator,
settlement_contract: H160,
market_orders_deprecation_date: Option<chrono::DateTime<Utc>>,
) -> Self {
OnchainOrderParser {
db,
Expand All @@ -88,7 +86,6 @@ where
domain_separator,
settlement_contract,
metrics: Metrics::get(),
market_orders_deprecation_date,
}
}
}
Expand Down Expand Up @@ -349,7 +346,6 @@ impl<T: Send + Sync + Clone, W: Send + Sync> OnchainOrderParser<T, W> {
self.domain_separator,
self.settlement_contract,
self.metrics,
self.market_orders_deprecation_date,
)
.await;

Expand Down Expand Up @@ -451,7 +447,6 @@ async fn parse_general_onchain_order_placement_data<'a>(
domain_separator: DomainSeparator,
settlement_contract: H160,
metrics: &'static Metrics,
market_orders_deprecation_date: Option<chrono::DateTime<Utc>>,
) -> Vec<GeneralOnchainOrderPlacementData> {
let futures = order_placement_events_and_quotes_zipped.into_iter().map(
|(EthContractEvent { data, meta }, event_timestamp, quote_id)| async move {
Expand All @@ -477,14 +472,7 @@ async fn parse_general_onchain_order_placement_data<'a>(
}
let (order_data, owner, signing_scheme, order_uid) = detailed_order_data?;

let quote_result = get_quote(
quoter,
order_data,
signing_scheme,
&quote_id,
market_orders_deprecation_date,
)
.await;
let quote_result = get_quote(quoter, order_data, signing_scheme, &quote_id).await;
let order_data = convert_onchain_order_placement(
&event,
event_timestamp,
Expand Down Expand Up @@ -543,7 +531,6 @@ async fn get_quote(
order_data: OrderData,
signing_scheme: SigningScheme,
quote_id: &i64,
market_orders_deprecation_date: Option<chrono::DateTime<Utc>>,
) -> Result<Quote, OnchainOrderPlacementError> {
let quote_signing_scheme = convert_signing_scheme_into_quote_signing_scheme(
signing_scheme,
Expand Down Expand Up @@ -582,15 +569,9 @@ async fn get_quote(
true => None,
false => Some(order_data.fee_amount),
};
get_quote_and_check_fee(
quoter,
&parameters.clone(),
Some(*quote_id),
fee_amount,
market_orders_deprecation_date,
)
.await
.map_err(onchain_order_placement_error_from)
get_quote_and_check_fee(quoter, &parameters.clone(), Some(*quote_id), fee_amount)
.await
.map_err(onchain_order_placement_error_from)
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -1136,7 +1117,6 @@ mod test {
domain_separator,
settlement_contract,
Metrics::get(),
None,
)
.await;
assert_eq!(result_vec.len(), 2);
Expand Down Expand Up @@ -1262,7 +1242,6 @@ mod test {
domain_separator,
settlement_contract: H160::zero(),
metrics: Metrics::get(),
market_orders_deprecation_date: None,
};
let result = onchain_order_parser
.extract_custom_and_general_order_data(vec![event_data_1.clone(), event_data_2.clone()])
Expand Down
1 change: 0 additions & 1 deletion crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ pub async fn run(args: Arguments) {
Box::new(custom_ethflow_order_parser),
DomainSeparator::new(chain_id, eth.contracts().settlement().address()),
eth.contracts().settlement().address(),
args.shared.market_orders_deprecation_date,
);
let broadcaster_event_updater = Arc::new(
EventUpdater::new_skip_blocks_before(
Expand Down
1 change: 0 additions & 1 deletion crates/e2e/tests/e2e/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ async fn app_data(web3: Web3) {
app_data,
sell_token: token_a.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
buy_token: token_b.address(),
buy_amount: to_wei(1),
valid_to,
Expand Down
1 change: 0 additions & 1 deletion crates/e2e/tests/e2e/app_data_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async fn order_creation_checks_metadata_signer(web3: Web3) {
app_data,
sell_token: token_a.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
buy_token: token_b.address(),
buy_amount: to_wei(1),
valid_to,
Expand Down
1 change: 0 additions & 1 deletion crates/e2e/tests/e2e/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {
let order = OrderCreation {
sell_token: token_a.address(),
sell_amount: to_wei(9),
fee_amount: to_wei(1),
buy_token: token_b.address(),
buy_amount: to_wei(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
7 changes: 1 addition & 6 deletions crates/e2e/tests/e2e/eth_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async fn eth_integration(web3: Web3) {
kind: OrderKind::Buy,
sell_token: token.address(),
sell_amount: to_wei(50),
fee_amount: to_wei(1),
buy_token: BUY_ETH_ADDRESS,
buy_amount: to_wei(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand All @@ -91,7 +90,6 @@ async fn eth_integration(web3: Web3) {
kind: OrderKind::Sell,
sell_token: token.address(),
sell_amount: to_wei(50),
fee_amount: to_wei(1),
buy_token: BUY_ETH_ADDRESS,
buy_amount: to_wei(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down Expand Up @@ -123,8 +121,5 @@ async fn eth_integration(web3: Web3) {
trader_a_eth_balance_after - trader_a_eth_balance_before,
to_wei(49)
);
assert_eq!(
trader_b_eth_balance_after - trader_b_eth_balance_before,
49_776_284_258_574_379_601_u128.into()
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests strike me as useful as a chocolate teapot, basically whenever they fail we just rerun the assertion and update the value (so it's not really testing anything useful).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the proper assert here would be
trader_b_eth_balance_after >= 49 eth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed as suggested by myself 😄

);
assert!(trader_b_eth_balance_after >= to_wei(49));
}
152 changes: 5 additions & 147 deletions crates/e2e/tests/e2e/ethflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use {
BuyTokenDestination,
EthflowData,
OnchainOrderData,
OnchainOrderPlacementError,
Order,
OrderBuilder,
OrderClass,
Expand Down Expand Up @@ -49,30 +48,17 @@ const DAI_PER_ETH: u32 = 1_000;

#[tokio::test]
#[ignore]
async fn local_node_eth_flow() {
async fn local_node_eth_flow_tx() {
run_test(eth_flow_tx).await;
}

#[tokio::test]
#[ignore]
async fn local_node_eth_flow_insufficient_fee() {
run_test(eth_flow_tx_insufficient_fee).await;
}

#[tokio::test]
#[ignore]
async fn local_node_eth_flow_indexing_after_refund() {
run_test(eth_flow_indexing_after_refund).await;
}

#[tokio::test]
#[ignore]
async fn local_node_eth_flow_zero_fee() {
run_test(eth_flow_tx_zero_fee).await;
}

/// Tests that eth flow orders can be created with 0 fee.
async fn eth_flow_tx_zero_fee(web3: Web3) {
async fn eth_flow_tx(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3.clone()).await;

let [solver] = onchain.make_solvers(to_wei(2)).await;
Expand Down Expand Up @@ -105,11 +91,8 @@ async fn eth_flow_tx_zero_fee(web3: Web3) {
let valid_to = chrono::offset::Utc::now().timestamp() as u32
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap()
+ 3600;
let mut ethflow_order =
let ethflow_order =
ExtendedEthFlowOrder::from_quote(&quote, valid_to).include_slippage_bps(300);
// Set fee_amount to 0 to make it behave like a limit order instead of a market
// order.
ethflow_order.0.fee_amount = 0.into();

submit_order(&ethflow_order, trader.account(), onchain.contracts()).await;

Expand Down Expand Up @@ -148,122 +131,6 @@ async fn eth_flow_tx_zero_fee(web3: Web3) {
.await;
}

async fn eth_flow_tx(web3: Web3) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this test removed, it still seems legit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I spent some time figuring out why some tests were removed. Would appreciate more context on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not actually removed, it's just code diff shows it in a weird 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.

local_node_eth_flow_insufficient_fee and local_node_eth_flow_zero_fee are removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and local_node_eth_flow_tx is changed to be actually local_node_eth_flow_zero_fee :)

let mut onchain = OnchainComponents::deploy(web3.clone()).await;

let [solver] = onchain.make_solvers(to_wei(2)).await;
let [trader] = onchain.make_accounts(to_wei(2)).await;

// Create token with Uniswap pool for price estimation
let [dai] = onchain
.deploy_tokens_with_weth_uni_v2_pools(to_wei(DAI_PER_ETH * 1_000), to_wei(1_000))
.await;

// Get a quote from the services
let buy_token = dai.address();
let receiver = H160([0x42; 20]);
let sell_amount = to_wei(1);
let intent = EthFlowTradeIntent {
sell_amount,
buy_token,
receiver,
};

let services = Services::new(onchain.contracts()).await;
services.start_protocol(solver).await;

let quote: OrderQuoteResponse = test_submit_quote(
&services,
&intent.to_quote_request(trader.account().address(), &onchain.contracts().weth),
)
.await;

let valid_to = chrono::offset::Utc::now().timestamp() as u32
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap()
+ 3600;
let ethflow_order =
ExtendedEthFlowOrder::from_quote(&quote, valid_to).include_slippage_bps(300);

submit_order(&ethflow_order, trader.account(), onchain.contracts()).await;

test_order_availability_in_api(
&services,
&ethflow_order,
&trader.address(),
onchain.contracts(),
)
.await;

tracing::info!("waiting for trade");
wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 1 })
.await
.unwrap();

test_order_was_settled(&services, &ethflow_order, &web3).await;

test_trade_availability_in_api(
services.client(),
&ethflow_order,
&trader.address(),
onchain.contracts(),
)
.await;
}

async fn eth_flow_tx_insufficient_fee(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3.clone()).await;

let [solver] = onchain.make_solvers(to_wei(2)).await;
let [trader] = onchain.make_accounts(to_wei(2)).await;

// Create token with Uniswap pool for price estimation
let [dai] = onchain
.deploy_tokens_with_weth_uni_v2_pools(to_wei(DAI_PER_ETH * 1_000), to_wei(1_000))
.await;

// Get a quote from the services
let buy_token = dai.address();
let receiver = H160([0x42; 20]);
let sell_amount = to_wei(1);
let intent = EthFlowTradeIntent {
sell_amount,
buy_token,
receiver,
};

let services = Services::new(onchain.contracts()).await;
services.start_protocol(solver).await;

let quote: OrderQuoteResponse = test_submit_quote(
&services,
&intent.to_quote_request(trader.account().address(), &onchain.contracts().weth),
)
.await;

let valid_to = chrono::offset::Utc::now().timestamp() as u32
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap()
+ 3600;
let mut ethflow_order =
ExtendedEthFlowOrder::from_quote(&quote, valid_to).include_slippage_bps(300);
// set a fee amount that is lower than the quoted fee amount
ethflow_order.0.fee_amount = 1.into();

submit_order(&ethflow_order, trader.account(), onchain.contracts()).await;

let uid = ethflow_order.uid(onchain.contracts()).await;
let is_available = || async { services.get_order(&uid).await.is_ok() };
wait_for_condition(TIMEOUT, is_available).await.unwrap();

let order = services.get_order(&uid).await.unwrap();
assert_eq!(
order.metadata.onchain_order_data.unwrap().placement_error,
Some(OnchainOrderPlacementError::InsufficientFee)
);

let auction_is_empty = || async { services.solvable_orders().await == 0 };
wait_for_condition(TIMEOUT, auction_is_empty).await.unwrap();
}

async fn eth_flow_indexing_after_refund(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3.clone()).await;

Expand Down Expand Up @@ -542,16 +409,7 @@ async fn test_order_parameters(
placement_error: None,
})
);

match order.0.fee_amount.is_zero() {
true => {
assert_eq!(response.metadata.class, OrderClass::Limit);
}
false => {
assert_eq!(response.metadata.class, OrderClass::Market);
}
}

assert_eq!(response.metadata.class, OrderClass::Limit);
assert!(order
.is_valid_cowswap_signature(&response.signature, contracts)
.await
Expand Down Expand Up @@ -609,7 +467,7 @@ impl ExtendedEthFlowOrder {
sell_amount: quote.sell_amount,
buy_amount: quote.buy_amount,
app_data: ethcontract::Bytes(quote.app_data.hash().0),
fee_amount: quote.fee_amount,
fee_amount: 0.into(),
valid_to, // note: valid to in the quote is always unlimited
partially_fillable: quote.partially_fillable,
quote_id: quote_response.id.expect("No quote id"),
Expand Down
6 changes: 2 additions & 4 deletions crates/e2e/tests/e2e/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ async fn allowance(web3: Web3) {

let order = OrderCreation {
sell_token: cow.address(),
sell_amount: to_wei(4),
fee_amount: to_wei(1),
sell_amount: to_wei(5),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(3),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down Expand Up @@ -305,8 +304,7 @@ async fn signature(web3: Web3) {
let mut order = OrderCreation {
from: Some(safe.address()),
sell_token: token.address(),
sell_amount: to_wei(4),
fee_amount: to_wei(1),
sell_amount: to_wei(5),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(3),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
Loading
Loading