Skip to content

Commit 2d11d09

Browse files
committed
fix: reintroducing config builder.
1 parent 2bfdf2a commit 2d11d09

File tree

1,338 files changed

+494
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,338 files changed

+494
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/mcr/clients/eth/src/client/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ sol!(
4040
);
4141

4242
pub struct Client<P> {
43-
run_commitment_admin_mode: bool,
44-
rpc_provider: P,
45-
ws_provider: RootProvider<PubSubFrontend>,
46-
pub signer_address: Address,
47-
contract_address: Address,
48-
send_transaction_error_rules: Vec<Box<dyn VerifyRule>>,
49-
gas_limit: u64,
50-
send_transaction_retries: u32,
43+
pub(crate) run_commitment_admin_mode: bool,
44+
pub(crate) rpc_provider: P,
45+
pub(crate) ws_provider: RootProvider<PubSubFrontend>,
46+
pub(crate) signer_address: Address,
47+
pub(crate) contract_address: Address,
48+
pub(crate) send_transaction_error_rules: Vec<Box<dyn VerifyRule>>,
49+
pub(crate) gas_limit: u64,
50+
pub(crate) send_transaction_retries: u32,
5151
}
5252

5353
impl<P> McrClientOperations for Client<P>
Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,163 @@
1+
use crate::client::Client;
2+
use crate::util::send_eth_transaction::InsufficentFunds;
3+
use crate::util::send_eth_transaction::SendTransactionErrorRule;
4+
use crate::util::send_eth_transaction::UnderPriced;
5+
use crate::util::send_eth_transaction::VerifyRule;
6+
use alloy::providers::fillers::ChainIdFiller;
7+
use alloy::providers::fillers::FillProvider;
8+
use alloy::providers::fillers::GasFiller;
9+
use alloy::providers::fillers::JoinFill;
10+
use alloy::providers::fillers::NonceFiller;
11+
use alloy::providers::fillers::WalletFiller;
12+
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
13+
use alloy::signers::Signer as _;
14+
use alloy_network::Ethereum;
15+
use alloy_network::EthereumWallet;
16+
use alloy_primitives::Address;
17+
use alloy_transport::BoxTransport;
18+
use alloy_transport_ws::WsConnect;
19+
use anyhow::Context;
20+
use secure_signer::cryptography::secp256k1::Secp256k1;
21+
use secure_signer_eth::Signer;
22+
use secure_signer_loader::{identifiers::SignerIdentifier, Load};
123
use serde::{Deserialize, Serialize};
24+
use tracing::info;
225

326
#[derive(Debug, Serialize, Deserialize)]
4-
pub struct Config {}
27+
pub struct Config {
28+
/// The address of the MCR settlement contract.
29+
pub mcr_contract_address: String,
30+
/// The Ethereum RPC connection URL.
31+
pub rpc_url: String,
32+
/// The Ethereum WebSocket connection URL.
33+
pub ws_url: String,
34+
/// The Ethereum chain ID.
35+
pub chain_id: u64,
36+
/// The signer identifier.
37+
pub signer_identifier: SignerIdentifier,
38+
/// Whether to run in settlement admin mode.
39+
pub run_commitment_admin_mode: bool,
40+
/// The gas limit for transactions.
41+
pub gas_limit: u64,
42+
/// The number of retries for sending transactions.
43+
pub transaction_send_retries: u32,
44+
}
45+
46+
impl Config {
47+
/// Creates a new MCR client configuration.
48+
pub fn new(
49+
mcr_contract_address: String,
50+
rpc_url: String,
51+
ws_url: String,
52+
chain_id: u64,
53+
signer_identifier: SignerIdentifier,
54+
run_commitment_admin_mode: bool,
55+
gas_limit: u64,
56+
transaction_send_retries: u32,
57+
) -> Self {
58+
Config {
59+
mcr_contract_address,
60+
rpc_url,
61+
ws_url,
62+
chain_id,
63+
signer_identifier,
64+
run_commitment_admin_mode,
65+
gas_limit,
66+
transaction_send_retries,
67+
}
68+
}
69+
70+
/// Builds the MCR client.
71+
pub async fn build(
72+
self,
73+
) -> Result<
74+
Client<
75+
FillProvider<
76+
JoinFill<
77+
JoinFill<
78+
JoinFill<JoinFill<alloy::providers::Identity, GasFiller>, NonceFiller>,
79+
ChainIdFiller,
80+
>,
81+
WalletFiller<EthereumWallet>,
82+
>,
83+
RootProvider<BoxTransport>,
84+
BoxTransport,
85+
Ethereum,
86+
>,
87+
>,
88+
anyhow::Error,
89+
> {
90+
let signer_identifier: Box<dyn Load<Secp256k1> + Send> =
91+
Box::new(self.signer_identifier.clone());
92+
let signer_provider = signer_identifier.load().await?;
93+
let signer = Signer::try_new(signer_provider, Some(self.chain_id)).await?;
94+
95+
let signer_address = signer.address();
96+
info!("Signer address: {}", signer_address);
97+
let contract_address = self
98+
.mcr_contract_address
99+
.parse()
100+
.context("Failed to parse the contract address for the MCR settlement client")?;
101+
102+
// Build the rpc provider
103+
let rpc_provider = ProviderBuilder::new()
104+
.with_recommended_fillers()
105+
.wallet(EthereumWallet::from(signer))
106+
.on_builtin(&self.rpc_url)
107+
.await
108+
.context("Failed to create the RPC provider for the MCR settlement client")?;
109+
110+
let client = Self::build_with_provider(
111+
self.run_commitment_admin_mode,
112+
rpc_provider,
113+
self.ws_url,
114+
signer_address,
115+
contract_address,
116+
self.gas_limit,
117+
self.transaction_send_retries,
118+
)
119+
.await
120+
.context(
121+
"Failed to create the MCR settlement client with the RPC provider and contract address",
122+
)?;
123+
Ok(client)
124+
}
125+
126+
// Helper to build the MCR client with a custom provider.
127+
async fn build_with_provider<S, P>(
128+
run_commitment_admin_mode: bool,
129+
rpc_provider: P,
130+
ws_url: S,
131+
signer_address: Address,
132+
contract_address: Address,
133+
gas_limit: u64,
134+
send_transaction_retries: u32,
135+
) -> Result<Client<P>, anyhow::Error>
136+
where
137+
P: Provider + Clone,
138+
S: Into<String>,
139+
{
140+
let ws = WsConnect::new(ws_url);
141+
142+
let ws_provider = ProviderBuilder::new()
143+
.on_ws(ws)
144+
.await
145+
.context("Failed to create the WebSocket provider for the MCR settlement client")?;
146+
147+
let rule1: Box<dyn VerifyRule> = Box::new(SendTransactionErrorRule::<UnderPriced>::new());
148+
let rule2: Box<dyn VerifyRule> =
149+
Box::new(SendTransactionErrorRule::<InsufficentFunds>::new());
150+
let send_transaction_error_rules = vec![rule1, rule2];
151+
152+
Ok(Client {
153+
run_commitment_admin_mode,
154+
rpc_provider,
155+
ws_provider,
156+
signer_address,
157+
contract_address,
158+
send_transaction_error_rules,
159+
gas_limit,
160+
send_transaction_retries,
161+
})
162+
}
163+
}

protocol/mcr/dlu/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Deployed Logic Units (DLU)
2+
DLUs are units of logic that are not generally run within an independent process, but which must be deployed somewhere. Smart contracts are DLU.
3+
4+
In this directory, we include DLU and the means via which to deploy them to various environments.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "mcr-settlement-manager"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
authors = { workspace = true }
7+
repository = { workspace = true }
8+
homepage = { workspace = true }
9+
publish = { workspace = true }
10+
rust-version = { workspace = true }
11+
12+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
14+
[dependencies]
15+
mcr-protocol-client-core-util = { workspace = true }
16+
17+
anyhow = { workspace = true }
18+
async-stream = { workspace = true }
19+
async-trait = { workspace = true }
20+
futures = { workspace = true }
21+
tokio = { workspace = true }
22+
tokio-stream = { workspace = true }
23+
serde_json = { workspace = true }
24+
mcr-types = { workspace = true }
25+
mcr-config = { workspace = true }
26+
27+
[dev-dependencies]
28+
mcr-protocol-client-core-mock = { workspace = true }
29+
30+
[lints]
31+
workspace = true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# ANVIL_URL should either be a a default value or the one specified by the surrounding en
5+
ANVIL_URL=${ANVIL_URL:-http://127.0.0.1:8545}
6+
7+
# SCRIPT_PATH should be assumed to be relative to the ETH DLU
8+
SCRIPT_PATH=${SCRIPT_PATH:-"./contracts/script/DeployMCRDev.s.sol"}
9+
10+
# Validate that PRIVATE_KEY is set
11+
if [ -z "$PRIVATE_KEY" ]; then
12+
echo "Error: PRIVATE_KEY is not set."
13+
exit 1
14+
fi
15+
16+
# Now run the script to deploy the contracts
17+
forge script $SCRIPT_PATH --rpc-url $ANVIL_URL --private-key $PRIVATE_KEY
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod artifacts;
2+
pub mod config;

0 commit comments

Comments
 (0)