Skip to content

Commit

Permalink
Bug: correctly handle denoms with / in pcli tx lp
Browse files Browse the repository at this point in the history
The parsing looked for the first occurrence of the slash for

nX@nY/fee

but if X or Y contains a slash, this will be incorrect.

This fixes this somewhat, by looking for the last slash, and only
considering that a fee if it ends with bps.

This will not correctly handle a denom containing both a slash and
ending with bps, but beyond that we'll need to change the format
probably.
  • Loading branch information
cronokirby committed Jul 25, 2024
1 parent 08f3b2b commit 4536375
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/core/component/dex/src/lp/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ pub struct SellOrder {

/// This doesn't parse the values yet, because we need to inspect their units.
fn parse_parts(input: &str) -> Result<(&str, &str, u32)> {
let (trade_part, fee_part) = match input.split_once('/') {
Some((trade_part, fee_part)) => (trade_part, fee_part),
None => (input, "0bps"),
let (trade_part, fee_part) = match input.rsplit_once('/') {
// In case we have a denom with a slash, and no fee
Some((trade_part, fee_part)) if fee_part.ends_with("bps") => (trade_part, fee_part),
_ => (input, "0bps"),
};

let Some((val1, val2)) = trade_part.split_once('@') else {
Expand Down

0 comments on commit 4536375

Please sign in to comment.