|
1 | | -use alloy::{ |
2 | | - hex::FromHex, |
3 | | - primitives::{Address, Bytes, U256}, |
4 | | -}; |
| 1 | +use alloy::primitives::{Address, Bytes, U256}; |
5 | 2 | use engine_aa_core::{ |
6 | 3 | account_factory::{AccountFactory, get_account_factory}, |
7 | 4 | smart_account::{DeterminedSmartAccount, SmartAccount, SmartAccountFromSalt}, |
@@ -54,6 +51,10 @@ pub struct ExternalBundlerSendJobData { |
54 | 51 | pub webhook_options: Option<Vec<WebhookOptions>>, |
55 | 52 |
|
56 | 53 | pub rpc_credentials: RpcCredentials, |
| 54 | + |
| 55 | + /// Pregenerated nonce for vault signed tokens |
| 56 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 57 | + pub pregenerated_nonce: Option<U256>, |
57 | 58 | } |
58 | 59 |
|
59 | 60 | impl HasWebhookOptions for ExternalBundlerSendJobData { |
@@ -262,21 +263,12 @@ where |
262 | 263 |
|
263 | 264 | let chain = chain.with_new_default_headers(chain_auth_headers); |
264 | 265 |
|
265 | | - // 2. Parse Account Salt |
266 | | - let salt_data = if job_data.execution_options.account_salt.starts_with("0x") { |
267 | | - Bytes::from_hex(job_data.execution_options.account_salt.clone()) |
268 | | - .map_err(|e| ExternalBundlerSendError::InvalidAccountSalt { |
269 | | - message: format!("Failed to parse hex salt: {}", e), |
270 | | - }) |
271 | | - .map_err_fail()? |
272 | | - } else { |
273 | | - let hex_string = hex::encode(job_data.execution_options.account_salt.clone()); |
274 | | - Bytes::from_hex(hex_string) |
| 266 | + // 2. Parse Account Salt using the helper method |
| 267 | + let salt_data = job_data.execution_options.get_salt_data() |
275 | 268 | .map_err(|e| ExternalBundlerSendError::InvalidAccountSalt { |
276 | | - message: format!("Failed to encode salt as hex: {}", e), |
| 269 | + message: e.to_string(), |
277 | 270 | }) |
278 | | - .map_err_fail()? |
279 | | - }; |
| 271 | + .map_err_fail()?; |
280 | 272 |
|
281 | 273 | // 3. Determine Smart Account |
282 | 274 | let smart_account = match job_data.execution_options.smart_account_address { |
@@ -363,15 +355,15 @@ where |
363 | 355 |
|
364 | 356 | tracing::debug!(lock_acquired = ?needs_init_code); |
365 | 357 |
|
366 | | - // 5. Get Nonce |
367 | | - let nonce = { |
| 358 | + // 5. Get Nonce - use pregenerated nonce if available, otherwise generate random |
| 359 | + let nonce = job_data.pregenerated_nonce.unwrap_or_else(|| { |
368 | 360 | use rand::Rng; |
369 | 361 | let mut rng = rand::rng(); |
370 | 362 | let limb1: u64 = rng.random(); |
371 | 363 | let limb2: u64 = rng.random(); |
372 | 364 | let limb3: u64 = rng.random(); |
373 | 365 | U256::from_limbs([0, limb1, limb2, limb3]) |
374 | | - }; |
| 366 | + }); |
375 | 367 |
|
376 | 368 | // 6. Prepare Init Call Data |
377 | 369 | let init_call_data = get_account_factory( |
|
0 commit comments