Skip to content

Commit

Permalink
save dev state
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Jan 20, 2025
1 parent f62a0de commit 2d6ae32
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5896,7 +5896,7 @@ impl MmCoin for EthCoin {
EthCoinType::Erc20 { platform, .. } => platform.to_owned(),
EthCoinType::Nft { .. } => return MmError::err(TradePreimageError::NftProtocolNotSupported),
};
if DexFee::Zero == dex_fee_amount {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: fee_coin,
amount: MmNumber::default(),
Expand Down
3 changes: 3 additions & 0 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3680,6 +3680,9 @@ impl DexFee {
Ok(None)
}
}

/// Check and return true if DexFee is not required to trade otherwise return false.
pub fn no_fee(&self) -> bool { matches!(self, Self::Zero) }
}

pub struct CoinsContext {
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ impl MmCoin for Qrc20Coin {
dex_fee_amount: DexFee,
stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: self.platform.clone(),
amount: MmNumber::default(),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ impl MmCoin for TendermintCoin {
dex_fee_amount: DexFee,
_stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: self.ticker.clone(),
amount: MmNumber::default(),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ impl MmCoin for SlpToken {
dex_fee_amount: DexFee,
stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: self.platform_coin.ticker().into(),
amount: MmNumber::default(),
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/utxo/utxo_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ fn generate_taker_fee_tx_outputs(
dex_fee: &DexFee,
) -> Result<Vec<TransactionOutput>, MmError<NumConversError>> {
// Don't add outputs for Zero DexFee.
if let DexFee::Zero = dex_fee {
if dex_fee.no_fee() {
return Ok(vec![]);
}

Expand Down Expand Up @@ -3989,7 +3989,7 @@ pub async fn get_fee_to_send_taker_fee<T>(
where
T: MarketCoinOps + UtxoCommonOps,
{
if DexFee::Zero == dex_fee {
if dex_fee.no_fee() {
return Ok(TradeFee {
coin: coin.ticker().to_owned(),
amount: MmNumber::default(),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ impl MmCoin for ZCoin {
dex_fee_amount: DexFee,
_stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: self.ticker().to_owned(),
amount: MmNumber::default(),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_main/src/lp_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ impl SwapTxDataMsg {
}
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct TransactionIdentifier {
/// Raw bytes of signed transaction in hexadecimal string, this should be sent as is to send_raw_transaction RPC to broadcast the transaction.
/// Some payments like lightning payments don't have a tx_hex, for such payments tx_hex will be equal to tx_hash.
Expand Down
8 changes: 2 additions & 6 deletions mm2src/mm2_main/src/lp_swap/maker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,9 @@ impl MakerSwap {
let taker_amount = MmNumber::from(self.taker_amount.clone());
let dex_fee = dex_fee_amount_from_taker_coin(self.taker_coin.deref(), &self.r().data.maker_coin, &taker_amount);

if coins::DexFee::Zero == dex_fee {
if dex_fee.no_fee() {
info!("Zero Dex Fee: Skipping taker fee");
let fee_ident = TransactionIdentifier {
tx_hex: BytesJson::from(vec![]),
tx_hash: BytesJson::from(vec![]),
};
swap_events.push(MakerSwapEvent::TakerFeeValidated(fee_ident));
swap_events.push(MakerSwapEvent::TakerFeeValidated(TransactionIdentifier::default()));
return Ok((Some(MakerSwapCommand::SendPayment), swap_events));
}

Expand Down
7 changes: 7 additions & 0 deletions mm2src/mm2_main/src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,13 @@ impl TakerSwap {

let fee_amount =
dex_fee_amount_from_taker_coin(self.taker_coin.deref(), &self.r().data.maker_coin, &self.taker_amount);
if fee_amount.no_fee() {
debug!("zero-dex-fee: skipping send taker fee");
return Ok((Some(TakerSwapCommand::WaitForMakerPayment), vec![
TakerSwapEvent::TakerFeeSent(TransactionIdentifier::default()),
]));
}

let fee_tx = self
.taker_coin
.send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, fee_amount, self.uuid.as_bytes(), expire_at)
Expand Down

0 comments on commit 2d6ae32

Please sign in to comment.