Skip to content

Commit 385b382

Browse files
committed
Don't force the taker to send all amount they offered in the Buy action
1 parent e19e1c5 commit 385b382

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

mm2src/mm2_main/src/lp_ordermatch.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,16 +2096,17 @@ impl MakerOrder {
20962096
return OrderMatchResult::NotMatched;
20972097
}
20982098

2099+
let result_rel_amount = taker_base_amount * &self.price;
2100+
20992101
if is_legacy {
21002102
// Legacy mode: use maker's price to calculate rel amount
2101-
OrderMatchResult::Matched((taker_base_amount.clone(), taker_base_amount * &self.price))
2103+
OrderMatchResult::Matched((taker_base_amount.clone(), result_rel_amount))
21022104
} else {
21032105
// taker_rel_amount must cover the premium requested by maker
2104-
let required_rel_amount =
2105-
taker_base_amount * &self.price + self.premium.clone().unwrap_or_default();
2106+
let required_rel_amount = result_rel_amount + self.premium.clone().unwrap_or_default();
21062107
if taker_rel_amount >= &required_rel_amount {
2107-
// TPU mode: treat buy as a limit order using taker's base and rel amounts
2108-
OrderMatchResult::Matched((taker_base_amount.clone(), taker_rel_amount.clone()))
2108+
// TPU mode: treat buy as a limit order using taker's base amount and required_rel_amount
2109+
OrderMatchResult::Matched((taker_base_amount.clone(), required_rel_amount))
21092110
} else {
21102111
OrderMatchResult::NotMatched
21112112
}

mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,8 @@ struct UtxoSwapV2TestParams {
629629
premium: Option<f64>,
630630
taker_method: TakerMethod,
631631
/// Expected locked amount on Bob’s side before maker payment is sent
632-
/// E.g. "777.00001"
633632
expected_bob_locked_amount: &'static str,
634633
/// Expected locked amount on Alice’s side before taker funding is sent
635-
/// E.g. "778.00779"
636634
expected_alice_locked_amount: &'static str,
637635
}
638636

@@ -771,12 +769,12 @@ fn test_v2_swap_utxo_utxo_impl_common(params: UtxoSwapV2TestParams) {
771769
fn test_v2_swap_utxo_utxo() {
772770
test_v2_swap_utxo_utxo_impl_common(UtxoSwapV2TestParams {
773771
maker_price: 1.0,
774-
taker_price: 1.00001,
775-
volume: 777.0,
776-
premium: Some(0.007),
772+
taker_price: 1.001,
773+
volume: 777.,
774+
premium: Some(0.777),
777775
taker_method: TakerMethod::Buy,
778776
expected_bob_locked_amount: "777.00001",
779-
expected_alice_locked_amount: "778.00779",
777+
expected_alice_locked_amount: "778.77801",
780778
});
781779
}
782780

@@ -786,12 +784,12 @@ fn test_v2_swap_utxo_utxo_burnkey_as_alice() {
786784
SET_BURN_PUBKEY_TO_ALICE.set(true);
787785
test_v2_swap_utxo_utxo_impl_common(UtxoSwapV2TestParams {
788786
maker_price: 1.0,
789-
taker_price: 1.00001,
787+
taker_price: 1.001,
790788
volume: 777.0,
791-
premium: Some(0.007),
789+
premium: Some(0.777),
792790
taker_method: TakerMethod::Buy,
793791
expected_bob_locked_amount: "777.00001",
794-
expected_alice_locked_amount: "777.00778", // no dex fee if dex pubkey is alice
792+
expected_alice_locked_amount: "777.77701", // no dex fee if dex pubkey is alice
795793
});
796794
}
797795

0 commit comments

Comments
 (0)