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 core/src/db_models/bam_boost_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::{constants::BAM_BOOST_VALIDATORS_COLLECTION_NAME, db_models::error::D

#[derive(Clone, Serialize, Deserialize, Default, Debug, PartialOrd, PartialEq)]
pub struct BamBoostValidator {
/// Validator name
pub name: Option<String>,

/// Epoch
pub epoch: u64,

Expand Down
34 changes: 30 additions & 4 deletions writer-service/src/bam_boost_manager.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{str::FromStr, sync::Arc};
use std::{collections::HashMap, str::FromStr, sync::Arc};

use borsh::BorshDeserialize;
use jito_bam_boost_merkle_tree::bam_boost_entry::BamBoostEntry;
use jito_program_client::bam_boost::config::Config;
use kobe_core::{
constants::JITOSOL_MINT,
db_models::bam_boost_validators::{BamBoostValidator, BamBoostValidatorsStore},
validators_app::Cluster,
validators_app::{Client, Cluster, ValidatorsAppResponseEntry},
};
use mongodb::Database;
use solana_client::nonblocking::rpc_client::RpcClient;
Expand All @@ -18,6 +18,9 @@ pub struct BamBoostManager {
/// RPC client
pub rpc_client: Arc<RpcClient>,

/// Validators app client
pub validators_app_client: Arc<Client>,

/// Cluster [Mainnet, Testnet, Devnet]
pub cluster: Cluster,

Expand All @@ -26,9 +29,14 @@ pub struct BamBoostManager {
}

impl BamBoostManager {
pub fn new(rpc_client: Arc<RpcClient>, cluster: Cluster) -> Self {
pub fn new(
rpc_client: Arc<RpcClient>,
validators_app_client: Arc<Client>,
cluster: Cluster,
) -> Self {
Self {
rpc_client,
validators_app_client,
cluster,
jito_bam_boost_program_id: Pubkey::from_str(
"BoostxbPp2ENYHGcTLYt1obpcY13HE4NojdqNWdzqSSb",
Expand Down Expand Up @@ -113,6 +121,19 @@ impl BamBoostManager {
pub async fn write_bam_boost_info(&self, db: &Database) -> Result<()> {
let epoch_info = self.rpc_client.get_epoch_info().await?;
let current_epoch = epoch_info.epoch;

let validators_app_client = self.validators_app_client.clone();
let network_validators = tokio::task::spawn_blocking(move || {
validators_app_client.validators(None, None, current_epoch)
})
.await??;
let network_validators_map: HashMap<Option<String>, &ValidatorsAppResponseEntry> =
network_validators
.as_ref()
.iter()
.map(|v| (v.account.clone(), v))
.collect();

let bam_boost_collection =
db.collection::<BamBoostValidator>(BamBoostValidatorsStore::COLLECTION);
let bam_boost_store = BamBoostValidatorsStore::new(bam_boost_collection);
Expand All @@ -126,10 +147,14 @@ impl BamBoostManager {

let mut bam_boost_validators = Vec::new();

for epoch in current_epoch - bam_boost_config.clawback_delay_epochs..current_epoch {
for epoch in current_epoch - bam_boost_config.clawback_delay_epochs..=current_epoch {
match self.fetch_bam_boost_entries(epoch).await {
Ok(epoch_bam_boost_entries) => {
for entry in epoch_bam_boost_entries {
let name = match network_validators_map.get(&Some(entry.pubkey.clone())) {
Some(validator_entry) => &validator_entry.name,
None => &None,
};
let distributor_pda = self.distributor_address(JITOSOL_MINT, epoch);

let claim_status_pda = self.claim_status_address(
Expand All @@ -139,6 +164,7 @@ impl BamBoostManager {
let claim_status = self.rpc_client.get_account(&claim_status_pda).await;

let bam_boost_validator = BamBoostValidator {
name: name.clone(),
epoch,
identity_account: entry.pubkey.to_string(),
amount: entry.amount,
Expand Down
6 changes: 4 additions & 2 deletions writer-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ impl KobeWriterService {
})
.await
.expect("Failed to initialize Validators App client");
let validators_app_client = Arc::new(validators_app_client);

let stake_pool_manager = StakePoolManager::new(
rpc_client.clone(),
validators_app_client,
validators_app_client.clone(),
bam_api_base_url,
cluster,
steward_config,
);

let bam_boost_manager = BamBoostManager::new(rpc_client.clone(), cluster);
let bam_boost_manager =
BamBoostManager::new(rpc_client.clone(), validators_app_client, cluster);

Ok(Self {
db,
Expand Down
4 changes: 2 additions & 2 deletions writer-service/src/stake_pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct StakePoolManager {
pub rpc_client: Arc<RpcClient>,

/// Validators app client
pub validators_app_client: Client,
pub validators_app_client: Arc<Client>,

/// BAM API client
pub bam_api_client: Option<BamApiClient>,
Expand All @@ -40,7 +40,7 @@ pub struct StakePoolManager {
impl StakePoolManager {
pub fn new(
rpc_client: Arc<RpcClient>,
validators_app_client: Client,
validators_app_client: Arc<Client>,
bam_api_base_url: Option<String>,
cluster: Cluster,
steward_config: Pubkey,
Expand Down
Loading