drift-rs
Experimental, high performance Rust SDK for building offchain clients for Drift V2 protocol.
See the offical docs
Install
# point to git (recommended)
= { = "https://github.com/drift-labs/drift-rs", = "v1.0.0-alpha.14" }
# use crates.io*
= "1.0.0-alpha.14"
* crates.io requires libdrift is installed and linked locally
Use
The DriftClient struct provides methods for reading drift program accounts and crafting transactions.
It is built on a subscription model where live account updates are transparently cached and made accessible via accessor methods.
The client may be subscribed either via Ws or gRPC.
use ;
use Keypair;
async
Setup
Mac
Install rosetta (m-series only) and configure Rust toolchain for x86_64
⚠️ 1.76.0-x86_64 must also be installed alongside latest stable rust
# replace '1.85.0' with preferred latest stable version
Linux
# replace '1.85.0' with preferred latest stable version
⚠️ the non-x86_64 toolchains are incompatible due to memory layout differences between solana program (BPF) and aarch64 and will fail at runtime with deserialization errors like: InvalidSize.
Local Development
drift-rs links to the drift program crate via FFI, build from source (default) by cloning git submodule or dynamically link with a version from drift-ffi-sys
clone repo and submodules
&&\
&&\
build
# 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"
Development
Release
git tag v<MAJOR.MINOR.PATCH> && git push
Updating IDL types
from repo root dir:
./scripts/idl-update.sh
cargo check # build new IDL types
# commit changes...