Skip to content

Commit

Permalink
Make execute_test() to accept impl ToString configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Mar 22, 2024
1 parent aff70ba commit 556dd23
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
27 changes: 2 additions & 25 deletions crates/autopilot/src/domain/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use {
crate::{
arguments,
boundary::{self},
domain::{
self,
fee::policy::{PriceImprovement, Surplus, Volume},
},
domain::{self},
},
app_data::Validator,
derive_more::Into,
Expand All @@ -31,29 +28,9 @@ pub struct ProtocolFee {

impl From<arguments::FeePolicy> for ProtocolFee {
fn from(policy_arg: arguments::FeePolicy) -> Self {
let policy = match policy_arg.fee_policy_kind {
arguments::FeePolicyKind::Surplus {
factor,
max_volume_factor,
} => policy::Policy::Surplus(Surplus {
factor,
max_volume_factor,
skip_market_orders: policy_arg.fee_policy_skip_market_orders,
}),
arguments::FeePolicyKind::PriceImprovement {
factor,
max_volume_factor,
} => policy::Policy::PriceImprovement(PriceImprovement {
factor,
max_volume_factor,
}),
arguments::FeePolicyKind::Volume { factor } => {
policy::Policy::Volume(Volume { factor })
}
};
Self {
policy,
max_partner_fee: policy_arg.fee_policy_max_partner_fee,
policy: policy_arg.into(),
}
}
}
Expand Down
36 changes: 30 additions & 6 deletions crates/autopilot/src/domain/fee/policy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
arguments,
boundary,
domain::{self, fee::FeeFactor},
};
Expand All @@ -10,18 +11,41 @@ pub enum Policy {
}

pub struct Surplus {
pub(crate) factor: FeeFactor,
pub(crate) max_volume_factor: FeeFactor,
pub(crate) skip_market_orders: bool,
factor: FeeFactor,
max_volume_factor: FeeFactor,
skip_market_orders: bool,
}

pub struct PriceImprovement {
pub(crate) factor: FeeFactor,
pub(crate) max_volume_factor: FeeFactor,
factor: FeeFactor,
max_volume_factor: FeeFactor,
}

pub struct Volume {
pub(crate) factor: FeeFactor,
factor: FeeFactor,
}

impl From<arguments::FeePolicy> for Policy {
fn from(policy_arg: arguments::FeePolicy) -> Self {
match policy_arg.fee_policy_kind {
arguments::FeePolicyKind::Surplus {
factor,
max_volume_factor,
} => Policy::Surplus(Surplus {
factor,
max_volume_factor,
skip_market_orders: policy_arg.fee_policy_skip_market_orders,
}),
arguments::FeePolicyKind::PriceImprovement {
factor,
max_volume_factor,
} => Policy::PriceImprovement(PriceImprovement {
factor,
max_volume_factor,
}),
arguments::FeePolicyKind::Volume { factor } => Policy::Volume(Volume { factor }),
}
}
}

impl Surplus {
Expand Down
20 changes: 10 additions & 10 deletions crates/e2e/tests/e2e/protocol_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async fn surplus_fee_sell_order_test(web3: Web3) {
// 1480603400674076736) = 1461589542731026166 DAI
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Sell,
None,
1480603400674076736u128.into(),
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn surplus_fee_sell_order_capped_test(web3: Web3) {
// 1000150353094783059) = 987306456662572858 DAI
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Sell,
None,
1000150353094783059u128.into(),
Expand All @@ -150,7 +150,7 @@ async fn volume_fee_sell_order_test(web3: Web3) {
// 1000150353094783059) = 987306456662572858 DAI
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Sell,
None,
1000150353094783059u128.into(),
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn partner_fee_sell_order_test(web3: Web3) {
// 100165388404261365) = 98879067931768848 DAI
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Sell,
Some(OrderCreationAppData::Full {
full: json!({
Expand Down Expand Up @@ -267,7 +267,7 @@ async fn surplus_fee_buy_order_test(web3: Web3) {
// Settlement contract balance after execution = executed_surplus_fee GNO
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Buy,
None,
1488043031123213136u128.into(),
Expand All @@ -292,7 +292,7 @@ async fn surplus_fee_buy_order_capped_test(web3: Web3) {
// Settlement contract balance after execution = executed_surplus_fee GNO
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Buy,
None,
504208401617866820u128.into(),
Expand All @@ -314,7 +314,7 @@ async fn volume_fee_buy_order_test(web3: Web3) {
// Settlement contract balance after execution = executed_surplus_fee GNO
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Buy,
None,
504208401617866820u128.into(),
Expand Down Expand Up @@ -352,7 +352,7 @@ async fn price_improvement_fee_sell_order_test(web3: Web3) {
// 205312824093583) = 202676203868731 DAI
execute_test(
web3.clone(),
vec![fee_policy.to_string()],
vec![fee_policy],
OrderKind::Sell,
None,
205312824093583u128.into(),
Expand All @@ -371,7 +371,7 @@ fn is_approximately_equal(executed_value: U256, expected_value: U256) -> bool {

async fn execute_test(
web3: Web3,
autopilot_config: Vec<String>,
autopilot_config: Vec<impl ToString>,
order_kind: OrderKind,
app_data: Option<OrderCreationAppData>,
expected_surplus_fee: U256,
Expand Down Expand Up @@ -449,7 +449,7 @@ async fn execute_test(
"--price-estimation-drivers=test_quoter|http://localhost:11088/test_solver".to_string(),
"--fee-policy-skip-market-orders=false".to_string(),
];
config.extend(autopilot_config);
config.extend(autopilot_config.iter().map(ToString::to_string));
services.start_autopilot(None, config);
services
.start_api(vec![
Expand Down

0 comments on commit 556dd23

Please sign in to comment.