Skip to content

Commit

Permalink
Remove balance endpoint (#20095)
Browse files Browse the repository at this point in the history
## Description 

Remove balance endpoint for Deepbook Indexer

## Test plan 

How did you test the new or updated feature?

Local indexer

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [x] Indexer: Deepbook Indexer endpoint removal
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
tonylee08 authored Nov 4, 2024
1 parent d4b1965 commit 7523fe8
Showing 1 changed file with 0 additions and 30 deletions.
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

0 comments on commit 7523fe8

Please sign in to comment.