Skip to content

Commit

Permalink
check for zero dex fee in other protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Jan 15, 2025
1 parent 49f08ac commit 1a8539a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,14 @@ impl MmCoin for Qrc20Coin {
dex_fee_amount: DexFee,
stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
return Ok(TradeFee {
coin: self.platform.clone(),
amount: MmNumber::default(),
paid_from_trading_vol: false,
});
}

let amount = wei_from_big_decimal(&dex_fee_amount.fee_amount().into(), self.utxo.decimals)?;

// pass the dummy params
Expand Down
9 changes: 9 additions & 0 deletions mm2src/coins/utxo/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,14 @@ impl MmCoin for SlpToken {
dex_fee_amount: DexFee,
stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
return Ok(TradeFee {
coin: self.platform_coin.ticker().into(),
amount: MmNumber::default(),
paid_from_trading_vol: false,
});
}

let slp_amount = sat_from_big_decimal(&dex_fee_amount.fee_amount().into(), self.decimals())?;
// can use dummy P2PKH script_pubkey here
let script_pubkey = ScriptBuilder::build_p2pkh(&H160::default().into()).into();
Expand All @@ -1861,6 +1869,7 @@ impl MmCoin for SlpToken {
&stage,
)
.await?;

Ok(TradeFee {
coin: self.platform_coin.ticker().into(),
amount: fee.into(),
Expand Down
10 changes: 9 additions & 1 deletion mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,9 +1750,17 @@ impl MmCoin for ZCoin {

async fn get_fee_to_send_taker_fee(
&self,
_dex_fee_amount: DexFee,
dex_fee_amount: DexFee,
_stage: FeeApproxStage,
) -> TradePreimageResult<TradeFee> {
if DexFee::Zero == dex_fee_amount {
return Ok(TradeFee {
coin: self.ticker().to_owned(),
amount: MmNumber::default(),
paid_from_trading_vol: false,
});
}

Ok(TradeFee {
coin: self.ticker().to_owned(),
amount: self.get_one_kbyte_tx_fee().await?.into(),
Expand Down

0 comments on commit 1a8539a

Please sign in to comment.