xORCA Rust Client
A Rust client library for interacting with the xORCA staking program on Solana.
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
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 *;
// 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 staking pool PDA
let = find_staking_pool_pda;
// Derive pending withdraw PDA
let = find_pending_withdraw_pda;
Account Data Deserialization
use *;
// Deserialize staking pool account data
let staking_pool: StakingPool = from_slice?;
// Access account fields
println!;
println!;
WASM Usage (with wasm feature)
use *;
// Math functions available in WASM
let result = calculate_rewards;
Available Instructions
The client provides type-safe wrappers for all program instructions:
initialize- Initialize a new staking poolstake- Stake ORCA tokensunstake- Unstake ORCA tokensclaim- Claim staking rewardswithdraw- Withdraw pending claimscancel_stake- Cancel a pending stakeset- Update pool parameters
Account Types
The client includes all account types from the program:
StakingPool- Main staking pool accountPendingClaim- Pending reward claimsPendingWithdraw- Pending withdrawals
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.