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

API: TVL in native and USD #199

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
306 changes: 303 additions & 3 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"account_traits_derive",
"api",
"bytemuck",
"cli",
"clients/rust/restaking_client",
Expand Down Expand Up @@ -41,6 +42,7 @@ readme = "README.md"
anchor-lang = { version = "0.30.1", features = ["idl-build"] }
anyhow = "1.0.86"
assert_matches = "1.5.0"
axum = "0.6.2"
borsh = { version = "0.10.3" }
bytemuck = { version = "1.16.3", features = ["min_const_generics"] }
cfg-if = "1.0.0"
Expand All @@ -52,6 +54,7 @@ dotenv = "0.15.0"
envfile = "0.2.1"
env_logger = "0.10.2"
futures = "0.3.31"
http = "0.2.1"
jito-bytemuck = { path = "bytemuck", version = "=0.0.3" }
jito-account-traits-derive = { path = "account_traits_derive", version = "=0.0.3" }
jito-jsm-core = { path = "core", version = "=0.0.3" }
Expand All @@ -69,7 +72,9 @@ num-derive = "0.4.2"
num-traits = "0.2.19"
proc-macro2 = "1.0.86"
quote = "1.0.36"
reqwest = "0.11.27"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "1.0.102"
serde_with = "3.9.0"
shank = "0.4.2"
shank_idl = "0.4.2"
Expand All @@ -89,3 +94,8 @@ syn = "2.0.72"
test-case = "3.3.1"
thiserror = "1.0.57"
tokio = { version = "1.36.0", features = ["full"] }
tower = { version = "0.4.13", features = ["limit", "buffer", "timeout", "load-shed"] }
tower-http = { version = "0.4.0", features = ["trace"] }
tracing = { version = "0.1.37" }
tracing-core = "0.1.32"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
37 changes: 37 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "jito-restaking-api"
description = "Jito Restaking API"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
readme = { workspace = true }

[[bin]]
name = "jito-restaking-api"
path = "src/bin/main.rs"

[dependencies]
anchor-lang = { workspace = true }
axum = { workspace = true }
clap = { workspace = true }
http = { workspace = true }
jito-bytemuck = { workspace = true }
jito-vault-client = { workspace = true, features = ["serde"] }
jito-vault-core = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
solana-account-decoder = { workspace = true }
solana-program = { workspace = true }
solana-rpc-client = { workspace = true }
solana-rpc-client-api = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tower = { workspace = true }
tower-http = { workspace = true }
tracing = { workspace = true }
tracing-core = { workspace = true }
tracing-subscriber = { workspace = true }
175 changes: 175 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Jito Restaking API

# StakeNet API

## Overview

This API allows users to:

- Retrieve TVL for each vault in native and USD vaules.
- List all vaults with their details.

## Endpoints

1. Get TVL for All Vaults

Fetches TVL for each vault in **native unit** and USD.

Endpoint:

```http
GET api/v1/vaults/tvl
```

Response:

```json
[
{
"vault_pubkey":"CugziSqZXcUStNPXbtRmq6atsrHqWY2fH2tAhsyApQrV",
"supported_mint":"J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"native_unit_tvl":291871.554825083,
"native_unit_symbol":"JITOSOL",
"usd_tvl":82042175.34578258
},
{
"vault_pubkey":"CQpvXgoaaawDCLh8FwMZEwQqnPakRUZ5BnzhjnEBPJv",
"supported_mint":"J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"native_unit_tvl":134310.541925135,
"native_unit_symbol":"JITOSOL",
"usd_tvl":37753350.229736194
},
]
```

2. Get TVL for a Specific Vault

Fetches TVL for a single vault.

Endpoint:

```http
GET api/v1/vaults/{vault_pubkey}/tvl/
```

Response:

```json
{
"vault_pubkey":"CugziSqZXcUStNPXbtRmq6atsrHqWY2fH2tAhsyApQrV",
"supported_mint":"J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"native_unit_tvl":291871.554825083,
"native_unit_symbol":"JITOSOL",
"usd_tvl":82042175.34578258
}
```

3. List All Vaults

Retrieves all vaults with details.

Endpoint:

```http
GET api/v1/vaults
```

Response:

```json
[
{
"discriminator":2,
"base":"AbH5RtAgpnxyRuT9LqXR9ye4JuuJoHs6E5ENPvCnSRDk",
"vrt_mint":"CtJcH6BeUPKEfBNaUoPjmEc88E4aLuEJZU4NkuSdnpZo",
"supported_mint":"J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"vrt_supply":9306868868,
"tokens_deposited":9306868868,
"deposit_capacity":680411000000000,
"delegation_state":
{
"staked_amount":0,
"enqueued_for_cooldown_amount":0,
"cooling_down_amount":0,
...
}
...
}
...
]
```

4. Get Vault Details

Retrieves details of a specific vault.

Endpoint:

```http
GET api/v1/vaults/{vault_pubkey}
```

Response:

```json
{
"discriminator":2,
"base":"AbH5RtAgpnxyRuT9LqXR9ye4JuuJoHs6E5ENPvCnSRDk",
"vrt_mint":"CtJcH6BeUPKEfBNaUoPjmEc88E4aLuEJZU4NkuSdnpZo",
"supported_mint":"J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"vrt_supply":9306868868,
"tokens_deposited":9306868868,
"deposit_capacity":680411000000000,
"delegation_state":
{
"staked_amount":0,
"enqueued_for_cooldown_amount":0,
"cooling_down_amount":0,
...
}
...
}
```


## Build

### Prerequisites

- [Solana's RPC Client](https://docs.rs/solana-rpc-client/latest/solana_rpc_client/)
- [Axum](https://docs.rs/axum/latest/axum/)

### Build for release

To build the API for release, run the following command:

```bash
cargo b --release --bin jito-restaking-api
```

### Check available options

To view the options available for configuring the API:

```bash
./target/release/jito-restaking-api --help

# Jito Restaking API
#
# Usage: jito-restaking-api [OPTIONS]
#
# Options:
# --bind-addr <BIND_ADDR> Bind address for the server [env: BIND_ADDR=] [default: 0.0.0.0:7001]
# --rpc-url <RPC_URL> RPC url [env: RPC_URL=] [default: https://api.mainnet-beta.solana.com]
# -h, --help Print help
# -V, --version Print version
```

### Running the API

Once built, run the API using the following command:

```bash
./target/release/jito-restaking-api -- --rpc-url "your-rpc-url"
```

42 changes: 42 additions & 0 deletions api/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::{net::SocketAddr, str::FromStr, sync::Arc};

use clap::Parser;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use tracing::{info, instrument};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Args {
/// Bind address for the server
#[arg(long, env, default_value_t = SocketAddr::from_str("0.0.0.0:7001").unwrap())]
pub bind_addr: SocketAddr,

Check warning on line 12 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L11-L12

Added lines #L11 - L12 were not covered by tests

/// RPC url
#[arg(long, env, default_value = "https://api.mainnet-beta.solana.com")]
pub rpc_url: String,

Check warning on line 16 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L16

Added line #L16 was not covered by tests
}

#[tokio::main]
#[instrument]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

tracing_subscriber::fmt().init();

info!("args: {:?}", args);

Check warning on line 26 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L20-L26

Added lines #L20 - L26 were not covered by tests

info!("starting server at {}", args.bind_addr);

Check warning on line 28 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L28

Added line #L28 was not covered by tests

let rpc_client = RpcClient::new(args.rpc_url.clone());
info!("started rpc client at {}", args.rpc_url);

Check warning on line 31 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L30-L31

Added lines #L30 - L31 were not covered by tests

let state = Arc::new(jito_restaking_api::router::RouterState { rpc_client });

let app = jito_restaking_api::router::get_routes(state);

axum::Server::bind(&args.bind_addr)
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await?;

Check warning on line 39 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L33-L39

Added lines #L33 - L39 were not covered by tests

Ok(())

Check warning on line 41 in api/src/bin/main.rs

View check run for this annotation

Codecov / codecov/patch

api/src/bin/main.rs#L41

Added line #L41 was not covered by tests
}
Loading
Loading