Skip to content

Commit

Permalink
Merge pull request #95 from openbook-dex/feature/market-errs
Browse files Browse the repository at this point in the history
better errors
  • Loading branch information
binyebarwe authored Jul 10, 2023
2 parents 0fcaca1 + 9eee64f commit af4e72e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions programs/openbook-v2/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum OpenBookError {
#[msg("")]
SomeError,

#[msg("Name lenght above limit")]
InvalidInputNameLength,
#[msg("Market cannot be created as expired")]
InvalidInputMarketExpired,
#[msg("Taker fees should be positive and if maker fees are negative, greater or equal to their abs value")]
Expand Down
12 changes: 12 additions & 0 deletions programs/openbook-v2/src/instructions/create_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ pub fn create_market(
) -> Result<()> {
let now_ts: u64 = Clock::get()?.unix_timestamp.try_into().unwrap();

require!(
maker_fee.unsigned_abs() as i128 <= FEES_SCALE_FACTOR,
OpenBookError::InvalidInputMarketFees
);
require!(
taker_fee.unsigned_abs() as i128 <= FEES_SCALE_FACTOR,
OpenBookError::InvalidInputMarketFees
);
require!(
taker_fee >= 0 && (maker_fee >= 0 || maker_fee.abs() <= taker_fee),
OpenBookError::InvalidInputMarketFees
);

require!(
time_expiry == 0 || time_expiry > Clock::get()?.unix_timestamp,
OpenBookError::InvalidInputMarketExpired
);

require_gt!(quote_lot_size, 0, OpenBookError::InvalidInputLots);
require_gt!(base_lot_size, 0, OpenBookError::InvalidInputLots);

let open_orders_admin: NonZeroPubkeyOption = ctx
.accounts
.open_orders_admin
Expand Down
2 changes: 1 addition & 1 deletion programs/openbook-v2/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct OracleConfigParams {
impl OracleConfigParams {
pub fn to_oracle_config(&self) -> OracleConfig {
OracleConfig {
conf_filter: I80F48::from_num(self.conf_filter),
conf_filter: I80F48::checked_from_num(self.conf_filter).unwrap_or(I80F48::MAX),
max_staleness_slots: self.max_staleness_slots.map(|v| v as i64).unwrap_or(-1),
reserved: [0; 72],
}
Expand Down
2 changes: 1 addition & 1 deletion programs/openbook-v2/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_lang::prelude::*;

pub fn fill_from_str<const N: usize>(name: &str) -> Result<[u8; N]> {
let name_bytes = name.as_bytes();
require!(name_bytes.len() <= N, OpenBookError::SomeError);
require!(name_bytes.len() <= N, OpenBookError::InvalidInputNameLength);
let mut name_ = [0u8; N];
name_[..name_bytes.len()].copy_from_slice(name_bytes);
Ok(name_)
Expand Down

0 comments on commit af4e72e

Please sign in to comment.