1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{error::ErrorCode, state::MarketState, SuspendMarket};
use anchor_lang::prelude::*;
impl<'info> SuspendMarket<'info> {
pub fn process(&mut self) -> Result<()> {
let market = &mut self.market;
let clock = &self.clock;
if market.state == MarketState::Ended {
return Err(ErrorCode::MarketIsEnded.into());
}
if let Some(end_date) = market.end_date {
if clock.unix_timestamp as u64 > end_date {
return Err(ErrorCode::MarketIsEnded.into());
}
}
if market.start_date > clock.unix_timestamp as u64 {
return Err(ErrorCode::MarketIsNotStarted.into());
}
if !market.mutable {
return Err(ErrorCode::MarketIsImmutable.into());
}
if market.state == MarketState::Suspended {
return Err(ErrorCode::MarketIsSuspended.into());
}
market.state = MarketState::Suspended;
Ok(())
}
}