Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check open_orders_admin on ixs instead of on the book #98

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading