-
Notifications
You must be signed in to change notification settings - Fork 86
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
22 changed files
with
178 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
risk-parameters = [0,0,0,0] |
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,26 @@ | ||
use super::{auction::GasPrice, eth::Gas}; | ||
|
||
/// Parameters that define the possibility of a revert when executing a | ||
/// solution. | ||
#[derive(Debug, Default, Clone)] | ||
pub struct Risk { | ||
pub gas_amount_factor: f64, | ||
pub gas_price_factor: f64, | ||
pub nmb_orders_factor: f64, | ||
pub intercept: f64, | ||
} | ||
|
||
impl Risk { | ||
pub fn success_probability( | ||
&self, | ||
gas_amount: Gas, | ||
gas_price: GasPrice, | ||
nmb_orders: usize, | ||
) -> f64 { | ||
let exponent = -self.intercept | ||
- self.gas_amount_factor * gas_amount.0.to_f64_lossy() / 1_000_000. | ||
- self.gas_price_factor * gas_price.0 .0.to_f64_lossy() / 10_000_000_000. | ||
- self.nmb_orders_factor * nmb_orders as f64; | ||
1. / (1. + exponent.exp()) | ||
} | ||
} |
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
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,40 @@ | ||
use { | ||
crate::{ | ||
domain::{solver::naive, Risk}, | ||
infra::config::unwrap_or_log, | ||
}, | ||
serde::Deserialize, | ||
serde_with::serde_as, | ||
std::path::Path, | ||
tokio::fs, | ||
}; | ||
|
||
#[serde_as] | ||
#[derive(Deserialize)] | ||
#[serde(rename_all = "kebab-case", deny_unknown_fields)] | ||
struct Config { | ||
/// Parameters used to calculate the revert risk of a solution. | ||
/// (gas_amount_factor, gas_price_factor, nmb_orders_factor, intercept) | ||
risk_parameters: (f64, f64, f64, f64), | ||
} | ||
|
||
/// Load the driver configuration from a TOML file. | ||
/// | ||
/// # Panics | ||
/// | ||
/// This method panics if the config is invalid or on I/O errors. | ||
pub async fn load(path: &Path) -> naive::Config { | ||
let data = fs::read_to_string(path) | ||
.await | ||
.unwrap_or_else(|e| panic!("I/O error while reading {path:?}: {e:?}")); | ||
// Not printing detailed error because it could potentially leak secrets. | ||
let config = unwrap_or_log(toml::de::from_str::<Config>(&data), &path); | ||
naive::Config { | ||
risk: Risk { | ||
gas_amount_factor: config.risk_parameters.0, | ||
gas_price_factor: config.risk_parameters.1, | ||
nmb_orders_factor: config.risk_parameters.2, | ||
intercept: config.risk_parameters.3, | ||
}, | ||
} | ||
} |
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
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
Oops, something went wrong.