x402_chain_solana/lib.rs
1//! Solana chain support for the x402 payment protocol.
2//!
3//! This crate provides implementations of the x402 payment protocol for Solana blockchain.
4//! It supports both V1 and V2 protocol versions with the "exact" payment scheme based on
5//! SPL Token `transfer` instructions with pre-signed authorization.
6//!
7//! # Features
8//!
9//! - **V1 and V2 Protocol Support**: Implements both protocol versions with network name
10//! (V1) and CAIP-2 chain ID (V2) addressing
11//! - **SPL Token Payments**: Token transfers using pre-signed transaction authorization
12//! - **Compute Budget Management**: Automatic compute unit limit and price configuration
13//! - **WebSocket Support**: Optional pubsub for faster transaction confirmation
14//! - **Balance Verification**: On-chain balance checks before settlement
15//!
16//! # Architecture
17//!
18//! The crate is organized into several modules:
19//!
20//! - [`chain`] - Core Solana chain types, providers, and configuration
21//! - [`v1_solana_exact`] - V1 protocol implementation with network names
22//! - [`v2_solana_exact`] - V2 protocol implementation with CAIP-2 chain IDs
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//! # Usage Examples
32//!
33//! ## Server: Creating a Price Tag
34//!
35//! ```ignore
36//! use x402_chain_solana::{V1SolanaExact, KnownNetworkSolana};
37//! use x402_types::networks::USDC;
38//!
39//! // Get USDC deployment on Solana mainnet
40//! let usdc = USDC::solana();
41//!
42//! // Create a price tag for 1 USDC
43//! let price_tag = V1SolanaExact::price_tag(
44//! "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
45//! usdc.amount(1_000_000u64),
46//! );
47//! ```
48//!
49//! ## Client: Signing a Payment
50//!
51//! ```ignore
52//! use x402_chain_solana::V1SolanaExactClient;
53//! use solana_keypair::Keypair;
54//!
55//! let keypair = Keypair::new();
56//! let client = V1SolanaExactClient::new(keypair);
57//!
58//! // Use client to sign payment candidates
59//! let candidates = client.accept(&payment_required);
60//! ```
61//!
62//! ## Facilitator: Verifying and Settling
63//!
64//! ```ignore
65//! use x402_chain_solana::{V1SolanaExact, SolanaChainProvider};
66//! use x402_types::scheme::X402SchemeFacilitatorBuilder;
67//!
68//! let provider = SolanaChainProvider::from_config(&config).await?;
69//! let facilitator = V1SolanaExact.build(provider, None)?;
70//!
71//! // Verify payment
72//! let verify_response = facilitator.verify(&verify_request).await?;
73//!
74//! // Settle payment
75//! let settle_response = facilitator.settle(&settle_request).await?;
76//! ```
77
78pub mod chain;
79pub mod v1_solana_exact;
80pub mod v2_solana_exact;
81
82mod networks;
83pub use networks::*;
84
85pub use v1_solana_exact::V1SolanaExact;
86pub use v2_solana_exact::V2SolanaExact;
87
88#[cfg(feature = "client")]
89pub use v1_solana_exact::client::V1SolanaExactClient;
90#[cfg(feature = "client")]
91pub use v2_solana_exact::client::V2SolanaExactClient;