Skip to content

bump IDL to latest devnet version #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/on-libdrift-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:

jobs:
update-libdrift-submodule:
permissions:
contents: write
runs-on: ubicloud
steps:
- name: Checkout
Expand All @@ -27,11 +29,13 @@ jobs:
git add -u

- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git diff --staged --quiet; then
echo "No changes to submodule, skipping commit"
exit 0
fi

git commit -m "chore: bump drift-ffi-sys to latest version 🤖"
git push origin main
git push origin main -f
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
repo: ['gateway', 'fastlane-server']
repo: ['gateway', 'swift']
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@ Experimental, high performance Rust SDK for building offchain clients for [Drift
## Install
```toml
# crates.io
drift-rs = "1.0.0-alpha.10"
drift-rs = "1.0.0-alpha.11"

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

## Use
```rust
use drift_rs::{DriftClient, Wallet};
use solana_sdk::signature::KeyPair;
use solana_sdk::signature::Keypair;

async fn main() {
let client = DriftClient::new(
Context::MainNet,
RpcClient::new("https://rpc-provider.com"),
KeyPair::new().into(),
Keypair::new().into(),
)
.await
.expect("connects");

/// Subscribe to Ws-based live prices, blockhashes, and oracle updates
// 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
Expand Down Expand Up @@ -73,6 +74,9 @@ CARGO_DRIFT_FFI_PATH="/path/to/libdrift_ffi_sys"
`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
from repo root dir:
```shell
./scripts/idl-update.sh
cargo check # build new IDL types
# commit changes...
```
208 changes: 208 additions & 0 deletions crates/src/drift_idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ pub mod instructions {
#[automatically_derived]
impl anchor_lang::InstructionData for ResizeSignedMsgUserOrders {}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct InitializeSignedMsgWsDelegates {
pub delegates: Vec<Pubkey>,
}
#[automatically_derived]
impl anchor_lang::Discriminator for InitializeSignedMsgWsDelegates {
const DISCRIMINATOR: [u8; 8] = [40, 132, 96, 219, 184, 193, 80, 8];
}
#[automatically_derived]
impl anchor_lang::InstructionData for InitializeSignedMsgWsDelegates {}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct ChangeSignedMsgWsDelegateStatus {
pub delegate: Pubkey,
pub add: bool,
}
#[automatically_derived]
impl anchor_lang::Discriminator for ChangeSignedMsgWsDelegateStatus {
const DISCRIMINATOR: [u8; 8] = [252, 202, 252, 219, 179, 27, 84, 138];
}
#[automatically_derived]
impl anchor_lang::InstructionData for ChangeSignedMsgWsDelegateStatus {}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct InitializeFuelOverflow {}
#[automatically_derived]
impl anchor_lang::Discriminator for InitializeFuelOverflow {
Expand Down Expand Up @@ -2062,6 +2083,7 @@ pub mod instructions {
pub struct UpdateProtectedMakerModeConfig {
pub max_users: u32,
pub reduce_only: bool,
pub current_users: Option<u32>,
}
#[automatically_derived]
impl anchor_lang::Discriminator for UpdateProtectedMakerModeConfig {
Expand Down Expand Up @@ -4603,6 +4625,46 @@ pub mod accounts {
}
}
#[repr(C)]
#[derive(
AnchorSerialize, AnchorDeserialize, Serialize, Deserialize, Clone, Default, Debug, PartialEq,
)]
pub struct SignedMsgWsDelegates {
pub delegates: Vec<Pubkey>,
}
#[automatically_derived]
impl anchor_lang::Discriminator for SignedMsgWsDelegates {
const DISCRIMINATOR: [u8; 8] = [190, 115, 111, 44, 216, 252, 108, 85];
}
#[automatically_derived]
impl anchor_lang::AccountSerialize for SignedMsgWsDelegates {
fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
if writer.write_all(&Self::DISCRIMINATOR).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
if AnchorSerialize::serialize(self, writer).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
Ok(())
}
}
#[automatically_derived]
impl anchor_lang::AccountDeserialize for SignedMsgWsDelegates {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let given_disc = &buf[..8];
if Self::DISCRIMINATOR != given_disc {
return Err(anchor_lang::error!(
anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
));
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}
#[repr(C)]
#[derive(
AnchorSerialize,
AnchorDeserialize,
Expand Down Expand Up @@ -5427,6 +5489,152 @@ pub mod accounts {
}
#[repr(C)]
#[derive(Copy, Clone, Default, AnchorSerialize, AnchorDeserialize, Serialize, Deserialize)]
pub struct InitializeSignedMsgWsDelegates {
pub signed_msg_ws_delegates: Pubkey,
pub authority: Pubkey,
pub rent: Pubkey,
pub system_program: Pubkey,
}
#[automatically_derived]
impl anchor_lang::Discriminator for InitializeSignedMsgWsDelegates {
const DISCRIMINATOR: [u8; 8] = [171, 35, 226, 71, 228, 189, 130, 139];
}
#[automatically_derived]
unsafe impl anchor_lang::__private::bytemuck::Pod for InitializeSignedMsgWsDelegates {}
#[automatically_derived]
unsafe impl anchor_lang::__private::bytemuck::Zeroable for InitializeSignedMsgWsDelegates {}
#[automatically_derived]
impl anchor_lang::ZeroCopy for InitializeSignedMsgWsDelegates {}
#[automatically_derived]
impl anchor_lang::InstructionData for InitializeSignedMsgWsDelegates {}
#[automatically_derived]
impl ToAccountMetas for InitializeSignedMsgWsDelegates {
fn to_account_metas(&self) -> Vec<AccountMeta> {
vec![
AccountMeta {
pubkey: self.signed_msg_ws_delegates,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: self.authority,
is_signer: true,
is_writable: true,
},
AccountMeta {
pubkey: self.rent,
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: self.system_program,
is_signer: false,
is_writable: false,
},
]
}
}
#[automatically_derived]
impl anchor_lang::AccountSerialize for InitializeSignedMsgWsDelegates {
fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
if writer.write_all(&Self::DISCRIMINATOR).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
if AnchorSerialize::serialize(self, writer).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
Ok(())
}
}
#[automatically_derived]
impl anchor_lang::AccountDeserialize for InitializeSignedMsgWsDelegates {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let given_disc = &buf[..8];
if Self::DISCRIMINATOR != given_disc {
return Err(anchor_lang::error!(
anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
));
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}
#[repr(C)]
#[derive(Copy, Clone, Default, AnchorSerialize, AnchorDeserialize, Serialize, Deserialize)]
pub struct ChangeSignedMsgWsDelegateStatus {
pub signed_msg_ws_delegates: Pubkey,
pub authority: Pubkey,
pub system_program: Pubkey,
}
#[automatically_derived]
impl anchor_lang::Discriminator for ChangeSignedMsgWsDelegateStatus {
const DISCRIMINATOR: [u8; 8] = [115, 165, 130, 151, 247, 6, 159, 9];
}
#[automatically_derived]
unsafe impl anchor_lang::__private::bytemuck::Pod for ChangeSignedMsgWsDelegateStatus {}
#[automatically_derived]
unsafe impl anchor_lang::__private::bytemuck::Zeroable for ChangeSignedMsgWsDelegateStatus {}
#[automatically_derived]
impl anchor_lang::ZeroCopy for ChangeSignedMsgWsDelegateStatus {}
#[automatically_derived]
impl anchor_lang::InstructionData for ChangeSignedMsgWsDelegateStatus {}
#[automatically_derived]
impl ToAccountMetas for ChangeSignedMsgWsDelegateStatus {
fn to_account_metas(&self) -> Vec<AccountMeta> {
vec![
AccountMeta {
pubkey: self.signed_msg_ws_delegates,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: self.authority,
is_signer: true,
is_writable: true,
},
AccountMeta {
pubkey: self.system_program,
is_signer: false,
is_writable: false,
},
]
}
}
#[automatically_derived]
impl anchor_lang::AccountSerialize for ChangeSignedMsgWsDelegateStatus {
fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> anchor_lang::Result<()> {
if writer.write_all(&Self::DISCRIMINATOR).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
if AnchorSerialize::serialize(self, writer).is_err() {
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
Ok(())
}
}
#[automatically_derived]
impl anchor_lang::AccountDeserialize for ChangeSignedMsgWsDelegateStatus {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let given_disc = &buf[..8];
if Self::DISCRIMINATOR != given_disc {
return Err(anchor_lang::error!(
anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
));
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}
#[repr(C)]
#[derive(Copy, Clone, Default, AnchorSerialize, AnchorDeserialize, Serialize, Deserialize)]
pub struct InitializeFuelOverflow {
pub fuel_overflow: Pubkey,
pub user_stats: Pubkey,
Expand Down
18 changes: 9 additions & 9 deletions crates/src/jit_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
build_accounts,
constants::{self, state_account, JIT_PROXY_ID},
drift_idl,
fastlane_order_subscriber::SignedOrderInfo,
swift_order_subscriber::SignedOrderInfo,
types::PositionDirection,
DriftClient, MarketId, MarketType, PostOnlyParam, ReferrerInfo, SdkError, SdkResult,
TransactionBuilder, Wallet,
Expand Down Expand Up @@ -228,7 +228,7 @@ impl JitProxyClient {
Ok(VersionedMessage::V0(message))
}

/// Build a fastlane fill tx against a taker order given by `taker_params`
/// Build a swift fill tx against a taker order given by `taker_params`
///
/// `signed_order_info` Fastlane (order) message to place-and-make against
/// `taker_params` taker account params
Expand All @@ -237,7 +237,7 @@ impl JitProxyClient {
/// `maker_account_data` Maker's (User) account data corresponding with the `maker_pubkey`
///
/// Returns a Solana `VersionedMessage` ready for signing
pub async fn build_fastlane_ix(
pub async fn build_swift_ix(
&self,
signed_order_info: &SignedOrderInfo,
taker_params: &JitTakerParams,
Expand Down Expand Up @@ -270,7 +270,7 @@ impl JitProxyClient {
user_stats: Wallet::derive_stats_account(&maker_authority),
taker: taker_params.taker_key,
taker_stats: taker_params.taker_stats_key,
taker_signed_msg_user_orders: Wallet::derive_fastlane_order_account(
taker_signed_msg_user_orders: Wallet::derive_swift_order_account(
&taker_params.taker.authority,
),
drift_program: constants::PROGRAM_ID,
Expand Down Expand Up @@ -320,7 +320,7 @@ impl JitProxyClient {
Cow::Borrowed(maker_account_data),
false,
)
.place_fastlane_order(&signed_order_info, &taker_params.taker)
.place_swift_order(&signed_order_info, &taker_params.taker)
.add_ix(fill_ix)
.build();

Expand Down Expand Up @@ -358,14 +358,14 @@ impl JitProxyClient {
.await
}

/// Try fill against a fastlane order with JIT-proxy protection
/// Try fill against a swift order with JIT-proxy protection
///
/// `signed_order_info` the fastlane order info
/// `signed_order_info` the swift order info
/// `taker_params` taker account data for the tx
/// `jit_params` bounds for the JIT fill
/// `maker_authority` the maker's authority key
/// `sub_account_id` the maker's sub-account for the fill
pub async fn try_fastlane_fill(
pub async fn try_swift_fill(
&self,
signed_order_info: &SignedOrderInfo,
taker_params: &JitTakerParams,
Expand All @@ -377,7 +377,7 @@ impl JitProxyClient {
Wallet::derive_user_account(maker_authority, sub_account_id.unwrap_or_default());
let sub_account_data = self.drift_client.get_user_account(&sub_account).await?;
let tx = self
.build_fastlane_ix(
.build_swift_ix(
signed_order_info,
taker_params,
jit_params,
Expand Down
Loading