Skip to content

feat(tpu): implement 0 dexfee for kmd trading pairs#2323

Merged
shamardy merged 24 commits intodevfrom
0-kmd-dex-fee
Mar 28, 2025
Merged

feat(tpu): implement 0 dexfee for kmd trading pairs#2323
shamardy merged 24 commits intodevfrom
0-kmd-dex-fee

Conversation

@borngraced
Copy link
Copy Markdown

@borngraced borngraced commented Jan 16, 2025

@borngraced borngraced self-assigned this Jan 16, 2025
@borngraced borngraced changed the title feat:(swap) implement 0 dexfee for kmd trading pairs feat(swap) implement 0 dexfee for kmd trading pairs Jan 16, 2025
@borngraced borngraced changed the title feat(swap) implement 0 dexfee for kmd trading pairs feat(swap): implement 0 dexfee for kmd trading pairs Jan 16, 2025
Comment on lines +5894 to +5898
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),
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +3684 to +3685
/// Check and return true if DexFee is not required to trade otherwise return false.
pub fn no_fee(&self) -> bool { matches!(self, Self::Zero) }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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) }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous notes are also still valid

) -> TradePreimageResult<TradeFee> {
if dex_fee_amount.no_fee() {
return Ok(TradeFee {
coin: self.platform_coin.ticker().into(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
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());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we have such issue
#2338

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@laruh
Copy link
Copy Markdown

laruh commented Feb 19, 2025

@borngraced could you tell why status is blocked? or was it misclick?

onur-ozkan
onur-ozkan previously approved these changes Feb 19, 2025
Copy link
Copy Markdown

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of non-blocker tiny nits, thanks for the fixes!

LGTM

}
}

/// Check and return true if DexFee is not required to trade otherwise return false.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit:

Suggested change
/// Check and return true if DexFee is not required to trade otherwise return false.
/// Whether this is DexFee::Zero.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +619 to +621
let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker();
let dex_fee = if is_kmd {
DexFee::Zero
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +735 to +737
let is_kmd = "KMD" == recreate_ctx.maker_coin.ticker() || "KMD" == recreate_ctx.taker_coin.ticker();
let dex_fee = if is_kmd {
DexFee::Zero
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@borngraced
Copy link
Copy Markdown
Author

borngraced commented Feb 19, 2025

@borngraced could you tell why status is blocked? or was it misclick?

this #2112 seems related and not sure which one will be merge first as both have some similar changes

laruh
laruh previously approved these changes Feb 19, 2025
Copy link
Copy Markdown

@laruh laruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown

@laruh laruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, next iteration
also please re check zero fee leftovers in legacy functionality

let sig_hash_type = match args.dex_fee {
DexFee::Standard(_) => SIGHASH_SINGLE,
DexFee::WithBurn { .. } => SIGHASH_ALL,
DexFee::WithBurn { .. } | DexFee::Zero => SIGHASH_ALL,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why we should use SIGHASH_ALL for zero fee?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I was just curious will it be the difference for zero fee, as for Standard dex fee we use SIGHASH_SINGLE

Copy link
Copy Markdown
Collaborator

@dimxy dimxy Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

@laruh laruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

laruh
laruh previously approved these changes Mar 6, 2025
Copy link
Copy Markdown

@laruh laruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM!

@shamardy
Copy link
Copy Markdown
Collaborator

shamardy commented Mar 6, 2025

Blocked as this requires merging #2112 first

@shamardy shamardy requested review from dimxy and shamardy March 17, 2025 11:19
dimxy
dimxy previously approved these changes Mar 17, 2025
Copy link
Copy Markdown
Collaborator

@dimxy dimxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@borngraced borngraced dismissed stale reviews from dimxy and laruh via 0d3be66 March 25, 2025 11:32
Copy link
Copy Markdown
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have 2 questions about what appears to be unneeded changes.

@shamardy shamardy changed the title feat(swap): implement 0 dexfee for kmd trading pairs feat(tpu): implement 0 dexfee for kmd trading pairs Mar 28, 2025
@shamardy shamardy merged commit 9c6f1ee into dev Mar 28, 2025
26 of 27 checks passed
@shamardy shamardy deleted the 0-kmd-dex-fee branch March 28, 2025 22:31
dimxy pushed a commit that referenced this pull request Apr 7, 2025
* 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)
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request May 27, 2025
* 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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants