diff --git a/crates/rpc/rpc-types/src/mev.rs b/crates/rpc/rpc-types/src/mev.rs index ae94375dbc..9126c09635 100644 --- a/crates/rpc/rpc-types/src/mev.rs +++ b/crates/rpc/rpc-types/src/mev.rs @@ -1,12 +1,11 @@ //! MEV bundle type bindings use crate::{BlockId, BlockNumberOrTag, Log}; -use alloy_primitives::{Address, Bytes, TxHash, B256, U256, U64}; +use alloy_primitives::{Address, Bytes, TxHash, B256, U256}; use serde::{ ser::{SerializeSeq, Serializer}, Deserialize, Deserializer, Serialize, }; - /// A bundle of transactions to send to the matchmaker. /// /// Note: this is for `mev_sendBundle` and not `eth_sendBundle`. @@ -35,28 +34,33 @@ pub struct SendBundleRequest { #[serde(rename_all = "camelCase")] pub struct Inclusion { /// The first block the bundle is valid for. - pub block: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub block: u64, /// The last block the bundle is valid for. - #[serde(skip_serializing_if = "Option::is_none")] - pub max_block: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub max_block: Option, } impl Inclusion { /// Creates a new inclusion with the given min block.. pub fn at_block(block: u64) -> Self { - Self { block: U64::from(block), max_block: None } + Self { block, max_block: None } } /// Returns the block number of the first block the bundle is valid for. #[inline] pub fn block_number(&self) -> u64 { - self.block.to() + self.block } /// Returns the block number of the last block the bundle is valid for. #[inline] pub fn max_block_number(&self) -> Option { - self.max_block.as_ref().map(|b| b.to()) + self.max_block.as_ref().map(|b| *b) } } @@ -100,8 +104,10 @@ pub struct Validity { #[serde(rename_all = "camelCase")] pub struct Refund { /// The index of the transaction in the bundle. + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub body_idx: u64, /// The minimum percent of the bundle's earnings to redistribute. + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub percent: u64, } @@ -113,6 +119,7 @@ pub struct RefundConfig { /// The address to refund. pub address: Address, /// The minimum percent of the bundle's earnings to redistribute. + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub percent: u64, } @@ -312,26 +319,42 @@ pub struct SimBundleOverrides { /// Block used for simulation state. Defaults to latest block. /// Block header data will be derived from parent block by default. /// Specify other params to override the default values. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub parent_block: Option, /// Block number used for simulation, defaults to parentBlock.number + 1 - #[serde(skip_serializing_if = "Option::is_none")] - pub block_number: Option, + #[serde(default, with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint")] + pub block_number: Option, /// Coinbase used for simulation, defaults to parentBlock.coinbase - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub coinbase: Option
, /// Timestamp used for simulation, defaults to parentBlock.timestamp + 12 - #[serde(skip_serializing_if = "Option::is_none")] - pub timestamp: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub timestamp: Option, /// Gas limit used for simulation, defaults to parentBlock.gasLimit - #[serde(skip_serializing_if = "Option::is_none")] - pub gas_limit: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub gas_limit: Option, /// Base fee used for simulation, defaults to parentBlock.baseFeePerGas - #[serde(skip_serializing_if = "Option::is_none")] - pub base_fee: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub base_fee: Option, /// Timeout in seconds, defaults to 5 - #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub timeout: Option, } /// Response from the matchmaker after sending a simulation request. @@ -341,20 +364,25 @@ pub struct SimBundleResponse { /// Whether the simulation was successful. pub success: bool, /// Error message if the simulation failed. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub error: Option, /// The block number of the simulated block. - pub state_block: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub state_block: u64, /// The gas price of the simulated block. - pub mev_gas_price: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub mev_gas_price: u64, /// The profit of the simulated block. - pub profit: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub profit: u64, /// The refundable value of the simulated block. - pub refundable_value: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub refundable_value: u64, /// The gas used by the simulated block. - pub gas_used: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub gas_used: u64, /// Logs returned by mev_simBundle. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub logs: Option>, } @@ -363,18 +391,18 @@ pub struct SimBundleResponse { #[serde(rename_all = "camelCase")] pub struct SimBundleLogs { /// Logs for transactions in bundle. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub tx_logs: Option>, /// Logs for bundles in bundle. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub bundle_logs: Option>, } impl SendBundleRequest { /// Create a new bundle request. pub fn new( - block_num: U64, - max_block: Option, + block_num: u64, + max_block: Option, protocol_version: ProtocolVersion, bundle_body: Vec, ) -> Self { @@ -404,8 +432,12 @@ pub struct PrivateTransactionRequest { pub tx: Bytes, /// Hex-encoded number string, optional. Highest block number in which the transaction should /// be included. - #[serde(skip_serializing_if = "Option::is_none")] - pub max_block_number: Option, + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] + pub max_block_number: Option, /// Preferences for private transaction. #[serde(default, skip_serializing_if = "PrivateTransactionPreferences::is_empty")] pub preferences: PrivateTransactionPreferences, @@ -415,10 +447,10 @@ pub struct PrivateTransactionRequest { #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] pub struct PrivateTransactionPreferences { /// Requirements for the bundle to be included in the block. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub validity: Option, /// Preferences on what data should be shared about the bundle and its transactions - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub privacy: Option, } @@ -593,18 +625,27 @@ pub struct EthSendBundle { /// A list of hex-encoded signed transactions pub txs: Vec, /// hex-encoded block number for which this bundle is valid - pub block_number: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub block_number: u64, /// unix timestamp when this bundle becomes active - #[serde(skip_serializing_if = "Option::is_none")] + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] pub min_timestamp: Option, /// unix timestamp how long this bundle stays valid - #[serde(skip_serializing_if = "Option::is_none")] + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] pub max_timestamp: Option, /// list of hashes of possibly reverting txs #[serde(default, skip_serializing_if = "Vec::is_empty")] pub reverting_tx_hashes: Vec, /// UUID that can be used to cancel/replace this bundle - #[serde(rename = "replacementUuid", skip_serializing_if = "Option::is_none")] + #[serde(default, rename = "replacementUuid", skip_serializing_if = "Option::is_none")] pub replacement_uuid: Option, } @@ -625,11 +666,16 @@ pub struct EthCallBundle { /// A list of hex-encoded signed transactions pub txs: Vec, /// hex encoded block number for which this bundle is valid on - pub block_number: U64, + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] + pub block_number: u64, /// Either a hex encoded number or a block tag for which state to base this simulation on pub state_block_number: BlockNumberOrTag, /// the timestamp to use for this bundle simulation, in seconds since the unix epoch - #[serde(skip_serializing_if = "Option::is_none")] + #[serde( + default, + with = "alloy_rpc_types::serde_helpers::num::u64_opt_via_ruint", + skip_serializing_if = "Option::is_none" + )] pub timestamp: Option, } @@ -654,8 +700,10 @@ pub struct EthCallBundleResponse { /// Results of individual transactions within the bundle pub results: Vec, /// The block number used as a base for this simulation + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub state_block_number: u64, /// The total gas used by all transactions in the bundle + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub total_gas_used: u64, } @@ -678,6 +726,7 @@ pub struct EthCallBundleTransactionResult { #[serde(with = "u256_numeric_string")] pub gas_price: U256, /// The amount of gas used by the transaction + #[serde(with = "alloy_rpc_types::serde_helpers::num::u64_via_ruint")] pub gas_used: u64, /// The address to which the transaction is sent (optional) pub to_address: Option
, @@ -827,7 +876,7 @@ mod tests { let bundle = SendBundleRequest { protocol_version: ProtocolVersion::V0_1, - inclusion: Inclusion { block: U64::from(1), max_block: None }, + inclusion: Inclusion { block: 1, max_block: None }, bundle_body, validity, privacy, diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index c2d56df313..0523141eb2 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -52,7 +52,7 @@ where EthBundleError::EmptyBundleTransactions.to_string(), )) } - if block_number.to::() == 0 { + if block_number == 0 { return Err(EthApiError::InvalidParams( EthBundleError::BundleMissingBlockNumber.to_string(), ))