diff --git a/programs/openbook-v2/src/error.rs b/programs/openbook-v2/src/error.rs index b177ffd7..372ce1a1 100644 --- a/programs/openbook-v2/src/error.rs +++ b/programs/openbook-v2/src/error.rs @@ -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")] diff --git a/programs/openbook-v2/src/instructions/create_market.rs b/programs/openbook-v2/src/instructions/create_market.rs index 857f71d3..f9d96eda 100644 --- a/programs/openbook-v2/src/instructions/create_market.rs +++ b/programs/openbook-v2/src/instructions/create_market.rs @@ -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 diff --git a/programs/openbook-v2/src/state/oracle.rs b/programs/openbook-v2/src/state/oracle.rs index ac765009..ad18e10e 100644 --- a/programs/openbook-v2/src/state/oracle.rs +++ b/programs/openbook-v2/src/state/oracle.rs @@ -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], } diff --git a/programs/openbook-v2/src/util.rs b/programs/openbook-v2/src/util.rs index 07e73d6e..748f8c55 100644 --- a/programs/openbook-v2/src/util.rs +++ b/programs/openbook-v2/src/util.rs @@ -3,7 +3,7 @@ use anchor_lang::prelude::*; pub fn fill_from_str(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_)