Skip to content

Fix/multi luts #131

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 2 commits into from
Apr 3, 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
20 changes: 11 additions & 9 deletions crates/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ pub const TOKEN_PROGRAM_ID: Pubkey =
solana_sdk::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

/// Drift market lookup table (DevNet)
pub const LUT_DEVNET: Pubkey = solana_sdk::pubkey!("FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb");
pub const LUTS_DEVNET: &[Pubkey] = &[solana_sdk::pubkey!(
"FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb"
)];
/// Drift market lookup table (MainNet)
pub const LUT_MAINNET: Pubkey = solana_sdk::pubkey!("Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL");
pub const LUTS_MAINNET: &[Pubkey] = &[
solana_sdk::pubkey!("Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL"),
solana_sdk::pubkey!("EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb"),
];

/// Drift state account
pub fn state_account() -> &'static Pubkey {
Expand Down Expand Up @@ -111,7 +116,7 @@ impl MarketExt for SpotMarket {
pub struct ProgramData {
spot_markets: &'static [SpotMarket],
perp_markets: &'static [PerpMarket],
pub lookup_table: AddressLookupTableAccount,
pub lookup_tables: &'static [AddressLookupTableAccount],
}

impl ProgramData {
Expand All @@ -120,17 +125,14 @@ impl ProgramData {
Self {
spot_markets: &[],
perp_markets: &[],
lookup_table: AddressLookupTableAccount {
key: Pubkey::new_from_array([0; 32]),
addresses: vec![],
},
lookup_tables: &[],
}
}
/// Initialize `ProgramData`
pub fn new(
mut spot: Vec<SpotMarket>,
mut perp: Vec<PerpMarket>,
lookup_table: AddressLookupTableAccount,
lookup_tables: Vec<AddressLookupTableAccount>,
) -> Self {
spot.sort_by(|a, b| a.market_index.cmp(&b.market_index));
perp.sort_by(|a, b| a.market_index.cmp(&b.market_index));
Expand All @@ -151,7 +153,7 @@ impl ProgramData {
Self {
spot_markets: Box::leak(spot.into_boxed_slice()),
perp_markets: Box::leak(perp.into_boxed_slice()),
lookup_table,
lookup_tables: Box::leak(lookup_tables.into_boxed_slice()),
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/src/jit_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ impl JitProxyClient {
}
ixs.push(ix);

let lut = program_data.lookup_table.clone();
let luts = program_data.lookup_tables;

// TODO: update with multiple-LUTs
let message =
v0::Message::try_compile(&maker_authority, ixs.as_slice(), &[lut], Default::default())
v0::Message::try_compile(&maker_authority, ixs.as_slice(), luts, Default::default())
.expect("failed to compile message");

Ok(VersionedMessage::V0(message))
Expand Down
24 changes: 16 additions & 8 deletions crates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,16 +737,24 @@ impl DriftClientBackend {
let spot_market_map =
MarketMap::<SpotMarket>::new(Arc::clone(&pubsub_client), rpc_client.commitment());

let lookup_table_address = context.lut();
let lut_pubkeys = context.luts();

let (_, _, lut) = tokio::try_join!(
let (_, _, lut_accounts) = tokio::try_join!(
perp_market_map.sync(&rpc_client),
spot_market_map.sync(&rpc_client),
rpc_client
.get_account(&lookup_table_address)
.get_multiple_accounts(lut_pubkeys)
.map_err(Into::into),
)?;
let lookup_table = utils::deserialize_alt(lookup_table_address, &lut)?;

let lookup_tables = lut_pubkeys
.iter()
.zip(lut_accounts.iter())
.map(|(pubkey, account_data)| {
utils::deserialize_alt(*pubkey, account_data.as_ref().unwrap())
.expect("LUT decodes")
})
.collect();

let mut all_oracles = Vec::<(MarketId, Pubkey, OracleSource)>::with_capacity(
perp_market_map.len() + spot_market_map.len(),
Expand Down Expand Up @@ -780,7 +788,7 @@ impl DriftClientBackend {
program_data: ProgramData::new(
spot_market_map.values(),
perp_market_map.values(),
lookup_table,
lookup_tables,
),
account_map,
perp_market_map,
Expand Down Expand Up @@ -1171,7 +1179,7 @@ impl<'a> TransactionBuilder<'a> {
account_data: user,
sub_account,
ixs: Default::default(),
lookup_tables: vec![program_data.lookup_table.clone()],
lookup_tables: program_data.lookup_tables.to_vec(),
legacy: false,
force_markets: Default::default(),
}
Expand All @@ -1186,11 +1194,11 @@ impl<'a> TransactionBuilder<'a> {
self.legacy = true;
self
}
/// Set the tx lookup tables
/// Extend the tx lookup tables (always includes the defacto drift LUTs)
pub fn lookup_tables(mut self, lookup_tables: &[AddressLookupTableAccount]) -> Self {
self.lookup_tables = lookup_tables.to_vec();
self.lookup_tables
.push(self.program_data.lookup_table.clone());
.extend(self.program_data.lookup_tables.iter().cloned());

self
}
Expand Down
12 changes: 0 additions & 12 deletions crates/src/oraclemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,6 @@ impl OracleMap {
.map(|x| x.pubkey)
}

/// Return Oracle data by pubkey, if known
/// deprecated, see `get_by_key` instead
// #[deprecated]
// pub fn get(&self, key: &Pubkey) -> Option<Oracle> {
// self.get_by_key(key)
// }

// /// Return Oracle data by pubkey, if known
// pub fn get_by_key(&self, key: &Pubkey) -> Option<Oracle> {
// self.oraclemap.get(key).map(|o| o.value().clone())
// }

/// Return Oracle data by market, if known
pub fn get_by_market(&self, market: &MarketId) -> Option<Oracle> {
if let Some((oracle_pubkey, oracle_source)) = self.oracle_by_market.get(market) {
Expand Down
14 changes: 7 additions & 7 deletions crates/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use crate::drift_idl::{
types::*,
};
use crate::{
constants::{ids, LUT_DEVNET, LUT_MAINNET},
constants::{ids, LUTS_DEVNET, LUTS_MAINNET},
drift_idl::errors::ErrorCode,
Wallet,
};
Expand All @@ -53,7 +53,7 @@ pub fn is_one_of_variant<T: PartialEq>(value: &T, variants: &[T]) -> bool {
pub struct Context {
name: &'static str,
/// market lookup table
lut: Pubkey,
luts: &'static [Pubkey],
/// pyth program ID
pyth: Pubkey,
}
Expand All @@ -63,20 +63,20 @@ impl Context {
#[allow(non_upper_case_globals)]
pub const MainNet: Context = Self {
name: "mainnet",
lut: LUT_MAINNET,
luts: LUTS_MAINNET,
pyth: ids::pyth_program::ID,
};
/// Target DevNet context
#[allow(non_upper_case_globals)]
pub const DevNet: Context = Self {
name: "devnet",
lut: LUT_DEVNET,
luts: LUTS_DEVNET,
pyth: ids::pyth_program::ID_DEVNET,
};

/// Return drift lookup table address
pub fn lut(&self) -> Pubkey {
self.lut
/// Return drift lookup table address(es)
pub fn luts(&self) -> &[Pubkey] {
self.luts
}

/// Return pyth owner address
Expand Down
Loading