QuasarSVM - Rust API
QuasarSVM is a lightweight Solana virtual machine that executes transactions locally without an RPC connection or validator. Provide program ELFs, account state, and instructions — get back logs, compute units, return data, and resulting accounts.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
use *;
use Account as SplTokenAccount;
use Pack;
let authority = new_unique;
let mint = create_keyed_mint_account;
let alice = create_keyed_associated_token_account;
let bob = create_keyed_associated_token_account;
let ix = transfer.unwrap;
let mut svm = new; // SPL programs loaded by default
let result = svm.process_instruction;
result.assert_success;
// Verify by unpacking account data
let bob_account = result.account.unwrap;
let bob_token = unpack.unwrap;
assert_eq!;
Architecture
QuasarSVM is built as a C FFI wrapper around the low-level Solana SVM execution pipeline. It directly uses:
solana-program-runtimesolana-bpf-loader-programagave-syscalls
The system produces libquasar_svm.dylib/.so/.dll and include/quasar_svm.h for FFI integration. SPL Token, Token-2022, and Associated Token Account program binaries are embedded via include_bytes!.
Core API
QuasarSvm
Creating a VM
let svm = new;
All SPL programs load by default.
To disable specific programs:
use QuasarSvmConfig;
let svm = new_with_config;
Or load programs manually:
let svm = new_with_config
.with_token_program
.with_token_2022_program
.with_associated_token_program;
Loading Programs
Load a custom program from an ELF binary:
let elf = read.unwrap;
svm.add_program;
// Builder-style
let svm = new
.with_program
.with_program_loader;
Load bundled SPL programs:
let svm = new
.with_token_program
.with_token_2022_program
.with_associated_token_program;
Executing Instructions
Two execution methods — single or chain:
| Method | Behavior |
|---|---|
process_instruction |
Execute one instruction atomically. |
process_instruction_chain |
Execute multiple instructions as one atomic chain. |
// Single instruction
let result = svm.process_instruction;
// Multiple instructions — atomic
let result = svm.process_instruction_chain;
Accounts are &[Account] — a slice of Account structs.
Sysvars
svm.sysvars.warp_to_slot; // updates clock.slot + slot_hashes
svm.set_clock;
svm.set_rent;
svm.set_epoch_schedule;
svm.set_compute_budget;
ExecutionResult
Every execution returns an ExecutionResult struct with methods for inspecting the execution outcome.
Fields
| Field | Type | Description |
|---|---|---|
raw_result |
Result<(), InstructionError> |
Status of the execution |
compute_units_consumed |
u64 |
Compute units used |
execution_time_us |
u64 |
Execution time in microseconds |
return_data |
Vec<u8> |
Program return data |
resulting_accounts |
Vec<Account> |
Resulting account states |
logs |
Vec<String> |
Execution logs |
Assertion Methods
result.assert_success;
result.assert_error;
assert!;
assert!;
result.print_logs;
Account Lookup
let acct: = result.account;
Account Types
Account
The universal account type:
Account Factories
All factories return Account with the address as the first parameter.
System Account
Create a system-owned account with a SOL balance:
use create_keyed_system_account;
let account = create_keyed_system_account;
Mint Account
Create a pre-initialized SPL Token mint:
use ;
// Uses SPL_TOKEN_PROGRAM_ID by default
let account = create_keyed_mint_account;
// Token-2022
let account = create_keyed_mint_account_with_program;
Token Account
Create a pre-initialized token account:
use ;
// Uses SPL_TOKEN_PROGRAM_ID by default
let account = create_keyed_token_account;
// Token-2022
let account = create_keyed_token_account_with_program;
Associated Token Account
Derive the ATA address automatically and create a pre-initialized token account:
use ;
// Uses SPL_TOKEN_PROGRAM_ID by default
let account = create_keyed_associated_token_account;
// account.address is the derived ATA address
// Token-2022
let account = create_keyed_associated_token_account_with_program;
Token Types
Mint
let mint = default; // decimals = 9, supply = 0, no authorities
let mint = Mint ;
TokenAccount
// Re-exported from spl_token::state
let token = TokenAccount ;
AccountState
// From spl_token::state::AccountState
Token Instructions
Use the spl_token crate directly to create instructions:
use instruction;
// Transfer
let ix = transfer.unwrap;
// MintTo
let ix = mint_to.unwrap;
// Burn
let ix = burn.unwrap;
Reading Token Account Data
Use spl_token::state to unpack account data from execution results:
use ;
use Pack;
let bob_account = result.account.unwrap;
let bob_token = unpack.unwrap;
assert_eq!;
let mint_account = result.account.unwrap;
let mint = unpack.unwrap;
assert_eq!;
Token-2022 Support
All factories that create token-related accounts have _with_program variants. Use SPL_TOKEN_2022_PROGRAM_ID to create Token-2022 accounts:
use SPL_TOKEN_2022_PROGRAM_ID;
let mint = create_keyed_mint_account_with_program;
let token = create_keyed_token_account_with_program;
let ata = create_keyed_associated_token_account_with_program;
Built-in Programs
The system program, BPF Loader v2, and Upgradeable Loader v3 are always available. SPL programs are bundled and loaded on demand.
Full Example
use ;
use *;
use Account as SplTokenAccount;
use Pack;
let authority = new_unique;
let recipient = new_unique;
let mint = create_keyed_mint_account;
let alice = create_keyed_associated_token_account;
let bob = create_keyed_associated_token_account;
let ix = transfer.unwrap;
let mut svm = new; // Token program loaded by default
let result = svm.process_instruction;
result.assert_success;
// Verify by unpacking account data
let bob_account = result.account.unwrap;
let bob_token = unpack.unwrap;
assert_eq!;
let alice_account = result.account.unwrap;
let alice_token = unpack.unwrap;
assert_eq!;
Workspace
| Crate | Path | Purpose |
|---|---|---|
quasar-svm |
svm/ |
Core execution engine — QuasarSvm, ExecutionResult, Account, token helpers |
quasar-svm-ffi |
ffi/ |
C-ABI wrapper for Node.js FFI via koffi |
| TypeScript bindings | bindings/node/ |
web3.js and kit API layers over the native engine |