Skip to content

Commit e25f11b

Browse files
committed
Update provider to use NonceManagerMiddleware
1 parent af860d3 commit e25f11b

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

core/src/deployer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub async fn deploy_oapp_contract(
1111
chain_client: &ChainClient,
1212
) -> Result<Address> {
1313
let endpoint_address = chain.endpoint_address();
14-
let delegator_address = chain_client.address();
14+
15+
let underlying_signer = chain_client.inner(); // returns &SignerMiddleware<Provider<Http>, LocalWallet>
16+
let delegator_address = underlying_signer.signer().address();
1517

1618
let deployed = MyOApp::deploy(chain_client.clone(), (endpoint_address, delegator_address))
1719
.map_err(|e| {

core/src/layer_zero.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ pub async fn setup_peer_connections(
6464

6565
// oapp_contract
6666
println!("Set peer for {} with value {}", chain_i, eid);
67-
oapp_contract.set_peer(eid, peer_addr).send().await?;
67+
let call = oapp_contract.set_peer(eid, peer_addr);
68+
let _pending_tx = call.send().await?;
69+
// pending_tx.confirmations(1).await?; // using nonce manager
6870
}
6971
}
7072
}
@@ -120,7 +122,9 @@ pub async fn send_cross_chain_message(
120122
.send(eid, message, adapter_params)
121123
.value(native_fee);
122124

123-
let tx_hash = tx.send().await?.tx_hash();
125+
let receipt = tx.send().await?;
126+
let tx_hash = receipt.tx_hash();
127+
// receipt.confirmations(1).await?; // using nonce manager
124128

125129
println!(
126130
"Message sent from {} to {}. Transaction hash: {:?}",
@@ -134,6 +138,7 @@ pub async fn send_cross_chain_message(
134138
Ok(tx_hash)
135139
}
136140

141+
// TODO Is possible to parallelize this function but only for a given source chain fixed
137142
pub async fn send_messages_to_all_chains(
138143
deployer: &LocalWallet,
139144
addresses: &HashMap<SupportedChain, H160>,

core/src/provider.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use dotenvy;
2-
use ethers::middleware::SignerMiddleware;
2+
use ethers::middleware::{NonceManagerMiddleware, SignerMiddleware};
33
use ethers::providers::{Http, Middleware, Provider};
44
use ethers::signers::{LocalWallet, Signer};
55
use foundry_config::{Config, RpcEndpoint};
@@ -11,15 +11,14 @@ use crate::chain::SupportedChain;
1111

1212
pub type ProviderHttp = Provider<Http>;
1313
pub type WalletLocal = LocalWallet;
14-
pub type ChainMiddleware = SignerMiddleware<ProviderHttp, WalletLocal>;
14+
pub type ChainMiddleware = NonceManagerMiddleware<SignerMiddleware<ProviderHttp, WalletLocal>>;
1515
pub type ChainClient = Arc<ChainMiddleware>;
1616

1717
pub fn get_rpc_endpoints_from_foundry_config()
1818
-> anyhow::Result<HashMap<SupportedChain, RpcEndpoint>> {
1919
dotenvy::dotenv().ok(); // load .env
2020

2121
let config = Config::load();
22-
println!("Config {:?}", config);
2322

2423
let mut rpc_endpoints = HashMap::new();
2524
for (alias, endpoint) in config.rpc_endpoints.iter() {
@@ -48,9 +47,11 @@ pub async fn build_chain_clients(
4847

4948
let chain_id = provider.get_chainid().await?.as_u64();
5049

51-
let signer_middleware =
52-
SignerMiddleware::new(provider, wallet.clone().with_chain_id(chain_id));
53-
let arc_client = Arc::new(signer_middleware);
50+
let signer = SignerMiddleware::new(provider, wallet.clone().with_chain_id(chain_id));
51+
let address = signer.address();
52+
let nonce_manager = NonceManagerMiddleware::new(signer, address);
53+
54+
let arc_client = Arc::new(nonce_manager);
5455

5556
clients.insert(alias.clone(), arc_client);
5657
}

0 commit comments

Comments
 (0)