https://github.com/drift-labs/drift-rs
rust sdk to interact with drift v2
https://github.com/drift-labs/drift-rs
dex driftv2 perpetuals rust solana
Last synced: about 2 months ago
JSON representation
rust sdk to interact with drift v2
- Host: GitHub
- URL: https://github.com/drift-labs/drift-rs
- Owner: drift-labs
- License: apache-2.0
- Created: 2024-02-26T03:13:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-12T02:52:48.000Z (3 months ago)
- Last Synced: 2025-02-13T09:12:00.835Z (3 months ago)
- Topics: dex, driftv2, perpetuals, rust, solana
- Language: Rust
- Homepage:
- Size: 1.55 MB
- Stars: 24
- Watchers: 7
- Forks: 17
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# drift-rs
Experimental, high performance Rust SDK for building offchain clients for [Drift V2](https://github.com/drift-labs/protocol-v2) protocol.
See the offical [docs](https://docs.rs/drift-rs/latest/drift_rs/)
## Install
```toml
# crates.io
drift-rs = "1.0.0-alpha.14"# build from source
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.14" }
```## Use
```rust
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 market and price changes
let markets = [MarketId::spot(1), MarketId::perp(0)];
client.subscribe_markets(&markets).await.unwrap();
client.subscribe_oracles(&markets).await.unwrap();
}
```
## 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```bash
softwareupdate --install-rosetta# replace '1.85.0' with preferred latest stable version
rustup install 1.85.0-x86_64-apple-darwin 1.76.0-x86_64-apple-darwin --force-non-hostrustup override set 1.85.0-x86_64-apple-darwin
```### Linux
```bash
# replace '1.85.0' with preferred latest stable version
rustup install 1.85.0-x86_64-unknown-linux-gnu 1.76.0-x86_64-unknown-linux-gnu --force-non-hostrustup override set 1.85.0-x86_64-unknown-linux-gnu
```⚠️ 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](https://github.com/drift-labs/drift-ffi-sys/releases)**clone repo and submodules**
```bash
git clone https://github.com/drift-labs/drift-rs &&\
cd drift-rs &&\
git submodule update --init --recursive
```
**build**
```bash
# Build from source (default)
CARGO_DRIFT_FFI_STATIC=1
# on linux distros may need to run `ldconfig` to link
ldconfig# Provide a prebuilt drift_ffi_sys lib
CARGO_DRIFT_FFI_PATH="/path/to/libdrift_ffi_sys"
```
## Development## Release
`git tag v && git push`## Updating IDL types
from repo root dir:
```shell
./scripts/idl-update.sh
cargo check # build new IDL types
# commit changes...
```