4.1 KiB
4.1 KiB
Artemis x Chainbound integration
This crate gives you access to the Chainbound suite of tools & services for MEV. It is built directly into the Artemis framework for seamless integration with your existing trading strategies.
This crate offers two main components, which are implemented following the standard Artemis traits:
- Fiber Collector: a low-latency, reliable
mempoolandnew_blocksstream for Ethereum. - Echo Executor: a feature-rich RPC endpoint to propagate your MEV bundles to block builders.
Usage
This example assumes you are using a new crate to implement your strategies.
First, add the following to your Cargo.toml:
[dependencies]
artemis-core = { git = "https://github.com/paradigmxyz/artemis.git" }
chainbound-artemis = { git = "https://github.com/paradigmxyz/artemis.git" }
# the following dependencies are also used in this example
ethers = { version = "2", features = ["ws", "rustls"] }
tokio = { version = "1.18", features = ["full"] }
anyhow = "1.0.70"
Then, in your main.rs:
use std::sync::Arc;
use artemis_core::{engine::Engine, types::ExecutorMap};
use chainbound_artemis::{Action, EchoExecutor, Event, FiberCollector, StreamType};
use ethers::{prelude::rand, providers::Provider, signers::LocalWallet};
#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
// Join the Chainbound Discord at https://discord.com/invite/J4KNdeCYGX
// or write to <sales@chainbound.io> to get a free trial.
let api_key = std::env::var("CHAINBOUND_API_KEY")?;
// You can select your desired object type to stream here.
// Please refer to the documentation at https://fiber.chainbound.io/docs/intro for more details.
//
// Possible values are:
// - StreamType::Transactions: new pending transactions in the mempool
// - StreamType::ExecutionHeaders: new execution headers (blocks) without the transactions
// - StreamType::ExecutionPayloads: new blocks with header + all transactions included
// - StreamType::BeaconBlocks: new beacon blocks (ETH2 consensus-layer blocks)
let stream_type = StreamType::Transactions;
// Simply create a new collector
let fiber_collector = Box::new(FiberCollector::new(api_key.clone(), stream_type).await);
// Now create the Echo Executor to send your bundles to your desired block builders.
// We also need to instantiate a regular HTTP provider middleware, and two signers
// (one to actually sign the transactions, one for Flashbots' authentication header)
//
// For more info, please refer to the documentation at https://echo.chainbound.io/docs/architecture
let provider = Arc::new(Provider::connect("wss://eth.llamarpc.com").await.unwrap());
let tx_signer = LocalWallet::new(&mut rand::thread_rng()); // or any other signer
let auth_signer = LocalWallet::new(&mut rand::thread_rng()); // or any other signer
let echo_executor = Box::new(EchoExecutor::new(provider, tx_signer, auth_signer, api_key));
let executor_map = ExecutorMap::new(echo_executor, |action| match action {
Action::SendBundle(bundle) => Some(bundle),
});
// And add these components to your Artemis engine
let mut engine: Engine<Event, Action> = Engine::default();
engine.add_collector(fiber_collector);
engine.add_executor(Box::new(executor_map));
// --- bootstrap your trading strategy here ---
// Finally, run the engine
if let Ok(mut set) = engine.run().await {
while let Some(res) = set.join_next().await {
println!("res: {:?}", res);
}
}
Ok(())
}