Skip to content

Commit

Permalink
fix GasMiddleware and rename signer to client
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeikui committed May 14, 2024
1 parent 72d1a42 commit 9d33506
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 121 deletions.
20 changes: 10 additions & 10 deletions crates/arpa-node/src/node_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async fn send<PC: Curve>(

let arpa_contract = ArpaContract::new(
context.config.find_arpa_address(main_chain_id)?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let trx_hash = ArpaClient::call_contract_transaction(
Expand Down Expand Up @@ -247,7 +247,7 @@ async fn send<PC: Curve>(

let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let is_operator = StakingClient::call_contract_view(
Expand All @@ -268,7 +268,7 @@ async fn send<PC: Curve>(

let arpa_contract = ArpaContract::new(
context.config.find_arpa_address(main_chain_id)?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let balance = ArpaClient::call_contract_view(
Expand Down Expand Up @@ -333,7 +333,7 @@ async fn send<PC: Curve>(

let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let staked_amount = StakingClient::call_contract_view(
Expand Down Expand Up @@ -375,7 +375,7 @@ async fn send<PC: Curve>(
let main_chain_id = context.config.get_main_chain_id();
let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let trx_hash = StakingClient::call_contract_transaction(
Expand Down Expand Up @@ -1058,7 +1058,7 @@ async fn call<PC: Curve>(
let main_chain_id = context.config.get_main_chain_id();
let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let delegation_reward = StakingClient::call_contract_view(
Expand All @@ -1078,7 +1078,7 @@ async fn call<PC: Curve>(
let main_chain_id = context.config.get_main_chain_id();
let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let delegates_count = StakingClient::call_contract_view(
Expand All @@ -1097,7 +1097,7 @@ async fn call<PC: Curve>(
let main_chain_id = context.config.get_main_chain_id();
let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let amount = StakingClient::call_contract_view(
Expand All @@ -1116,7 +1116,7 @@ async fn call<PC: Curve>(
let main_chain_id = context.config.get_main_chain_id();
let staking_contract = StakingContract::new(
context.staking_contract_address().await?,
context.chain_identity(main_chain_id)?.get_signer(),
context.chain_identity(main_chain_id)?.get_client(),
);

let (amounts, timestamps) = StakingClient::call_contract_view(
Expand Down Expand Up @@ -1152,7 +1152,7 @@ async fn call<PC: Curve>(
let chain_id = sub_matches.get_one::<usize>("chain-id").unwrap();
let arpa_contract = ArpaContract::new(
context.config.find_arpa_address(*chain_id)?,
context.chain_identity(*chain_id)?.get_signer(),
context.chain_identity(*chain_id)?.get_client(),
);

let balance = ArpaClient::call_contract_view(
Expand Down
14 changes: 7 additions & 7 deletions crates/contract-client/src/ethers/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct AdapterClient {
chain_id: usize,
main_id_address: Address,
adapter_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -33,15 +33,15 @@ impl AdapterClient {
chain_id: usize,
main_id_address: Address,
adapter_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
) -> Self {
AdapterClient {
chain_id,
main_id_address,
adapter_address,
signer,
client,
contract_transaction_retry_descriptor,
contract_view_retry_descriptor,
}
Expand All @@ -56,7 +56,7 @@ impl AdapterClientBuilder for GeneralMainChainIdentity {
self.get_chain_id(),
main_id_address,
self.get_adapter_address(),
self.get_signer(),
self.get_client(),
self.get_contract_transaction_retry_descriptor(),
self.get_contract_view_retry_descriptor(),
)
Expand All @@ -71,7 +71,7 @@ impl AdapterClientBuilder for GeneralRelayedChainIdentity {
self.get_chain_id(),
main_id_address,
self.get_adapter_address(),
self.get_signer(),
self.get_client(),
self.get_contract_transaction_retry_descriptor(),
self.get_contract_view_retry_descriptor(),
)
Expand All @@ -83,7 +83,7 @@ type AdapterContract = Adapter<WsWalletSigner>;
#[async_trait]
impl ServiceClient<AdapterContract> for AdapterClient {
async fn prepare_service_client(&self) -> ContractClientResult<AdapterContract> {
let adapter_contract = Adapter::new(self.adapter_address, self.signer.clone());
let adapter_contract = Adapter::new(self.adapter_address, self.client.clone());

Ok(adapter_contract)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ impl AdapterLogs for AdapterClient {
&self,
mut cb: C,
) -> ContractClientResult<()> {
let contract = Adapter::new(self.adapter_address, self.signer.clone());
let contract = Adapter::new(self.adapter_address, self.client.clone());

let events = contract
.event::<RandomnessRequestFilter>()
Expand Down
8 changes: 4 additions & 4 deletions crates/contract-client/src/ethers/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use threshold_bls::group::Curve;
pub struct ControllerClient {
chain_id: usize,
controller_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -41,7 +41,7 @@ impl ControllerClient {
ControllerClient {
chain_id,
controller_address,
signer: identity.get_signer(),
client: identity.get_client(),
contract_transaction_retry_descriptor,
contract_view_retry_descriptor,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ type ControllerContract = Controller<WsWalletSigner>;
#[async_trait]
impl ServiceClient<ControllerContract> for ControllerClient {
async fn prepare_service_client(&self) -> ContractClientResult<ControllerContract> {
let controller_contract = Controller::new(self.controller_address, self.signer.clone());
let controller_contract = Controller::new(self.controller_address, self.client.clone());

Ok(controller_contract)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ impl ControllerLogs for ControllerClient {
&self,
mut cb: C,
) -> ContractClientResult<()> {
let contract = Controller::new(self.controller_address, self.signer.clone());
let contract = Controller::new(self.controller_address, self.client.clone());

let events = contract
.event::<DkgTaskFilter>()
Expand Down
6 changes: 3 additions & 3 deletions crates/contract-client/src/ethers/controller_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use threshold_bls::group::Curve;
pub struct ControllerOracleClient {
chain_id: usize,
controller_oracle_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -36,7 +36,7 @@ impl ControllerOracleClient {
ControllerOracleClient {
chain_id,
controller_oracle_address,
signer: identity.get_signer(),
client: identity.get_client(),
contract_transaction_retry_descriptor,
contract_view_retry_descriptor,
}
Expand Down Expand Up @@ -71,7 +71,7 @@ type ControllerOracleContract = ControllerOracle<WsWalletSigner>;
impl ServiceClient<ControllerOracleContract> for ControllerOracleClient {
async fn prepare_service_client(&self) -> ContractClientResult<ControllerOracleContract> {
let controller_oracle_contract =
ControllerOracle::new(self.controller_oracle_address, self.signer.clone());
ControllerOracle::new(self.controller_oracle_address, self.client.clone());

Ok(controller_oracle_contract)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/contract-client/src/ethers/controller_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;
pub struct ControllerRelayerClient {
chain_id: usize,
controller_relayer_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
}

Expand All @@ -29,7 +29,7 @@ impl ControllerRelayerClient {
ControllerRelayerClient {
chain_id,
controller_relayer_address,
signer: identity.get_signer(),
client: identity.get_client(),
contract_transaction_retry_descriptor,
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ type ControllerRelayerContract = ControllerRelayer<WsWalletSigner>;
impl ServiceClient<ControllerRelayerContract> for ControllerRelayerClient {
async fn prepare_service_client(&self) -> ContractClientResult<ControllerRelayerContract> {
let controller_relayer_contract =
ControllerRelayer::new(self.controller_relayer_address, self.signer.clone());
ControllerRelayer::new(self.controller_relayer_address, self.client.clone());

Ok(controller_relayer_contract)
}
Expand Down
19 changes: 5 additions & 14 deletions crates/contract-client/src/ethers/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use threshold_bls::group::Curve;
pub struct CoordinatorClient {
chain_id: usize,
coordinator_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -40,7 +40,7 @@ impl CoordinatorClient {
CoordinatorClient {
chain_id,
coordinator_address,
signer: identity.get_signer(),
client: identity.get_client(),
contract_transaction_retry_descriptor,
contract_view_retry_descriptor,
}
Expand Down Expand Up @@ -74,7 +74,7 @@ type CoordinatorContract = Coordinator<WsWalletSigner>;
#[async_trait]
impl ServiceClient<CoordinatorContract> for CoordinatorClient {
async fn prepare_service_client(&self) -> ContractClientResult<CoordinatorContract> {
let coordinator_contract = Coordinator::new(self.coordinator_address, self.signer.clone());
let coordinator_contract = Coordinator::new(self.coordinator_address, self.client.clone());

Ok(coordinator_contract)
}
Expand Down Expand Up @@ -230,11 +230,10 @@ pub mod coordinator_tests {
use crate::contract_stub::coordinator::Coordinator;
use crate::coordinator::CoordinatorTransactions;
use crate::error::ContractClientError;
use arpa_core::build_client;
use arpa_core::eip1559_gas_price_estimator;
use arpa_core::Config;
use arpa_core::GasMiddleware;
use arpa_core::GeneralMainChainIdentity;
use arpa_core::GAS_RAISE_PERCENTAGE;
use ethers::abi::Tokenize;
use ethers::prelude::ContractError::Revert;
use ethers::prelude::*;
Expand Down Expand Up @@ -275,15 +274,7 @@ pub mod coordinator_tests {
);

// 4. instantiate the client with the wallet
let nonce_manager = NonceManagerMiddleware::new(
provider.wrap_into(|s| GasMiddleware::new(s, GAS_RAISE_PERCENTAGE).unwrap()),
wallet.address(),
);

let client = Arc::new(SignerMiddleware::new(
nonce_manager,
wallet.with_chain_id(anvil.chain_id()),
));
let client = build_client(wallet, anvil.chain_id() as usize, provider);

// 5. deploy contract
let mut call = Coordinator::deploy(client.clone(), (3u8, 30u8)).unwrap();
Expand Down
17 changes: 9 additions & 8 deletions crates/contract-client/src/ethers/node_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::Arc;
pub struct NodeRegistryClient {
chain_id: usize,
node_registry_address: Address,
signer: Arc<WsWalletSigner>,
client: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -35,7 +35,7 @@ impl NodeRegistryClient {
NodeRegistryClient {
chain_id,
node_registry_address,
signer: identity.get_signer(),
client: identity.get_client(),
contract_transaction_retry_descriptor,
contract_view_retry_descriptor,
}
Expand Down Expand Up @@ -70,7 +70,7 @@ type NodeRegistryContract = NodeRegistry<WsWalletSigner>;
impl ServiceClient<NodeRegistryContract> for NodeRegistryClient {
async fn prepare_service_client(&self) -> ContractClientResult<NodeRegistryContract> {
let node_registry_contract =
NodeRegistry::new(self.node_registry_address, self.signer.clone());
NodeRegistry::new(self.node_registry_address, self.client.clone());

Ok(node_registry_contract)
}
Expand All @@ -96,15 +96,15 @@ impl NodeRegistryTransactions for NodeRegistryClient {
let service_manager_address =
node_registry_contract.get_node_registry_config().await?.2;
let service_manager_contract =
service_manager::ServiceManager::new(service_manager_address, self.signer.clone());
service_manager::ServiceManager::new(service_manager_address, self.client.clone());
let avs_directory_address = service_manager_contract.avs_directory().await?;
let avs_directory_contract =
iavs_directory::IAVSDirectory::new(avs_directory_address, self.signer.clone());
iavs_directory::IAVSDirectory::new(avs_directory_address, self.client.clone());
// generate random salt
let salt = rand::thread_rng().gen::<[u8; 32]>();

let expiry = self
.signer
.client
.provider()
.get_block(BlockNumber::Latest)
.await
Expand All @@ -114,14 +114,15 @@ impl NodeRegistryTransactions for NodeRegistryClient {

let digest_hash = avs_directory_contract
.calculate_operator_avs_registration_digest_hash(
self.signer.address(),
self.client.inner().address(),
service_manager_address,
salt,
expiry,
)
.await?;
let signature = self
.signer
.client
.inner()
.signer()
.sign_hash(digest_hash.into())?
.to_vec()
Expand Down
Loading

0 comments on commit 9d33506

Please sign in to comment.