feat(tpu): implement 0 dexfee for kmd trading pairs#2323
Conversation
mm2src/coins/eth.rs
Outdated
| 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), | ||
| }; |
There was a problem hiding this comment.
You can use platform_ticker instead. I am not sure if you intentionally drop the nft support, but if we want to do that we need to add a if check before using platform_ticker.
mm2src/coins/lp_coins.rs
Outdated
| /// Check and return true if DexFee is not required to trade otherwise return false. | ||
| pub fn no_fee(&self) -> bool { matches!(self, Self::Zero) } |
There was a problem hiding this comment.
| /// Check and return true if DexFee is not required to trade otherwise return false. | |
| pub fn no_fee(&self) -> bool { matches!(self, Self::Zero) } | |
| /// Check and return true if DexFee is not required to trade otherwise return false. | |
| pub fn zero_fee(&self) -> bool { matches!(self, Self::Zero) } |
onur-ozkan
left a comment
There was a problem hiding this comment.
Previous notes are also still valid
mm2src/coins/utxo/slp.rs
Outdated
| ) -> TradePreimageResult<TradeFee> { | ||
| if dex_fee_amount.no_fee() { | ||
| return Ok(TradeFee { | ||
| coin: self.platform_coin.ticker().into(), |
There was a problem hiding this comment.
nit:
| coin: self.platform_coin.ticker().into(), | |
| coin: self.platform_coin.ticker().to_owned(), |
| }; | ||
| swap_events.push(MakerSwapEvent::MakerPaymentInstructionsReceived(instructions)); | ||
|
|
||
| let taker_amount = MmNumber::from(self.taker_amount.clone()); |
There was a problem hiding this comment.
MmNumber::from only takes a reference inside the function. You can implement:
impl From<&BigDecimal> for MmNumber {
fn from(n: &BigDecimal) -> MmNumber { from_dec_to_ratio(n).into() }
}to avoid unnecessary cloning in cases like this.
There was a problem hiding this comment.
@borngraced could you please introduce From<&BigDecimal> for MmNumber and start using it for your changes. after pr merge someone can take refactoring as a separate task.
|
@borngraced could you tell why status is blocked? or was it misclick? |
onur-ozkan
left a comment
There was a problem hiding this comment.
Just a couple of non-blocker tiny nits, thanks for the fixes!
LGTM
mm2src/coins/lp_coins.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// Check and return true if DexFee is not required to trade otherwise return false. |
There was a problem hiding this comment.
tiny nit:
| /// Check and return true if DexFee is not required to trade otherwise return false. | |
| /// Whether this is DexFee::Zero. |
| let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker(); | ||
| let dex_fee = if is_kmd { | ||
| DexFee::Zero |
There was a problem hiding this comment.
| let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker(); | |
| let dex_fee = if is_kmd { | |
| DexFee::Zero | |
| let dex_fee = if "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker() { | |
| DexFee::Zero |
| let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker(); | ||
| let dex_fee = if is_kmd { | ||
| DexFee::Zero |
There was a problem hiding this comment.
| let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker(); | |
| let dex_fee = if is_kmd { | |
| DexFee::Zero | |
| let dex_fee = if "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker() { | |
| DexFee::Zero |
this #2112 seems related and not sure which one will be merge first as both have some similar changes |
laruh
left a comment
There was a problem hiding this comment.
Thanks, next iteration
also please re check zero fee leftovers in legacy functionality
mm2src/coins/utxo/utxo_common.rs
Outdated
| let sig_hash_type = match args.dex_fee { | ||
| DexFee::Standard(_) => SIGHASH_SINGLE, | ||
| DexFee::WithBurn { .. } => SIGHASH_ALL, | ||
| DexFee::WithBurn { .. } | DexFee::Zero => SIGHASH_ALL, |
There was a problem hiding this comment.
Could you clarify why we should use SIGHASH_ALL for zero fee?
There was a problem hiding this comment.
SIGHASH_ALL: Signs all inputs and outputs, preventing any changes after signing
SIGHASH_SINGLE: Only signs the input and the corresponding output at the same index, allowing other outputs to be modified.
I guess using either for zero fees won't make a significant diff. cc @dimxy
There was a problem hiding this comment.
ok I was just curious will it be the difference for zero fee, as for Standard dex fee we use SIGHASH_SINGLE
There was a problem hiding this comment.
Yes, we should use SIGHASH_ALL wherever possible.
SIGHASH_SINGLE could be used only in a special case (DexFee::Standard) when maker can add an output to the spending taker payment transaction (with only a single dexfee output signed by the taker with the SIGHASH_SINGLE flag), without the other party signature.
(this is how the SIGHASH_SINGLE feature works)
laruh
left a comment
There was a problem hiding this comment.
Almost done!
pls update SEPOLIA_TAKER_SWAP_V2 address to this one 0x3B19873b81a6B426c8B2323955215F7e89CfF33F
above SEPOLIA_TAKER_SWAP_V2 you can leave comment that this version was deployed
https://github.com/KomodoPlatform/etomic-swap/blob/bbdeb369eab0753454dae29640adaa4fdba221ba/contracts/EtomicSwapTakerV2.sol
and in taker_send_approve_and_spend_erc20 test change dex fee to &DexFee::Zero
https://github.com/KomodoPlatform/komodo-defi-framework/blob/8ba9aaba47b56b990d132df37d3abbc74aa94cd6/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs#L1806
|
Blocked as this requires merging #2112 first |
dimxy
left a comment
There was a problem hiding this comment.
Approving.
This PR is very close to #2112.
#2112 is larger in size and changes how DexFee is created (in a dedicated function) so it will affect this PR code.
I think it's easier to merge this PR first and then incorporate the changes into #2112.
(Maybe it's good to add a full swap test for zero dexfee though)
# Conflicts: # mm2src/coins/lp_coins.rs # mm2src/coins/utxo/utxo_common.rs # mm2src/mm2_main/src/lp_swap.rs # mm2src/mm2_main/src/lp_swap/maker_swap.rs # mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs # mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs # mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs
shamardy
left a comment
There was a problem hiding this comment.
LGTM! I have 2 questions about what appears to be unneeded changes.
* dev: improvement(best-orders): return an rpc error when we can't find best orders (#2318) feat(utxo): support FIRO Spark verbose tx feat(ARRR): dockerize zombie/pirate tests (#2374) improvement(event-streaming): move UnknownClient error to trace level (#2401) feat(tpu): implement 0 dexfee for kmd trading pairs (#2323) feat(db-arch): ctx functions and use of global db (#2378) feat(swap): add utxo/cosmos/ARRR pre-burn address output (#2112)
* lr-swap-wip: (45 commits) review (mariocynicys): fix iterators zipping, refactor 1inch url builder, add docs to cross prices data, remove extra coin decimals check added doc comments for LrData struct error msg improved fix tx value eth conversion eliminate from_api_error fn fix src_decimals var name improve bad api TokenInfo error messages improvement(best-orders): return an rpc error when we can't find best orders (GLEECBTC#2318) feat(utxo): support FIRO Spark verbose tx feat(ARRR): dockerize zombie/pirate tests (GLEECBTC#2374) improvement(event-streaming): move UnknownClient error to trace level (GLEECBTC#2401) feat(tpu): implement 0 dexfee for kmd trading pairs (GLEECBTC#2323) feat(db-arch): ctx functions and use of global db (GLEECBTC#2378) feat(swap): add utxo/cosmos/ARRR pre-burn address output (GLEECBTC#2112) review (laruh): rename fn review (laruh): add fn to get contracts from LrData add TODO fix find best lr swap behaviour: skip lr provider error results (to use successful ones) refactor 1inch url builder fix 1inch result conversion test ...
#2320
#2338