https://github.com/drift-labs/protocol-v2
On-chain perpetuals dex with multiple liquidity mechanisms
https://github.com/drift-labs/protocol-v2
rust smart-contracts solana
Last synced: 6 months ago
JSON representation
On-chain perpetuals dex with multiple liquidity mechanisms
- Host: GitHub
- URL: https://github.com/drift-labs/protocol-v2
- Owner: drift-labs
- License: apache-2.0
- Created: 2022-05-27T15:21:34.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-05-12T19:06:44.000Z (about 1 year ago)
- Last Synced: 2025-05-12T20:27:31.034Z (about 1 year ago)
- Topics: rust, smart-contracts, solana
- Language: TypeScript
- Homepage:
- Size: 34.3 MB
- Stars: 272
- Watchers: 14
- Forks: 141
- Open Issues: 78
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Audit: AUDIT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-agent-cortex - Drift Protocol v2 - On-chain perpetuals protocol infrastructure for autonomous trading agents. (DeFi Agents / Benchmark Reality Check (real-world tool use))
- awesome-solana-programs - Drift Protocol - Decentralized derivatives exchange (DeFi / Derivatives)
README
# Drift Protocol v2
This repository provides open source access to Drift V2's Typescript SDK, Solana Programs, and more.
Integrating Drift? [Go here](./sdk/README.md)
# SDK Guide
SDK docs can be found [here](./sdk/README.md)
# Example Bot Implementations
Example bots (makers, liquidators, fillers, etc) can be found [here](https://github.com/drift-labs/keeper-bots-v2)
# Building Locally
Note: If you are running the build on an Apple computer with an M1 chip, please set the default rust toolchain to `stable-x86_64-apple-darwin`
```bash
rustup default stable-x86_64-apple-darwin
```
## Compiling Programs
```bash
# build v2
anchor build
# install packages
yarn
# build sdk
cd sdk/ && yarn && yarn build && cd ..
```
## Running Rust Test
```bash
cargo test
```
## Running Javascript Tests
```bash
bash test-scripts/run-anchor-tests.sh
```
# Development (with devcontainer)
We've provided a devcontainer `Dockerfile` to help you spin up a dev environment with the correct versions of Rust, Solana, and Anchor for program development.
Build the container and tag it `drift-dev`:
```
cd .devcontainer && docker build -t drift-dev .
```
Open a shell to the container:
```
# Find the container ID first
docker ps
# Then exec into it
docker exec -it /bin/bash
```
Alternatively use an extension provided by your IDE to make use of the dev container. For example on vscode/cursor:
```
1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
2. Type "Dev Containers: Reopen in Container"
3. Select it and wait for the container to build
4. The IDE terminal should be targeting the dev container now
```
Use the dev container as you would a local build environment:
```
# build program
anchor build
# update idl
anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json
# run cargo tests
cargo test
# run typescript tests
bash test-scripts/run-anchor-tests.sh
```
# Bug Bounty
Information about the Bug Bounty can be found [here](./bug-bounty/README.md)