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

[DRAFT] Observe multiple contracts for ETH flow #3249

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ pub struct Arguments {
#[clap(flatten)]
pub price_estimation: price_estimation::Arguments,

/// Address of the ethflow contract. If not specified, eth-flow orders are
/// Address of the ethflow contracts. If not specified, eth-flow orders are
/// disabled.
/// In general, one contract is sufficient for the service to function.
/// Support for multiple contract was added to support transition period for
/// integrators when the migration of the eth-flow contract happens.
#[clap(long, env)]
pub ethflow_contract: Option<H160>,
pub ethflow_contract: Vec<H160>,

/// Timestamp at which we should start indexing eth-flow contract events.
/// If there are already events in the database for a date later than this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ const ORDER_REFUND_TOPIC: H256 = H256(hex!(

pub struct EthFlowRefundRetriever {
web3: Web3,
address: H160,
addresses: Vec<H160>,
}

impl EthFlowRefundRetriever {
pub fn new(web3: Web3, address: H160) -> Self {
Self { web3, address }
pub fn new(web3: Web3, addresses: Vec<H160>) -> Self {
Self { web3, addresses }
}
}

impl EventRetrieving for EthFlowRefundRetriever {
type Event = contracts::cowswap_eth_flow::Event;

fn get_events(&self) -> AllEventsBuilder<DynTransport, Self::Event> {
let mut events = AllEventsBuilder::new(self.web3.clone(), self.address, None);
let mut events =
AllEventsBuilder::new(self.web3.clone(), *self.addresses.first().unwrap(), None);
// We want to observe multiple addresses for events.
events.filter = events.filter.address(self.addresses.clone());
// Filter out events that we don't want to listen for in the contract. `Self` is
// designed to only pick up refunding events. Adding a filter also makes
// the query more efficient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ static ALL_VALID_ONCHAIN_ORDER_TOPICS: [H256; 2] =
// onchain-order contract ABI).
pub struct CoWSwapOnchainOrdersContract {
web3: Web3,
address: H160,
addresses: Vec<H160>,
}

impl CoWSwapOnchainOrdersContract {
pub fn new(web3: Web3, address: H160) -> Self {
Self { web3, address }
pub fn new(web3: Web3, addresses: Vec<H160>) -> Self {
Self { web3, addresses }
}
}

impl EventRetrieving for CoWSwapOnchainOrdersContract {
type Event = cowswap_onchain_orders::Event;

fn get_events(&self) -> AllEventsBuilder<DynTransport, Self::Event> {
let mut events = AllEventsBuilder::new(self.web3.clone(), self.address, None);
let mut events =
AllEventsBuilder::new(self.web3.clone(), *self.addresses.first().unwrap(), None);
// We want to observe multiple addresses for events.
events.filter = events.filter.address(self.addresses.clone());
// Filter out events that don't belong to the ABI of `OnchainOrdersContract`.
// This is done because there could be other unrelated events fired by
// the contract which should be ignored. Also, it makes the request more
Expand Down
6 changes: 3 additions & 3 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub async fn run(args: Arguments) {
let mut maintenance = Maintenance::new(settlement_event_indexer, db.clone());
maintenance.with_cow_amms(&cow_amm_registry);

if let Some(ethflow_contract) = args.ethflow_contract {
if !args.ethflow_contract.is_empty() {
let ethflow_refund_start_block = determine_ethflow_refund_indexing_start(
&skip_event_sync_start,
args.ethflow_indexing_start,
Expand All @@ -489,7 +489,7 @@ pub async fn run(args: Arguments) {
let refund_event_handler = EventUpdater::new_skip_blocks_before(
// This cares only about ethflow refund events because all the other ethflow
// events are already indexed by the OnchainOrderParser.
EthFlowRefundRetriever::new(web3.clone(), ethflow_contract),
EthFlowRefundRetriever::new(web3.clone(), args.ethflow_contract.clone()),
db.clone(),
block_retriever.clone(),
ethflow_refund_start_block,
Expand Down Expand Up @@ -518,7 +518,7 @@ pub async fn run(args: Arguments) {
let onchain_order_indexer = EventUpdater::new_skip_blocks_before(
// The events from the ethflow contract are read with the more generic contract
// interface called CoWSwapOnchainOrders.
CoWSwapOnchainOrdersContract::new(web3.clone(), ethflow_contract),
CoWSwapOnchainOrdersContract::new(web3.clone(), args.ethflow_contract),
onchain_order_event_parser,
block_retriever,
ethflow_start_block,
Expand Down
Loading