Skip to content

Commit

Permalink
Explicit fee amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Mar 5, 2024
1 parent 38135e8 commit 287c1f9
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions crates/driver/src/tests/cases/protocol_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct TestCase {
order_side: order::Side,
fee_policy: FeePolicy,
order_sell_amount: eth::U256,
solver_fee: Option<eth::U256>,
network_fee: Option<eth::U256>,
quote_sell_amount: eth::U256,
quote_buy_amount: eth::U256,
executed: eth::U256,
Expand All @@ -44,7 +44,7 @@ async fn protocol_fee_test_case(test_case: TestCase) {
.kind(order::Kind::Limit)
.sell_amount(test_case.order_sell_amount)
.side(test_case.order_side)
.solver_fee(test_case.solver_fee)
.solver_fee(test_case.network_fee)
.fee_policy(test_case.fee_policy)
.executed(test_case.executed)
.expected_amounts(expected_amounts);
Expand All @@ -71,7 +71,7 @@ async fn surplus_protocol_fee_buy_order_not_capped() {
order_side: order::Side::Buy,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -94,7 +94,7 @@ async fn surplus_protocol_fee_sell_order_not_capped() {
order_side: order::Side::Sell,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -117,7 +117,7 @@ async fn surplus_protocol_fee_buy_order_capped() {
order_side: order::Side::Buy,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -140,7 +140,7 @@ async fn surplus_protocol_fee_sell_order_capped() {
order_side: order::Side::Sell,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -159,7 +159,7 @@ async fn volume_protocol_fee_buy_order() {
order_side: order::Side::Buy,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -178,7 +178,7 @@ async fn volume_protocol_fee_sell_order() {
order_side: order::Side::Sell,
fee_policy,
order_sell_amount: 50000000000000000000u128.into(),
solver_fee: Some(10000000000000000000u128.into()),
network_fee: Some(10000000000000000000u128.into()),
quote_sell_amount: 50000000000000000000u128.into(),
quote_buy_amount: 40000000000000000000u128.into(),
executed: 40000000000000000000u128.into(),
Expand All @@ -192,16 +192,13 @@ async fn volume_protocol_fee_sell_order() {
#[tokio::test]
#[ignore]
async fn price_improvement_fee_buy_out_of_market_order() {
let quote_sell_amount = 50000000000000000000u128.into();
let quote_buy_amount = 35000000000000000000u128.into();
let fee: eth::U256 = 1000000000000000000u128.into();
let fee_policy = FeePolicy::PriceImprovement {
factor: 0.5,
max_volume_factor: 1.0,
quote: PriceImprovementQuote {
sell_amount: quote_sell_amount,
buy_amount: quote_buy_amount,
fee,
sell_amount: 50000000000000000000u128.into(),
buy_amount: 35000000000000000000u128.into(),
fee: 1000000000000000000u128.into(),
},
};
let order_sell_amount = 50000000000000000000u128.into();
Expand All @@ -210,7 +207,7 @@ async fn price_improvement_fee_buy_out_of_market_order() {
order_side: order::Side::Buy,
fee_policy,
order_sell_amount,
solver_fee: Some(fee),
network_fee: Some(2000000000000000000u128.into()),
quote_sell_amount: order_sell_amount,
quote_buy_amount: order_buy_amount,
executed: order_buy_amount,
Expand All @@ -224,28 +221,26 @@ async fn price_improvement_fee_buy_out_of_market_order() {
#[tokio::test]
#[ignore]
async fn price_improvement_fee_sell_out_of_market_order() {
let quote_sell_amount = 50000000000000000000u128.into();
let quote_buy_amount = 35000000000000000000u128.into();
let fee: eth::U256 = 1000000000000000000u128.into();
let fee_policy = FeePolicy::PriceImprovement {
factor: 0.5,
max_volume_factor: 1.0,
quote: PriceImprovementQuote {
sell_amount: quote_sell_amount,
buy_amount: quote_buy_amount,
fee,
sell_amount: 50000000000000000000u128.into(),
buy_amount: 35000000000000000000u128.into(),
fee: 1000000000000000000u128.into(),
},
};
let order_sell_amount = 50000000000000000000u128.into();
let order_buy_amount = 40000000000000000000u128.into();
let network_fee = 2000000000000000000u128.into();
let test_case = TestCase {
order_side: order::Side::Sell,
fee_policy,
order_sell_amount,
solver_fee: Some(fee),
network_fee: Some(network_fee),
quote_sell_amount: order_sell_amount,
quote_buy_amount: order_buy_amount,
executed: order_sell_amount - fee,
executed: order_sell_amount - network_fee,
executed_sell_amount: order_sell_amount,
executed_buy_amount: 37156862745098039215u128.into(),
};
Expand All @@ -256,25 +251,22 @@ async fn price_improvement_fee_sell_out_of_market_order() {
#[tokio::test]
#[ignore]
async fn price_improvement_fee_buy_in_market_order() {
let quote_sell_amount: eth::U256 = 50000000000000000000u128.into();
let quote_buy_amount: eth::U256 = 40000000000000000000u128.into();
let fee = 1000000000000000000u128.into();
let fee_policy = FeePolicy::PriceImprovement {
factor: 0.5,
max_volume_factor: 1.0,
quote: PriceImprovementQuote {
sell_amount: quote_sell_amount,
buy_amount: quote_buy_amount,
fee,
sell_amount: 50000000000000000000u128.into(),
buy_amount: 40000000000000000000u128.into(),
fee: 1000000000000000000u128.into(),
},
};
let order_sell_amount = 50000000000000000000u128.into();
let order_buy_amount = 35000000000000000000u128.into();
let test_case = TestCase {
order_side: order::Side::Buy,
fee_policy,
order_sell_amount: quote_sell_amount,
solver_fee: Some(fee),
order_sell_amount,
network_fee: Some(2000000000000000000u128.into()),
quote_sell_amount: order_sell_amount,
quote_buy_amount: order_buy_amount,
executed: order_buy_amount,
Expand All @@ -288,28 +280,26 @@ async fn price_improvement_fee_buy_in_market_order() {
#[tokio::test]
#[ignore]
async fn price_improvement_fee_sell_in_market_order() {
let quote_sell_amount: eth::U256 = 50000000000000000000u128.into();
let quote_buy_amount: eth::U256 = 40000000000000000000u128.into();
let fee = 1000000000000000000u128.into();
let fee_policy = FeePolicy::PriceImprovement {
factor: 0.5,
max_volume_factor: 1.0,
quote: PriceImprovementQuote {
sell_amount: quote_sell_amount,
buy_amount: quote_buy_amount,
fee,
sell_amount: 50000000000000000000u128.into(),
buy_amount: 40000000000000000000u128.into(),
fee: 1000000000000000000u128.into(),
},
};
let order_sell_amount: eth::U256 = 50000000000000000000u128.into();
let order_buy_amount: eth::U256 = 35000000000000000000u128.into();
let network_fee = 20000000000000000000u128.into();
let test_case = TestCase {
order_side: order::Side::Sell,
fee_policy,
order_sell_amount,
solver_fee: Some(fee),
network_fee: Some(network_fee),
quote_sell_amount: order_sell_amount,
quote_buy_amount: order_buy_amount,
executed: order_sell_amount - fee,
executed: order_sell_amount - network_fee,
executed_sell_amount: order_sell_amount,
executed_buy_amount: order_buy_amount,
};
Expand Down

0 comments on commit 287c1f9

Please sign in to comment.