lightcone_sdk/lib.rs
1//! # Lightcone Pinocchio Rust SDK
2//!
3//! A Rust SDK for interacting with the Lightcone protocol.
4//!
5//! ## Modules
6//!
7//! This SDK provides three main modules:
8//! - [`program`]: On-chain program interaction (smart contract)
9//! - [`api`]: REST API client for market data, orders, and positions
10//! - [`websocket`]: Real-time data streaming via WebSocket
11//!
12//! Plus a shared module:
13//! - [`shared`]: Shared utilities, types, and constants
14//!
15//! ## Quick Start - REST API
16//!
17//! ```rust,ignore
18//! use lightcone_sdk::api::LightconeApiClient;
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! // Create API client
23//! let api = LightconeApiClient::new("https://api.lightcone.io");
24//!
25//! // Get all markets
26//! let markets = api.get_markets().await?;
27//! println!("Found {} markets", markets.total);
28//!
29//! // Get orderbook
30//! let orderbook = api.get_orderbook("orderbook_id", Some(10)).await?;
31//! println!("Best bid: {:?}", orderbook.best_bid);
32//!
33//! Ok(())
34//! }
35//! ```
36//!
37//! ## Quick Start - On-Chain Program
38//!
39//! ```rust,ignore
40//! use lightcone_sdk::program::LightconePinocchioClient;
41//! use lightcone_sdk::shared::types::*;
42//! use solana_sdk::pubkey::Pubkey;
43//!
44//! #[tokio::main]
45//! async fn main() {
46//! // Create on-chain client
47//! let client = LightconePinocchioClient::new("https://api.devnet.solana.com");
48//!
49//! // Fetch exchange state
50//! let exchange = client.get_exchange().await.unwrap();
51//! println!("Market count: {}", exchange.market_count);
52//!
53//! // Create an order
54//! let order = client.create_bid_order(BidOrderParams {
55//! nonce: 1,
56//! maker: Pubkey::new_unique(),
57//! market: Pubkey::new_unique(),
58//! base_mint: Pubkey::new_unique(),
59//! quote_mint: Pubkey::new_unique(),
60//! maker_amount: 1000,
61//! taker_amount: 500,
62//! expiration: 0,
63//! });
64//! }
65//! ```
66
67// ============================================================================
68// MODULES
69// ============================================================================
70
71/// On-chain program interaction module.
72/// Contains the client and utilities for interacting with the Lightcone smart contract.
73pub mod program;
74
75/// Shared utilities, types, and constants.
76/// Used across all SDK modules.
77pub mod shared;
78
79/// REST API client module for market data, orders, and positions.
80pub mod api;
81
82/// WebSocket client module for real-time data streaming.
83pub mod websocket;
84
85// ============================================================================
86// PRELUDE
87// ============================================================================
88
89/// Prelude module for convenient imports.
90///
91/// ```rust,ignore
92/// use lightcone_sdk::prelude::*;
93/// ```
94pub mod prelude {
95 // Program module exports
96 pub use crate::program::{
97 // Account types
98 Exchange, Market, OrderStatus, Position, UserNonce,
99 // Client
100 LightconePinocchioClient,
101 // Errors
102 SdkError, SdkResult,
103 // Ed25519 verification
104 create_batch_ed25519_verify_instruction, create_cross_ref_ed25519_instructions,
105 create_ed25519_verify_instruction, create_order_verify_instruction, Ed25519VerifyParams,
106 // Order utilities
107 calculate_taker_fill, derive_condition_id, is_order_expired, orders_can_cross,
108 CompactOrder, FullOrder,
109 // Order builder
110 OrderBuilder,
111 // PDA functions
112 get_exchange_pda, get_market_pda, get_vault_pda, get_mint_authority_pda,
113 get_conditional_mint_pda, get_order_status_pda, get_user_nonce_pda, get_position_pda,
114 get_all_conditional_mint_pdas,
115 // Types (moved from shared)
116 MarketStatus, OrderSide, OutcomeMetadata,
117 BidOrderParams, AskOrderParams, CreateMarketParams, MatchOrdersMultiParams,
118 MintCompleteSetParams, MergeCompleteSetParams, SettleMarketParams, RedeemWinningsParams,
119 AddDepositMintParams, ActivateMarketParams, WithdrawFromPositionParams,
120 // Constants (moved from shared)
121 PROGRAM_ID, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID,
122 };
123
124 // API module exports
125 pub use crate::api::{
126 LightconeApiClient, LightconeApiClientBuilder, ApiError, ApiResult,
127 // Common types
128 MarketsResponse, MarketInfoResponse, Market as ApiMarket, DepositAsset, ConditionalToken,
129 OrderbookResponse, PriceLevel,
130 SubmitOrderRequest, OrderResponse, CancelResponse, CancelAllResponse,
131 PositionsResponse, Position as ApiPosition, OutcomeBalance,
132 PriceHistoryParams, PriceHistoryResponse,
133 TradesParams, TradesResponse, Trade,
134 };
135
136 // Shared utilities (used by both API and WebSocket)
137 pub use crate::shared::{derive_orderbook_id, format_decimal, parse_decimal, Resolution};
138
139 // WebSocket module exports
140 pub use crate::websocket::{
141 LightconeWebSocketClient, WebSocketConfig, WebSocketError, WsResult,
142 ConnectionState, WsEvent,
143 BookUpdateData, TradeData, UserEventData, PriceHistoryData, MarketEventData,
144 LocalOrderbook, UserState, PriceHistory,
145 };
146}