| Crates.io | xorca |
| lib.rs | xorca |
| version | 0.1.4 |
| created_at | 2025-09-11 12:17:20.576539+00 |
| updated_at | 2025-12-19 12:02:54.285693+00 |
| description | A Rust client library for interacting with the xORCA staking program on Solana. |
| homepage | https://orca.so |
| repository | https://github.com/orca-so/xorca |
| max_upload_size | |
| id | 1833783 |
| size | 337,248 |
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.
Add the following to your Cargo.toml:
[dependencies]
xorca = { path = "path/to/xorca/rust-client" }
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[dependencies]
xorca = { path = "path/to/xorca/rust-client", features = ["serde", "fetch", "wasm"] }
use xorca::*;
use solana_program::instruction::Instruction;
// Get the program ID
let program_id = XORCA_STAKING_PROGRAM_ID;
// Create instruction data for staking
let stake_ix = stake::instruction::Stake {
orca_stake_amount: 1000000, // 1 ORCA token (6 decimals)
};
// Build the instruction
let instruction = stake_ix.instruction();
use xorca::pda::*;
// Derive state PDA
let (state_pda, _bump) = find_state_pda(&program_id);
// Derive pending withdraw PDA
let (pending_withdraw_pda, _bump) = find_pending_withdraw_pda(
&program_id,
&unstaker_pubkey,
0, // withdraw_index
);
use xorca::accounts::*;
// Deserialize state account data
let state: State = borsh::from_slice(&account_data)?;
// Access account fields
println!("Cool down period: {}", state.cool_down_period_s);
println!("Escrowed ORCA amount: {}", state.escrowed_orca_amount);
println!("Update authority: {}", state.update_authority);
// Deserialize pending withdraw account data
let pending_withdraw: PendingWithdraw = borsh::from_slice(&pending_withdraw_data)?;
println!("Withdrawable ORCA amount: {}", pending_withdraw.withdrawable_orca_amount);
println!("Withdrawable timestamp: {}", pending_withdraw.withdrawable_timestamp);
wasm feature)use xorca::math::*;
// Math functions available in WASM for conversion calculations
let result = calculate_xorca_amount(orca_amount, total_orca, total_xorca);
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)The client includes all account types from the program:
State - Main program state account (PDA)PendingWithdraw - Pending withdrawal accounts for unstakingAll program errors are available as Rust enums:
use xorca::errors::*;
match result {
Ok(_) => println!("Success!"),
Err(XorcaStakingProgramError::InsufficientFunds) => {
println!("Insufficient funds for operation");
}
Err(XorcaStakingProgramError::CooldownNotElapsed) => {
println!("Cooldown period has not elapsed");
}
Err(XorcaStakingProgramError::InvalidAuthority) => {
println!("Invalid authority provided");
}
Err(e) => println!("Other error: {:?}", e),
}
# Build with default features
cargo build
# Build with WASM support
cargo build --features wasm
# Build with all features
cargo build --features "serde,fetch,wasm"
cargo test
This client is auto-generated from the Solana program IDL using the Codama framework. The generated code includes:
To regenerate the code after program changes:
yarn generate
See LICENSE for details.