Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 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 (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T04:03:11.000Z (3 months ago)
- Last Synced: 2024-10-24T16:34:35.543Z (3 months ago)
- Topics: dex, driftv2, perpetuals, rust, solana
- Language: Rust
- Homepage:
- Size: 1.42 MB
- Stars: 19
- Watchers: 7
- Forks: 10
- Open Issues: 2
-
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.
## Install
```toml
# crates.io*
drift-rs = "1.0.0-alpha.3"# 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.3" }
```_*_`drift-rs` uses drift program over ffi.
ensure [libdrift_ffi_sys](https://github.com/drift-labs/drift-ffi-sys/blob/master/README.md#installation) is installed when using via crates.io.## 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 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`
```bash
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
```⚠️ 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 or optionally install from [drift-ffi-sys](https://github.com/drift-labs/drift-ffi-sys/releases)
```bash
# Build from source
CARGO_DRIFT_FFI_STATIC=1
# Provide a prebuilt drift_ffi_sys lib
CARGO_DRIFT_FFI_PATH="/path/to/libdrift_ffi_sys"
```