Experimental, high performance Rust SDK for building offchain clients for Drift V2 protocol.
# crates.io*
drift-rs = "1.0.0-alpha.4"
# build from source (also builds and links 'libdrift_ffi_sys')
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.5" }
*drift-rs
uses drift program over ffi.
ensure libdrift_ffi_sys is installed when using via crates.io.
use drift_rs::{DriftClient, Wallet};
use solana_sdk::signature::KeyPair;
async fn main() {
let client = DriftClient::new(
Context::MainNet,
RpcClient::new("https://rpc-provider.com"),
KeyPair::new().into(),
)
.await
.expect("connects");
/// Subscribe to Ws-based live prices, blockhashes, and oracle updates
let markets = [MarketId::spot(1), MarketId::perp(0)];
client.subscribe_markets(&markets).await.unwrap();
}
Install rosetta and configure Rust toolchain for x86_64
softwareupdate --install-rosetta
# replace `1.81.0` with preferred stable version
rustup install 1.81.0-x86_64-apple-darwin
rustup override set 1.81.0-x86_64-apple-darwin
InvalidSize
.
drift-rs links to the drift program crate via FFI, build from source (default) or optionally install from drift-ffi-sys
# Build from source (default)
CARGO_DRIFT_FFI_STATIC=1
# Provide a prebuilt drift_ffi_sys lib
CARGO_DRIFT_FFI_PATH="/path/to/libdrift_ffi_sys"
- copy the updated IDL to
res/drift.json
from protocol-v2 branch cargo check
- commit changes