Skip to content

Commit

Permalink
fix: update units
Browse files Browse the repository at this point in the history
  • Loading branch information
wiseaidev committed Jun 23, 2024
1 parent a9212ce commit 9b3d56c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
25 changes: 12 additions & 13 deletions programs/openbook-v2/src/state/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ impl Market {
pub fn max_quote_lots(&self) -> i64 {
i64::MAX / self.quote_lot_size
}
a

pub fn max_base_lots_from_lamports(&self, lamports: u64) -> i64 {
let base_lots = lamports / self.base_lot_size as u64;
Expand All @@ -219,21 +218,21 @@ a
/ I80F48::from_num(self.base_lot_size)
}

/// Convert the quantity from quote lots to native quantity (e.g. 5 SOL, 0.3 USDC, etc)
pub fn quote_lot_to_native_quantity(&self, quote_lots: i64) -> f64 {
let quote_lot_size = self.quote_lot_size as f64;
let quote_decimals = self.quote_decimals as u32;
let quote_units = quote_lots as f64 * quote_lot_size;
let quantity = quote_units / 10_i64.pow(quote_decimals) as f64;
/// Convert the quantity from quote lots to native quantity (e.g. 5 SOL, 3 USDC, etc)
pub fn quote_lot_to_native_quantity(&self, quote_lots: i64) -> i64 {
let quote_lot_size = self.quote_lot_size;
let quote_decimals = self.quote_decimals;
let quote_units = quote_lots * quote_lot_size;
let quantity = quote_units / 10_i64.pow(quote_decimals.into());
quantity
}

/// Convert the quantity from base lots to native quantity (e.g. 5 SOL, 0.3 USDC, etc)
pub fn base_lot_to_native_quantity(&self, base_lots: i64) -> f64 {
let base_lot_size = self.base_lot_size as f64;
let base_decimals = self.base_decimals as u32;
let base_units = base_lots as f64 * base_lot_size;
let quantity = base_units / 10_i64.pow(base_decimals) as f64;
/// Convert the quantity from base lots to native quantity (e.g. 5 SOL, 3 USDC, etc)
pub fn base_lot_to_native_quantity(&self, base_lots: i64) -> i64 {
let base_lot_size = self.base_lot_size;
let base_decimals = self.base_decimals;
let base_units = base_lots * base_lot_size;
let quantity = base_units / 10_i64.pow(base_decimals.into());
quantity
}

Expand Down
1 change: 1 addition & 0 deletions programs/openbook-v2/src/state/orderbook/bookside.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl BookSide {
Some(
self.iter_valid(now_ts, oracle_price_lots)
.next()?
.node
.quantity,
)
}
Expand Down

0 comments on commit 9b3d56c

Please sign in to comment.