Expand description
§PerpCity Rust SDK
A Rust SDK for the PerpCity perpetual futures protocol on Base L2.
§Module overview
| Module | Purpose |
|---|---|
constants | Protocol constants mirrored from on-chain Constants.sol |
contracts | ABI bindings via Alloy sol! — structs, events, errors, functions |
convert | Conversions between client f64 values and on-chain representations |
errors | SDK-wide error types using thiserror |
hft | HFT infrastructure: nonce, gas, pipeline, state cache, latency, positions |
math | Pure math: tick ↔ price, liquidity estimation, position calculations |
transport | Multi-endpoint RPC transport with health-aware routing |
types | Client-facing types with human-readable f64 fields |
§Quick start
use perpcity_sdk::{
PerpClient, HftTransport, TransportConfig, Urgency,
Deployments, OpenTakerParams, OpenMakerParams,
PerpCityError, Result,
};
use alloy::signers::local::PrivateKeySigner;Modules§
- IERC20
- Minimal ERC20 interface for USDC interactions.
- IFees
- Fee module — returns trading fees for a perp.
- IMargin
Ratios - Margin ratio module — returns min/max/liquidation margin ratios.
- Perp
Manager - The PerpManager contract interface. Contains all structs, events, errors, and function signatures from IPerpManager.sol and PerpManager.sol.
- client
- High-level client for the PerpCity perpetual futures protocol.
- constants
- Protocol constants from
perpcity-contracts/src/libraries/Constants.sol. - contracts
- On-chain contract bindings generated via Alloy’s
sol!macro. - convert
- Conversions between client-facing types (
f64, human-readable) and on-chain types (6-decimal integers,U256,sqrtPriceX96). - errors
- Error types for the PerpCity SDK.
- hft
- High-frequency trading infrastructure.
- math
- Pure math functions for the PerpCity protocol.
- transport
- Multi-endpoint RPC transport with health-aware routing.
- types
- Client-facing types for the PerpCity SDK.
Structs§
- Bounds
- Leverage and margin constraints for a perpetual market.
- Close
Params - Client-facing parameters for closing a position.
- Close
Result - Result of closing a position.
- Deployments
- Deployed contract addresses for a PerpCity instance.
- Fees
- Fee percentages for a perpetual market, expressed as fractions of 1.
- GasLimits
- Pre-empirically derived gas limits for PerpCity operations.
- HftTransport
- Multi-endpoint RPC transport with health-aware routing.
- Live
Details - Real-time position metrics, typically from a
quoteClosePositioncall. - Open
Interest - Taker open interest for a perp market, in USDC.
- Open
Maker Params - Client-facing parameters for opening a maker (LP) position.
- Open
Taker Params - Client-facing parameters for opening a taker (long/short) position.
- Perp
Client - High-level client for the PerpCity protocol.
- Perp
Data - Metadata about a perpetual market.
- PoolKey
- Identifies a Uniswap V4 pool (and PerpCity perp) by its constituent parameters.
- Swap
Config - Swap configuration for quoting through the Uniswap V4 pool.
- Transport
Config - Complete transport configuration.
Enums§
- Perp
City Error - Central error type for the PerpCity SDK.
- Urgency
- Transaction urgency level, controlling EIP-1559 fee scaling.
Type Aliases§
- Result
- Convenience alias used throughout the SDK.