Skip to main content

Crate perpcity_sdk

Crate perpcity_sdk 

Source
Expand description

§PerpCity Rust SDK

A Rust SDK for the PerpCity perpetual futures protocol on Base L2.

§Module overview

ModulePurpose
constantsProtocol constants mirrored from on-chain Constants.sol
contractsABI bindings via Alloy sol! — structs, events, errors, functions
convertConversions between client f64 values and on-chain representations
errorsSDK-wide error types using thiserror
hftHFT infrastructure: nonce, gas, pipeline, state cache, latency, positions
mathPure math: tick ↔ price, liquidity estimation, position calculations
transportMulti-endpoint RPC transport with health-aware routing
typesClient-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.
IMarginRatios
Margin ratio module — returns min/max/liquidation margin ratios.
PerpManager
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.
CloseParams
Client-facing parameters for closing a position.
CloseResult
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.
LiveDetails
Real-time position metrics, typically from a quoteClosePosition call.
OpenInterest
Taker open interest for a perp market, in USDC.
OpenMakerParams
Client-facing parameters for opening a maker (LP) position.
OpenTakerParams
Client-facing parameters for opening a taker (long/short) position.
PerpClient
High-level client for the PerpCity protocol.
PerpData
Metadata about a perpetual market.
PoolKey
Identifies a Uniswap V4 pool (and PerpCity perp) by its constituent parameters.
SwapConfig
Swap configuration for quoting through the Uniswap V4 pool.
TransportConfig
Complete transport configuration.

Enums§

PerpCityError
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.