Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

chore(deps): use alloy for everything #73

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ repository = "https://github.com/init4tech/zenith"
license = "AGPL-3.0"

[dependencies]
alloy = { version = "=0.7.3", features = ["full", "json-rpc", "signer-aws", "rpc-types-mev"] }
alloy-primitives = { version = "0.8.11", features = ["serde", "tiny-keccak"] }
alloy-sol-types = { version = "0.8.11", features = ["json"] }
alloy-rlp = { version = "0.3.4" }
alloy-contract = { version = "=0.7.3", features = ["pubsub"] }
alloy = { version = "=0.7.3", features = ["full", "json-rpc", "signer-aws", "rpc-types-mev", "rlp"] }

serde = { version = "1.0.197", features = ["derive"] }

Expand Down
17 changes: 8 additions & 9 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![allow(clippy::too_many_arguments)]
#![allow(missing_docs)]
use alloy_primitives::{Address, Bytes, FixedBytes, U256};

use alloy::primitives::{Address, Bytes, FixedBytes, U256};
mod mint {
alloy::sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
function mint(address to, uint256 amount);
);
Expand All @@ -13,7 +12,7 @@ pub use mint::mintCall;
mod zenith {
use super::*;

alloy::sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
Zenith,
Expand Down Expand Up @@ -107,7 +106,7 @@ mod zenith {
mod passage {
use super::*;

alloy::sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
Passage,
Expand Down Expand Up @@ -207,7 +206,7 @@ mod passage {
mod orders {
use super::*;

alloy::sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
Orders,
Expand Down Expand Up @@ -303,7 +302,7 @@ mod orders {
mod transactor {
use super::*;

alloy::sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
Transactor,
Expand Down Expand Up @@ -358,7 +357,7 @@ mod transactor {

mod rollup_passage {

alloy_sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
RollupPassage,
Expand All @@ -381,7 +380,7 @@ mod rollup_passage {
}

mod bundle_helper {
alloy_sol_types::sol!(
alloy::sol!(
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[sol(rpc)]
BundleHelper,
Expand Down
9 changes: 4 additions & 5 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{marker::PhantomData, sync::OnceLock};
use crate::Zenith::BlockHeader as ZenithHeader;
use alloy::consensus::TxEnvelope;
use alloy::eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, B256};
use alloy_rlp::Decodable;
use alloy::primitives::{keccak256, Address, B256};
use alloy::rlp::Decodable;

/// Zenith processes normal Ethereum txns.
pub type ZenithTransaction = TxEnvelope;
Expand Down Expand Up @@ -216,15 +216,14 @@ where
let encoded_txns = transactions.into_iter().map(|tx| C::encode(tx)).collect::<Vec<Vec<u8>>>();

let mut buf = Vec::new();
alloy_rlp::Encodable::encode(&encoded_txns, &mut buf);
alloy::rlp::Encodable::encode(&encoded_txns, &mut buf);
buf
}

#[cfg(test)]
mod test {
use alloy::consensus::{Signed, TxEip1559};
use alloy_primitives::PrimitiveSignature;
use alloy_primitives::{b256, bytes, Address, U256};
use alloy::primitives::{b256, bytes, Address, PrimitiveSignature, U256};

use super::*;

Expand Down
8 changes: 4 additions & 4 deletions src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloy::primitives::{keccak256, Address, Bytes, B256, U256};
use alloy::{
eips::{eip2718::Encodable2718, BlockNumberOrTag},
rpc::types::mev::{EthCallBundle, EthCallBundleResponse, EthSendBundle},
};
use alloy_primitives::{keccak256, Address, Bytes, B256, U256};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -222,7 +222,7 @@ impl ZenithCallBundle {
/// `keccak(NUM_OF_ASSETS_LE + asset1 + NUM_OF_FILLS_LE + asset1_user1 + user1_amount2 + ... + asset1_usern + asset1_amountn + ...)`.
/// For the number of users/fills and amounts in the host_preimage, the amounts are serialized as little-endian U256 slice.
pub fn bundle_hash(&self) -> B256 {
let mut hasher = alloy_primitives::Keccak256::new();
let mut hasher = alloy::primitives::Keccak256::new();

// Concatenate the transaction hashes, to then hash them. This is the tx_preimage.
for tx in self.bundle.txs.iter() {
Expand All @@ -237,7 +237,7 @@ impl ZenithCallBundle {
// 3. Concatenate the asset address.
// 4. Prefix the number of fills.
// 5. For each fill, concatenate the user and amount, the latter encoded as a little-endian U256 slice.
let mut hasher = alloy_primitives::Keccak256::new();
let mut hasher = alloy::primitives::Keccak256::new();

// Prefix the list of users with the number of assets.
hasher.update(U256::from(self.host_fills.len()).as_le_slice());
Expand All @@ -259,7 +259,7 @@ impl ZenithCallBundle {
// Hash the host pre-image.
let host_preimage = hasher.finalize();

let mut pre_image = alloy_primitives::Keccak256::new();
let mut pre_image = alloy::primitives::Keccak256::new();
pre_image.update(tx_preimage.as_slice());
pre_image.update(host_preimage.as_slice());

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ pub use req::SignRequest;
mod resp;
pub use resp::SignResponse;

use alloy_primitives::{address, Address};
use alloy::primitives::{address, Address};

/// System address with permission to mint tokens on pre-deploys.
pub const MINTER_ADDRESS: Address = address!("00000000000000000000746f6b656e61646d696e");

/// A [`RequestSigner`] signs [`SignRequest`]s by delegating to an
/// [`alloy::signers::Signer`].
pub trait RequestSigner {
/// Signs a [`SignRequest`] and returns the [`alloy_primitives::Signature`].
/// Signs a [`SignRequest`] and returns the [`alloy::primitives::Signature`].
fn sign_request(
&self,
request: &SignRequest,
) -> impl std::future::Future<
Output = Result<alloy_primitives::PrimitiveSignature, alloy::signers::Error>,
Output = Result<alloy::primitives::PrimitiveSignature, alloy::signers::Error>,
> + Send;
}

Expand All @@ -57,7 +57,7 @@ where
async fn sign_request(
&self,
request: &SignRequest,
) -> Result<alloy_primitives::PrimitiveSignature, alloy::signers::Error> {
) -> Result<alloy::primitives::PrimitiveSignature, alloy::signers::Error> {
let hash = request.signing_hash();
self.sign_hash(&hash).await
}
Expand Down
4 changes: 2 additions & 2 deletions src/orders/agg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::RollupOrders;
use alloy_primitives::{Address, U256};
use alloy::primitives::{Address, U256};
use std::collections::HashMap;

/// Aggregated orders for a transaction or set of transactions.
Expand Down Expand Up @@ -67,7 +67,7 @@ impl<'a> FromIterator<&'a RollupOrders::Order> for AggregateOrders {
#[cfg(test)]
mod test {
use super::*;
use alloy_primitives::{Address, U256};
use alloy::primitives::{Address, U256};

const ASSET_A: Address = Address::repeat_byte(1);
const ASSET_B: Address = Address::repeat_byte(2);
Expand Down
4 changes: 2 additions & 2 deletions src/req.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{Address, Keccak256, B256, U256};
use alloy::primitives::{Address, Keccak256, B256, U256};
use serde::{Deserialize, Serialize};

/// The domain binding for the signing service.
Expand Down Expand Up @@ -55,7 +55,7 @@ impl core::fmt::Display for SignRequest {
#[cfg(test)]
mod test {
use super::*;
use alloy_primitives::b256;
use alloy::primitives::b256;

#[test]
fn roundtrip() {
Expand Down
4 changes: 2 additions & 2 deletions src/resp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::SignRequest;
use alloy_primitives::{Address, PrimitiveSignature, SignatureError};
use alloy::primitives::{Address, PrimitiveSignature, SignatureError};
use serde::{Deserialize, Serialize};

/// A signature response from a [`RequestSigner`].
Expand Down Expand Up @@ -29,7 +29,7 @@ impl SignResponse {
mod test {
use super::*;
use crate::{RequestSigner, SignRequest};
use alloy_primitives::U256;
use alloy::primitives::U256;

#[tokio::test]
async fn test_sign_response() {
Expand Down
Loading