Skip to content

Commit ddd563f

Browse files
committed
Migrate token_list to alloy
1 parent bf5df59 commit ddd563f

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

crates/autopilot/src/arguments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct Arguments {
141141
/// Hardcoded list of trusted tokens to use in addition to
142142
/// `trusted_tokens_url`.
143143
#[clap(long, env, use_value_delimiter = true)]
144-
pub trusted_tokens: Option<Vec<H160>>,
144+
pub trusted_tokens: Option<Vec<Address>>,
145145

146146
/// Time interval after which the trusted tokens list needs to be updated.
147147
#[clap(
@@ -677,9 +677,9 @@ impl FromStr for FeePolicy {
677677
#[derive(Debug, Clone)]
678678
pub struct CowAmmConfig {
679679
/// Which contract to index for CoW AMM deployment events.
680-
pub factory: H160,
680+
pub factory: Address,
681681
/// Which helper contract to use for interfacing with the indexed CoW AMMs.
682-
pub helper: H160,
682+
pub helper: Address,
683683
/// At which block indexing should start on the factory.
684684
pub index_start: u64,
685685
}

crates/autopilot/src/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
491491
cow_amm_registry
492492
.add_listener(
493493
config.index_start,
494-
config.factory.into_alloy(),
495-
config.helper.into_alloy(),
494+
config.factory,
495+
config.helper,
496496
db_write.pool.clone(),
497497
)
498498
.await;

crates/autopilot/src/run_loop.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use {
2929
::observe::metrics,
3030
anyhow::{Context, Result},
3131
database::order_events::OrderEventLabel,
32-
ethrpc::block_stream::BlockInfo,
32+
ethrpc::{alloy::conversions::IntoLegacy, block_stream::BlockInfo},
3333
futures::{FutureExt, TryFutureExt},
3434
itertools::Itertools,
3535
model::solver_competition::{
@@ -580,7 +580,12 @@ impl RunLoop {
580580
) -> Vec<competition::Participant<Unranked>> {
581581
let request = solve::Request::new(
582582
auction,
583-
&self.trusted_tokens.all(),
583+
&self
584+
.trusted_tokens
585+
.all()
586+
.into_iter()
587+
.map(IntoLegacy::into_legacy)
588+
.collect(),
584589
self.config.solve_deadline,
585590
);
586591

crates/autopilot/src/shadow.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {
2323
},
2424
::observe::metrics,
2525
anyhow::Context,
26-
ethrpc::block_stream::CurrentBlockWatcher,
26+
ethrpc::{alloy::conversions::IntoLegacy, block_stream::CurrentBlockWatcher},
2727
itertools::Itertools,
2828
num::{CheckedSub, Saturating},
2929
shared::token_list::AutoUpdatingTokenList,
@@ -178,7 +178,16 @@ impl RunLoop {
178178
/// Runs the solver competition, making all configured drivers participate.
179179
#[instrument(skip_all)]
180180
async fn competition(&self, auction: &domain::Auction) -> Vec<Participant<Unranked>> {
181-
let request = solve::Request::new(auction, &self.trusted_tokens.all(), self.solve_deadline);
181+
let request = solve::Request::new(
182+
auction,
183+
&self
184+
.trusted_tokens
185+
.all()
186+
.into_iter()
187+
.map(IntoLegacy::into_legacy)
188+
.collect(),
189+
self.solve_deadline,
190+
);
182191

183192
futures::future::join_all(
184193
self.drivers

crates/shared/src/token_list.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
2+
alloy::primitives::Address,
23
anyhow::Result,
3-
ethcontract::H160,
44
prometheus::IntCounterVec,
55
reqwest::{Client, Url},
66
serde::Deserialize,
@@ -18,12 +18,12 @@ pub struct TokenListConfiguration {
1818
pub chain_id: u64,
1919
pub client: Client,
2020
pub update_interval: Duration,
21-
pub hardcoded: Vec<H160>,
21+
pub hardcoded: Vec<Address>,
2222
}
2323

2424
impl TokenListConfiguration {
2525
#[instrument(skip_all)]
26-
async fn get_external_list(&self) -> Result<HashSet<H160>> {
26+
async fn get_external_list(&self) -> Result<HashSet<Address>> {
2727
let model: TokenListModel = if let Some(url) = &self.url {
2828
self.client.get(url.clone()).send().await?.json().await?
2929
} else {
@@ -32,7 +32,7 @@ impl TokenListConfiguration {
3232
Ok(self.get_list(model.tokens))
3333
}
3434

35-
fn get_list(&self, tokens: Vec<TokenModel>) -> HashSet<H160> {
35+
fn get_list(&self, tokens: Vec<TokenModel>) -> HashSet<Address> {
3636
tokens
3737
.into_iter()
3838
.filter(|token| token.chain_id == self.chain_id)
@@ -43,7 +43,7 @@ impl TokenListConfiguration {
4343
}
4444
#[derive(Clone, Debug, Default)]
4545
pub struct AutoUpdatingTokenList {
46-
tokens: Arc<RwLock<HashSet<H160>>>,
46+
tokens: Arc<RwLock<HashSet<Address>>>,
4747
}
4848

4949
impl AutoUpdatingTokenList {
@@ -91,17 +91,17 @@ impl AutoUpdatingTokenList {
9191
Self { tokens }
9292
}
9393

94-
pub fn new(tokens: HashSet<H160>) -> Self {
94+
pub fn new(tokens: HashSet<Address>) -> Self {
9595
Self {
9696
tokens: Arc::new(RwLock::new(tokens)),
9797
}
9898
}
9999

100-
pub fn contains(&self, address: &H160) -> bool {
100+
pub fn contains(&self, address: &Address) -> bool {
101101
self.tokens.read().unwrap().contains(address)
102102
}
103103

104-
pub fn all(&self) -> HashSet<H160> {
104+
pub fn all(&self) -> HashSet<Address> {
105105
self.tokens.read().unwrap().clone()
106106
}
107107
}
@@ -118,7 +118,7 @@ struct TokenListModel {
118118
#[serde(rename_all = "camelCase")]
119119
struct TokenModel {
120120
chain_id: u64,
121-
address: H160,
121+
address: Address,
122122
}
123123

124124
#[derive(prometheus_metric_storage::MetricStorage, Clone, Debug)]
@@ -130,7 +130,7 @@ struct Metrics {
130130

131131
#[cfg(test)]
132132
pub mod tests {
133-
use {super::*, ethrpc::alloy::conversions::IntoLegacy};
133+
use {super::*, alloy::primitives::address};
134134

135135
// https://github.com/Uniswap/token-lists/blob/master/test/schema/example.tokenlist.json
136136
const EXAMPLE_LIST: &str = r#"
@@ -194,11 +194,11 @@ pub mod tests {
194194
tokens: vec![
195195
TokenModel {
196196
chain_id: 1,
197-
address: testlib::tokens::USDC.into_legacy(),
197+
address: testlib::tokens::USDC,
198198
},
199199
TokenModel {
200200
chain_id: 4,
201-
address: addr!("39AA39c021dfbaE8faC545936693aC917d5E7563"),
201+
address: address!("39AA39c021dfbaE8faC545936693aC917d5E7563"),
202202
}
203203
]
204204
}
@@ -217,9 +217,9 @@ pub mod tests {
217217
};
218218
let tokens = config.get_list(list.tokens);
219219
let instance = AutoUpdatingTokenList::new(tokens);
220-
assert!(instance.contains(&testlib::tokens::USDC.into_legacy()));
220+
assert!(instance.contains(&testlib::tokens::USDC));
221221
// Chain ID 4
222-
assert!(!instance.contains(&addr!("39AA39c021dfbaE8faC545936693aC917d5E7563")),);
222+
assert!(!instance.contains(&address!("39AA39c021dfbaE8faC545936693aC917d5E7563")));
223223
}
224224

225225
#[ignore]
@@ -234,13 +234,13 @@ pub mod tests {
234234
hardcoded: Default::default(),
235235
};
236236
let tokens = config.get_external_list().await.unwrap();
237-
assert!(tokens.contains(&testlib::tokens::USDC.into_legacy()));
238-
let gc_token = addr!("39AA39c021dfbaE8faC545936693aC917d5E7563");
237+
assert!(tokens.contains(&testlib::tokens::USDC));
238+
let gc_token = address!("39AA39c021dfbaE8faC545936693aC917d5E7563");
239239
assert!(!tokens.contains(&gc_token));
240240

241241
config.chain_id = 4;
242242
let tokens = config.get_list(list.tokens);
243-
assert!(!tokens.contains(&testlib::tokens::USDC.into_legacy()));
243+
assert!(!tokens.contains(&testlib::tokens::USDC));
244244
assert!(tokens.contains(&gc_token));
245245
}
246246
}

0 commit comments

Comments
 (0)