Skip to content

Commit 8573afb

Browse files
committed
restructuring crates
1 parent 1d1dc4d commit 8573afb

File tree

16 files changed

+194
-109
lines changed

16 files changed

+194
-109
lines changed

Cargo.lock

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
2-
members = ["aa-core", "core", "executors", "server", "thirdweb-core", "twmq", "types-core"]
2+
members = ["aa-types", "aa-core", "core", "executors", "server", "thirdweb-core", "twmq"]
33
resolver = "2"

aa-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ edition = "2024"
66
[dependencies]
77
alloy = { version = "1.0.8", features = ["serde"] }
88
tokio = "1.44.2"
9+
engine-aa-types = { path = "../aa-types" }
910
engine-core = { path = "../core" }
10-
thirdweb-core = { path = "../thirdweb-core" }
1111
vault-types = { version = "0.1.0", git = "ssh://git@github.com/thirdweb-dev/vault.git", branch = "main" }
1212
vault-sdk = { version = "0.1.0", git = "ssh://git@github.com/thirdweb-dev/vault.git", branch = "main" }
1313
serde = "1.0.219"

aa-core/src/userop/builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use alloy::{
66
providers::Provider,
77
rpc::types::{PackedUserOperation, UserOperation},
88
};
9+
use engine_aa_types::VersionedUserOp;
910
use engine_core::{
1011
chain::Chain,
1112
credentials::SigningCredential,
1213
error::{AlloyRpcErrorToEngineError, EngineError},
1314
execution_options::aa::{EntrypointAndFactoryDetails, EntrypointVersion},
1415
userop::{UserOpSigner, UserOpSignerParams},
1516
};
16-
use thirdweb_core::iaw::UserOpVersion;
1717

1818
pub struct UserOpBuilderConfig<'a, C: Chain> {
1919
pub account_address: Address,
@@ -41,7 +41,7 @@ impl<'a, C: Chain> UserOpBuilder<'a, C> {
4141
Self { config }
4242
}
4343

44-
pub async fn build(self) -> Result<UserOpVersion, EngineError> {
44+
pub async fn build(self) -> Result<VersionedUserOp, EngineError> {
4545
let mut userop = match self.config.entrypoint_and_factory.version {
4646
EntrypointVersion::V0_6 => UserOpBuilderV0_6::new(&self.config).build().await?,
4747
EntrypointVersion::V0_7 => UserOpBuilderV0_7::new(&self.config).build().await?,
@@ -62,10 +62,10 @@ impl<'a, C: Chain> UserOpBuilder<'a, C> {
6262
.await?;
6363

6464
match &mut userop {
65-
UserOpVersion::V0_6(userop) => {
65+
VersionedUserOp::V0_6(userop) => {
6666
userop.signature = signature;
6767
}
68-
UserOpVersion::V0_7(userop) => {
68+
VersionedUserOp::V0_7(userop) => {
6969
userop.signature = signature;
7070
}
7171
}
@@ -115,7 +115,7 @@ impl<'a, C: Chain> UserOpBuilderV0_6<'a, C> {
115115
}
116116
}
117117

118-
async fn build(mut self) -> Result<UserOpVersion, EngineError> {
118+
async fn build(mut self) -> Result<VersionedUserOp, EngineError> {
119119
let prices = self
120120
.chain
121121
.provider()
@@ -154,7 +154,7 @@ impl<'a, C: Chain> UserOpBuilderV0_6<'a, C> {
154154
.chain
155155
.bundler_client()
156156
.estimate_user_op_gas(
157-
&UserOpVersion::V0_6(self.userop.clone()),
157+
&VersionedUserOp::V0_6(self.userop.clone()),
158158
self.entrypoint,
159159
None,
160160
)
@@ -173,7 +173,7 @@ impl<'a, C: Chain> UserOpBuilderV0_6<'a, C> {
173173
self.userop.verification_gas_limit = verification_gas_limit;
174174
self.userop.pre_verification_gas = pre_verification_gas;
175175

176-
Ok(UserOpVersion::V0_6(self.userop))
176+
Ok(VersionedUserOp::V0_6(self.userop))
177177
}
178178
}
179179

@@ -220,7 +220,7 @@ impl<'a, C: Chain> UserOpBuilderV0_7<'a, C> {
220220
}
221221
}
222222

223-
async fn build(mut self) -> Result<UserOpVersion, EngineError> {
223+
async fn build(mut self) -> Result<VersionedUserOp, EngineError> {
224224
// Get gas prices, same as v0.6
225225
let prices = self
226226
.chain
@@ -273,7 +273,7 @@ impl<'a, C: Chain> UserOpBuilderV0_7<'a, C> {
273273
.chain
274274
.bundler_client()
275275
.estimate_user_op_gas(
276-
&UserOpVersion::V0_7(self.userop.clone()),
276+
&VersionedUserOp::V0_7(self.userop.clone()),
277277
self.entrypoint,
278278
None,
279279
)
@@ -301,6 +301,6 @@ impl<'a, C: Chain> UserOpBuilderV0_7<'a, C> {
301301
self.userop.paymaster_verification_gas_limit = Some(paymaster_verification_gas_limit);
302302
self.userop.paymaster_post_op_gas_limit = Some(paymaster_post_op_gas_limit);
303303

304-
Ok(UserOpVersion::V0_7(self.userop))
304+
Ok(VersionedUserOp::V0_7(self.userop))
305305
}
306306
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[package]
2-
name = "types-core"
2+
name = "engine-aa-types"
33
version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
77
alloy = { version = "1.0.8", features = ["serde"] }
88
serde = { version = "1.0.219", features = ["derive"] }
9-
serde_json = "1.0.140"
9+
serde_json = "1.0.140"
10+
thiserror = "2.0.12"
11+
schemars = "0.8.22"
12+
utoipa = "5.4.0"

aa-types/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod userop;
2+
3+
pub use userop::*;

thirdweb-core/src/iaw/userop.rs renamed to aa-types/src/userop.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@ use alloy::{
33
primitives::{keccak256, Address, ChainId, Bytes, U256, B256},
44
rpc::types::{PackedUserOperation, UserOperation},
55
};
6+
use serde::{Deserialize, Serialize};
7+
8+
/// UserOp version enum
9+
#[derive(Debug, Clone, Serialize, Deserialize)]
10+
#[serde(untagged)]
11+
pub enum VersionedUserOp {
12+
V0_6(UserOperation),
13+
V0_7(PackedUserOperation),
14+
}
615

7-
use super::IAWError;
16+
/// Error type for UserOp operations
17+
#[derive(Debug, Clone, thiserror::Error, serde::Serialize, serde::Deserialize, schemars::JsonSchema, utoipa::ToSchema)]
18+
#[serde(tag = "type", rename_all = "SCREAMING_SNAKE_CASE")]
19+
pub enum UserOpError {
20+
#[error("Unexpected error: {0}")]
21+
UnexpectedError(String),
22+
}
823

924
/// Compute UserOperation v0.6 hash
1025
pub fn compute_user_op_v06_hash(
1126
op: &UserOperation,
1227
entrypoint: Address,
1328
chain_id: ChainId,
14-
) -> Result<B256, IAWError> {
29+
) -> Result<B256, UserOpError> {
1530
// Hash the byte fields first
1631
let init_code_hash = keccak256(&op.init_code);
1732
let call_data_hash = keccak256(&op.call_data);
@@ -49,7 +64,7 @@ pub fn compute_user_op_v07_hash(
4964
op: &PackedUserOperation,
5065
entrypoint: Address,
5166
chain_id: ChainId,
52-
) -> Result<B256, IAWError> {
67+
) -> Result<B256, UserOpError> {
5368
// Construct initCode from factory and factoryData
5469
let init_code: Bytes = if let Some(factory) = op.factory {
5570
if factory != Address::ZERO {
@@ -63,10 +78,10 @@ pub fn compute_user_op_v07_hash(
6378

6479
// Construct accountGasLimits
6580
let vgl_u128: u128 = op.verification_gas_limit.try_into().map_err(|_| {
66-
IAWError::UnexpectedError("verification_gas_limit too large".to_string())
81+
UserOpError::UnexpectedError("verification_gas_limit too large".to_string())
6782
})?;
6883
let cgl_u128: u128 = op.call_gas_limit.try_into().map_err(|_| {
69-
IAWError::UnexpectedError("call_gas_limit too large".to_string())
84+
UserOpError::UnexpectedError("call_gas_limit too large".to_string())
7085
})?;
7186

7287
let mut account_gas_limits_bytes = [0u8; 32];
@@ -76,10 +91,10 @@ pub fn compute_user_op_v07_hash(
7691

7792
// Construct gasFees
7893
let mpfpg_u128: u128 = op.max_priority_fee_per_gas.try_into().map_err(|_| {
79-
IAWError::UnexpectedError("max_priority_fee_per_gas too large".to_string())
94+
UserOpError::UnexpectedError("max_priority_fee_per_gas too large".to_string())
8095
})?;
8196
let mfpg_u128: u128 = op.max_fee_per_gas.try_into().map_err(|_| {
82-
IAWError::UnexpectedError("max_fee_per_gas too large".to_string())
97+
UserOpError::UnexpectedError("max_fee_per_gas too large".to_string())
8398
})?;
8499

85100
let mut gas_fees_bytes = [0u8; 32];
@@ -91,10 +106,10 @@ pub fn compute_user_op_v07_hash(
91106
let paymaster_and_data: Bytes = if let Some(paymaster) = op.paymaster {
92107
if paymaster != Address::ZERO {
93108
let pm_vgl_u128: u128 = op.paymaster_verification_gas_limit.unwrap_or_default().try_into().map_err(|_| {
94-
IAWError::UnexpectedError("paymaster_verification_gas_limit too large".to_string())
109+
UserOpError::UnexpectedError("paymaster_verification_gas_limit too large".to_string())
95110
})?;
96111
let pm_pogl_u128: u128 = op.paymaster_post_op_gas_limit.unwrap_or_default().try_into().map_err(|_| {
97-
IAWError::UnexpectedError("paymaster_post_op_gas_limit too large".to_string())
112+
UserOpError::UnexpectedError("paymaster_post_op_gas_limit too large".to_string())
98113
})?;
99114
[
100115
&paymaster[..],
@@ -139,4 +154,4 @@ pub fn compute_user_op_v07_hash(
139154
let outer_encoded = outer_tuple.abi_encode();
140155
let final_hash = keccak256(&outer_encoded);
141156
Ok(final_hash)
142-
}
157+
}

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
alloy = { version = "1.0.8", features = ["serde", "json-rpc"] }
8+
engine-aa-types = { path = "../aa-types" }
89
schemars = "0.8.22"
910
serde = { version = "1.0.219", features = ["derive"] }
1011
serde_json = "1.0.140"
@@ -16,7 +17,6 @@ tracing = "0.1.41"
1617
async-nats = "0.40.0"
1718
twmq = { version = "0.1.0", path = "../twmq" }
1819
thirdweb-core = { version = "0.1.0", path = "../thirdweb-core" }
19-
types-core = { path = "../types-core" }
2020
uuid = { version = "1.17.0", features = ["v4"] }
2121
utoipa = { version = "5.4.0", features = ["preserve_order"] }
2222
serde_with = "3.13.0"

core/src/error.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ pub enum EngineError {
208208
VaultError { message: String },
209209

210210
#[schema(title = "Engine IAW Service Error")]
211-
#[error("Error interaction with IAW service: {message}")]
211+
#[error("Error interaction with IAW service: {error}")]
212212
#[serde(rename_all = "camelCase")]
213-
IawError { message: String },
213+
IawError {
214+
#[from]
215+
error: thirdweb_core::iaw::IAWError,
216+
},
214217

215218
#[schema(title = "RPC Configuration Error")]
216219
#[error("Bad RPC configuration: {message}")]
@@ -463,10 +466,3 @@ impl From<TwmqError> for EngineError {
463466
}
464467
}
465468

466-
impl From<thirdweb_core::iaw::IAWError> for EngineError {
467-
fn from(error: thirdweb_core::iaw::IAWError) -> Self {
468-
EngineError::IawError {
469-
message: error.to_string(),
470-
}
471-
}
472-
}

core/src/rpc_clients/bundler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy::transports::{IntoBoxTransport, TransportResult};
66
use serde::{Deserialize, Serialize};
77
use std::collections::HashMap;
88

9-
use types_core::UserOpVersion;
9+
use crate::userop::VersionedUserOp;
1010

1111
// Gas buffer added for managed account factories (matches TypeScript)
1212
pub const MANAGED_ACCOUNT_GAS_BUFFER: U256 = U256::from_limbs([21_000, 0, 0, 0]);
@@ -81,7 +81,7 @@ impl BundlerClient {
8181
/// Estimate the gas for a user operation
8282
pub async fn estimate_user_op_gas(
8383
&self,
84-
user_op: &UserOpVersion,
84+
user_op: &VersionedUserOp,
8585
entrypoint: Address,
8686
state_overrides: Option<HashMap<String, HashMap<String, String>>>,
8787
) -> TransportResult<UseropGasEstimation> {
@@ -104,7 +104,7 @@ impl BundlerClient {
104104

105105
pub async fn send_user_op(
106106
&self,
107-
user_op: &UserOpVersion,
107+
user_op: &VersionedUserOp,
108108
entrypoint: Address,
109109
) -> TransportResult<Bytes> {
110110
let result: Bytes = self

0 commit comments

Comments
 (0)