Skip to content

Commit 332f726

Browse files
committed
setup utoipa foundations
1 parent 59191b2 commit 332f726

File tree

23 files changed

+436
-612
lines changed

23 files changed

+436
-612
lines changed

Cargo.lock

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

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ async-nats = "0.40.0"
1717
twmq = { version = "0.1.0", path = "../twmq" }
1818
thirdweb-core = { version = "0.1.0", path = "../thirdweb-core" }
1919
uuid = { version = "1.17.0", features = ["v4"] }
20+
utoipa = "5.4.0"

core/src/defs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use alloy::primitives::{Address, Bytes};
22
use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
44

5-
#[derive(JsonSchema, Serialize, Deserialize, Clone)]
5+
#[derive(JsonSchema, Serialize, Deserialize, Clone, utoipa::ToSchema)]
66
#[serde(remote = "Address", transparent)]
7-
/// # Address
7+
/// ### Address
88
/// Used to represent an EVM address. This is a string of length 42 with a `0x` prefix. Non-checksummed addresses are also supported, but will be converted to checksummed.
99
pub struct AddressDef(pub String);
1010

11-
#[derive(JsonSchema, Serialize, Deserialize, Clone)]
11+
#[derive(JsonSchema, Serialize, Deserialize, Clone, utoipa::ToSchema)]
1212
#[serde(remote = "Bytes", transparent)]
1313
/// # Bytes
1414
/// Used to represent "bytes". This is a 0x prefixed hex string.
1515
pub struct BytesDef(pub String);
1616

17-
#[derive(JsonSchema, Serialize, Deserialize, Clone)]
17+
#[derive(JsonSchema, Serialize, Deserialize, Clone, utoipa::ToSchema)]
1818
/// # U256
1919
/// Used to represent a 256-bit unsigned integer. Engine can parse these from any valid encoding of the Ethereum "quantity" format.
2020
pub struct U256Def(pub String);

core/src/error.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use twmq::error::TwmqError;
1313

1414
use crate::chain::Chain;
1515

16-
#[derive(Debug, Error, Clone, Serialize, Deserialize, JsonSchema)]
16+
#[derive(Debug, Error, Clone, Serialize, Deserialize, JsonSchema, utoipa::ToSchema)]
1717
pub enum RpcErrorKind {
1818
/// Server returned an error response.
1919
#[error("server returned an error response: {0}")]
@@ -58,7 +58,7 @@ pub enum RpcErrorKind {
5858
OtherTransportError(String),
5959
}
6060

61-
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
61+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, utoipa::ToSchema)]
6262
pub struct RpcErrorResponse {
6363
/// The error code.
6464
pub code: i64,
@@ -99,7 +99,7 @@ pub struct RpcErrorInfo {
9999
}
100100

101101
/// A serializable contract interaction error type
102-
#[derive(Debug, Error, Serialize, Deserialize, Clone, JsonSchema)]
102+
#[derive(Debug, Error, Serialize, Deserialize, Clone, JsonSchema, utoipa::ToSchema)]
103103
pub enum ContractInteractionErrorKind {
104104
/// Unknown function referenced.
105105
#[error("unknown function: function {0} does not exist")]
@@ -159,7 +159,7 @@ pub enum ContractInteractionErrorKind {
159159
FunctionResolutionFailed(String),
160160
}
161161

162-
#[derive(Error, Debug, Serialize, Clone, Deserialize, JsonSchema)]
162+
#[derive(Error, Debug, Serialize, Clone, Deserialize, JsonSchema, utoipa::ToSchema)]
163163
pub enum EngineError {
164164
#[error("RPC error on chain {chain_id} at {rpc_url}: {message}")]
165165
RpcError {
@@ -198,6 +198,7 @@ pub enum EngineError {
198198
ContractInteractionError {
199199
/// Contract address
200200
#[schemars(with = "Option<AddressDef>")]
201+
#[schema(value_type = Option<AddressDef>)]
201202
contract_address: Option<Address>,
202203
/// Chain ID
203204
chain_id: u64,

core/src/execution_options/aa.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Deserializer, Serialize};
88

99
use crate::constants::{DEFAULT_FACTORY_ADDRESS_V0_7, ENTRYPOINT_ADDRESS_V0_7};
1010

11-
#[derive(Deserialize, Serialize, Debug, JsonSchema, Clone, Copy)]
11+
#[derive(Deserialize, Serialize, Debug, JsonSchema, Clone, Copy, utoipa::ToSchema)]
1212
pub enum EntrypointVersion {
1313
#[serde(rename = "0.6")]
1414
V0_6,
@@ -28,55 +28,58 @@ pub struct EntrypointAndFactoryDetails {
2828
pub factory_address: Address,
2929
}
3030

31-
/// # ERC-4337 Execution Options
31+
/// ### ERC-4337 Execution Options
3232
/// This struct allows flexible configuration of ERC-4337 execution options,
3333
/// with intelligent defaults and inferences based on provided values.
3434
///
35-
/// ## Field Inference
35+
/// ### Field Inference
3636
/// When fields are omitted, the system uses the following inference rules:
3737
///
38-
/// 1. **Version Inference**:
39-
/// - If `entrypointVersion` is provided, it's used directly
40-
/// - Otherwise, tries to infer from `entrypointAddress` (if provided)
41-
/// - If that fails, tries to infer from `factoryAddress` (if provided)
42-
/// - Defaults to version 0.7 if no inference is possible
38+
/// 1. Version Inference:
39+
/// - If `entrypointVersion` is provided, it's used directly
40+
/// - Otherwise, tries to infer from `entrypointAddress` (if provided)
41+
/// - If that fails, tries to infer from `factoryAddress` (if provided)
42+
/// - Defaults to version 0.7 if no inference is possible
4343
///
44-
/// 2. **Entrypoint Address Inference**:
44+
/// 2. Entrypoint Address Inference:
4545
/// - If provided explicitly, it's used as-is
4646
/// - Otherwise, uses the default address corresponding to the inferred version:
4747
/// - V0.6: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
4848
/// - V0.7: 0x0576a174D229E3cFA37253523E645A78A0C91B57
4949
///
50-
/// 3. **Factory Address Inference**:
50+
/// 3. Factory Address Inference:
5151
/// - If provided explicitly, it's used as-is
5252
/// - Otherwise, uses the default factory corresponding to the inferred version:
53-
/// - V0.6: [DEFAULT_FACTORY_ADDRESS_V0_6]
54-
/// - V0.7: [DEFAULT_FACTORY_ADDRESS_V0_7]
53+
/// - V0.6: 0x85e23b94e7F5E9cC1fF78BCe78cfb15B81f0DF00 [DEFAULT_FACTORY_ADDRESS_V0_6]
54+
/// - V0.7: 0x4bE0ddfebcA9A5A4a617dee4DeCe99E7c862dceb [DEFAULT_FACTORY_ADDRESS_V0_7]
5555
///
56-
/// 4. **Account Salt**:
56+
/// 4. Account Salt:
5757
/// - If provided explicitly, it's used as-is
5858
/// - Otherwise, defaults to "0x" (commonly used as the defauult "null" salt for smart accounts)
5959
///
60-
/// 5. **Smart Account Address**:
60+
/// 5. Smart Account Address:
6161
/// - If provided explicitly, it's used as-is
6262
/// - Otherwise, it's read from the smart account factory
6363
///
6464
/// All optional fields can be omitted for a minimal configuration using version 0.7 defaults.
65-
#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)]
65+
#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema, utoipa::ToSchema)]
6666
#[serde(rename_all = "camelCase")]
6767
pub struct Erc4337ExecutionOptions {
6868
#[schemars(with = "AddressDef")]
69+
#[schema(value_type = AddressDef)]
6970
pub signer_address: Address,
7071

7172
#[serde(flatten)]
7273
#[schemars(with = "EntrypointAndFactoryDetailsDeserHelper")]
74+
#[schema(value_type = EntrypointAndFactoryDetailsDeserHelper)]
7375
pub entrypoint_details: EntrypointAndFactoryDetails,
7476

7577
#[serde(default = "default_account_salt")]
7678
pub account_salt: String,
7779

7880
#[serde(skip_serializing_if = "Option::is_none")]
7981
#[schemars(with = "Option::<AddressDef>")]
82+
#[schema(value_type = Option<AddressDef>)]
8083
pub smart_account_address: Option<Address>,
8184
}
8285

@@ -91,41 +94,41 @@ pub fn default_entrypoint_address() -> Address {
9194
pub fn default_account_salt() -> String {
9295
"0x".to_string()
9396
}
94-
#[derive(Deserialize, JsonSchema)]
97+
#[derive(Deserialize, JsonSchema, utoipa::ToSchema)]
9598
struct EntrypointAndFactoryDetailsDeserHelper {
96-
/// # Entrypoint Contract Address
99+
/// ### Entrypoint Contract Address
97100
/// The address of the ERC-4337 entrypoint contract.
98101
///
99102
/// If omitted, defaults to the standard address for the specified/inferred version.
100103
///
101104
/// Known addresses:
102105
///
103106
/// - V0.6: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
104-
///
105107
/// - V0.7: 0x0000000071727De22E5E9d8BAf0edAc6f37da032
106108
#[serde(rename = "entrypointAddress")]
107109
#[schemars(with = "Option<AddressDef>")]
110+
#[schema(value_type = Option<AddressDef>)]
108111
entrypoint_address: Option<Address>,
109112

110-
/// # Entrypoint Version
113+
/// ### Entrypoint Version
111114
/// The version of the ERC-4337 standard to use.
112115
///
113116
/// If omitted, the version will be inferred from the entrypoint address,
114117
/// then from factory address, or defaults to V0.7.
115118
#[serde(rename = "entrypointVersion")]
116119
version: Option<EntrypointVersion>,
117120

118-
/// # Account Factory Address
121+
/// ### Account Factory Address
119122
/// The address of the smart account factory contract.
120123
/// If omitted, defaults to the thirweb default account factory for the specified/inferred version.
121124
///
122125
/// Known addresses:
123126
///
124127
/// - V0.6: 0x85e23b94e7F5E9cC1fF78BCe78cfb15B81f0DF00
125-
///
126128
/// - V0.7: 0x4bE0ddfebcA9A5A4a617dee4DeCe99E7c862dceb
127129
#[serde(rename = "factoryAddress")]
128130
#[schemars(with = "Option<AddressDef>")]
131+
#[schema(value_type = Option<AddressDef>)]
129132
factory_address: Option<Address>,
130133
}
131134

core/src/execution_options/auto.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, utoipa::ToSchema)]
5+
#[schema(title = "Auto Determine Execution")]
6+
#[serde(rename_all = "camelCase")]
7+
/// This is the default execution option.
8+
/// If you do not specify an execution type, and only specify a "from" string,
9+
/// engine will automatically determine the most optimal options for you.
10+
/// If you would like to specify granular options about execution strategy
11+
/// choose one of the other executionOptions type and provide them.
12+
pub struct AutoExecutionOptions {
13+
/// The identifier of the entity to send the transaction from.
14+
/// Automatically picks best execution strategy based on the identifier.
15+
/// - If EOA address, execution uses EIP7702 based smart-wallet execution
16+
/// - If 7702 not supported on chain, falls back to smart-contract wallet (ERC4337) with default smart account for this EOA (v0.7)
17+
/// - UNLESS this is a zk-chain, in which case, zk-sync native-aa is used
18+
pub from: String,
19+
}

0 commit comments

Comments
 (0)