Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix get_receiver_trade_fee for cosmos #1767

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- - Break the loop right after processing any of `SWAP_PREFIX`, `WATCHER_PREFIX`, `TX_HELPER_PREFIX` topic.
- An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757)
- optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759)
- fix receiver trade fee for cosmos swaps [#1767](https://github.com/KomodoPlatform/atomicDEX-API/pull/1767)


## v1.0.2-beta - 2023-04-11
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4320,7 +4320,7 @@ impl MmCoin for EthCoin {
})
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
let coin = self.clone();
let fut = async move {
let gas_price = coin.get_gas_price().compat().await?;
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ fn get_receiver_trade_preimage() {
};

let actual = coin
.get_receiver_trade_fee(Default::default(), FeeApproxStage::WithoutApprox)
.get_receiver_trade_fee(FeeApproxStage::WithoutApprox)
.wait()
.expect("!get_sender_trade_fee");
assert_eq!(actual, expected_fee);
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ impl MmCoin for LightningCoin {
}

// Todo: This uses dummy data for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning
fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
Box::new(futures01::future::ok(TradeFee {
coin: self.ticker().to_owned(),
amount: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ pub trait MmCoin:
) -> TradePreimageResult<TradeFee>;

/// Get fee to be paid by receiver per whole swap and check if the wallet has sufficient balance to pay the fee.
fn get_receiver_trade_fee(&self, send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut<TradeFee>;
fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut<TradeFee>;

/// Get transaction fee the Taker has to pay to send a `TakerFee` transaction and check if the wallet has sufficient balance to pay the fee.
async fn get_fee_to_send_taker_fee(
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ impl MmCoin for Qrc20Coin {
})
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
let selfi = self.clone();
let fut = async move {
// pass the dummy params
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20/qrc20_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ fn test_receiver_trade_preimage() {
check_tx_fee(&coin, ActualTxFee::FixedPerKb(EXPECTED_TX_FEE as u64));

let actual = coin
.get_receiver_trade_fee(Default::default(), FeeApproxStage::WithoutApprox)
.get_receiver_trade_fee(FeeApproxStage::WithoutApprox)
.wait()
.expect("!get_receiver_trade_fee");
// only one contract call should be included into the expected trade fee
Expand Down
4 changes: 1 addition & 3 deletions mm2src/coins/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,7 @@ impl MmCoin for SolanaCoin {
unimplemented!()
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
unimplemented!()
}
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> { unimplemented!() }

async fn get_fee_to_send_taker_fee(
&self,
Expand Down
4 changes: 1 addition & 3 deletions mm2src/coins/solana/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ impl MmCoin for SplToken {
unimplemented!()
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
unimplemented!()
}
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> { unimplemented!() }

async fn get_fee_to_send_taker_fee(
&self,
Expand Down
11 changes: 8 additions & 3 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1988,13 +1988,18 @@ impl MmCoin for TendermintCoin {
.await
}

fn get_receiver_trade_fee(&self, send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
let coin = self.clone();
let fut = async move {
// We can't simulate Claim Htlc without having information about broadcasted htlc tx.
// Since create and claim htlc fees are almost same, we can simply simulate create htlc tx.
coin.get_sender_trade_fee_for_denom(coin.ticker.clone(), coin.denom.clone(), coin.decimals, send_amount)
.await
coin.get_sender_trade_fee_for_denom(
coin.ticker.clone(),
coin.denom.clone(),
coin.decimals,
coin.min_tx_amount(),
)
.await
};
Box::new(fut.boxed().compat())
}
Expand Down
9 changes: 7 additions & 2 deletions mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,19 @@ impl MmCoin for TendermintToken {
.await
}

fn get_receiver_trade_fee(&self, send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
let token = self.clone();
let fut = async move {
// We can't simulate Claim Htlc without having information about broadcasted htlc tx.
// Since create and claim htlc fees are almost same, we can simply simulate create htlc tx.
token
.platform_coin
.get_sender_trade_fee_for_denom(token.ticker.clone(), token.denom.clone(), token.decimals, send_amount)
.get_sender_trade_fee_for_denom(
token.ticker.clone(),
token.denom.clone(),
token.decimals,
token.min_tx_amount(),
)
.await
};
Box::new(fut.boxed().compat())
Expand Down
4 changes: 1 addition & 3 deletions mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ impl MmCoin for TestCoin {
unimplemented!()
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
unimplemented!()
}
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> { unimplemented!() }

async fn get_fee_to_send_taker_fee(
&self,
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ impl MmCoin for BchCoin {
utxo_common::get_sender_trade_fee(self, value, stage).await
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
utxo_common::get_receiver_trade_fee(self.clone())
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/qtum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ impl MmCoin for QtumCoin {
utxo_common::get_sender_trade_fee(self, value, stage).await
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
utxo_common::get_receiver_trade_fee(self.clone())
}

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 @@ -1788,7 +1788,7 @@ impl MmCoin for SlpToken {
})
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
let coin = self.clone();

let fut = async move {
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/utxo_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl MmCoin for UtxoStandardCoin {
utxo_common::get_sender_trade_fee(self, value, stage).await
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
utxo_common::get_receiver_trade_fee(self.clone())
}

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 @@ -1618,7 +1618,7 @@ impl MmCoin for ZCoin {
})
}

fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut<TradeFee> {
utxo_common::get_receiver_trade_fee(self.clone())
}

Expand Down
12 changes: 4 additions & 8 deletions mm2src/mm2_main/src/lp_ordermatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4545,13 +4545,9 @@ async fn cancel_orders_on_error<T, E>(ctx: &MmArc, req: &SetPriceReq, error: E)
Err(error)
}

pub async fn check_other_coin_balance_for_order_issue(
ctx: &MmArc,
other_coin: &MmCoinEnum,
my_coin_volume: BigDecimal,
) -> CheckBalanceResult<()> {
pub async fn check_other_coin_balance_for_order_issue(ctx: &MmArc, other_coin: &MmCoinEnum) -> CheckBalanceResult<()> {
let trade_fee = other_coin
.get_receiver_trade_fee(my_coin_volume, FeeApproxStage::OrderIssue)
.get_receiver_trade_fee(FeeApproxStage::OrderIssue)
.compat()
.await
.mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?;
Expand Down Expand Up @@ -4605,7 +4601,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result<MakerOr
.or_else(|e| cancel_orders_on_error(ctx, &req, e))
.await
);
try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin, volume.to_decimal()).await);
try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin).await);
(volume, balance.to_decimal())
} else {
let balance = try_s!(
Expand Down Expand Up @@ -4779,7 +4775,7 @@ pub async fn update_maker_order(ctx: &MmArc, req: MakerOrderUpdateReq) -> Result
// Calculate order volume and add to update_msg if new_volume is found in the request
let new_volume = if req.max.unwrap_or(false) {
let max_volume = try_s!(get_max_maker_vol(ctx, &base_coin).await).volume + reserved_amount.clone();
try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin, max_volume.to_decimal()).await);
try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin).await);
update_msg.with_new_max_volume(max_volume.clone().into());
max_volume
} else if Option::is_some(&req.volume_delta) {
Expand Down
8 changes: 3 additions & 5 deletions mm2src/mm2_main/src/lp_swap/maker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ impl MakerSwap {
)]))
},
};
let taker_payment_spend_trade_fee_fut = self
.taker_coin
.get_receiver_trade_fee(self.maker_amount.clone(), stage.clone());
let taker_payment_spend_trade_fee_fut = self.taker_coin.get_receiver_trade_fee(stage.clone());
let taker_payment_spend_trade_fee = match taker_payment_spend_trade_fee_fut.compat().await {
Ok(fee) => fee,
Err(e) => {
Expand Down Expand Up @@ -2149,7 +2147,7 @@ pub async fn check_balance_for_maker_swap(
.await
.mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, my_coin.ticker()))?;
let taker_payment_spend_trade_fee = other_coin
.get_receiver_trade_fee(volume.to_decimal(), stage)
.get_receiver_trade_fee(stage)
.compat()
.await
.mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?;
Expand Down Expand Up @@ -2203,7 +2201,7 @@ pub async fn maker_swap_trade_preimage(
.await
.mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, base_coin_ticker))?;
let rel_coin_fee = rel_coin
.get_receiver_trade_fee(volume.to_decimal(), FeeApproxStage::TradePreimage)
.get_receiver_trade_fee(FeeApproxStage::TradePreimage)
.compat()
.await
.mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, rel_coin_ticker))?;
Expand Down
8 changes: 3 additions & 5 deletions mm2src/mm2_main/src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,9 +971,7 @@ impl TakerSwap {
)]))
},
};
let maker_payment_spend_trade_fee_fut = self
.maker_coin
.get_receiver_trade_fee(self.taker_amount.to_decimal(), stage.clone());
let maker_payment_spend_trade_fee_fut = self.maker_coin.get_receiver_trade_fee(stage.clone());
let maker_payment_spend_trade_fee = match maker_payment_spend_trade_fee_fut.compat().await {
Ok(fee) => fee,
Err(e) => {
Expand Down Expand Up @@ -2257,7 +2255,7 @@ pub async fn check_balance_for_taker_swap(
.await
.mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, my_coin.ticker()))?;
let maker_payment_spend_trade_fee = other_coin
.get_receiver_trade_fee(volume.to_decimal(), stage)
.get_receiver_trade_fee(stage)
.compat()
.await
.mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?;
Expand Down Expand Up @@ -2352,7 +2350,7 @@ pub async fn taker_swap_trade_preimage(
.await
.mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, my_coin_ticker))?;
let other_coin_trade_fee = other_coin
.get_receiver_trade_fee(my_coin_volume.to_decimal(), stage.clone())
.get_receiver_trade_fee(stage.clone())
.compat()
.await
.mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, other_coin_ticker))?;
Expand Down