-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(swap): implement 0 dexfee for kmd trading pairs #2323
base: dev
Are you sure you want to change the base?
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.
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
.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this 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
mm2src/coins/utxo/slp.rs
Outdated
@@ -1844,6 +1844,14 @@ impl MmCoin for SlpToken { | |||
dex_fee_amount: DexFee, | |||
stage: FeeApproxStage, | |||
) -> TradePreimageResult<TradeFee> { | |||
if dex_fee_amount.no_fee() { | |||
return Ok(TradeFee { | |||
coin: self.platform_coin.ticker().into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
coin: self.platform_coin.ticker().into(), | |
coin: self.platform_coin.ticker().to_owned(), |
@@ -739,6 +739,15 @@ impl MakerSwap { | |||
}; | |||
swap_events.push(MakerSwapEvent::MakerPaymentInstructionsReceived(instructions)); | |||
|
|||
let taker_amount = MmNumber::from(self.taker_amount.clone()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@borngraced could you tell why status is blocked? or was it misclick? |
There was a problem hiding this 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
mm2src/coins/lp_coins.rs
Outdated
@@ -3676,6 +3680,9 @@ impl DexFee { | |||
Ok(None) | |||
} | |||
} | |||
|
|||
/// Check and return true if DexFee is not required to trade otherwise return false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit:
/// Check and return true if DexFee is not required to trade otherwise return false. | |
/// Whether this is DexFee::Zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
this #2112 seems related and not sure which one will be merge first as both have some similar changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed in swap json.
Before:
"fee_to_send_taker_fee": {
"coin": "KMD",
"amount": "0.00001",
"paid_from_trading_vol": false
},
...
{
"timestamp": 1732532884206,
"event": {
"type": "TakerFeeSent",
"data": {
"tx_hex": "040...000",
"tx_hash": "fa...b5"
}
}
},
After:
"fee_to_send_taker_fee": {
"coin": "KMD",
"amount": "0",
"paid_from_trading_vol": false
},
...
{
"timestamp": 1740128668082,
"event": {
"type": "TakerFeeSent",
"data": {
"tx_hex": "",
"tx_hash": ""
}
}
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsequent to prior comment, all swaps attempted selling KMD with this binary have failed, so approval rescinded for now until further testing can confirm cause.
In all cases, the error was taker_swap:1401] Error waiting for 'maker-payment' data: lp_swap:416] Timeout (691 > 690)
Example failed swap error info: https://dexapi.cipig.net/public/error.php?uuid=a4a0445e-fa7e-473e-980f-21f8015b9c7b
I can DM full swap json if needed
This is a breaking change no BC...so I guess both nodes involved in this swap uses a different versions of |
@borngraced the 0 dex fee should be for TPU only, for legacy protocol the dex fee is needed as an anti-ddos measure. Did you implement it for TPU only? |
ah thanks for the further clarification...I missed that!! |
I see. @borngraced please merge dev to this branch to keep it up to date, when you fix legacy. |
let threshold_coef = &(&MmNumber::from(1) + &dex_fee_rate) / &dex_fee_rate; | ||
let max_vol = if available > min_tx_amount * &threshold_coef { | ||
available / (MmNumber::from(1) + dex_fee_rate) | ||
} else { | ||
let max_vol = if base == "KMD" || rel == "KMD" { | ||
&available - min_tx_amount | ||
} else { | ||
let dex_fee_rate = dex_fee_rate(base, rel); | ||
let threshold_coef = &(&MmNumber::from(1) + &dex_fee_rate) / &dex_fee_rate; | ||
if available > min_tx_amount * &threshold_coef { | ||
available / (MmNumber::from(1) + dex_fee_rate) | ||
} else { | ||
&available - min_tx_amount | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this should be reverted, as KMD zero dexfee is only for TPU?
@@ -3186,6 +3190,7 @@ mod taker_swap_tests { | |||
let min_tx_amount = MmNumber::from("0.00001"); | |||
|
|||
// For these `availables` the dex_fee must be greater than min_tx_amount | |||
// For these `availables` the dex_fee must be lesser than min_tx_amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for legacy test
// KMD pairs: for these `availables` the dex_fee must be 0 | ||
// Non KMD pairs: for these `availables` the dex_fee must be the same as min_tx_amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be reverted
#2320
#2338