From dc45a358e63164b1e840f3eb24fc76601358875b Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Wed, 15 Jan 2025 03:08:46 +0100 Subject: [PATCH] eth and tendermint --- mm2src/coins/eth.rs | 17 ++++++++++++++--- mm2src/coins/tendermint/tendermint_coin.rs | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index b8db8c7c12..a3d461772c 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -5891,11 +5891,24 @@ impl MmCoin for EthCoin { dex_fee_amount: DexFee, stage: FeeApproxStage, ) -> TradePreimageResult { - let dex_fee_amount = wei_from_big_decimal(&dex_fee_amount.fee_amount().into(), self.decimals)?; + let fee_coin = match &self.coin_type { + EthCoinType::Eth => self.ticker.to_owned(), + EthCoinType::Erc20 { platform, .. } => platform.to_owned(), + EthCoinType::Nft { .. } => return MmError::err(TradePreimageError::NftProtocolNotSupported), + }; + if DexFee::Zero == dex_fee_amount { + return Ok(TradeFee { + coin: fee_coin, + amount: MmNumber::default(), + paid_from_trading_vol: false, + }); + } + let dex_fee_amount = wei_from_big_decimal(&dex_fee_amount.fee_amount().into(), self.decimals)?; // pass the dummy params let to_addr = addr_from_raw_pubkey(&DEX_FEE_ADDR_RAW_PUBKEY) .expect("addr_from_raw_pubkey should never fail with DEX_FEE_ADDR_RAW_PUBKEY"); + let my_address = self.derivation_method.single_addr_or_err().await?; let (eth_value, data, call_addr, fee_coin) = match &self.coin_type { EthCoinType::Eth => (dex_fee_amount, Vec::new(), &to_addr, &self.ticker), EthCoinType::Erc20 { platform, token_addr } => { @@ -5905,8 +5918,6 @@ impl MmCoin for EthCoin { }, EthCoinType::Nft { .. } => return MmError::err(TradePreimageError::NftProtocolNotSupported), }; - - let my_address = self.derivation_method.single_addr_or_err().await?; let fee_policy_for_estimate = get_swap_fee_policy_for_estimate(self.get_swap_transaction_fee_policy()); let pay_for_gas_option = self.get_swap_pay_for_gas_option(fee_policy_for_estimate).await?; let pay_for_gas_option = increase_gas_price_by_stage(pay_for_gas_option, &stage); diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 9573e6de4b..231747f765 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -2478,6 +2478,14 @@ impl MmCoin for TendermintCoin { dex_fee_amount: DexFee, _stage: FeeApproxStage, ) -> TradePreimageResult { + if DexFee::Zero == dex_fee_amount { + return Ok(TradeFee { + coin: self.ticker.clone(), + amount: MmNumber::default(), + paid_from_trading_vol: false, + }); + } + self.get_fee_to_send_taker_fee_for_denom(self.ticker.clone(), self.denom.clone(), self.decimals, dex_fee_amount) .await }