Skip to content

Commit 80a96a7

Browse files
authored
Bump version to v0.1.2 (#101)
* fix: withdraw * fix: lint * docs: add comment
1 parent 398447b commit 80a96a7

File tree

3 files changed

+56
-44
lines changed

3 files changed

+56
-44
lines changed

Cargo.lock

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

jito-bell/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jito-bell"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Jito Network Maintainers <[email protected]>"]
55
repository = "https://github.com/jito-foundation/jito-bell"
66
edition = "2021"

jito-bell/src/lib.rs

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub mod program;
4949
pub mod subscribe_option;
5050
pub mod threshold_config;
5151

52+
pub const DEFAULT_VRT_SYMBOL: &str = "VRT";
53+
5254
pub struct JitoBellHandler {
5355
/// Configuration for Notification
5456
pub config: JitoBellConfig,
@@ -109,6 +111,27 @@ impl JitoBellHandler {
109111
10_f64.powi(decimals as i32)
110112
}
111113

114+
/// Get VRT Symbol
115+
///
116+
/// - Fetch Metadata account to get symbol value, if fails return default "VRT"
117+
pub async fn vrt_symbol(&self, vrt: &Pubkey) -> String {
118+
let meta_pubkey =
119+
jito_vault_sdk::inline_mpl_token_metadata::pda::find_metadata_account(vrt).0;
120+
let symbol = match self.rpc_client.get_account(&meta_pubkey).await {
121+
Ok(meta_acc) => {
122+
match jito_vault_client::log::metadata::Metadata::deserialize(
123+
&mut meta_acc.data.as_slice(),
124+
) {
125+
Ok(meta) => meta.symbol,
126+
Err(_e) => DEFAULT_VRT_SYMBOL.to_string(),
127+
}
128+
}
129+
Err(_e) => DEFAULT_VRT_SYMBOL.to_string(),
130+
};
131+
132+
symbol
133+
}
134+
112135
/// Start heart beating
113136
pub async fn heart_beat(
114137
&mut self,
@@ -565,21 +588,7 @@ impl JitoBellHandler {
565588

566589
if vrt_mint_info.pubkey.eq(&vrt) {
567590
let divisor = self.divisor(&vrt).await;
568-
569-
let meta_pubkey =
570-
jito_vault_sdk::inline_mpl_token_metadata::pda::find_metadata_account(&vrt)
571-
.0;
572-
let symbol = match self.rpc_client.get_account(&meta_pubkey).await {
573-
Ok(meta_acc) => {
574-
match jito_vault_client::log::metadata::Metadata::deserialize(
575-
&mut meta_acc.data.as_slice(),
576-
) {
577-
Ok(meta) => meta.symbol,
578-
Err(_e) => "VRT".to_string(),
579-
}
580-
}
581-
Err(_e) => "VRT".to_string(),
582-
};
591+
let symbol = self.vrt_symbol(&vrt).await;
583592

584593
for threshold in self.sorted_thresholds(instruction).iter() {
585594
let min_amount_out = *min_amount_out as f64 / divisor;
@@ -612,6 +621,7 @@ impl JitoBellHandler {
612621
// VRT amount
613622
if vault.vrt_mint.eq(&vrt) {
614623
let divisor = self.divisor(&vrt).await;
624+
let symbol = self.vrt_symbol(&vrt).await;
615625

616626
for threshold in self.sorted_thresholds(instruction).iter() {
617627
let amount = *amount as f64 / divisor;
@@ -620,7 +630,7 @@ impl JitoBellHandler {
620630
&threshold.notification.destinations,
621631
&threshold.notification.description,
622632
amount,
623-
"VRT",
633+
&symbol,
624634
&parser.transaction_signature,
625635
)
626636
.await?;
@@ -629,32 +639,34 @@ impl JitoBellHandler {
629639
}
630640

631641
// USD amount
632-
let client = DefiLlamaClient::new();
633-
let vrt = Token::new(Chain::Solana, vrt.to_string());
634-
let prices = client.get_price(&vrt).await?;
635-
636-
if let Some(usd_price) = prices.coins.values().last() {
637-
let mut sorted_usd_thresholds = instruction.usd_thresholds.clone();
638-
sorted_usd_thresholds.sort_by(|a, b| {
639-
b.value
640-
.partial_cmp(&a.value)
641-
.unwrap_or(std::cmp::Ordering::Equal)
642-
});
643-
644-
for usd_threshold in sorted_usd_thresholds.iter() {
645-
let amount = *amount as f64 / 1_000_000_000_f64;
646-
let amount = (amount * usd_price.price) as u64;
647-
648-
if amount >= usd_threshold.value {
649-
self.dispatch_platform_notifications(
650-
&usd_threshold.notification.destinations,
651-
&usd_threshold.notification.description,
652-
amount as f64,
653-
"USD",
654-
&parser.transaction_signature,
655-
)
656-
.await?;
657-
break;
642+
if !instruction.usd_thresholds.is_empty() {
643+
let client = DefiLlamaClient::new();
644+
let vrt = Token::new(Chain::Solana, vrt.to_string());
645+
let prices = client.get_price(&vrt).await?;
646+
647+
if let Some(usd_price) = prices.coins.values().last() {
648+
let mut sorted_usd_thresholds = instruction.usd_thresholds.clone();
649+
sorted_usd_thresholds.sort_by(|a, b| {
650+
b.value
651+
.partial_cmp(&a.value)
652+
.unwrap_or(std::cmp::Ordering::Equal)
653+
});
654+
655+
for usd_threshold in sorted_usd_thresholds.iter() {
656+
let amount = *amount as f64 / 1_000_000_000_f64;
657+
let amount = (amount * usd_price.price) as u64;
658+
659+
if amount >= usd_threshold.value {
660+
self.dispatch_platform_notifications(
661+
&usd_threshold.notification.destinations,
662+
&usd_threshold.notification.description,
663+
amount as f64,
664+
"USD",
665+
&parser.transaction_signature,
666+
)
667+
.await?;
668+
break;
669+
}
658670
}
659671
}
660672
}

0 commit comments

Comments
 (0)