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 e225f86 commit a4c3062
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ impl OpenBookClient {
open_orders_account: self.open_orders_account,
signer: self.owner(),
open_orders_admin: market.open_orders_admin.into(),
user_quote_account: user_quote_account,
user_base_account: user_base_account,
user_quote_account,
user_base_account,
market: market_address,
bids: market.bids,
asks: market.asks,
Expand Down
27 changes: 12 additions & 15 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,22 +218,20 @@ 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;
quantity
/// 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;
quote_units / 10_i64.pow(quote_decimals.into())
}

/// 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;
quantity
/// 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;
base_units / 10_i64.pow(base_decimals.into())
}

pub fn native_price_to_lot(&self, price: I80F48) -> Result<i64> {
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 a4c3062

Please sign in to comment.