Skip to content

Commit

Permalink
Capped surplus partially fillable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Mar 13, 2024
1 parent 9c9bf73 commit e196e42
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
61 changes: 60 additions & 1 deletion crates/driver/src/tests/cases/protocol_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ async fn surplus_protocol_fee_buy_order_capped() {
},
},
};

protocol_fee_test_case(test_case).await;
}

Expand Down Expand Up @@ -299,6 +298,66 @@ async fn surplus_protocol_fee_sell_order_capped() {
protocol_fee_test_case(test_case).await;
}

#[tokio::test]
#[ignore]
async fn surplus_protocol_fee_partial_buy_order_capped() {
let fee_policy = Policy::Surplus {
factor: 0.5,
// low enough so we get capped by volume fee
max_volume_factor: 0.2,
};
let test_case = TestCase {
fee_policy,
order: Order {
sell_amount: 50.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
side: order::Side::Buy,
},
execution: Execution {
// Fee is capped at 20% of solver proposed sell volume
solver: Amounts {
sell: 25.ether().into_wei(),
buy: 28.ether().into_wei(),
},
driver: Amounts {
sell: 30.ether().into_wei(),
buy: 28.ether().into_wei(),
},
},
};
protocol_fee_test_case(test_case).await;
}

#[tokio::test]
#[ignore]
async fn surplus_protocol_fee_partial_sell_order_capped() {
let fee_policy = Policy::Surplus {
factor: 0.5,
// log enough so we get capped by volume fee
max_volume_factor: 0.1,
};
let test_case = TestCase {
fee_policy,
order: Order {
sell_amount: 50.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
side: order::Side::Sell,
},
execution: Execution {
// Fee is capped at 10% of solver proposed buy volume
solver: Amounts {
sell: 25.ether().into_wei(),
buy: 26.ether().into_wei(),
},
driver: Amounts {
sell: 25.ether().into_wei(),
buy: "23.4".ether().into_wei(),
},
},
};
protocol_fee_test_case(test_case).await;
}

#[tokio::test]
#[ignore]
async fn volume_protocol_fee_buy_order() {
Expand Down
10 changes: 8 additions & 2 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,14 @@ impl<'a> SolveOk<'a> {
fulfillment.quoted_order.buy,
),
};
assert!(u256(trade.get("sellAmount").unwrap()) == expected_sell);
assert!(u256(trade.get("buyAmount").unwrap()) == expected_buy);
let u257 = u256(trade.get("sellAmount").unwrap());
let u258 = u256(trade.get("buyAmount").unwrap());
tracing::info!("newlog u257={:?}", u257);
tracing::info!("newlog expected_sell={:?}", expected_sell);
tracing::info!("newlog u258={:?}", u258);
tracing::info!("newlog expected_buy={:?}", expected_buy);
assert!(u257 == expected_sell);
assert!(u258 == expected_buy);
}
self
}
Expand Down

0 comments on commit e196e42

Please sign in to comment.