Skip to content

Commit

Permalink
chore: replace ethers Chain with alloy_chains (#6318)
Browse files Browse the repository at this point in the history
* chore: replace ethers `Chain` with `alloy_chains`

* chore: clippy

* try patch

* fix: `chain_id` field extraction

* readd polygon gas estimator
  • Loading branch information
DaniPopes authored Nov 15, 2023
1 parent 64b0e8f commit c9538c0
Show file tree
Hide file tree
Showing 39 changed files with 235 additions and 406 deletions.
93 changes: 42 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ alloy-json-abi = "0.4.1"
alloy-sol-types = "0.4.1"
syn-solidity = "0.4.1"

alloy-chains = "0.1.0"
alloy-rlp = "0.3.3"
solang-parser = "=0.3.3"

Expand Down Expand Up @@ -200,7 +201,7 @@ ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "0543e
ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", rev = "0543e1ccbaab70996ab21b5ceeff2fe599728b74" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "0543e1ccbaab70996ab21b5ceeff2fe599728b74" }

foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers" }
alloy-chains = { git = "https://github.com/alloy-rs/chains/", branch = "dani/fix-serde" }

alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-primitives = { git = "https://github.com/alloy-rs/core/" }
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl AccessListArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let chain = utils::get_chain(config.chain, &provider).await?;
let sender = eth.wallet.sender().await;

access_list(&provider, sender.to_ethers(), to, sig, args, data, tx, chain, block, to_json)
Expand Down
3 changes: 1 addition & 2 deletions crates/cast/bin/cmd/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ impl BindArgs {
async fn abigen_etherscan(&self) -> Result<MultiAbigen> {
let config = Config::from(&self.etherscan);

let chain = config.chain_id.unwrap_or_default();
let chain = config.chain.unwrap_or_default();
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let chain = chain.named()?;

let client = Client::new(chain, api_key)?;
let address = self.path_or_address.parse()?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl CallArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let chain = utils::get_chain(config.chain, &provider).await?;
let sender = eth.wallet.sender().await;

let mut builder: TxBuilder<'_, Provider> =
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl EstimateArgs {
let config = Config::from_provider(figment);

let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let chain = utils::get_chain(config.chain, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain));

let mut builder = TxBuilder::new(&provider, from, to, chain, false).await?;
Expand Down
3 changes: 1 addition & 2 deletions crates/cast/bin/cmd/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ impl InterfaceArgs {
AbiPath::Local { path: path_or_address, name }
} else {
let config = Config::from(&etherscan);
let chain = config.chain_id.unwrap_or_default();
let chain = config.chain.unwrap_or_default();
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let chain = chain.named()?;
AbiPath::Etherscan {
chain,
api_key,
Expand Down
5 changes: 2 additions & 3 deletions crates/cast/bin/cmd/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ fn build_filter_event_sig(event: Event, args: Vec<String>) -> Result<TopicFilter
.partition(|(_, (_, arg))| !arg.is_empty());

// Only parse the inputs with arguments
let indexed_tokens =
parse_params(with_args.clone().into_iter().map(|(_, p)| p).collect::<Vec<_>>(), true)?;
let indexed_tokens = parse_params(with_args.iter().map(|(_, p)| *p), true)?;

// Merge the inputs restoring the original ordering
let mut tokens = with_args
Expand Down Expand Up @@ -217,7 +216,7 @@ fn parse_params<'a, I: IntoIterator<Item = (&'a ParamType, &'a str)>>(
) -> eyre::Result<Vec<Token>> {
let mut tokens = Vec::new();

for (param, value) in params.into_iter() {
for (param, value) in params {
let mut token = if lenient {
LenientTokenizer::tokenize(param, value)
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/cast/bin/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl SendTxArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain_id, &provider).await?;
let chain = utils::get_chain(config.chain, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain));

// Case 1:
Expand All @@ -121,7 +121,7 @@ impl SendTxArgs {
// or remote RPC with unlocked accounts.
if unlocked {
// only check current chain id if it was specified in the config
if let Some(config_chain) = config.chain_id {
if let Some(config_chain) = config.chain {
let current_chain_id = provider.get_chainid().await?.as_u64();
let config_chain_id = config_chain.id();
// switch chain if current chain id is not the same as the one specified in the
Expand Down
4 changes: 2 additions & 2 deletions crates/cast/bin/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ impl StorageArgs {
eyre::bail!("You must provide an Etherscan API key if you're fetching a remote contract's storage.");
}

let chain = utils::get_chain(config.chain_id, &provider).await?;
let chain = utils::get_chain(config.chain, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let client = Client::new(chain.named()?, api_key)?;
let client = Client::new(chain, api_key)?;
let addr = address
.as_address()
.ok_or_else(|| eyre::eyre!("Could not resolve address"))?
Expand Down
Loading

0 comments on commit c9538c0

Please sign in to comment.