Skip to content

Commit e373ab8

Browse files
authored
Avoid using hardcoding divisor (#71)
1 parent 7c868b4 commit e373ab8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ solana-rpc-client = "1.17.6"
3333
solana-rpc-client-api = "1.17.6"
3434
solana-sdk = "1.17.6"
3535
spl-stake-pool = { version = "^1.0.0", features = ["no-entrypoint"] }
36+
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
3637
spl-token-2022 = { version = "0.9", features = [ "no-entrypoint", "serde-traits" ] }
3738
thiserror = "2.0.12"
3839
tokio = { version = "1.0.1", features = ["full"] }

src/lib.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ use parser::{
1919
use solana_metrics::datapoint_info;
2020
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
2121
use solana_sdk::{
22-
clock::DEFAULT_SLOTS_PER_EPOCH, commitment_config::CommitmentConfig, pubkey::Pubkey,
22+
clock::DEFAULT_SLOTS_PER_EPOCH, commitment_config::CommitmentConfig, program_pack::Pack,
23+
pubkey::Pubkey,
2324
};
25+
use spl_token::state::Mint;
2426
use subscribe_option::SubscribeOption;
2527
use threshold_config::ThresholdConfig;
2628
use tonic::transport::channel::ClientTlsConfig;
@@ -91,6 +93,21 @@ impl JitoBellHandler {
9193
sorted_thresholds
9294
}
9395

96+
/// Get divisor
97+
///
98+
/// - Fetch Mint account to get decimals value, if fails return default 9
99+
pub async fn divisor(&self, vrt: &Pubkey) -> f64 {
100+
let decimals = match self.rpc_client.get_account(vrt).await {
101+
Ok(mint_acc) => match Mint::unpack(&mint_acc.data) {
102+
Ok(acc) => acc.decimals,
103+
Err(_) => 9,
104+
},
105+
Err(_e) => 9,
106+
};
107+
108+
10_f64.powi(decimals as i32)
109+
}
110+
94111
/// Start heart beating
95112
pub async fn heart_beat(
96113
&mut self,
@@ -546,8 +563,10 @@ impl JitoBellHandler {
546563
let _vault_fee_token_account = &ix.accounts[7];
547564

548565
if vrt_mint_info.pubkey.eq(&vrt) {
566+
let divisor = self.divisor(&vrt).await;
567+
549568
for threshold in self.sorted_thresholds(instruction).iter() {
550-
let min_amount_out = *min_amount_out as f64 / 1_000_000_000_f64;
569+
let min_amount_out = *min_amount_out as f64 / divisor;
551570
if min_amount_out >= threshold.value {
552571
self.dispatch_platform_notifications(
553572
&threshold.notification.destinations,
@@ -576,8 +595,10 @@ impl JitoBellHandler {
576595

577596
// VRT amount
578597
if vault.vrt_mint.eq(&vrt) {
598+
let divisor = self.divisor(&vrt).await;
599+
579600
for threshold in self.sorted_thresholds(instruction).iter() {
580-
let amount = *amount as f64 / 1_000_000_000_f64;
601+
let amount = *amount as f64 / divisor;
581602
if amount >= threshold.value {
582603
self.dispatch_platform_notifications(
583604
&threshold.notification.destinations,

0 commit comments

Comments
 (0)