diff --git a/crates/autopilot/src/database/ethflow_events/event_retriever.rs b/crates/autopilot/src/database/ethflow_events/event_retriever.rs index 7482ee4269..2edf21381a 100644 --- a/crates/autopilot/src/database/ethflow_events/event_retriever.rs +++ b/crates/autopilot/src/database/ethflow_events/event_retriever.rs @@ -17,6 +17,10 @@ pub struct EthFlowRefundRetriever { impl EthFlowRefundRetriever { pub fn new(web3: Web3, addresses: Vec) -> Self { + assert!( + !addresses.is_empty(), + "EthFlowRefundRetriever must have at least one address to listen to." + ); Self { web3, addresses } } } diff --git a/crates/autopilot/src/database/onchain_order_events/event_retriever.rs b/crates/autopilot/src/database/onchain_order_events/event_retriever.rs index 940ed44ac4..9d870d9c1f 100644 --- a/crates/autopilot/src/database/onchain_order_events/event_retriever.rs +++ b/crates/autopilot/src/database/onchain_order_events/event_retriever.rs @@ -28,6 +28,10 @@ pub struct CoWSwapOnchainOrdersContract { impl CoWSwapOnchainOrdersContract { pub fn new(web3: Web3, addresses: Vec) -> Self { + assert!( + !addresses.is_empty(), + "CoWSwapOnchainOrdersContract must have at least one address to listen to." + ); Self { web3, addresses } } } diff --git a/crates/e2e/tests/e2e/ethflow.rs b/crates/e2e/tests/e2e/ethflow.rs index 515db28693..761aaf705c 100644 --- a/crates/e2e/tests/e2e/ethflow.rs +++ b/crates/e2e/tests/e2e/ethflow.rs @@ -646,7 +646,7 @@ impl ExtendedEthFlowOrder { .expect("Couldn't query domain separator") .0, ); - self.to_cow_swap_order(ðflow_contract, &contracts.weth) + self.to_cow_swap_order(ethflow_contract, &contracts.weth) .data .uid(&domain_separator, ðflow_contract.address()) } diff --git a/crates/e2e/tests/e2e/refunder.rs b/crates/e2e/tests/e2e/refunder.rs index db481c6df6..8a50ae7a96 100644 --- a/crates/e2e/tests/e2e/refunder.rs +++ b/crates/e2e/tests/e2e/refunder.rs @@ -33,7 +33,7 @@ async fn refunder_tx(web3: Web3) { let receiver = Some(H160([42; 20])); let sell_amount = U256::from("3000000000000000"); - let ethflow_contract = onchain.contracts().ethflows.get(0).unwrap(); + let ethflow_contract = onchain.contracts().ethflows.first().unwrap(); let quote = OrderQuoteRequest { from: ethflow_contract.address(), sell_token: onchain.contracts().weth.address(), diff --git a/crates/refunder/src/refund_service.rs b/crates/refunder/src/refund_service.rs index 35fdcd3cfc..cc5a9be0e5 100644 --- a/crates/refunder/src/refund_service.rs +++ b/crates/refunder/src/refund_service.rs @@ -24,6 +24,8 @@ pub const NO_OWNER: H160 = H160([0u8; 20]); pub const INVALIDATED_OWNER: H160 = H160([255u8; 20]); const MAX_NUMBER_OF_UIDS_PER_REFUND_TX: usize = 30; +type CoWSwapEthFlowAddress = H160; + pub struct RefundService { pub db: PgPool, pub web3: Web3, @@ -98,7 +100,7 @@ impl RefundService { async fn identify_uids_refunding_status_via_web3_calls( &self, refundable_order_uids: Vec, - ) -> Result> { + ) -> Result> { let mut batch = Web3CallBatch::new(self.web3.transport().clone()); let futures = refundable_order_uids .iter() @@ -121,6 +123,8 @@ impl RefundService { for (index, call) in contract_calls.into_iter().enumerate() { match call.await { Ok((owner, _)) => { + // if an order is found to be invalidated in any contract, it is + // already refunded and we can skip the rest if owner == INVALIDATED_OWNER { return Some(( eth_order_placement.uid, @@ -128,6 +132,8 @@ impl RefundService { None, )); } + // if an order has a valid owner in any contract, it should be + // refunded for that contract if owner != NO_OWNER { return Some(( eth_order_placement.uid, @@ -147,7 +153,7 @@ impl RefundService { } } - // otherwise the order has no owner in all contract and therefore is invalid + // otherwise the order has no owner in all contracts and therefore is invalid Some((eth_order_placement.uid, RefundStatus::Invalid, None)) } }) @@ -189,7 +195,10 @@ impl RefundService { Ok(order_to_ethflow_data(order, ethflow_order)) } - async fn send_out_refunding_tx(&mut self, uids: Vec<(OrderUid, H160)>) -> Result<()> { + async fn send_out_refunding_tx( + &mut self, + uids: Vec<(OrderUid, CoWSwapEthFlowAddress)>, + ) -> Result<()> { if uids.is_empty() { return Ok(()); }