Skip to content
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
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default = ["reqwest"]
reqwest = ["dep:reqwest", "dep:serde_json", "dep:tower"]

[dependencies]
alloy = { version = "0.5", features = [
alloy = { version = "1.0.30", features = [
"rpc",
"rpc-client",
"rpc-types-mev",
Expand All @@ -28,7 +28,6 @@ alloy = { version = "0.5", features = [
"transport-http",
"signers",
] }
hyper = { version = "1.4", features = ["client"], optional = true }
tower = { version = "0.5", optional = true }
futures = "0.3"
pin-project = "1.1"
Expand All @@ -41,7 +40,7 @@ async-trait = "0.1"
dotenv = "0.15"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
anyhow = "1.0"
alloy = { version = "0.5", features = [
alloy = { version = "1.0.30", features = [
"rpc-client",
"consensus",
"signer-local",
Expand Down
7 changes: 3 additions & 4 deletions examples/mev_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy::{
primitives::{address, U256},
providers::{Provider, ProviderBuilder},
rpc::types::{
mev::{Inclusion, SendBundleRequest},
mev::{Inclusion, MevSendBundle},
TransactionRequest,
},
signers::local::PrivateKeySigner,
Expand All @@ -27,17 +27,16 @@ async fn main() -> Result<()> {

// Build a provider with MEV
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(tx_signer.clone())
.on_http(eth_rpc.parse()?);
.connect_http(eth_rpc.parse()?);

// Pay Vitalik using a MEV-Share bundle!
let tx = TransactionRequest::default()
.to(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045")) // vitalik.eth
.value(U256::from(1000000000));

// Build a bundle...
let bundle = SendBundleRequest {
let bundle = MevSendBundle {
bundle_body: vec![provider.build_bundle_item(tx, false).await?],
inclusion: Inclusion::at_block(provider.get_block_number().await? + 1),
..Default::default()
Expand Down
8 changes: 6 additions & 2 deletions examples/send_to_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ async fn main() -> Result<()> {
let tx_signer = EthereumWallet::new(bundle_signer.clone());

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(tx_signer.clone())
.on_http(eth_rpc.parse()?);
.connect_http(eth_rpc.parse()?);

// Select which builders the bundle will be sent to
let endpoints = provider
Expand All @@ -47,6 +46,11 @@ async fn main() -> Result<()> {
max_timestamp: None,
reverting_tx_hashes: vec![],
replacement_uuid: None,
dropping_tx_hashes: vec![],
refund_percent: None,
refund_recipient: None,
refund_tx_hashes: vec![],
extra_fields: Default::default(),
},
&endpoints,
)
Expand Down
8 changes: 4 additions & 4 deletions src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::{
network::Network,
primitives::{Bytes, B256},
providers::Provider,
rpc::types::mev::{EthSendBundle, SendBundleResponse},
rpc::types::mev::{EthSendBundle, EthBundleHash},
transports::{Transport, TransportResult},
};

Expand All @@ -14,7 +14,7 @@ use crate::{BroadcastableCall, Endpoints};
#[derive(Debug)]
pub struct EthBundle<'a, P, T, N>
where
P: Provider<T, N>,
P: Provider<N>,
T: Transport + Clone,
N: Network,
{
Expand All @@ -25,7 +25,7 @@ where

impl<'a, P, T, N> EthBundle<'a, P, T, N>
where
P: Provider<T, N>,
P: Provider<N>,
T: Transport + Clone,
N: Network,
{
Expand Down Expand Up @@ -82,7 +82,7 @@ where

/// Submits a bundle to the given endpoints. It takes in a bundle and
/// provides a bundle hash as a return value.
pub async fn send(self, endpoints: &Endpoints) -> Vec<TransportResult<SendBundleResponse>> {
pub async fn send(self, endpoints: &Endpoints) -> Vec<TransportResult<EthBundleHash>> {
BroadcastableCall::new(
endpoints,
self.provider
Expand Down
2 changes: 1 addition & 1 deletion src/eth/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Endpoints {
}

/// Returns an iterator over the transports.
pub fn iter(&self) -> Iter<BoxTransport> {
pub fn iter(&self) -> Iter<'_, BoxTransport> {
self.0.iter()
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/eth/provider_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use alloy::{
primitives::{Bytes, B256},
providers::Provider,
rpc::types::mev::{
CancelBundleRequest, EthCallBundle, EthCallBundleResponse, EthSendBundle,
PrivateTransactionRequest, SendBundleResponse,
EthBundleHash, EthCallBundle, EthCallBundleResponse, EthCancelBundle, EthSendBundle,
EthSendPrivateTransaction,
},
transports::{http::Http, Transport, TransportResult},
};
Expand All @@ -16,7 +16,7 @@ use super::{Endpoints, EndpointsBuilder};

/// Extension trait for sending and simulate eth bundles.
#[async_trait]
pub trait EthMevProviderExt<C, N>: Provider<Http<C>, N> + Sized
pub trait EthMevProviderExt<C, N>: Provider<N> + Sized
where
C: Clone,
N: Network,
Expand All @@ -38,13 +38,13 @@ where
&self,
bundle: EthSendBundle,
endpoints: &Endpoints,
) -> Vec<TransportResult<SendBundleResponse>>;
) -> Vec<TransportResult<EthBundleHash>>;

/// Submits a single transaction to one or more builder(s). It takes in a
/// bundle and provides a bundle hash as a return value.
async fn send_eth_private_transaction(
&self,
request: PrivateTransactionRequest,
request: EthSendPrivateTransaction,
) -> TransportResult<B256>;

/// simulates a bundle against a specific block number.
Expand All @@ -55,5 +55,5 @@ where
) -> Vec<TransportResult<EthCallBundleResponse>>;

/// Cancels a previously submitted bundle.
async fn cancel_eth_bundle(&self, request: CancelBundleRequest) -> TransportResult<()>;
async fn cancel_eth_bundle(&self, request: EthCancelBundle) -> TransportResult<()>;
}
24 changes: 16 additions & 8 deletions src/eth/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use alloy::{
Provider,
},
rpc::types::mev::{
CancelBundleRequest, EthCallBundle, EthCallBundleResponse, EthSendBundle,
PrivateTransactionRequest, SendBundleResponse,
EthBundleHash, EthCallBundle, EthCallBundleResponse, EthCancelBundle, EthSendBundle,
EthSendPrivateTransaction,
},
transports::{http::Http, TransportErrorKind, TransportResult},
};
Expand All @@ -20,15 +20,23 @@ use crate::{BroadcastableCall, Endpoints, EndpointsBuilder, EthBundle, EthMevPro
pub type EthereumReqwestEthBundle<'a, P> = EthBundle<'a, P, Http<reqwest::Client>, Ethereum>;

#[async_trait]
impl<F, P, N> EthMevProviderExt<reqwest::Client, N> for FillProvider<F, P, Http<reqwest::Client>, N>
impl<F, P, N> EthMevProviderExt<reqwest::Client, N> for FillProvider<F, P, N>
where
F: TxFiller<N>,
P: Provider<Http<reqwest::Client>, N>,
P: Provider<N>,
N: Network,
<N as Network>::TxEnvelope: Encodable2718 + Clone,
{
fn endpoints_builder(&self) -> EndpointsBuilder<reqwest::Client> {
EndpointsBuilder::new(self.client().transport().clone())
let base_transport = self
.client()
.transport()
.as_any()
.downcast_ref::<Http<reqwest::Client>>()
.expect("Expected Http<reqwest::Client> transport, but got different type")
.clone();

EndpointsBuilder::new(base_transport)
}

async fn encode_request(&self, tx: N::TransactionRequest) -> TransportResult<Bytes> {
Expand All @@ -49,7 +57,7 @@ where
&self,
bundle: EthSendBundle,
endpoints: &Endpoints,
) -> Vec<TransportResult<SendBundleResponse>> {
) -> Vec<TransportResult<EthBundleHash>> {
BroadcastableCall::new(
endpoints,
self.client().make_request("eth_sendBundle", (bundle,)),
Expand All @@ -59,7 +67,7 @@ where

async fn send_eth_private_transaction(
&self,
request: PrivateTransactionRequest,
request: EthSendPrivateTransaction,
) -> TransportResult<B256> {
self.client()
.request("eth_sendPrivateTransaction", (request,))
Expand All @@ -78,7 +86,7 @@ where
.await
}

async fn cancel_eth_bundle(&self, request: CancelBundleRequest) -> TransportResult<()> {
async fn cancel_eth_bundle(&self, request: EthCancelBundle) -> TransportResult<()> {
self.client().request("eth_cancelBundle", (request,)).await
}
}
30 changes: 21 additions & 9 deletions src/mev_share/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ use alloy::{
rpc::{
client::RpcCall,
types::mev::{
BundleItem, Privacy, SendBundleRequest, SendBundleResponse, SimBundleOverrides,
BundleItem, EthBundleHash, MevSendBundle, Privacy, SimBundleOverrides,
SimBundleResponse, Validity,
},
},
signers::Signer,
transports::{http::Http, Transport, TransportResult},
};

use crate::MevHttp;
use crate::transport::MevHttp;

/// A MEV-Share bundle hat can be sent or simulated.
#[derive(Debug)]
pub struct MevShareBundle<'a, P, C, N, S>
where
P: Provider<Http<C>, N>,
P: Provider<N>,
C: Clone,
N: Network,
S: Signer + Send + Sync + 'static,
Http<C>: Transport,
{
provider: &'a P,
bundle: SendBundleRequest,
bundle: MevSendBundle,
bundle_signer: S,
phantom: PhantomData<(C, N)>,
}

impl<'a, P, C, N, S> MevShareBundle<'a, P, C, N, S>
where
P: Provider<Http<C>, N>,
P: Provider<N>,
C: Clone,
N: Network,
S: Signer + Send + Sync + 'static,
Expand All @@ -46,7 +46,7 @@ where
pub fn new(provider: &'a P, bundle_signer: S) -> Self {
Self {
provider,
bundle: SendBundleRequest::default(),
bundle: MevSendBundle::default(),
bundle_signer,
phantom: PhantomData,
}
Expand Down Expand Up @@ -95,7 +95,7 @@ where

/// Submits a bundle to the MEV-Share matchmaker. It takes in a bundle and
/// provides a bundle hash as a return value.
pub async fn send(self) -> TransportResult<SendBundleResponse> {
pub async fn send(self) -> TransportResult<EthBundleHash> {
Comment thread
leruaa marked this conversation as resolved.
let request = self
.provider
.client()
Expand All @@ -104,7 +104,13 @@ where
RpcCall::new(
request,
MevHttp::flashbots(
self.provider.client().transport().clone(),
self.provider
.client()
.transport()
.as_any()
.downcast_ref::<Http<C>>()
.expect("Expected Http<C> transport, but got different type")
.clone(),
self.bundle_signer,
),
)
Expand All @@ -126,7 +132,13 @@ where
RpcCall::new(
request,
MevHttp::flashbots(
self.provider.client().transport().clone(),
self.provider
.client()
.transport()
.as_any()
.downcast_ref::<Http<C>>()
.expect("Expected Http<C> transport, but got different type")
.clone(),
self.bundle_signer,
),
)
Expand Down
10 changes: 5 additions & 5 deletions src/mev_share/provider_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy::{
network::Network,
providers::Provider,
rpc::types::mev::{
BundleItem, SendBundleRequest, SendBundleResponse, SimBundleOverrides, SimBundleResponse,
BundleItem, MevSendBundle, EthBundleHash, SimBundleOverrides, SimBundleResponse,
},
signers::Signer,
transports::{http::Http, Transport, TransportResult},
Expand All @@ -13,7 +13,7 @@ use crate::MevShareBundle;

/// Extension trait for sending and simulate MEV-Share bundles.
#[async_trait]
pub trait MevShareProviderExt<C, N>: Provider<Http<C>, N> + Sized
pub trait MevShareProviderExt<C, N>: Provider<N> + Sized
where
C: Clone,
N: Network,
Expand All @@ -35,9 +35,9 @@ where
/// provides a bundle hash as a return value.
async fn send_mev_bundle<S>(
&self,
bundle: SendBundleRequest,
bundle: MevSendBundle,
signer: S,
) -> TransportResult<SendBundleResponse>
) -> TransportResult<EthBundleHash>
where
S: Signer + Clone + Send + Sync + 'static;

Expand All @@ -46,7 +46,7 @@ where
/// can be simulated.
async fn sim_mev_bundle<S>(
&self,
bundle: SendBundleRequest,
bundle: MevSendBundle,
sim_overrides: SimBundleOverrides,
signer: S,
) -> TransportResult<SimBundleResponse>
Expand Down
Loading
Loading