Skip to content

Commit

Permalink
feat(types): use alloy/native types in types crate
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Sep 19, 2024
1 parent 7b4f685 commit 819403f
Show file tree
Hide file tree
Showing 18 changed files with 816 additions and 823 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ publish = false

[dependencies]
rundler-utils = { path = "../utils" }
rundler-contracts = { path = "../contracts" }

alloy-primitives.workspace = true
alloy-sol-types.workspace = true

anyhow.workspace = true
async-trait.workspace = true
chrono = "0.4.38"
constcat = "0.5.0"
const-hex = "1.12.0"
ethers.workspace = true
futures-util.workspace = true
num_enum = "0.7.3"
parse-display.workspace = true
Expand All @@ -32,6 +35,7 @@ ethers.workspace = true

[dev-dependencies]
rundler-types = { path = ".", features = ["test-utils"] }
alloy-primitives = { workspace = true, features = ["rand"] }

[features]
test-utils = [ "mockall" ]
172 changes: 0 additions & 172 deletions crates/types/build.rs

This file was deleted.

6 changes: 3 additions & 3 deletions crates/types/src/builder/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use ethers::types::{Address, H256};
use alloy_primitives::{Address, B256};
#[cfg(feature = "test-utils")]
use mockall::automock;

Expand All @@ -23,14 +23,14 @@ pub type BuilderResult<T> = std::result::Result<T, BuilderError>;
/// Builder
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait::async_trait]
pub trait Builder: Send + Sync + 'static {
pub trait Builder: Send + Sync {
/// Get the supported entry points of this builder
async fn get_supported_entry_points(&self) -> BuilderResult<Vec<Address>>;

/// Trigger the builder to send a bundle now, used for debugging.
///
/// Bundling mode must be set to `Manual`, or this will error
async fn debug_send_bundle_now(&self) -> BuilderResult<(H256, u64)>;
async fn debug_send_bundle_now(&self) -> BuilderResult<(B256, u64)>;

/// Set the bundling mode
async fn debug_set_bundling_mode(&self, mode: BundlingMode) -> BuilderResult<()>;
Expand Down
44 changes: 22 additions & 22 deletions crates/types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use std::str::FromStr;

use ethers::types::{Address, U256};
use alloy_primitives::Address;
use serde::{Deserialize, Serialize};

const ENTRY_POINT_ADDRESS_V6_0: &str = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
Expand All @@ -40,24 +40,24 @@ pub struct ChainSpec {
///
/// NOTE: This must take into account when the storage slot was originally 0
/// and is now non-zero, making the overhead slightly higher for most operations.
pub deposit_transfer_overhead: U256,
pub deposit_transfer_overhead: u128,
/// The maximum size of a transaction in bytes
pub max_transaction_size_bytes: usize,
/// Intrinsic gas cost for a transaction
pub transaction_intrinsic_gas: U256,
pub transaction_intrinsic_gas: u128,
/// Per user operation gas cost for v0.6
pub per_user_op_v0_6_gas: U256,
pub per_user_op_v0_6_gas: u128,
/// Per user operation gas cost for v0.7
pub per_user_op_v0_7_gas: U256,
pub per_user_op_v0_7_gas: u128,
/// Per user operation deploy gas cost overhead, to capture
/// deploy costs that are not metered by the entry point
pub per_user_op_deploy_overhead_gas: U256,
pub per_user_op_deploy_overhead_gas: u128,
/// Gas cost for a user operation word in a bundle transaction
pub per_user_op_word_gas: U256,
pub per_user_op_word_gas: u128,
/// Gas cost for a zero byte in calldata
pub calldata_zero_byte_gas: U256,
pub calldata_zero_byte_gas: u128,
/// Gas cost for a non-zero byte in calldata
pub calldata_non_zero_byte_gas: U256,
pub calldata_non_zero_byte_gas: u128,

/*
* Gas estimation
Expand All @@ -81,9 +81,9 @@ pub struct ChainSpec {
/// Type of oracle for estimating priority fees
pub priority_fee_oracle_type: PriorityFeeOracleType,
/// Minimum max priority fee per gas for the network
pub min_max_priority_fee_per_gas: U256,
pub min_max_priority_fee_per_gas: u128,
/// Maximum max priority fee per gas for the network
pub max_max_priority_fee_per_gas: U256,
pub max_max_priority_fee_per_gas: u128,
/// Usage ratio of the chain that determines "congestion"
/// Some chains have artificially high block gas limits but
/// actually cap block gas usage at a lower value.
Expand Down Expand Up @@ -149,22 +149,22 @@ impl Default for ChainSpec {
id: 0,
entry_point_address_v0_6: Address::from_str(ENTRY_POINT_ADDRESS_V6_0).unwrap(),
entry_point_address_v0_7: Address::from_str(ENTRY_POINT_ADDRESS_V7_0).unwrap(),
deposit_transfer_overhead: U256::from(30_000),
transaction_intrinsic_gas: U256::from(21_000),
per_user_op_v0_6_gas: U256::from(18_300),
per_user_op_v0_7_gas: U256::from(19_500),
per_user_op_deploy_overhead_gas: U256::from(0),
per_user_op_word_gas: U256::from(4),
calldata_zero_byte_gas: U256::from(4),
calldata_non_zero_byte_gas: U256::from(16),
deposit_transfer_overhead: 30_000,
transaction_intrinsic_gas: 21_000,
per_user_op_v0_6_gas: 18_300,
per_user_op_v0_7_gas: 19_500,
per_user_op_deploy_overhead_gas: 0,
per_user_op_word_gas: 4,
calldata_zero_byte_gas: 4,
calldata_non_zero_byte_gas: 16,
eip1559_enabled: true,
calldata_pre_verification_gas: false,
l1_gas_oracle_contract_type: L1GasOracleContractType::default(),
l1_gas_oracle_contract_address: Address::zero(),
l1_gas_oracle_contract_address: Address::ZERO,
include_l1_gas_in_gas_limit: true,
priority_fee_oracle_type: PriorityFeeOracleType::default(),
min_max_priority_fee_per_gas: U256::zero(),
max_max_priority_fee_per_gas: U256::MAX,
min_max_priority_fee_per_gas: 0,
max_max_priority_fee_per_gas: u128::MAX,
congestion_trigger_usage_ratio_threshold: 0.75,
max_transaction_size_bytes: 131072, // 128 KiB
bundle_max_send_interval_millis: u64::MAX,
Expand Down
6 changes: 3 additions & 3 deletions crates/types/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

use std::{fmt::Display, hash::Hash, str::FromStr};

use alloy_primitives::Address;
use anyhow::bail;
use ethers::{types::Address, utils::to_checksum};
use parse_display::Display;
use serde::{ser::SerializeStruct, Deserialize, Serialize};
use strum::{EnumIter, IntoEnumIterator};
Expand Down Expand Up @@ -113,14 +113,14 @@ impl Entity {

impl Display for Entity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{:?}", self.kind, to_checksum(&self.address, None))
write!(f, "{}:{:?}", self.kind, self.address.to_checksum(None))
}
}

impl Serialize for Entity {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut e = serializer.serialize_struct("Entity", 1)?;
e.serialize_field(self.kind.to_str(), &to_checksum(&self.address, None))?;
e.serialize_field(self.kind.to_str(), &self.address.to_checksum(None))?;
e.end()
}
}
Expand Down
Loading

0 comments on commit 819403f

Please sign in to comment.