Skip to content

Commit

Permalink
comments and small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Jan 28, 2025
1 parent a3aedab commit a3dc00c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub struct EthFlowRefundRetriever {

impl EthFlowRefundRetriever {
pub fn new(web3: Web3, addresses: Vec<H160>) -> Self {
assert!(
!addresses.is_empty(),
"EthFlowRefundRetriever must have at least one address to listen to."
);
Self { web3, addresses }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct CoWSwapOnchainOrdersContract {

impl CoWSwapOnchainOrdersContract {
pub fn new(web3: Web3, addresses: Vec<H160>) -> Self {
assert!(
!addresses.is_empty(),
"CoWSwapOnchainOrdersContract must have at least one address to listen to."
);
Self { web3, addresses }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/ethflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl ExtendedEthFlowOrder {
.expect("Couldn't query domain separator")
.0,
);
self.to_cow_swap_order(&ethflow_contract, &contracts.weth)
self.to_cow_swap_order(ethflow_contract, &contracts.weth)
.data
.uid(&domain_separator, &ethflow_contract.address())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/refunder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 12 additions & 3 deletions crates/refunder/src/refund_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -98,7 +100,7 @@ impl RefundService {
async fn identify_uids_refunding_status_via_web3_calls(
&self,
refundable_order_uids: Vec<EthOrderPlacement>,
) -> Result<Vec<(OrderUid, H160)>> {
) -> Result<Vec<(OrderUid, CoWSwapEthFlowAddress)>> {
let mut batch = Web3CallBatch::new(self.web3.transport().clone());
let futures = refundable_order_uids
.iter()
Expand All @@ -121,13 +123,17 @@ 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,
RefundStatus::Refunded,
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,
Expand All @@ -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))
}
})
Expand Down Expand Up @@ -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(());
}
Expand Down

0 comments on commit a3dc00c

Please sign in to comment.