A reference implementation of an off-chain state channel built using Anza's SVM API.
PayTube is an SVM-based payment channel that enables two or more parties to exchange SOL or SPL tokens off-chain. The channel is initialized by a "VM" (in this case, a Rust program) and, once transactions are complete, the final payment ledger is submitted to the Solana blockchain for settlement.
- Off-Chain Transactions: Facilitates rapid, low-cost transactions without the overhead of on-chain processing for each transfer.
- SVM-Based: Leverages the Solana SVM for transaction processing within the channel.
- Settlement to Solana: Ensures final balances are reflected on the Solana blockchain.
- Native SOL and SPL Token Support: Supports transfers of both native SOL and SPL tokens.
-
Channel Initialization: A
PayTubeChannel
is created with a set of keys and anRpcClient
. -
Transaction Processing:
PayTubeTransaction
objects are processed by thePayTubeChannel::process_paytube_transfers
method. This involves:- Conversion to SVM-compatible transactions.
- Execution within the SVM using a
TransactionBatchProcessor
. - Account loading via
PayTubeAccountLoader
.
-
Settlement: The final ledger is generated by the
PayTubeSettler
, which creates and submits settlement transactions to the Solana blockchain.
src/lib.rs
: Main library file, defining thePayTubeChannel
and its methods.src/loader.rs
: Implements thePayTubeAccountLoader
for loading accounts into the SVM.src/log.rs
: Provides logging utilities.src/processor.rs
: Contains theTransactionBatchProcessor
and related functions for processing transactions within the SVM.src/settler.rs
: Implements thePayTubeSettler
for settling the final ledger to the Solana blockchain.src/transaction.rs
: Defines thePayTubeTransaction
structure and related utilities.
- Rust toolchain
- Solana CLI
cargo build