Skip to content

Commit

Permalink
oracles not needed for jup
Browse files Browse the repository at this point in the history
  • Loading branch information
binyebarwe committed Jan 26, 2024
1 parent 270b2d2 commit a6c7d2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
17 changes: 1 addition & 16 deletions lib/client/src/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ pub fn remaining_accounts_to_crank(
max_base_lots: i64,
max_quote_lots_including_fees: i64,
market: &Market,
oracle_price: Option<I80F48>,
now_ts: u64,
) -> Result<Vec<Pubkey>> {
let oracle_price_lots = if let Some(oracle_price) = oracle_price {
Some(market.native_price_to_lot(oracle_price)?)
} else {
None
};
let mut accounts = Vec::new();

iterate_book(
Expand All @@ -40,7 +34,6 @@ pub fn remaining_accounts_to_crank(
max_base_lots,
max_quote_lots_including_fees,
market,
oracle_price_lots,
now_ts,
&mut accounts,
);
Expand Down Expand Up @@ -69,14 +62,8 @@ pub fn amounts_from_book(
max_base_lots: i64,
max_quote_lots_including_fees: i64,
market: &Market,
oracle_price: Option<I80F48>,
now_ts: u64,
) -> Result<Amounts> {
let oracle_price_lots = if let Some(oracle_price) = oracle_price {
Some(market.native_price_to_lot(oracle_price)?)
} else {
None
};
let mut accounts = Vec::new();
let (total_base_lots_taken, total_quote_lots_taken, makers_rebates, not_enough_liquidity) =
iterate_book(
Expand All @@ -85,7 +72,6 @@ pub fn amounts_from_book(
max_base_lots,
max_quote_lots_including_fees,
market,
oracle_price_lots,
now_ts,
&mut accounts,
);
Expand All @@ -108,7 +94,6 @@ pub fn iterate_book(
max_base_lots: i64,
max_quote_lots_including_fees: i64,
market: &Market,
oracle_price_lots: Option<i64>,
now_ts: u64,
accounts: &mut Vec<Pubkey>,
) -> (i64, i64, u64, bool) {
Expand All @@ -127,7 +112,7 @@ pub fn iterate_book(
let mut remaining_quote_lots = order_max_quote_lots;

let opposing_bookside = book.bookside(side.invert_side());
for best_opposing in opposing_bookside.iter_all_including_invalid(now_ts, oracle_price_lots) {
for best_opposing in opposing_bookside.iter_all_including_invalid(now_ts, None) {
if !best_opposing.is_valid() {
// Remove the order from the book unless we've done that enough
if number_of_dropped_expired_orders < DROP_EXPIRED_ORDER_LIMIT {
Expand Down
34 changes: 4 additions & 30 deletions lib/client/src/jup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ use anchor_lang::__private::bytemuck::Zeroable;
use anchor_lang::prelude::*;
use anchor_spl::token::Token;
use anyhow::Result;
use fixed::types::I80F48;
use openbook_v2::{
accounts::PlaceTakeOrder,
accounts_zerocopy,
pubkey_option::NonZeroPubkeyOption,
state::{BookSide, EventHeap, Market, Orderbook, Side},
};

Expand All @@ -34,7 +31,6 @@ pub struct OpenBookMarket {
label: String,
related_accounts: Vec<Pubkey>,
reserve_mints: [Pubkey; 2],
oracle_price: Option<I80F48>,
}

impl Amm for OpenBookMarket {
Expand Down Expand Up @@ -69,12 +65,6 @@ impl Amm for OpenBookMarket {
clock::ID,
];

related_accounts.extend(
[market.oracle_a, market.oracle_b]
.into_iter()
.filter_map(Option::<Pubkey>::from),
);

Ok(OpenBookMarket {
market,
key: keyed_account.key,
Expand All @@ -84,7 +74,6 @@ impl Amm for OpenBookMarket {
event_heap: EventHeap::zeroed(),
bids: BookSide::zeroed(),
asks: BookSide::zeroed(),
oracle_price: None,
timestamp: 0,
})
}
Expand All @@ -102,19 +91,6 @@ impl Amm for OpenBookMarket {
let clock_data = account_map.get(&clock::ID).unwrap();
let clock: Clock = bincode::deserialize(clock_data.data.as_slice())?;

let oracle_acc =
|nonzero_pubkey: NonZeroPubkeyOption| -> Option<accounts_zerocopy::KeyedAccount> {
let key = Option::from(nonzero_pubkey)?;
let account = account_map.get(&key).unwrap().clone();
Some(accounts_zerocopy::KeyedAccount { key, account })
};

self.oracle_price = self.market.oracle_price(
oracle_acc(self.market.oracle_a).as_ref(),
oracle_acc(self.market.oracle_b).as_ref(),
clock.slot,
)?;

self.timestamp = clock.unix_timestamp.try_into().unwrap();

Ok(())
Expand Down Expand Up @@ -155,7 +131,6 @@ impl Amm for OpenBookMarket {
max_base_lots,
max_quote_lots_including_fees,
&self.market,
self.oracle_price,
self.timestamp,
)?;

Expand Down Expand Up @@ -216,8 +191,8 @@ impl Amm for OpenBookMarket {
market_base_vault: self.market.market_base_vault,
market_quote_vault: self.market.market_quote_vault,
event_heap: self.market.event_heap,
oracle_a: Option::from(self.market.oracle_a),
oracle_b: Option::from(self.market.oracle_b),
oracle_a: None,
oracle_b: None,
token_program: Token::id(),
system_program: System::id(),
open_orders_admin: None,
Expand Down Expand Up @@ -252,7 +227,6 @@ impl Amm for OpenBookMarket {
max_base_lots,
max_quote_lots_including_fees,
&self.market,
self.oracle_price,
self.timestamp,
)?;

Expand Down Expand Up @@ -441,8 +415,8 @@ mod test {
market_base_vault: market_data.market_base_vault,
market_quote_vault: market_data.market_quote_vault,
event_heap: market_data.event_heap,
oracle_a: Option::from(market_data.oracle_a),
oracle_b: Option::from(market_data.oracle_b),
oracle_a: None,
oracle_b: None,
token_program: Token::id(),
system_program: System::id(),
open_orders_admin: None,
Expand Down

0 comments on commit a6c7d2f

Please sign in to comment.