Skip to content

Commit 342fb1b

Browse files
committed
convert atomic swaps to 'sell'
1 parent 638f99d commit 342fb1b

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

mm2src/mm2_main/src/lr_swap/lr_quote.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,19 @@ impl LrSwapCandidates {
522522
continue;
523523
};
524524
let Some(dst_amount) = lr_data_0.dst_amount else {
525-
log::debug!("estimate_lr_0_source_amounts no lr_data_0.dst_amount skipping candidate");
525+
log::debug!(
526+
"estimate_lr_0_source_amounts no lr_data_0.dst_amount for {}/{} skipping candidate",
527+
lr_data_0._src_token,
528+
lr_data_0._dst_token
529+
);
526530
continue; // We may not calculate dst_amount if no cross prices were received at LR_1
527531
};
528532
let Some(ref lr_price) = lr_data_0.lr_price else {
529-
log::debug!("estimate_lr_0_source_amounts no lr_data_0.lr_price skipping candidate");
533+
log::debug!(
534+
"estimate_lr_0_source_amounts no lr_data_0.lr_price for {}/{} skipping candidate",
535+
lr_data_0._src_token,
536+
lr_data_0._dst_token
537+
);
530538
continue;
531539
};
532540
let dst_amount = mm_number_from_u256(dst_amount);
@@ -597,13 +605,17 @@ impl LrSwapCandidates {
597605
for candidate in self.inner.iter_mut() {
598606
let taker_amount = if let Some(ref lr_data_0) = candidate.lr_data_0 {
599607
let Some(ref lr_swap_data) = lr_data_0.lr_swap_data else {
600-
log::debug!("estimate_lr_1_source_amounts_from_lr_0 lr_data_0 src_token {} dst_token={} no swap_data skipping",
601-
lr_data_0._src_token, lr_data_0._dst_token);
608+
log::debug!(
609+
"estimate_lr_1_source_amounts_from_lr_0 lr_data_0 {}/{} no swap_data skipping",
610+
lr_data_0._src_token,
611+
lr_data_0._dst_token
612+
);
602613
continue; // No LR provider quote - skip this candidate
603614
};
604615
let quote_dst_amount = U256::from_dec_str(&lr_swap_data.dst_amount)?; // Get the 'real' destination amount from the LR quote (not estimated)
605616
let est_dst_amount = candidate.lr_data_0.as_ref().and_then(|lr_data_0| lr_data_0.dst_amount);
606-
log::debug!("estimate_lr_1_source_amounts_from_lr_0 quote_dst_amount={quote_dst_amount} est_dst_amount={est_dst_amount:?}");
617+
log::debug!("estimate_lr_1_source_amounts_from_lr_0 lr_data_0 {}/{} quote_dst_amount={quote_dst_amount} est_dst_amount={est_dst_amount:?}",
618+
lr_data_0._src_token, lr_data_0._dst_token);
607619
let volume_with_fees =
608620
wei_to_coins_mm_number(quote_dst_amount, lr_data_0.dst_decimals()?).map_mm_err()?;
609621
let maker_ticker = candidate.maker_order.maker_ticker();

mm2src/mm2_main/src/rpc/lp_commands/lr_swap_api.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use lr_api_types::{AtomicSwapRpcParams, LrExecuteRoutedTradeRequest, LrExecuteRo
1010
use mm2_core::mm_ctx::MmArc;
1111
use mm2_err_handle::prelude::MmResultExt;
1212
use mm2_err_handle::{map_mm_error::MapMmError, mm_error::MmResult};
13-
use mm2_rpc::data::legacy::TakerAction;
1413

1514
#[cfg(all(test, not(target_arch = "wasm32"), feature = "test-ext-api"))]
1615
mod lr_api_tests;
@@ -57,8 +56,8 @@ pub async fn lr_find_best_quote_rpc(
5756
) -> MmResult<LrFindBestQuoteResponse, ExtApiRpcError> {
5857
// TODO: add validation:
5958
// order.base_min_volume << req.amount <= order.base_max_volume - DONE
60-
// when best order is selected validate against req.rel_max_volume and req.rel_min_volume - DONE
61-
// order.coin is supported in 1inch
59+
// when best order is selected validate against req.rel_max_volume and req.rel_min_volume (?)
60+
// order coins are supported in 1inch
6261
// order.price not zero
6362
// coins in orders should be unique (?)
6463
// Check user available balance for user_base/user_rel when selecting best swap (?)
@@ -99,28 +98,15 @@ pub async fn lr_find_best_quote_rpc(
9998
.mm_err(|err| ExtApiRpcError::OneInchDataError(err.to_string()))
10099
})
101100
.transpose()?;
102-
103-
let (base, rel, price) = match action {
104-
TakerAction::Buy => (
105-
best_order.maker_ticker(),
106-
best_order.taker_ticker(),
107-
best_order.sell_price(),
108-
),
109-
TakerAction::Sell => (
110-
best_order.taker_ticker(),
111-
best_order.maker_ticker(),
112-
best_order.buy_price(),
113-
),
114-
};
115101
Ok(LrFindBestQuoteResponse {
116102
lr_data_0,
117103
lr_data_1,
118104
atomic_swap: AtomicSwapRpcParams {
119105
volume: atomic_swap_volume,
120-
base,
121-
rel,
122-
price,
123-
method: req.method,
106+
base: best_order.taker_ticker(),
107+
rel: best_order.maker_ticker(),
108+
price: best_order.sell_price(),
109+
method: "sell".to_owned(), // Always convert to the 'sell' action to simplify LR_0 estimations
124110
order_uuid: best_order.order().uuid,
125111
match_by: None,
126112
order_type: None,

mm2src/mm2_main/src/rpc/lp_commands/lr_swap_api/lr_api_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl AskOrBidOrder {
6262
}
6363
}
6464
/// Convert to maker buy price
65+
#[allow(unused)]
6566
pub fn buy_price(&self) -> MmNumber {
6667
match self {
6768
AskOrBidOrder::Ask { order, .. } => &MmNumber::from(1) / &order.price.rational.clone().into(),

0 commit comments

Comments
 (0)