diff --git a/crates/common/types/transaction.rs b/crates/common/types/transaction.rs index cdc7a9a0a5c..7c26c0f9f55 100644 --- a/crates/common/types/transaction.rs +++ b/crates/common/types/transaction.rs @@ -2454,8 +2454,8 @@ mod serde_impl { InvalidTxType(TxType), #[error("Blob bundle error: {0}")] BlobBundleError(#[from] BlobsBundleError), - #[error("Missing fee token address")] - MissingFeeToken, + #[error("Missing field: {0}")] + MissingField(String), } /// Unsigned Transaction struct generic to all types which may not contain all required transaction fields @@ -2710,6 +2710,41 @@ mod serde_impl { } } + impl TryFrom for EIP7702Transaction { + type Error = GenericTransactionError; + + fn try_from(value: GenericTransaction) -> Result { + if value.r#type != TxType::EIP7702 { + return Err(GenericTransactionError::InvalidTxType(value.r#type)); + } + let TxKind::Call(to) = value.to else { + return Err(GenericTransactionError::MissingField("to".to_owned())); + }; + Ok(Self { + chain_id: value.chain_id.unwrap_or_default(), + nonce: value.nonce.unwrap_or_default(), + max_priority_fee_per_gas: value.max_priority_fee_per_gas.unwrap_or_default(), + max_fee_per_gas: value.max_fee_per_gas.unwrap_or(value.gas_price), + gas_limit: value.gas.unwrap_or_default(), + to, + value: value.value, + data: value.input, + access_list: value + .access_list + .into_iter() + .map(|v| (v.address, v.storage_keys)) + .collect::>(), + authorization_list: value + .authorization_list + .unwrap_or_default() + .into_iter() + .map(AuthorizationTuple::from) + .collect(), + ..Default::default() + }) + } + } + impl From for GenericTransaction { fn from(value: PrivilegedL2Transaction) -> Self { Self { @@ -2818,7 +2853,9 @@ mod serde_impl { .collect::>(), fee_token: value .fee_token - .ok_or(GenericTransactionError::MissingFeeToken)?, + .ok_or(GenericTransactionError::MissingField( + "fee token".to_owned(), + ))?, chain_id: value.chain_id.unwrap_or_default(), ..Default::default() }) diff --git a/crates/l2/sdk/src/sdk.rs b/crates/l2/sdk/src/sdk.rs index ca342940d12..8438e6d360a 100644 --- a/crates/l2/sdk/src/sdk.rs +++ b/crates/l2/sdk/src/sdk.rs @@ -1,6 +1,7 @@ use bytes::Bytes; use calldata::encode_calldata; use ethereum_types::{H160, H256, U256}; +use ethrex_common::types::EIP7702Transaction; use ethrex_common::types::FeeTokenTransaction; use ethrex_common::types::Fork; use ethrex_common::utils::keccak; @@ -810,6 +811,14 @@ pub async fn send_generic_transaction( tx.encode(&mut encoded_tx); } + TxType::EIP7702 => { + let tx: EIP7702Transaction = generic_tx.try_into()?; + let signed_tx = tx + .sign(signer) + .await + .map_err(|err| EthClientError::Custom(err.to_string()))?; + signed_tx.encode(&mut encoded_tx); + } TxType::FeeToken => { let tx: FeeTokenTransaction = generic_tx.try_into()?; let signed_tx = tx @@ -820,9 +829,10 @@ pub async fn send_generic_transaction( signed_tx.encode(&mut encoded_tx); } _ => { - return Err(EthClientError::Custom( - "Unsupported transaction type".to_string(), - )); + return Err(EthClientError::Custom(format!( + "Unsupported transaction type: {:?}", + generic_tx.r#type + ))); } }; @@ -956,8 +966,12 @@ pub async fn build_generic_tx( overrides: Overrides, ) -> Result { match r#type { - TxType::EIP1559 | TxType::EIP4844 | TxType::Privileged | TxType::FeeToken => {} - TxType::EIP2930 | TxType::EIP7702 | TxType::Legacy => { + TxType::EIP1559 + | TxType::EIP4844 + | TxType::EIP7702 + | TxType::Privileged + | TxType::FeeToken => {} + TxType::EIP2930 | TxType::Legacy => { return Err(EthClientError::Custom( "Unsupported tx type in build_generic_tx".to_owned(), )); @@ -996,6 +1010,7 @@ pub async fn build_generic_tx( fee_token: overrides.fee_token, from, wrapper_version: overrides.wrapper_version, + authorization_list: overrides.authorization_list, ..Default::default() }; tx.gas_price = tx.max_fee_per_gas.unwrap_or_default(); diff --git a/crates/networking/rpc/clients/eth/mod.rs b/crates/networking/rpc/clients/eth/mod.rs index 38b2dff18fd..2bd59f53fbd 100644 --- a/crates/networking/rpc/clients/eth/mod.rs +++ b/crates/networking/rpc/clients/eth/mod.rs @@ -25,7 +25,7 @@ use errors::{ }; use ethrex_common::{ Address, H256, U256, - types::{BlobsBundle, Block, GenericTransaction, TxKind}, + types::{AuthorizationTupleEntry, BlobsBundle, Block, GenericTransaction, TxKind}, utils::decode_hex, }; use ethrex_rlp::decode::RLPDecode; @@ -70,6 +70,7 @@ pub struct Overrides { pub gas_price_per_blob: Option, pub block: Option, pub blobs_bundle: Option, + pub authorization_list: Option>, pub wrapper_version: Option, }