From 83b30be79991e3f985abf17cdafdc247fccd57bd Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Wed, 30 Oct 2024 10:05:51 -0500 Subject: [PATCH 1/2] bug --- crates/sui-deepbook-indexer/src/server.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/sui-deepbook-indexer/src/server.rs b/crates/sui-deepbook-indexer/src/server.rs index 0d2b1ff85092f..e4d78e8f67489 100644 --- a/crates/sui-deepbook-indexer/src/server.rs +++ b/crates/sui-deepbook-indexer/src/server.rs @@ -195,23 +195,21 @@ async fn get_manager_balance( ) -> Result>, DeepBookError> { let connection = &mut state.pool.get().await?; - // Query to get the balance for all assets for the specified manager_id let query = format!( - "SELECT asset, SUM(CASE WHEN deposit THEN amount ELSE -amount END)::bigint AS amount, deposit FROM balances \ + "SELECT asset, SUM(amount)::bigint AS amount, deposit FROM balances \ WHERE balance_manager_id = '{}' GROUP BY asset, deposit", manager_id ); let results: Vec = diesel::sql_query(query).load(connection).await?; - // Aggregate results into a HashMap as {asset: balance} let mut manager_balances = HashMap::new(); for result in results { let mut asset = result.asset; if !asset.starts_with("0x") { asset.insert_str(0, "0x"); } - manager_balances.insert(asset, result.amount); + *manager_balances.entry(asset).or_insert(0) += result.amount; } Ok(Json(manager_balances)) From 66f997dc64be2e032cb4635b3f765556f54c19f3 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Wed, 30 Oct 2024 12:44:53 -0500 Subject: [PATCH 2/2] remove endpoint --- crates/sui-deepbook-indexer/src/server.rs | 28 ----------------------- 1 file changed, 28 deletions(-) diff --git a/crates/sui-deepbook-indexer/src/server.rs b/crates/sui-deepbook-indexer/src/server.rs index e4d78e8f67489..518db2353da49 100644 --- a/crates/sui-deepbook-indexer/src/server.rs +++ b/crates/sui-deepbook-indexer/src/server.rs @@ -29,7 +29,6 @@ pub const GET_24HR_VOLUME_BY_BALANCE_MANAGER_ID: &str = pub const GET_HISTORICAL_VOLUME_PATH: &str = "/get_historical_volume/:pool_ids/:start_time/:end_time"; pub const GET_NET_DEPOSITS: &str = "/get_net_deposits/:asset_ids/:timestamp"; -pub const GET_MANAGER_BALANCE: &str = "/get_manager_balance/:manager_id"; pub fn run_server(socket_address: SocketAddr, state: PgDeepbookPersistent) -> JoinHandle<()> { tokio::spawn(async move { @@ -48,7 +47,6 @@ pub(crate) fn make_router(state: PgDeepbookPersistent) -> Router { GET_24HR_VOLUME_BY_BALANCE_MANAGER_ID, get(get_24hr_volume_by_balance_manager_id), ) - .route(GET_MANAGER_BALANCE, get(get_manager_balance)) .route(GET_NET_DEPOSITS, get(get_net_deposits)) .with_state(state) } @@ -189,32 +187,6 @@ async fn get_24hr_volume_by_balance_manager_id( Ok(Json(vec![maker_vol, taker_vol])) } -async fn get_manager_balance( - Path(manager_id): Path, - State(state): State, -) -> Result>, DeepBookError> { - let connection = &mut state.pool.get().await?; - - let query = format!( - "SELECT asset, SUM(amount)::bigint AS amount, deposit FROM balances \ - WHERE balance_manager_id = '{}' GROUP BY asset, deposit", - manager_id - ); - - let results: Vec = diesel::sql_query(query).load(connection).await?; - - let mut manager_balances = HashMap::new(); - for result in results { - let mut asset = result.asset; - if !asset.starts_with("0x") { - asset.insert_str(0, "0x"); - } - *manager_balances.entry(asset).or_insert(0) += result.amount; - } - - Ok(Json(manager_balances)) -} - #[debug_handler] async fn get_net_deposits( Path((asset_ids, timestamp)): Path<(String, String)>,