Skip to content
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

Remove balance endpoint #20095

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
30 changes: 0 additions & 30 deletions crates/sui-deepbook-indexer/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -189,34 +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<String>,
State(state): State<PgDeepbookPersistent>,
) -> Result<Json<HashMap<String, i64>>, 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 \
WHERE balance_manager_id = '{}' GROUP BY asset, deposit",
manager_id
);

let results: Vec<BalancesSummary> = 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);
}

Ok(Json(manager_balances))
}

#[debug_handler]
async fn get_net_deposits(
Path((asset_ids, timestamp)): Path<(String, String)>,
Expand Down
Loading