Skip to content

Commit b257ed6

Browse files
committed
working end to end
1 parent c215245 commit b257ed6

34 files changed

+2374
-1149
lines changed

Cargo.lock

Lines changed: 25 additions & 1 deletion
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
aide = { version = "0.14.2", features = ["axum"] }
87
alloy = { version = "1.0.8", features = ["serde", "json-rpc"] }
98
schemars = "0.8.22"
10-
serde = "1.0.219"
9+
serde = { version = "1.0.219", features = ["derive"] }
1110
serde_json = "1.0.140"
1211
thiserror = "2.0.12"
1312
vault-types = { version = "0.1.0", git = "ssh://git@github.com/thirdweb-dev/vault.git", branch = "main" }

core/src/defs.rs

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

@@ -7,3 +7,14 @@ use serde::{Deserialize, Serialize};
77
/// # 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);
10+
11+
#[derive(JsonSchema, Serialize, Deserialize, Clone)]
12+
#[serde(remote = "Bytes", transparent)]
13+
/// # Bytes
14+
/// Used to represent "bytes". This is a 0x prefixed hex string.
15+
pub struct BytesDef(pub String);
16+
17+
#[derive(JsonSchema, Serialize, Deserialize, Clone)]
18+
/// # U256
19+
/// Used to represent a 256-bit unsigned integer. Engine can parse these from any valid encoding of the Ethereum "quantity" format.
20+
pub struct U256Def(pub String);

core/src/error.rs

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
use crate::defs::AddressDef;
12
use alloy::{
23
primitives::Address,
34
transports::{
45
RpcError as AlloyRpcError, TransportErrorKind, http::reqwest::header::InvalidHeaderValue,
56
},
67
};
8+
use schemars::JsonSchema;
79
use serde::{Deserialize, Serialize};
810
use thirdweb_core::error::ThirdwebError;
911
use thiserror::Error;
1012
use twmq::error::TwmqError;
1113

1214
use crate::chain::Chain;
1315

14-
#[derive(Debug, Error, Clone, Serialize, Deserialize)]
16+
#[derive(Debug, Error, Clone, Serialize, Deserialize, JsonSchema)]
1517
pub enum RpcErrorKind {
1618
/// Server returned an error response.
1719
#[error("server returned an error response: {0}")]
@@ -56,7 +58,7 @@ pub enum RpcErrorKind {
5658
OtherTransportError(String),
5759
}
5860

59-
#[derive(Debug, Serialize, Deserialize, Clone)]
61+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
6062
pub struct RpcErrorResponse {
6163
/// The error code.
6264
pub code: i64,
@@ -80,7 +82,7 @@ impl RpcErrorResponse {
8082
}
8183
}
8284

83-
#[derive(Debug, Serialize, Deserialize)]
85+
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
8486
pub struct RpcErrorInfo {
8587
/// The chain ID where the error occurred
8688
pub chain_id: u64,
@@ -97,7 +99,7 @@ pub struct RpcErrorInfo {
9799
}
98100

99101
/// A serializable contract interaction error type
100-
#[derive(Debug, Error, Serialize, Deserialize, Clone)]
102+
#[derive(Debug, Error, Serialize, Deserialize, Clone, JsonSchema)]
101103
pub enum ContractInteractionErrorKind {
102104
/// Unknown function referenced.
103105
#[error("unknown function: function {0} does not exist")]
@@ -135,9 +137,29 @@ pub enum ContractInteractionErrorKind {
135137
/// An error occured while waiting for a pending transaction.
136138
#[error("pending transaction error: {0}")]
137139
PendingTransactionError(String),
140+
141+
/// Error during contract function preparation (ABI resolution, parameter encoding)
142+
#[error("contract preparation failed: {0}")]
143+
PreparationFailed(String),
144+
145+
/// Error during multicall execution
146+
#[error("multicall execution failed: {0}")]
147+
MulticallExecutionFailed(String),
148+
149+
/// Error during result decoding
150+
#[error("result decoding failed: {0}")]
151+
ResultDecodingFailed(String),
152+
153+
/// Parameter validation error
154+
#[error("parameter validation failed: {0}")]
155+
ParameterValidationFailed(String),
156+
157+
/// Function resolution error
158+
#[error("function resolution failed: {0}")]
159+
FunctionResolutionFailed(String),
138160
}
139161

140-
#[derive(Error, Debug, Serialize, Clone, Deserialize)]
162+
#[derive(Error, Debug, Serialize, Clone, Deserialize, JsonSchema)]
141163
pub enum EngineError {
142164
#[error("RPC error on chain {chain_id} at {rpc_url}: {message}")]
143165
RpcError {
@@ -175,6 +197,7 @@ pub enum EngineError {
175197
#[error("Contract interaction error: {message}")]
176198
ContractInteractionError {
177199
/// Contract address
200+
#[schemars(with = "Option<AddressDef>")]
178201
contract_address: Option<Address>,
179202
/// Chain ID
180203
chain_id: u64,
@@ -202,6 +225,43 @@ impl From<InvalidHeaderValue> for EngineError {
202225
}
203226
}
204227

228+
impl EngineError {
229+
pub fn contract_preparation_error(
230+
contract_address: Option<Address>,
231+
chain_id: u64,
232+
message: String,
233+
) -> Self {
234+
EngineError::ContractInteractionError {
235+
contract_address,
236+
chain_id,
237+
message: message.clone(),
238+
kind: ContractInteractionErrorKind::PreparationFailed(message),
239+
}
240+
}
241+
242+
pub fn contract_multicall_error(chain_id: u64, message: String) -> Self {
243+
EngineError::ContractInteractionError {
244+
contract_address: None,
245+
chain_id,
246+
message: message.clone(),
247+
kind: ContractInteractionErrorKind::MulticallExecutionFailed(message),
248+
}
249+
}
250+
251+
pub fn contract_decoding_error(
252+
contract_address: Option<Address>,
253+
chain_id: u64,
254+
message: String,
255+
) -> Self {
256+
EngineError::ContractInteractionError {
257+
contract_address,
258+
chain_id,
259+
message: message.clone(),
260+
kind: ContractInteractionErrorKind::ResultDecodingFailed(message),
261+
}
262+
}
263+
}
264+
205265
pub trait AlloyRpcErrorToEngineError {
206266
fn to_engine_error(&self, chain: &impl Chain) -> EngineError;
207267
fn to_engine_bundler_error(&self, chain: &impl Chain) -> EngineError;

core/src/execution_options/aa.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,21 @@ pub fn default_account_salt() -> String {
9595
struct EntrypointAndFactoryDetailsDeserHelper {
9696
/// # Entrypoint Contract Address
9797
/// The address of the ERC-4337 entrypoint contract.
98+
///
9899
/// If omitted, defaults to the standard address for the specified/inferred version.
100+
///
99101
/// Known addresses:
102+
///
100103
/// - V0.6: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
104+
///
101105
/// - V0.7: 0x0000000071727De22E5E9d8BAf0edAc6f37da032
102106
#[serde(rename = "entrypointAddress")]
103-
#[schemars(with = "AddressDef")]
107+
#[schemars(with = "Option<AddressDef>")]
104108
entrypoint_address: Option<Address>,
105109

106110
/// # Entrypoint Version
107111
/// The version of the ERC-4337 standard to use.
112+
///
108113
/// If omitted, the version will be inferred from the entrypoint address,
109114
/// then from factory address, or defaults to V0.7.
110115
#[serde(rename = "entrypointVersion")]
@@ -113,11 +118,14 @@ struct EntrypointAndFactoryDetailsDeserHelper {
113118
/// # Account Factory Address
114119
/// The address of the smart account factory contract.
115120
/// If omitted, defaults to the thirweb default account factory for the specified/inferred version.
121+
///
116122
/// Known addresses:
123+
///
117124
/// - V0.6: 0x85e23b94e7F5E9cC1fF78BCe78cfb15B81f0DF00
125+
///
118126
/// - V0.7: 0x4bE0ddfebcA9A5A4a617dee4DeCe99E7c862dceb
119127
#[serde(rename = "factoryAddress")]
120-
#[schemars(with = "AddressDef")]
128+
#[schemars(with = "Option<AddressDef>")]
121129
factory_address: Option<Address>,
122130
}
123131

0 commit comments

Comments
 (0)