From 32b31afa32b33e4580834691727664db93a4c177 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 24 Oct 2024 12:33:54 +0800 Subject: [PATCH] Update drift-rs v1.0.0-alpha.3 (#87) Better debug msgs for missing market subs with --verbose Make calculations just work when markets are not subscribed (fallback to network fetch) --- Cargo.lock | 10 +++++----- Cargo.toml | 4 ++-- src/controller.rs | 17 +++++++---------- src/main.rs | 17 ++++++++++------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57288de..006a02d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1763,12 +1763,12 @@ dependencies = [ [[package]] name = "drift-gateway" -version = "1.1.0" +version = "1.1.1" dependencies = [ "actix-web", "argh", "drift-rs", - "env_logger 0.9.3", + "env_logger 0.11.5", "futures-util", "log", "rust_decimal", @@ -1785,7 +1785,7 @@ dependencies = [ [[package]] name = "drift-idl-gen" version = "0.1.1" -source = "git+https://github.com/drift-labs/drift-rs?tag=v1.0.0-alpha.2#8bf9630aa8cc7a3749e8c0e9afd41254c418e370" +source = "git+https://github.com/drift-labs/drift-rs?tag=v1.0.0-alpha.3#b297da37e8b85661d5f6157385d81c4253712e3d" dependencies = [ "proc-macro2", "quote", @@ -1797,8 +1797,8 @@ dependencies = [ [[package]] name = "drift-rs" -version = "1.0.0-alpha.2" -source = "git+https://github.com/drift-labs/drift-rs?tag=v1.0.0-alpha.2#8bf9630aa8cc7a3749e8c0e9afd41254c418e370" +version = "1.0.0-alpha.3" +source = "git+https://github.com/drift-labs/drift-rs?tag=v1.0.0-alpha.3#b297da37e8b85661d5f6157385d81c4253712e3d" dependencies = [ "abi_stable", "ahash 0.8.11", diff --git a/Cargo.toml b/Cargo.toml index 4529a76..40065b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "drift-gateway" -version = "1.1.0" +version = "1.1.1" edition = "2021" [dependencies] actix-web = "*" argh = "*" -drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.2" } +drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.3" } env_logger = "*" futures-util = "*" log = "*" diff --git a/src/controller.rs b/src/controller.rs index 09adce7..ee8723f 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -335,34 +335,31 @@ impl AppState { let sub_account = self.resolve_sub_account(ctx.sub_account_id); let user = self.client.get_user_account(&sub_account).await?; - let oracle_price = self - .client - .oracle_price(MarketId::perp(market.market_index)) - .await?; let perp_position = user .perp_positions .iter() .find(|p| p.market_index == market.market_index && !p.is_available()); if let Some(perp_position) = perp_position { - let result = calculate_liquidation_price_and_unrealized_pnl( + let calc = calculate_liquidation_price_and_unrealized_pnl( &self.client, &user, market.market_index, - )?; + ) + .await?; let unsettled_pnl = Decimal::from_i128_with_scale( perp_position - .get_unrealized_pnl(oracle_price) + .get_unrealized_pnl(calc.oracle_price) .unwrap_or_default(), PRICE_DECIMALS, ); let mut p: PerpPosition = (*perp_position).into(); p.set_extended_info(PerpPositionExtended { - liquidation_price: Decimal::new(result.liquidation_price, PRICE_DECIMALS), - unrealized_pnl: Decimal::new(result.unrealized_pnl as i64, PRICE_DECIMALS), + liquidation_price: Decimal::new(calc.liquidation_price, PRICE_DECIMALS), + unrealized_pnl: Decimal::new(calc.unrealized_pnl as i64, PRICE_DECIMALS), unsettled_pnl: unsettled_pnl.normalize(), - oracle_price: Decimal::new(oracle_price, PRICE_DECIMALS), + oracle_price: Decimal::new(calc.oracle_price, PRICE_DECIMALS), }); Ok(p) diff --git a/src/main.rs b/src/main.rs index 6e262c8..8e881aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -209,14 +209,17 @@ async fn get_collateral( #[actix_web::main] async fn main() -> std::io::Result<()> { let config: GatewayConfig = argh::from_env(); - let log_level = if config.verbose { - log::LevelFilter::Debug + + let mut logger = env_logger::Builder::from_default_env(); + if config.verbose { + logger + .filter_module(LOG_TARGET, log::LevelFilter::Debug) + .filter_module("rpc", log::LevelFilter::Debug) } else { - log::LevelFilter::Info - }; - env_logger::Builder::from_default_env() - .filter_module(LOG_TARGET, log_level) - .init(); + logger.filter_module(LOG_TARGET, log::LevelFilter::Info) + } + .init(); + let secret_key = std::env::var("DRIFT_GATEWAY_KEY"); let delegate = config .delegate