xORCA Rust Client
A Rust client library for interacting with the xORCA staking program on Solana. Provides type-safe interactions with the liquid staking functionality, allowing users to stake ORCA tokens and receive xORCA tokens in return.
Features
- Type-safe interactions with the xORCA staking program
- Auto-generated code from the program IDL using Codama
- WASM support for use in web applications
- PDA (Program Derived Address) utilities for account derivation
- Math utilities with WASM compilation support
- Serialization support with optional serde integration
- Complete program coverage - all instructions, accounts, and errors
Installation
Add the following to your Cargo.toml:
[]
= { = "path/to/xorca/rust-client" }
Features
The crate supports several optional features:
serde- Enable serde serialization/deserializationfetch- Enable Solana client integration for fetching account datafloats- Enable floating-point math operations (default)wasm- Enable WASM compilation for web use
Example with features:
[]
= { = "path/to/xorca/rust-client", = ["serde", "fetch", "wasm"] }
Usage
Basic Program Interaction
use *;
use Instruction;
// Get the program ID
let program_id = XORCA_STAKING_PROGRAM_ID;
// Create instruction data for staking
let stake_ix = Stake ;
// Build the instruction
let instruction = stake_ix.instruction;
PDA Derivation
use *;
// Derive state PDA
let = find_state_pda;
// Derive pending withdraw PDA
let = find_pending_withdraw_pda;
Account Data Deserialization
use *;
// Deserialize state account data
let state: State = from_slice?;
// Access account fields
println!;
println!;
println!;
// Deserialize pending withdraw account data
let pending_withdraw: PendingWithdraw = from_slice?;
println!;
println!;
WASM Usage (with wasm feature)
use *;
// Math functions available in WASM for conversion calculations
let result = calculate_xorca_amount;
Available Instructions
The client provides type-safe wrappers for all program instructions:
initialize- Initialize the staking programstake- Stake ORCA tokens to receive xORCAunstake- Unstake xORCA tokens (creates pending withdrawal)withdraw- Withdraw ORCA from pending withdrawal after cooldownset- Update program parameters (cooldown period, authority)
Account Types
The client includes all account types from the program:
State- Main program state account (PDA)PendingWithdraw- Pending withdrawal accounts for unstaking
Error Handling
All program errors are available as Rust enums:
use *;
match result
Development
Building
# Build with default features
# Build with WASM support
# Build with all features
Testing
Code Generation
This client is auto-generated from the Solana program IDL using the Codama framework. The generated code includes:
- Type-safe instruction builders
- Account data structures
- Error types
- Program constants
To regenerate the code after program changes:
License
See LICENSE for details.