Skip to content

Commit

Permalink
feat: base <=> quote function
Browse files Browse the repository at this point in the history
  • Loading branch information
detectivekim committed Jun 21, 2024
1 parent b8d0561 commit f09b952
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libraries/tick.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ pub impl TickImpl of TickTrait {
}
price
}

fn base_to_quote(tick: Tick, base: u256, rounding_up: bool) -> u256 {
let price: u256 = Self::to_price(tick);
if rounding_up {
return (base * price + TWO_POW_96 - 1) / TWO_POW_96;
}
base * price / TWO_POW_96
}

fn quote_to_base(tick: Tick, quote: u256, rounding_up: bool) -> u256 {
let price: u256 = Self::to_price(tick);
if rounding_up {
return (quote * TWO_POW_96 + price - 1) / price;
}
quote * TWO_POW_96 / price
}
}

impl TickPartialEq of PartialEq<Tick> {
Expand Down

0 comments on commit f09b952

Please sign in to comment.