diff --git a/Cargo.toml b/Cargo.toml index 3275ef83..62e730d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,24 @@ homepage = "https://github.com/alloy-rs/op-alloy" repository = "https://github.com/alloy-rs/op-alloy" exclude = ["benches/", "tests/"] +[workspace.dependencies] +# Alloy +alloy-primitives = { version = "0.7.1", default-features = false } +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" } +alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" } +alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" } +alloy-op-rpc-types = { version = "0.1.0", path = "crates/rpc-types" } + +# Serde +serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } +serde_json = { version = "1.0", default-features = false, features = ["alloc"] } + +## misc-testing +arbitrary = { version = "1.3", features = ["derive"] } +rand = "0.8" +proptest = "1.4" +proptest-derive = "0.4" + [workspace.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] \ No newline at end of file diff --git a/crates/op-rpc-types/Cargo.toml b/crates/op-rpc-types/Cargo.toml deleted file mode 100644 index 3ee5ad6c..00000000 --- a/crates/op-rpc-types/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "op-rpc-types" -description = "Optimism RPC types" - -version.workspace = true -edition.workspace = true -rust-version.workspace = true -license.workspace = true -homepage.workspace = true -authors.workspace = true -repository.workspace = true -exclude.workspace = true diff --git a/crates/op-rpc-types/src/lib.rs b/crates/op-rpc-types/src/lib.rs deleted file mode 100644 index 8b137891..00000000 --- a/crates/op-rpc-types/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/rpc-types/Cargo.toml b/crates/rpc-types/Cargo.toml new file mode 100644 index 00000000..632666c7 --- /dev/null +++ b/crates/rpc-types/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "alloy-op-rpc-types" +description = "Optimism RPC types" + +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +authors.workspace = true +repository.workspace = true +exclude.workspace = true + +[dependencies] +alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] } +alloy-consensus = { workspace = true, features = ["std", "serde"] } +alloy-rpc-types.workspace = true + +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true + +# arbitrary +arbitrary = { version = "1.3", features = ["derive"], optional = true } + +[dev-dependencies] +alloy-primitives = { workspace = true, features = ["arbitrary"] } +alloy-consensus = { workspace = true, features = ["arbitrary"] } +alloy-rpc-types = { workspace = true, features = ["arbitrary"] } + +arbitrary = { workspace = true, features = ["derive"] } +rand.workspace = true + +[features] +arbitrary = [ + "dep:arbitrary", + "alloy-primitives/arbitrary", + "alloy-consensus/arbitrary", + "alloy-rpc-types/arbitrary", +] \ No newline at end of file diff --git a/crates/rpc-types/README.md b/crates/rpc-types/README.md new file mode 100644 index 00000000..e9cc01c5 --- /dev/null +++ b/crates/rpc-types/README.md @@ -0,0 +1,3 @@ +# alloy-rpc-types + +Ethereum RPC-related types for Alloy. diff --git a/crates/rpc-types/src/lib.rs b/crates/rpc-types/src/lib.rs new file mode 100644 index 00000000..2ee5bc67 --- /dev/null +++ b/crates/rpc-types/src/lib.rs @@ -0,0 +1,17 @@ +#![doc = include_str!("../README.md")] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg", + html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico" +)] +#![warn( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + unreachable_pub, + clippy::missing_const_for_fn, + rustdoc::all +)] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +pub mod transaction; diff --git a/crates/rpc-types/src/transaction/mod.rs b/crates/rpc-types/src/transaction/mod.rs new file mode 100644 index 00000000..290a98f3 --- /dev/null +++ b/crates/rpc-types/src/transaction/mod.rs @@ -0,0 +1,31 @@ +//! Optimism specific types related to transactions. + +use alloy_primitives::B256; +use serde::{Deserialize, Serialize}; + +pub use self::tx_type::TxType; + +pub mod tx_type; + +/// OP Transaction type +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] +#[serde(rename_all = "camelCase")] +pub struct Transaction { + /// Ethereum Transaction Types + #[serde(flatten)] + pub inner: alloy_rpc_types::Transaction, + /// The ETH value to mint on L2 + #[serde(rename = "mint", skip_serializing_if = "Option::is_none")] + pub mint: Option, + /// Hash that uniquely identifies the source of the deposit. + #[serde(rename = "sourceHash", skip_serializing_if = "Option::is_none")] + pub source_hash: Option, + /// Field indicating whether the transaction is a system transaction, and therefore + /// exempt from the L2 gas limit. + #[serde(rename = "isSystemTx", skip_serializing_if = "Option::is_none")] + pub is_system_tx: Option, + /// Deposit receipt version for deposit transactions post-canyon + #[serde(skip_serializing_if = "Option::is_none")] + pub deposit_receipt_version: Option, +} diff --git a/crates/rpc-types/src/transaction/tx_type.rs b/crates/rpc-types/src/transaction/tx_type.rs new file mode 100644 index 00000000..5c26fd93 --- /dev/null +++ b/crates/rpc-types/src/transaction/tx_type.rs @@ -0,0 +1,49 @@ +//! OP transaction identifiers. + +use serde::{Deserialize, Serialize}; + +/// Identifier for legacy transaction, however a legacy tx is technically not +/// typed. +pub const LEGACY_TX_TYPE_ID: u8 = 0; + +/// Identifier for an EIP2930 transaction. +pub const EIP2930_TX_TYPE_ID: u8 = 1; + +/// Identifier for an EIP1559 transaction. +pub const EIP1559_TX_TYPE_ID: u8 = 2; + +/// Identifier for an EIP4844 transaction. +pub const EIP4844_TX_TYPE_ID: u8 = 3; + +/// Identifier for an Optimism deposit transaction +pub const DEPOSIT_TX_TYPE_ID: u8 = 126; + +/// Transaction Type +#[derive( + Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Hash, +)] +pub enum TxType { + /// Legacy transaction pre EIP-2929 + #[default] + Legacy = 0_isize, + /// AccessList transaction + Eip2930 = 1_isize, + /// Transaction with Priority fee + Eip1559 = 2_isize, + /// Shard Blob Transactions - EIP-4844 + Eip4844 = 3_isize, + /// Optimism Deposit transaction. + Deposit = 126_isize, +} + +impl From for u8 { + fn from(value: TxType) -> Self { + match value { + TxType::Legacy => LEGACY_TX_TYPE_ID, + TxType::Eip2930 => EIP2930_TX_TYPE_ID, + TxType::Eip1559 => EIP1559_TX_TYPE_ID, + TxType::Eip4844 => EIP4844_TX_TYPE_ID, + TxType::Deposit => DEPOSIT_TX_TYPE_ID, + } + } +} diff --git a/deny.toml b/deny.toml index a916dc7f..63556efa 100644 --- a/deny.toml +++ b/deny.toml @@ -7,7 +7,7 @@ notice = "warn" [bans] multiple-versions = "warn" -wildcards = "deny" +wildcards = "allow" highlight = "all" [licenses] @@ -52,5 +52,6 @@ license-files = [{ path = "LICENSE", hash = 0x001c7e6c }] [sources] unknown-registry = "deny" unknown-git = "deny" -# TODO: Remove once alloy-contract is stable. This is only used in tests for `sol!`. -allow-git = ["https://github.com/alloy-rs/core"] +allow-git = [ + "https://github.com/alloy-rs/alloy", +]