1use alloy::primitives::U256;
4use serde::{Deserialize, Serialize};
5
6use crate::contracts::OrderBook;
7
8pub const LOT_SIZE: u64 = 10_000_000_000_000_000;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[repr(u8)]
17pub enum Side {
18 Bid = 0,
19 Ask = 1,
20 SellYes = 2,
21 SellNo = 3,
22}
23
24impl From<Side> for u8 {
25 fn from(s: Side) -> u8 {
26 s as u8
27 }
28}
29
30impl TryFrom<u8> for Side {
31 type Error = &'static str;
32 fn try_from(v: u8) -> Result<Self, Self::Error> {
33 match v {
34 0 => Ok(Self::Bid),
35 1 => Ok(Self::Ask),
36 2 => Ok(Self::SellYes),
37 3 => Ok(Self::SellNo),
38 _ => Err("invalid side value (must be 0-3)"),
39 }
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
45#[repr(u8)]
46pub enum OrderType {
47 GoodTilBatch = 0,
49 GoodTilCancelled = 1,
51}
52
53impl From<OrderType> for u8 {
54 fn from(o: OrderType) -> u8 {
55 o as u8
56 }
57}
58
59#[derive(Debug, Clone, Copy)]
64pub struct OrderParam {
65 pub side: Side,
67 pub order_type: OrderType,
69 pub tick: u8,
71 pub lots: u64,
73}
74
75impl OrderParam {
76 pub fn new(side: Side, order_type: OrderType, tick: u8, lots: u64) -> Self {
78 Self {
79 side,
80 order_type,
81 tick,
82 lots,
83 }
84 }
85
86 pub fn bid(tick: u8, lots: u64) -> Self {
88 Self::new(Side::Bid, OrderType::GoodTilCancelled, tick, lots)
89 }
90
91 pub fn ask(tick: u8, lots: u64) -> Self {
93 Self::new(Side::Ask, OrderType::GoodTilCancelled, tick, lots)
94 }
95
96 pub fn sell_yes(tick: u8, lots: u64) -> Self {
98 Self::new(Side::SellYes, OrderType::GoodTilCancelled, tick, lots)
99 }
100
101 pub fn sell_no(tick: u8, lots: u64) -> Self {
103 Self::new(Side::SellNo, OrderType::GoodTilCancelled, tick, lots)
104 }
105
106 pub(crate) fn to_contract_param(self) -> OrderBook::OrderParam {
108 OrderBook::OrderParam {
109 side: self.side as u8,
110 orderType: self.order_type as u8,
111 tick: self.tick,
112 lots: self.lots,
113 }
114 }
115}
116
117#[derive(Debug, Clone)]
119pub struct PlacedOrder {
120 pub order_id: U256,
122 pub side: Side,
124 pub market_id: u64,
126}
127
128#[derive(Debug, Clone)]
130pub enum StrikeEvent {
131 MarketCreated {
133 market_id: u64,
134 price_id: [u8; 32],
135 strike_price: i64,
136 expiry_time: u64,
137 },
138 BatchCleared {
140 market_id: u64,
141 batch_id: u64,
142 clearing_tick: u64,
143 matched_lots: u64,
144 },
145 OrderSettled {
147 order_id: U256,
148 owner: alloy::primitives::Address,
149 filled_lots: u64,
150 },
151 GtcAutoCancelled {
153 order_id: U256,
154 owner: alloy::primitives::Address,
155 },
156 OrderPlaced {
158 order_id: U256,
159 market_id: u64,
160 side: u8,
161 tick: u8,
162 lots: u64,
163 owner: alloy::primitives::Address,
164 },
165 OrderCancelled {
167 order_id: U256,
168 market_id: u64,
169 owner: alloy::primitives::Address,
170 },
171}