lightcone_sdk/program/types.rs
1//! Type definitions for the Lightcone Pinocchio on-chain program.
2//!
3//! This module contains enums, parameter structs, and other type definitions
4//! used for on-chain program interaction.
5
6use solana_sdk::pubkey::Pubkey;
7
8use crate::program::error::SdkError;
9
10// ============================================================================
11// Enums
12// ============================================================================
13
14/// Market status enum
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16#[repr(u8)]
17pub enum MarketStatus {
18 /// Market is pending activation
19 Pending = 0,
20 /// Market is active and trading is enabled
21 Active = 1,
22 /// Market has been resolved with a winning outcome
23 Resolved = 2,
24 /// Market has been cancelled
25 Cancelled = 3,
26}
27
28impl TryFrom<u8> for MarketStatus {
29 type Error = SdkError;
30
31 fn try_from(value: u8) -> Result<Self, Self::Error> {
32 match value {
33 0 => Ok(MarketStatus::Pending),
34 1 => Ok(MarketStatus::Active),
35 2 => Ok(MarketStatus::Resolved),
36 3 => Ok(MarketStatus::Cancelled),
37 _ => Err(SdkError::InvalidMarketStatus(value)),
38 }
39 }
40}
41
42/// Order side enum
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44#[repr(u8)]
45pub enum OrderSide {
46 /// Bid/Buy - maker wants to buy base tokens, gives quote tokens
47 Bid = 0,
48 /// Ask/Sell - maker wants to sell base tokens, receives quote tokens
49 Ask = 1,
50}
51
52impl TryFrom<u8> for OrderSide {
53 type Error = SdkError;
54
55 fn try_from(value: u8) -> Result<Self, Self::Error> {
56 match value {
57 0 => Ok(OrderSide::Bid),
58 1 => Ok(OrderSide::Ask),
59 _ => Err(SdkError::InvalidSide(value)),
60 }
61 }
62}
63
64// ============================================================================
65// Parameter Structs
66// ============================================================================
67
68/// Parameters for creating a market
69#[derive(Debug, Clone)]
70pub struct CreateMarketParams {
71 /// Authority pubkey (must be exchange authority)
72 pub authority: Pubkey,
73 /// Number of outcomes (2-6)
74 pub num_outcomes: u8,
75 /// Oracle pubkey that can settle the market
76 pub oracle: Pubkey,
77 /// Question ID (32 bytes)
78 pub question_id: [u8; 32],
79}
80
81/// Metadata for a single outcome token
82#[derive(Debug, Clone)]
83pub struct OutcomeMetadata {
84 /// Token name (max 32 chars)
85 pub name: String,
86 /// Token symbol (max 10 chars)
87 pub symbol: String,
88 /// Token URI (max 200 chars)
89 pub uri: String,
90}
91
92/// Parameters for adding a deposit mint to a market
93#[derive(Debug, Clone)]
94pub struct AddDepositMintParams {
95 /// Payer for account creation
96 pub payer: Pubkey,
97 /// Market ID
98 pub market_id: u64,
99 /// Deposit mint pubkey
100 pub deposit_mint: Pubkey,
101 /// Metadata for each outcome token
102 pub outcome_metadata: Vec<OutcomeMetadata>,
103}
104
105/// Parameters for minting a complete set
106#[derive(Debug, Clone)]
107pub struct MintCompleteSetParams {
108 /// User pubkey (payer and recipient)
109 pub user: Pubkey,
110 /// Market pubkey
111 pub market: Pubkey,
112 /// Deposit mint pubkey
113 pub deposit_mint: Pubkey,
114 /// Amount of collateral to deposit
115 pub amount: u64,
116}
117
118/// Parameters for merging a complete set
119#[derive(Debug, Clone)]
120pub struct MergeCompleteSetParams {
121 /// User pubkey
122 pub user: Pubkey,
123 /// Market pubkey
124 pub market: Pubkey,
125 /// Deposit mint pubkey
126 pub deposit_mint: Pubkey,
127 /// Amount of each outcome token to burn
128 pub amount: u64,
129}
130
131/// Parameters for settling a market
132#[derive(Debug, Clone)]
133pub struct SettleMarketParams {
134 /// Oracle pubkey (must match market oracle)
135 pub oracle: Pubkey,
136 /// Market ID
137 pub market_id: u64,
138 /// Winning outcome index
139 pub winning_outcome: u8,
140}
141
142/// Parameters for redeeming winnings
143#[derive(Debug, Clone)]
144pub struct RedeemWinningsParams {
145 /// User pubkey
146 pub user: Pubkey,
147 /// Market pubkey
148 pub market: Pubkey,
149 /// Deposit mint pubkey
150 pub deposit_mint: Pubkey,
151 /// Amount of winning tokens to redeem
152 pub amount: u64,
153}
154
155/// Parameters for withdrawing from a position
156#[derive(Debug, Clone)]
157pub struct WithdrawFromPositionParams {
158 /// User pubkey (must be position owner)
159 pub user: Pubkey,
160 /// Market pubkey
161 pub market: Pubkey,
162 /// Mint pubkey (deposit or conditional)
163 pub mint: Pubkey,
164 /// Amount to withdraw
165 pub amount: u64,
166}
167
168/// Parameters for activating a market
169#[derive(Debug, Clone)]
170pub struct ActivateMarketParams {
171 /// Authority pubkey (must be exchange authority)
172 pub authority: Pubkey,
173 /// Market ID
174 pub market_id: u64,
175}
176
177/// Parameters for creating a bid order
178#[derive(Debug, Clone)]
179pub struct BidOrderParams {
180 /// Order nonce (unique per user)
181 pub nonce: u64,
182 /// Maker pubkey
183 pub maker: Pubkey,
184 /// Market pubkey
185 pub market: Pubkey,
186 /// Base mint (token being bought)
187 pub base_mint: Pubkey,
188 /// Quote mint (token used for payment)
189 pub quote_mint: Pubkey,
190 /// Quote tokens to give (maker_amount)
191 pub maker_amount: u64,
192 /// Base tokens to receive (taker_amount)
193 pub taker_amount: u64,
194 /// Expiration timestamp (0 for no expiration)
195 pub expiration: i64,
196}
197
198/// Parameters for creating an ask order
199#[derive(Debug, Clone)]
200pub struct AskOrderParams {
201 /// Order nonce (unique per user)
202 pub nonce: u64,
203 /// Maker pubkey
204 pub maker: Pubkey,
205 /// Market pubkey
206 pub market: Pubkey,
207 /// Base mint (token being sold)
208 pub base_mint: Pubkey,
209 /// Quote mint (token to receive)
210 pub quote_mint: Pubkey,
211 /// Base tokens to give (maker_amount)
212 pub maker_amount: u64,
213 /// Quote tokens to receive (taker_amount)
214 pub taker_amount: u64,
215 /// Expiration timestamp (0 for no expiration)
216 pub expiration: i64,
217}
218
219/// Parameters for matching orders
220#[derive(Debug, Clone)]
221pub struct MatchOrdersMultiParams {
222 /// Operator pubkey (must be exchange operator)
223 pub operator: Pubkey,
224 /// Market pubkey
225 pub market: Pubkey,
226 /// Base mint pubkey
227 pub base_mint: Pubkey,
228 /// Quote mint pubkey
229 pub quote_mint: Pubkey,
230 /// Taker order (signed)
231 pub taker_order: crate::program::orders::FullOrder,
232 /// Maker orders (signed)
233 pub maker_orders: Vec<crate::program::orders::FullOrder>,
234 /// Fill amounts for each maker
235 pub fill_amounts: Vec<u64>,
236}