Skip to main content

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_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.
80#[cfg(feature = "api")]
81pub mod api;
82
83/// WebSocket client module for real-time data streaming.
84#[cfg(feature = "websocket")]
85pub mod websocket;
86
87// ============================================================================
88// PRELUDE
89// ============================================================================
90
91/// Prelude module for convenient imports.
92///
93/// ```rust,ignore
94/// use lightcone_sdk::prelude::*;
95/// ```
96pub mod prelude {
97    // Program module exports
98    pub use crate::program::{
99        // Account types
100        Exchange, Market, OrderStatus, Position, UserNonce,
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    // Client (conditionally exported)
125    #[cfg(feature = "client")]
126    pub use crate::program::LightconePinocchioClient;
127
128    // API module exports
129    #[cfg(feature = "api")]
130    pub use crate::api::{
131        LightconeApiClient, LightconeApiClientBuilder, ApiError, ApiResult,
132        // Common types
133        MarketsResponse, MarketInfoResponse, Market as ApiMarket, DepositAsset, ConditionalToken,
134        OrderbookResponse, PriceLevel,
135        SubmitOrderRequest, OrderResponse, CancelResponse, CancelAllResponse,
136        PositionsResponse, Position as ApiPosition, OutcomeBalance,
137        PriceHistoryParams, PriceHistoryResponse,
138        TradesParams, TradesResponse, Trade,
139        DecimalsResponse,
140    };
141
142    // Shared utilities (used by both API and WebSocket)
143    pub use crate::shared::{
144        derive_orderbook_id, format_decimal, parse_decimal, scale_price_size, OrderbookDecimals,
145        Resolution, ScaledAmounts, ScalingError,
146    };
147
148    // WebSocket module exports
149    #[cfg(feature = "websocket")]
150    pub use crate::websocket::{
151        LightconeWebSocketClient, WebSocketConfig, WebSocketError, WsResult,
152        ConnectionState, WsEvent,
153        BookUpdateData, TradeData, UserEventData, PriceHistoryData, MarketEventData,
154        LocalOrderbook, UserState, PriceHistory,
155    };
156}