#solana #drift #api-bindings #sdk #dex

drift-rs

Rust SDK for Drift V2 Protocol on the Solana blockchain

9 releases

new 1.0.0-alpha.11 Feb 20, 2025
1.0.0-alpha.10 Feb 12, 2025
1.0.0-alpha.6 Jan 23, 2025
1.0.0-alpha.4 Nov 22, 2024
1.0.0-alpha.3 Oct 24, 2024

#51 in Magic Beans

Download history 17/week @ 2024-10-29 21/week @ 2024-11-05 132/week @ 2024-11-19 18/week @ 2024-11-26 1/week @ 2024-12-03 7/week @ 2024-12-10 118/week @ 2025-01-21 9/week @ 2025-01-28 260/week @ 2025-02-04 224/week @ 2025-02-11

611 downloads per month

Apache-2.0

1.5MB
32K SLoC

drift-rs

Crates.io Docs Discord Chat License

drift-rs

Experimental, high performance Rust SDK for building offchain clients for Drift V2 protocol.

Install

# crates.io
drift-rs = "1.0.0-alpha.10"

# build from source
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.10" }

Use

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();
}

Setup

Mac (m-series)

Install rosetta and configure Rust toolchain for x86_64

softwareupdate --install-rosetta
# replace `1.84.0` with preferred stable version
rustup install 1.84.0-x86_64-apple-darwin
rustup override set 1.84.0-x86_64-apple-darwin

⚠️ the default toolchain is 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) or dynamically link with a version 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"

Development

Release

git tag v<MAJOR.MINOR.PATCH> && git push

Updating IDL types

  1. copy the updated IDL to res/drift.json from protocol-v2 branch
  2. cargo check
  3. commit changes

Dependencies

~86MB
~1.5M SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy