Skip to main content

perpcity_sdk/
lib.rs

1//! # PerpCity Rust SDK
2//!
3//! A Rust SDK for the [PerpCity](https://perpcity.com) perpetual futures
4//! protocol on Base L2.
5//!
6//! ## Module overview
7//!
8//! | Module | Purpose |
9//! |---|---|
10//! | [`constants`] | Protocol constants mirrored from on-chain `Constants.sol` |
11//! | [`contracts`] | ABI bindings via Alloy `sol!` — structs, events, errors, functions |
12//! | [`convert`] | Conversions between client f64 values and on-chain representations |
13//! | [`errors`] | SDK-wide error types using `thiserror` |
14//! | [`events`] | Event decoding: raw logs → typed `MarketEvent` values |
15//! | [`feed`] | Live market event feed over WebSocket |
16//! | [`hft`] | HFT infrastructure: nonce, gas, pipeline, state cache, latency, positions |
17//! | [`math`] | Pure math: tick ↔ price, liquidity estimation, position calculations |
18//! | [`transport`] | Multi-endpoint RPC transport with health-aware routing |
19//! | [`types`] | Client-facing types with human-readable f64 fields |
20//!
21//! ## Quick start
22//!
23//! ```rust,no_run
24//! use perpcity_sdk::{
25//!     PerpClient, HftTransport, TransportConfig, Urgency,
26//!     Deployments, OpenTakerParams, OpenMakerParams,
27//!     PerpCityError, Result,
28//! };
29//! use alloy::signers::local::PrivateKeySigner;
30//! ```
31
32#![deny(unreachable_pub)]
33#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
34
35pub mod client;
36pub mod constants;
37pub mod contracts;
38pub mod convert;
39pub mod errors;
40pub mod events;
41pub mod feed;
42pub mod hft;
43pub mod math;
44pub mod transport;
45pub mod types;
46
47#[doc(inline)]
48pub use client::PerpClient;
49
50#[doc(inline)]
51pub use contracts::{
52    IBeacon, IERC20, IFees, IMarginRatios, IMulticall3, PerpManager, PoolKey, SwapConfig,
53};
54
55#[doc(inline)]
56pub use events::{MarketEvent, decode_log};
57
58#[doc(inline)]
59pub use feed::MarketFeed;
60
61#[doc(inline)]
62pub use errors::{PerpCityError, Result};
63
64#[doc(inline)]
65pub use hft::gas::{GasLimits, Urgency};
66
67#[doc(inline)]
68pub use transport::{config::TransportConfig, provider::HftTransport};
69
70#[doc(inline)]
71pub use types::{
72    AdjustMarginParams, AdjustMarginResult, AdjustNotionalParams, AdjustNotionalResult, Bounds,
73    CloseParams, CloseResult, Deployments, Fees, LiveDetails, OpenInterest, OpenMakerParams,
74    OpenMakerQuote, OpenResult, OpenTakerParams, OpenTakerQuote, PerpData, PerpSnapshot, SwapQuote,
75};
76
77#[doc(inline)]
78pub use math::tick::{
79    align_tick_down, align_tick_up, get_sqrt_ratio_at_tick, price_to_tick, tick_to_price,
80};