Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ scripts/keys
.DS_store

.env

# Test coverage
tarpaulin-report.html
8 changes: 6 additions & 2 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use kobe_api::{
validator::ValidatorsRequest,
},
};
use kobe_core::db_models::mev_rewards::{StakerRewardsStore, ValidatorRewardsStore};
use kobe_core::{
db_models::mev_rewards::{StakerRewardsStore, ValidatorRewardsStore},
validators_app::Cluster,
};
use log::*;
use mongodb::Client;
use serde_json::json;
Expand Down Expand Up @@ -245,8 +248,9 @@ async fn run_server(args: &Args) {
.await
.expect("Mongo connection failed.");
let db = c.database(&args.mongo_db_name);
let cluster = Cluster::get_cluster(&args.solana_cluster);

let query_resolver = QueryResolver::new(&db, &args.rpc_url);
let query_resolver = QueryResolver::new(&db, &args.rpc_url, cluster);

let cors = CorsLayer::new()
.allow_headers(Any)
Expand Down
33 changes: 27 additions & 6 deletions api/src/resolvers/query_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
use std::collections::{HashMap, HashSet};
use std::{
collections::{HashMap, HashSet},
str::FromStr,
};

use axum::{http::StatusCode, Extension, Json};
use cached::{proc_macro::cached, TimedCache};
use kobe_core::{
constants::{JITOSOL_VALIDATOR_LIST_MAINNET, JITOSOL_VALIDATOR_LIST_TESTNET},
db_models::{
error::DataStoreError,
mev_rewards::{StakerRewardsStore, ValidatorRewardsStore},
stake_pool_stats::{StakePoolStats, StakePoolStatsStore},
steward_events::StewardEventsStore,
validators::ValidatorStore,
},
validators_app::Cluster,
SortOrder, LAMPORTS_PER_SOL,
};
use log::error;
use mongodb::Database;
use serde::{Deserialize, Serialize};
use solana_borsh::v1::try_from_slice_unchecked;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_pubkey::{pubkey, Pubkey};
use solana_pubkey::Pubkey;
use spl_stake_pool::state::ValidatorList;
use thiserror::Error;

Expand All @@ -42,8 +47,6 @@ use log::warn;

type Result<T> = core::result::Result<T, QueryResolverError>;

const JITOSOL_VALIDATOR_LIST: Pubkey = pubkey!("3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn");

#[derive(Error, Debug)]
pub enum QueryResolverError {
#[error("querying data store error")]
Expand Down Expand Up @@ -72,7 +75,12 @@ pub struct QueryResolver {
validator_rewards_store: ValidatorRewardsStore,
staker_rewards_store: StakerRewardsStore,
steward_events_store: StewardEventsStore,

/// RPC Client URL
rpc_client_url: String,

/// Solana Cluster
cluster: Cluster,
}

fn aggregate_mev_rewards(stats_entries: &[StakePoolStats]) -> u64 {
Expand Down Expand Up @@ -364,7 +372,7 @@ pub async fn jitosol_ratio_cacheable_wrapper(
}

impl QueryResolver {
pub fn new(database: &Database, rpc_client_url: &str) -> Self {
pub fn new(database: &Database, rpc_client_url: &str, cluster: Cluster) -> Self {
Self {
stake_pool_store: StakePoolStatsStore::new(
database.collection(StakePoolStatsStore::COLLECTION),
Expand All @@ -380,6 +388,7 @@ impl QueryResolver {
database.collection(StewardEventsStore::COLLECTION),
),
rpc_client_url: rpc_client_url.into(),
cluster,
}
}

Expand Down Expand Up @@ -498,9 +507,21 @@ impl QueryResolver {

let rpc_client = RpcClient::new(self.rpc_client_url.clone());

let jito_sol_validator_list_address = match self.cluster {
Cluster::MainnetBeta => JITOSOL_VALIDATOR_LIST_MAINNET,
Cluster::Testnet => JITOSOL_VALIDATOR_LIST_TESTNET,
Cluster::Devnet => {
return Err(QueryResolverError::InvalidRequest(
"Devnet is not supported yet".to_string(),
));
}
};
let jitosol_validator_list = Pubkey::from_str(jito_sol_validator_list_address)
.map_err(|e| QueryResolverError::CustomError(e.to_string()))?;

// Get stake pool validator list
let validator_list_account = rpc_client
.get_account_data(&JITOSOL_VALIDATOR_LIST)
.get_account_data(&jitosol_validator_list)
.await
.map_err(|e| QueryResolverError::RpcError(e.to_string()))?;

Expand Down
2 changes: 2 additions & 0 deletions core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub const TIP_DISTRIBUTION_PROGRAM_TESTNET: &str = "F2Zu7QZiTYUhPd7u9ukRVwxh7B71
pub const VALIDATOR_HISTORY_PROGRAM_MAINNET: &str = "HistoryJTGbKQD2mRgLZ3XhqHnN811Qpez8X9kCcGHoa";
pub const VALIDATOR_HISTORY_PROGRAM_TESTNET: &str = "HistoryJTGbKQD2mRgLZ3XhqHnN811Qpez8X9kCcGHoa";
pub const PRIORITY_FEE_DISTRIBUTION_PROGRAM: &str = "Priority6weCZ5HwDn29NxLFpb7TDp2iLZ6XKc5e8d3";
pub const JITOSOL_VALIDATOR_LIST_MAINNET: &str = "3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn";
pub const JITOSOL_VALIDATOR_LIST_TESTNET: &str = "G5N6K3qW86GSkNEpywcbJk42LjEZoshzECFg1LNVjSLa";
pub const DATABASE_NAME: &str = "validators";
pub const VALIDATOR_COLLECTION_NAME: &str = "validators";
pub const STAKE_POOL_STATS_COLLECTION_NAME: &str = "stake_pool_stats";
Expand Down
Loading