Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matchmaker Client #18

Merged
merged 13 commits into from
Jun 2, 2023
Merged
Prev Previous commit
Next Next commit
lints
  • Loading branch information
FrankieIsLost committed Jun 2, 2023
commit a18c273cd1b6f69b54dbf6f3a093a4538819b5a4
9 changes: 9 additions & 0 deletions crate-template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "artemis-crate-template"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/paradigmxyz/artemis"
readme = "README.md"

[dependencies]
8 changes: 8 additions & 0 deletions crate-template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]

//! artemis crate template
1 change: 1 addition & 0 deletions crates/clients/matchmaker/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{

/// Matchmaker client to interact with MEV-share
pub struct Client<S> {
/// Underlying HTTP client
pub http_client: HttpClient<FlashbotsSigner<S, HttpBackend>>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/clients/matchmaker/src/flashbots_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use tower::{Layer, Service};

/// Layer that applies [`FlashbotsSigner`] which adds a request header with a signed payload.
#[derive(Clone)]
pub struct FlashbotsSignerLayer<S> {
pub(crate) struct FlashbotsSignerLayer<S> {
signer: Arc<S>,
}

impl<S> FlashbotsSignerLayer<S> {
pub fn new(signer: Arc<S>) -> Self {
pub(crate) fn new(signer: Arc<S>) -> Self {
FlashbotsSignerLayer { signer }
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/clients/matchmaker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]

//! Client library for Flashbots MEV-share Matchmaker, fulfilling the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good!

//! [MEV-share spec](https://github.com/flashbots/mev-share).

/// Core client implementation
pub mod client;
mod flashbots_signer;
/// Core type definitions for the client
pub mod types;
21 changes: 20 additions & 1 deletion crates/clients/matchmaker/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,71 @@
use ethers::types::{Bytes, H256, U64};
use serde::{Deserialize, Serialize};

/// A bundle of transactions to send to the matchmaker.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BundleRequest {
/// The version of the MEV-share API to use.
pub version: ProtocolVersion,
/// Data used by block builders to check if the bundle should be considered for inclusion.
pub inclusion: Inclusion,
/// The transactions to include in the bundle.
pub body: Vec<BundleTx>,
}

/// Data used by block builders to check if the bundle should be considered for inclusion.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Inclusion {
/// The first block the bundle is valid for.
pub block: U64,
/// The last block the bundle is valid for.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_block: Option<U64>,
}

/// A bundle tx, which can either be a transaction hash, or a full tx
/// A bundle tx, which can either be a transaction hash, or a full tx.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
#[serde(rename_all = "camelCase")]
pub enum BundleTx {
/// The hash of the transaction we are trying to backrun.
TxHash {
/// Tx hash.
hash: H256,
},
/// A new signed transaction.
#[serde(rename_all = "camelCase")]
Tx {
/// Bytes of the signed transaction.
tx: Bytes,
/// If true, the transaction can revert without the bundle being considered invalid.
can_revert: bool,
},
}

/// Response from the matchmaker after sending a bundle.
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SendBundleResponse {
/// Hash of the bundle bodies.
bundle_hash: H256,
}

/// The version of the MEV-share API to use.
#[derive(Deserialize, Debug, Serialize, Clone, Default)]
pub enum ProtocolVersion {
#[default]
#[serde(rename = "beta-1")]
/// The beta-1 version of the API.
Beta1,
/// The 0.1 version of the API.
#[serde(rename = "v0.1")]
V0_1,
}

impl BundleRequest {
/// Create a new bundle request.
pub fn new(
block_num: U64,
max_block: Option<U64>,
Expand All @@ -64,6 +82,7 @@ impl BundleRequest {
}
}

/// Helper function to create a simple bundle request with sensible defaults.
FrankieIsLost marked this conversation as resolved.
Show resolved Hide resolved
pub fn make_simple(block_num: U64, transactions: Vec<BundleTx>) -> Self {
// bundle is valid for 5 blocks
let max_block = block_num.saturating_add(U64::from(5));
Expand Down