Skip to content

Commit 07451e6

Browse files
committed
refactor: migrate to init4-bin-base
1 parent 330a35a commit 07451e6

File tree

12 files changed

+46
-314
lines changed

12 files changed

+46
-314
lines changed

Cargo.toml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path = "bin/submit_transaction.rs"
2525
integration = []
2626

2727
[dependencies]
28-
init4-bin-base = "0.3"
28+
init4-bin-base = { version = "0.3.4", features = ["perms"] }
2929

3030
signet-bundle = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
3131
signet-constants = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
@@ -46,24 +46,20 @@ alloy = { version = "0.12.6", features = [
4646
"serde",
4747
] }
4848

49-
aws-config = "1.1.7"
50-
aws-sdk-kms = "1.15.0"
51-
52-
hex = { package = "const-hex", version = "1", default-features = false, features = [
53-
"alloc",
54-
] }
55-
5649
serde = { version = "1.0.197", features = ["derive"] }
5750

5851
axum = "0.7.5"
5952
eyre = "0.6.12"
6053
openssl = { version = "0.10", features = ["vendored"] }
6154
reqwest = { version = "0.11.24", features = ["blocking", "json"] }
6255
serde_json = "1.0"
63-
thiserror = "1.0.68"
6456
tokio = { version = "1.36.0", features = ["full", "macros", "rt-multi-thread"] }
6557

66-
async-trait = "0.1.80"
67-
oauth2 = "4.4.2"
58+
oauth2 = "5"
6859
chrono = "0.4.41"
6960
tokio-stream = "0.1.17"
61+
url = "2.5.4"
62+
63+
64+
[patch.crates-io]
65+
init4-bin-base = { path = "../shared" }

bin/submit_transaction.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use alloy::{
33
primitives::{Address, U256},
44
providers::{Provider as _, ProviderBuilder, WalletProvider},
55
rpc::types::eth::TransactionRequest,
6-
signers::aws::AwsSigner,
76
};
87
use builder::config::HostProvider;
98
use init4_bin_base::{
@@ -12,7 +11,7 @@ use init4_bin_base::{
1211
tracing,
1312
},
1413
init4,
15-
utils::from_env::FromEnv,
14+
utils::{from_env::FromEnv, signer::LocalOrAwsConfig},
1615
};
1716
use std::time::{Duration, Instant};
1817
use tokio::time::timeout;
@@ -21,10 +20,7 @@ use tokio::time::timeout;
2120
struct Config {
2221
#[from_env(var = "RPC_URL", desc = "Ethereum RPC URL")]
2322
rpc_url: String,
24-
#[from_env(var = "CHAIN_ID", desc = "Ethereum chain ID")]
25-
chain_id: u64,
26-
#[from_env(var = "AWS_KMS_KEY_ID", desc = "AWS KMS key ID")]
27-
kms_key_id: String,
23+
kms_key_id: LocalOrAwsConfig,
2824
#[from_env(var = "RECIPIENT_ADDRESS", desc = "Recipient address")]
2925
recipient_address: Address,
3026
#[from_env(var = "SLEEP_TIME", desc = "Time to sleep between transactions")]
@@ -33,10 +29,7 @@ struct Config {
3329

3430
impl Config {
3531
async fn provider(&self) -> HostProvider {
36-
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
37-
let client = aws_sdk_kms::Client::new(&config);
38-
let signer =
39-
AwsSigner::new(client, self.kms_key_id.clone(), Some(self.chain_id)).await.unwrap();
32+
let signer = self.kms_key_id.connect_remote().await.unwrap();
4033

4134
ProviderBuilder::new()
4235
.wallet(EthereumWallet::from(signer))

src/config.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use crate::{
2-
quincey::Quincey,
3-
signer::{LocalOrAws, SignerError},
4-
tasks::oauth::{Authenticator, SharedToken},
5-
};
1+
use crate::quincey::Quincey;
62
use alloy::{
73
network::{Ethereum, EthereumWallet},
84
primitives::Address,
@@ -15,8 +11,14 @@ use alloy::{
1511
},
1612
};
1713
use eyre::Result;
18-
use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv};
19-
use oauth2::url;
14+
use init4_bin_base::{
15+
perms::{Authenticator, OAuthConfig, SharedToken},
16+
utils::{
17+
calc::SlotCalculator,
18+
from_env::FromEnv,
19+
signer::{LocalOrAws, SignerError},
20+
},
21+
};
2022
use signet_zenith::Zenith;
2123
use std::borrow::Cow;
2224

@@ -41,7 +43,7 @@ pub type HostProvider = FillProvider<
4143

4244
/// Configuration for a builder running a specific rollup on a specific host
4345
/// chain.
44-
#[derive(serde::Deserialize, Debug, Clone, FromEnv)]
46+
#[derive(Debug, Clone, FromEnv)]
4547
pub struct BuilderConfig {
4648
/// The chain ID of the host chain
4749
#[from_env(var = "HOST_CHAIN_ID", desc = "The chain ID of the host chain")]
@@ -129,30 +131,10 @@ pub struct BuilderConfig {
129131
desc = "Duration in seconds transactions can live in the tx-pool cache"
130132
)]
131133
pub tx_pool_cache_duration: u64,
132-
/// OAuth client ID for the builder.
133-
#[from_env(var = "OAUTH_CLIENT_ID", desc = "OAuth client ID for the builder")]
134-
pub oauth_client_id: String,
135-
/// OAuth client secret for the builder.
136-
#[from_env(var = "OAUTH_CLIENT_SECRET", desc = "OAuth client secret for the builder")]
137-
pub oauth_client_secret: String,
138-
/// OAuth authenticate URL for the builder for performing OAuth logins.
139-
#[from_env(
140-
var = "OAUTH_AUTHENTICATE_URL",
141-
desc = "OAuth authenticate URL for the builder for performing OAuth logins"
142-
)]
143-
pub oauth_authenticate_url: String,
144-
/// OAuth token URL for the builder to get an OAuth2 access token
145-
#[from_env(
146-
var = "OAUTH_TOKEN_URL",
147-
desc = "OAuth token URL for the builder to get an OAuth2 access token"
148-
)]
149-
pub oauth_token_url: String,
150-
/// The oauth token refresh interval in seconds.
151-
#[from_env(
152-
var = "AUTH_TOKEN_REFRESH_INTERVAL",
153-
desc = "The oauth token refresh interval in seconds"
154-
)]
155-
pub oauth_token_refresh_interval: u64,
134+
135+
/// Oauth2 configuration for the builder to connect to ini4 services.
136+
pub oauth: OAuthConfig,
137+
156138
/// The max number of simultaneous block simulations to run.
157139
#[from_env(
158140
var = "CONCURRENCY_LIMIT",
@@ -220,7 +202,7 @@ impl BuilderConfig {
220202
static ONCE: std::sync::OnceLock<SharedToken> = std::sync::OnceLock::new();
221203

222204
ONCE.get_or_init(|| {
223-
let authenticator = Authenticator::new(self).unwrap();
205+
let authenticator = Authenticator::new(&self.oauth);
224206
let token = authenticator.token();
225207
authenticator.spawn();
226208
token

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ pub mod quincey;
2121
/// Implements the `/healthcheck` endpoint.
2222
pub mod service;
2323

24-
/// Builder transaction signer.
25-
pub mod signer;
26-
2724
/// Actor-based tasks used to construct a builder.
2825
pub mod tasks;
2926

src/quincey.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use crate::{signer::LocalOrAws, tasks::oauth::SharedToken};
21
use alloy::signers::Signer;
32
use eyre::bail;
4-
use init4_bin_base::deps::tracing::{self, debug, info, instrument, trace};
3+
use init4_bin_base::{
4+
deps::tracing::{self, debug, info, instrument, trace},
5+
perms::SharedToken,
6+
utils::signer::LocalOrAws,
7+
};
58
use oauth2::TokenResponse;
69
use reqwest::Client;
710
use signet_types::{SignRequest, SignResponse};

src/signer.rs

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/tasks/cache/bundle.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Bundler service responsible for fetching bundles and sending them to the simulator.
2-
use crate::{config::BuilderConfig, tasks::oauth::SharedToken};
3-
use init4_bin_base::deps::tracing::{Instrument, debug, debug_span, error, trace, warn};
2+
use crate::config::BuilderConfig;
3+
use init4_bin_base::{
4+
deps::tracing::{Instrument, debug, debug_span, error, trace, warn},
5+
perms::SharedToken,
6+
};
47
use oauth2::TokenResponse;
58
use reqwest::{Client, Url};
69
use serde::{Deserialize, Serialize};

src/tasks/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ pub mod cache;
77
/// Tx submission metric task
88
pub mod metrics;
99

10-
/// OAuth token refresh task
11-
pub mod oauth;
12-
1310
/// Tx submission task
1411
pub mod submit;
1512

0 commit comments

Comments
 (0)