-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod protect_executor; | ||
pub mod public_1559_executor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::sync::Arc; | ||
use tracing::info; | ||
|
||
use anyhow::{Context, Result}; | ||
use artemis_core::types::Executor; | ||
use async_trait::async_trait; | ||
use ethers::{providers::Middleware, types::U256}; | ||
|
||
use crate::strategies::types::SubmitTxToMempoolWithAdvancedProfitCalculation; | ||
|
||
/// An executor that sends transactions to the public mempool. | ||
pub struct Public1559Executor<M, N> { | ||
client: Arc<M>, | ||
sender_client: Arc<N>, | ||
} | ||
|
||
impl<M: Middleware, N: Middleware> Public1559Executor<M, N> { | ||
pub fn new(client: Arc<M>, sender_client: Arc<N>) -> Self { | ||
Self { | ||
client, | ||
sender_client, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<M, N> Executor<SubmitTxToMempoolWithAdvancedProfitCalculation> for Public1559Executor<M, N> | ||
where | ||
M: Middleware, | ||
M::Error: 'static, | ||
N: Middleware, | ||
N::Error: 'static, | ||
{ | ||
/// Send a transaction to the mempool. | ||
async fn execute(&self, mut action: SubmitTxToMempoolWithAdvancedProfitCalculation) -> Result<()> { | ||
let gas_usage_result = self | ||
.client | ||
.estimate_gas(&action.execution.tx, None) | ||
.await | ||
.context("Error estimating gas usage: {}"); | ||
info!("Gas Usage {:?}", gas_usage_result); | ||
// let gas_usage = gas_usage_result?; | ||
|
||
let bid_priority_fee; | ||
let base_fee: U256 = self | ||
.client | ||
.get_gas_price() | ||
.await | ||
.context("Error getting gas price: {}")?; | ||
|
||
if let Some(gas_bid_info) = action.execution.gas_bid_info { | ||
// priority fee at which we'd break even, meaning 100% of profit goes to user in the form of price improvement | ||
// TODO: use gas estimate here | ||
bid_priority_fee = action.profit_calculation.calculate_priority_fee(gas_bid_info.bid_percentage) | ||
} else { | ||
bid_priority_fee = Some(U256::from(50)); | ||
} | ||
action.execution.tx.as_eip1559_mut().unwrap().max_fee_per_gas = Some(base_fee); | ||
action.execution.tx.as_eip1559_mut().unwrap().max_priority_fee_per_gas = bid_priority_fee; | ||
info!("Executing tx {:?}", action.execution.tx); | ||
self.sender_client.send_transaction(action.execution.tx, None).await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters