r402_solana/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Solana chain support for the x402 payment protocol.
4//!
5//! This crate provides implementations of the x402 payment protocol for Solana blockchain
6//! with the "exact" payment scheme based on SPL Token `transfer` instructions with
7//! pre-signed authorization.
8//!
9//! # Features
10//!
11//! - **CAIP-2 Addressing**: Uses CAIP-2 chain IDs for chain identification
12//! - **SPL Token Payments**: Token transfers using pre-signed transaction authorization
13//! - **Compute Budget Management**: Automatic compute unit limit and price configuration
14//! - **`WebSocket` Support**: Optional pubsub for faster transaction confirmation
15//! - **Balance Verification**: On-chain balance checks before settlement
16//!
17//! # Architecture
18//!
19//! The crate is organized into several modules:
20//!
21//! - [`chain`] - Core Solana chain types, providers, and configuration
22//! - [`exact`] - Solana "exact" payment scheme
23//!
24//! # Feature Flags
25//!
26//! - `server` - Server-side price tag generation
27//! - `client` - Client-side payment signing
28//! - `facilitator` - Facilitator-side payment verification and settlement
29//! - `telemetry` - `OpenTelemetry` tracing support
30//!
31
32// Consumed by feature-gated modules; quiet the linter when default features
33// disable every consumer.
34#[cfg(not(feature = "facilitator"))]
35use base64 as _;
36#[cfg(not(feature = "facilitator"))]
37use futures_util as _;
38
39/// Recommended hard cap for `max_compute_unit_price` (micro-lamports).
40///
41/// Aligned with the Go reference SDK
42/// (`mechanisms/svm/exact/facilitator/scheme.go: maxComputeUnitPriceMicroLamports`)
43/// so that any client transaction passing Go's verifier passes r402's, and
44/// vice versa. A value of 5 000 000 micro-lamports per CU corresponds to
45/// roughly 0.005 SOL per million CU, well above realistic priority-fee
46/// surge prices on Solana mainnet, while bounding the worst-case fee a
47/// fee-paying facilitator can be tricked into paying.
48pub const SOLANA_MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS: u64 = 5_000_000;
49
50pub mod chain;
51pub mod exact;
52
53mod networks;
54pub use exact::SolanaExact;
55#[cfg(feature = "client")]
56pub use exact::client::SolanaExactClient;
57pub use networks::*;