Skip to content

Commit

Permalink
check open_orders_admin on ixs instead of on the book
Browse files Browse the repository at this point in the history
  • Loading branch information
binyebarwe committed Jul 13, 2023
1 parent 7ff1b8f commit 389fa82
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
19 changes: 14 additions & 5 deletions programs/openbook-v2/src/instructions/place_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::accounts_zerocopy::*;
use crate::error::*;
use crate::state::*;

// TODO
#[allow(clippy::too_many_arguments)]
pub fn place_order(ctx: Context<PlaceOrder>, order: Order, limit: u8) -> Result<Option<u128>> {
require_gte!(order.max_base_lots, 0, OpenBookError::InvalidInputLots);
Expand All @@ -29,6 +28,20 @@ pub fn place_order(ctx: Context<PlaceOrder>, order: Order, limit: u8) -> Result<
market.time_expiry == 0 || market.time_expiry > Clock::get()?.unix_timestamp,
OpenBookError::MarketHasExpired
);
if let Some(open_orders_admin) = Option::<Pubkey>::from(market.open_orders_admin) {
let open_orders_admin_signer = ctx
.accounts
.open_orders_admin
.as_ref()
.map(|signer| signer.key())
.ok_or(OpenBookError::MissingOpenOrdersAdmin)?;
require_eq!(
open_orders_admin,
open_orders_admin_signer,
OpenBookError::InvalidOpenOrdersAdmin
);
}

let mut book = Orderbook {
bids: ctx.accounts.bids.load_mut()?,
asks: ctx.accounts.asks.load_mut()?,
Expand Down Expand Up @@ -58,10 +71,6 @@ pub fn place_order(ctx: Context<PlaceOrder>, order: Order, limit: u8) -> Result<
&open_orders_account_pk,
now_ts,
limit,
ctx.accounts
.open_orders_admin
.as_ref()
.map(|signer| signer.key()),
ctx.remaining_accounts,
)?;

Expand Down
18 changes: 13 additions & 5 deletions programs/openbook-v2/src/instructions/place_take_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::accounts_zerocopy::*;
use crate::error::*;
use crate::state::*;

// TODO
#[allow(clippy::too_many_arguments)]
pub fn place_take_order<'info>(
ctx: Context<'_, '_, '_, 'info, PlaceTakeOrder<'info>>,
Expand All @@ -25,6 +24,19 @@ pub fn place_take_order<'info>(
market.time_expiry == 0 || market.time_expiry > Clock::get()?.unix_timestamp,
OpenBookError::MarketHasExpired
);
if let Some(open_orders_admin) = Option::<Pubkey>::from(market.open_orders_admin) {
let open_orders_admin_signer = ctx
.accounts
.open_orders_admin
.as_ref()
.map(|signer| signer.key())
.ok_or(OpenBookError::MissingOpenOrdersAdmin)?;
require_eq!(
open_orders_admin,
open_orders_admin_signer,
OpenBookError::InvalidOpenOrdersAdmin
);
}

let mut book = Orderbook {
bids: ctx.accounts.bids.load_mut()?,
Expand Down Expand Up @@ -56,10 +68,6 @@ pub fn place_take_order<'info>(
&ctx.accounts.signer.key(),
now_ts,
limit,
ctx.accounts
.open_orders_admin
.as_ref()
.map(|signer| signer.key()),
ctx.remaining_accounts,
)?;

Expand Down
10 changes: 0 additions & 10 deletions programs/openbook-v2/src/state/orderbook/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,9 @@ impl<'a> Orderbook<'a> {
owner: &Pubkey,
now_ts: u64,
mut limit: u8,
open_orders_admin_signer: Option<Pubkey>,
remaining_accs: &[AccountInfo],
) -> std::result::Result<OrderWithAmounts, Error> {
let market = open_book_market;
if let Some(open_orders_admin) = Option::<Pubkey>::from(market.open_orders_admin) {
let open_orders_admin_signer =
open_orders_admin_signer.ok_or(OpenBookError::MissingOpenOrdersAdmin)?;
require_eq!(
open_orders_admin,
open_orders_admin_signer,
OpenBookError::InvalidOpenOrdersAdmin
);
}

let side = order.side;

Expand Down

0 comments on commit 389fa82

Please sign in to comment.