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

estimate and set EIP1559 gas price when sending transactions #57

Merged
Merged
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
25 changes: 17 additions & 8 deletions crates/arpa-node/src/node_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use arpa_contract_client::ethers::controller_oracle::ControllerOracleClient;
use arpa_contract_client::{ServiceClient, TransactionCaller, ViewCaller};
use arpa_core::{
address_to_string, build_wallet_from_config, pad_to_bytes32, Config, ConfigError,
GeneralMainChainIdentity, GeneralRelayedChainIdentity, WalletSigner,
GeneralMainChainIdentity, GeneralRelayedChainIdentity, WsWalletSigner,
DEFAULT_WEBSOCKET_PROVIDER_RECONNECT_TIMES,
};
use arpa_dal::NodeInfoFetcher;
Expand Down Expand Up @@ -193,6 +193,7 @@ async fn send<PC: Curve>(
let trx_hash = ArpaClient::call_contract_transaction(
main_chain_id,
"approve-arpa-to-staking",
arpa_contract.client_ref(),
arpa_contract.approve(context.staking_contract_address().await?, amount),
context
.config
Expand Down Expand Up @@ -278,6 +279,7 @@ async fn send<PC: Curve>(
let trx_hash = StakingClient::call_contract_transaction(
main_chain_id,
"stake",
staking_contract.client_ref(),
staking_contract.stake(amount),
context
.config
Expand Down Expand Up @@ -322,6 +324,7 @@ async fn send<PC: Curve>(
let trx_hash = StakingClient::call_contract_transaction(
main_chain_id,
"unstake",
staking_contract.client_ref(),
staking_contract.unstake(amount),
context
.config
Expand All @@ -346,6 +349,7 @@ async fn send<PC: Curve>(
let trx_hash = StakingClient::call_contract_transaction(
main_chain_id,
"claim_frozen_principal",
staking_contract.client_ref(),
staking_contract.claim_frozen_principal(),
context
.config
Expand Down Expand Up @@ -410,6 +414,7 @@ async fn send<PC: Curve>(
let trx_hash = ControllerClient::call_contract_transaction(
main_chain_id,
"node_activate",
controller_contract.client_ref(),
controller_contract.node_activate(),
context
.config
Expand Down Expand Up @@ -442,6 +447,7 @@ async fn send<PC: Curve>(
let trx_hash = ControllerClient::call_contract_transaction(
main_chain_id,
"node_quit",
controller_contract.client_ref(),
controller_contract.node_quit(),
context
.config
Expand Down Expand Up @@ -484,6 +490,7 @@ async fn send<PC: Curve>(
let trx_hash = ControllerClient::call_contract_transaction(
main_chain_id,
"change_dkg_public_key",
controller_contract.client_ref(),
controller_contract
.change_dkg_public_key(bincode::serialize(&dkg_public_key)?.into()),
context
Expand Down Expand Up @@ -523,6 +530,7 @@ async fn send<PC: Curve>(
let trx_hash = ControllerClient::call_contract_transaction(
*chain_id,
"node_withdraw",
controller_contract.client_ref(),
controller_contract.node_withdraw(recipient),
context
.config
Expand All @@ -546,6 +554,7 @@ async fn send<PC: Curve>(
let trx_hash = ControllerOracleClient::call_contract_transaction(
*chain_id,
"node_withdraw",
controller_oracle_contract.client_ref(),
controller_oracle_contract.node_withdraw(recipient),
context
.config
Expand Down Expand Up @@ -929,7 +938,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let filter = adapter_contract
Expand Down Expand Up @@ -972,7 +981,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.chain_identity(*chain_id)?.get_id_address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let filter = adapter_contract
Expand Down Expand Up @@ -1127,7 +1136,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let (
Expand Down Expand Up @@ -1167,7 +1176,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let last_assigned_group_index = AdapterClient::call_contract_view(
Expand All @@ -1191,7 +1200,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let randomness_count = AdapterClient::call_contract_view(
Expand Down Expand Up @@ -1290,7 +1299,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let (
Expand Down Expand Up @@ -1325,7 +1334,7 @@ async fn call<PC: Curve>(
.build_adapter_client(context.wallet.address());

let adapter_contract =
ServiceClient::<AdapterContract<WalletSigner>>::prepare_service_client(&client)
ServiceClient::<AdapterContract<WsWalletSigner>>::prepare_service_client(&client)
.await?;

let r_id = sub_matches.get_one::<String>("request-id").unwrap();
Expand Down
13 changes: 3 additions & 10 deletions crates/contract-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use arpa_core::{HttpWalletSigner, WalletSigner};
use ethers::providers::Http as HttpProvider;
use ethers::{
prelude::{signer::SignerMiddlewareError, ContractError, ProviderError},
providers::Provider,
signers::LocalWallet,
};
use arpa_core::{HttpWalletSigner, WsWalletSigner};
use ethers::prelude::{ContractError, ProviderError};
use rustc_hex::FromHexError;
use thiserror::Error;

Expand All @@ -19,12 +14,10 @@ pub enum ContractClientError {
#[error(transparent)]
ChainProviderError(#[from] ProviderError),
#[error(transparent)]
ContractError(#[from] ContractError<WalletSigner>),
WsContractError(#[from] ContractError<WsWalletSigner>),
#[error(transparent)]
HttpContractError(#[from] ContractError<HttpWalletSigner>),
#[error(transparent)]
SignerError(#[from] SignerMiddlewareError<Provider<HttpProvider>, LocalWallet>),
#[error(transparent)]
AddressParseError(#[from] FromHexError),
#[error("can't fetch new block, please check provider")]
FetchingBlockError,
Expand Down
9 changes: 5 additions & 4 deletions crates/contract-client/src/ethers/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use arpa_core::{
pad_to_bytes32, ChainIdentity, ExponentialBackoffRetryDescriptor, GeneralMainChainIdentity,
GeneralRelayedChainIdentity, PartialSignature, RandomnessRequestType, RandomnessTask,
WalletSigner, DEFAULT_MINIMUM_THRESHOLD, FULFILL_RANDOMNESS_GAS_EXCEPT_CALLBACK,
WsWalletSigner, DEFAULT_MINIMUM_THRESHOLD, FULFILL_RANDOMNESS_GAS_EXCEPT_CALLBACK,
RANDOMNESS_REWARD_GAS, VERIFICATION_GAS_OVER_MINIMUM_THRESHOLD,
};
use async_trait::async_trait;
Expand All @@ -23,7 +23,7 @@ pub struct AdapterClient {
chain_id: usize,
main_id_address: Address,
adapter_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand All @@ -33,7 +33,7 @@ impl AdapterClient {
chain_id: usize,
main_id_address: Address,
adapter_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
) -> Self {
Expand Down Expand Up @@ -78,7 +78,7 @@ impl AdapterClientBuilder for GeneralRelayedChainIdentity {
}
}

type AdapterContract = Adapter<WalletSigner>;
type AdapterContract = Adapter<WsWalletSigner>;

#[async_trait]
impl ServiceClient<AdapterContract> for AdapterClient {
Expand Down Expand Up @@ -151,6 +151,7 @@ impl AdapterTransactions for AdapterClient {
AdapterClient::call_contract_transaction(
self.chain_id,
"fulfill_randomness",
adapter_contract.client_ref(),
call.gas(
task.callback_gas_limit
+ FULFILL_RANDOMNESS_GAS_EXCEPT_CALLBACK
Expand Down
9 changes: 6 additions & 3 deletions crates/contract-client/src/ethers/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{TransactionCaller, ViewCaller};
use arpa_core::{
u256_to_vec, ChainIdentity, DKGTask, ExponentialBackoffRetryDescriptor,
GeneralMainChainIdentity, GeneralRelayedChainIdentity, Group, MainChainIdentity, Member, Node,
WalletSigner,
WsWalletSigner,
};
use async_trait::async_trait;
use ethers::prelude::*;
Expand All @@ -25,7 +25,7 @@ use threshold_bls::group::Curve;
pub struct ControllerClient {
chain_id: usize,
controller_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<C: Curve> ControllerClientBuilder<C> for GeneralRelayedChainIdentity {
}
}

type ControllerContract = Controller<WalletSigner>;
type ControllerContract = Controller<WsWalletSigner>;

#[async_trait]
impl ServiceClient<ControllerContract> for ControllerClient {
Expand Down Expand Up @@ -98,6 +98,7 @@ impl ControllerTransactions for ControllerClient {
ControllerClient::call_contract_transaction(
self.chain_id,
"node_register",
controller_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
true,
Expand Down Expand Up @@ -127,6 +128,7 @@ impl ControllerTransactions for ControllerClient {
ControllerClient::call_contract_transaction(
self.chain_id,
"commit_dkg",
controller_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
true,
Expand All @@ -147,6 +149,7 @@ impl ControllerTransactions for ControllerClient {
ControllerClient::call_contract_transaction(
self.chain_id,
"post_process_dkg",
controller_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
false,
Expand Down
7 changes: 4 additions & 3 deletions crates/contract-client/src/ethers/controller_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use crate::{TransactionCaller, ViewCaller};
use arpa_core::{
u256_to_vec, ChainIdentity, ExponentialBackoffRetryDescriptor, GeneralMainChainIdentity,
GeneralRelayedChainIdentity, Group, Member, RelayedChainIdentity, WalletSigner,
GeneralRelayedChainIdentity, Group, Member, RelayedChainIdentity, WsWalletSigner,
};
use async_trait::async_trait;
use ethers::prelude::*;
Expand All @@ -20,7 +20,7 @@ use threshold_bls::group::Curve;
pub struct ControllerOracleClient {
chain_id: usize,
controller_oracle_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<C: Curve> ControllerOracleClientBuilder<C> for GeneralRelayedChainIdentity
}
}

type ControllerOracleContract = ControllerOracle<WalletSigner>;
type ControllerOracleContract = ControllerOracle<WsWalletSigner>;

#[async_trait]
impl ServiceClient<ControllerOracleContract> for ControllerOracleClient {
Expand Down Expand Up @@ -94,6 +94,7 @@ impl ControllerOracleTransactions for ControllerOracleClient {
ControllerOracleClient::call_contract_transaction(
self.chain_id,
"node_withdraw",
controller_oracle_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
true,
Expand Down
7 changes: 4 additions & 3 deletions crates/contract-client/src/ethers/controller_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use arpa_core::{
ChainIdentity, ExponentialBackoffRetryDescriptor, GeneralMainChainIdentity,
GeneralRelayedChainIdentity, MainChainIdentity, WalletSigner,
GeneralRelayedChainIdentity, MainChainIdentity, WsWalletSigner,
};
use async_trait::async_trait;
use ethers::prelude::*;
Expand All @@ -15,7 +15,7 @@ use std::sync::Arc;
pub struct ControllerRelayerClient {
chain_id: usize,
controller_relayer_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
}

Expand Down Expand Up @@ -56,7 +56,7 @@ impl ControllerRelayerClientBuilder for GeneralRelayedChainIdentity {
}
}

type ControllerRelayerContract = ControllerRelayer<WalletSigner>;
type ControllerRelayerContract = ControllerRelayer<WsWalletSigner>;

#[async_trait]
impl ServiceClient<ControllerRelayerContract> for ControllerRelayerClient {
Expand All @@ -82,6 +82,7 @@ impl ControllerRelayerTransactions for ControllerRelayerClient {
ControllerRelayerClient::call_contract_transaction(
self.chain_id,
"relay_group",
controller_relayer_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
false,
Expand Down
13 changes: 7 additions & 6 deletions crates/contract-client/src/ethers/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use ::core::panic;
use arpa_core::{
ChainIdentity, ExponentialBackoffRetryDescriptor, GeneralMainChainIdentity,
GeneralRelayedChainIdentity, WalletSigner,
GeneralRelayedChainIdentity, WsWalletSigner,
};
use async_trait::async_trait;
use dkg_core::{
Expand All @@ -24,7 +24,7 @@ use threshold_bls::group::Curve;
pub struct CoordinatorClient {
chain_id: usize,
coordinator_address: Address,
signer: Arc<WalletSigner>,
signer: Arc<WsWalletSigner>,
contract_transaction_retry_descriptor: ExponentialBackoffRetryDescriptor,
contract_view_retry_descriptor: ExponentialBackoffRetryDescriptor,
}
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<C: Curve + 'static> CoordinatorClientBuilder<C> for GeneralRelayedChainIden
}
}

type CoordinatorContract = Coordinator<WalletSigner>;
type CoordinatorContract = Coordinator<WsWalletSigner>;

#[async_trait]
impl ServiceClient<CoordinatorContract> for CoordinatorClient {
Expand Down Expand Up @@ -97,6 +97,7 @@ impl CoordinatorTransactions for CoordinatorClient {
CoordinatorClient::call_contract_transaction(
self.chain_id,
"publish",
coordinator_contract.client_ref(),
call,
self.contract_transaction_retry_descriptor,
false,
Expand Down Expand Up @@ -225,7 +226,7 @@ impl<C: Curve + 'static> BoardPublisher<C> for CoordinatorClient {

#[cfg(test)]
pub mod coordinator_tests {
use super::{CoordinatorClient, WalletSigner};
use super::{CoordinatorClient, WsWalletSigner};
use crate::contract_stub::coordinator::Coordinator;
use crate::coordinator::CoordinatorTransactions;
use crate::error::ContractClientError;
Expand Down Expand Up @@ -257,7 +258,7 @@ pub mod coordinator_tests {
Anvil::new().chain_id(1u64).mnemonic(PHRASE).spawn()
}

async fn deploy_contract(anvil: &AnvilInstance) -> Coordinator<WalletSigner> {
async fn deploy_contract(anvil: &AnvilInstance) -> Coordinator<WsWalletSigner> {
// 2. instantiate our wallet
let wallet: LocalWallet = anvil.keys()[0].clone().into();

Expand Down Expand Up @@ -357,7 +358,7 @@ pub mod coordinator_tests {

let res = client.publish(mock_value.clone()).await;
assert!(res.is_err());
if let ContractClientError::ContractError(Revert(bytes)) = res.unwrap_err() {
if let ContractClientError::WsContractError(Revert(bytes)) = res.unwrap_err() {
let error_msg = String::decode_with_selector(&bytes).unwrap();
assert_eq!("share existed", error_msg);
} else {
Expand Down
Loading
Loading