Skip to content

Commit 4933889

Browse files
committed
Add deposit notifier to sys-lend
1 parent e4635c6 commit 4933889

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/bin/sys-lend.rs

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use {
1919
},
2020
sys::{
2121
app_version,
22+
notifier::*,
2223
priority_fee::{apply_priority_fee, PriorityFee},
2324
send_transaction_until_expired,
2425
token::*,
@@ -125,6 +126,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
125126
};
126127

127128
let mut wallet_manager = None;
129+
let notifier = Notifier::default();
128130

129131
match matches.subcommand() {
130132
("deposit", Some(matches)) => {
@@ -190,6 +192,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
190192
if !send_transaction_until_expired(&rpc_client, &transaction, last_valid_block_height) {
191193
return Err("Deposit failed".into());
192194
}
195+
196+
let msg = format!(
197+
"Deposited {} from {} into {}",
198+
token.format_amount(deposit_amount),
199+
address,
200+
pool
201+
);
202+
notifier.send(&msg).await;
203+
println!("{msg}");
193204
}
194205
_ => unreachable!(),
195206
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod exchange;
77
pub mod helius_rpc;
88
pub mod kraken_exchange;
99
pub mod metrics;
10+
pub mod notifier;
1011
pub mod priority_fee;
1112
pub mod token;
1213
//pub mod tulip;

src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod amount;
22
mod db;
33
mod field_as_string;
44
mod get_transaction_balance_change;
5-
mod notifier;
65
mod rpc_client_utils;
76
mod stake_spreader;
87

@@ -17,7 +16,6 @@ use {
1716
console::{style, Style},
1817
db::*,
1918
itertools::Itertools,
20-
notifier::*,
2119
rpc_client_utils::get_signature_date,
2220
rust_decimal::prelude::*,
2321
separator::FixedPlaceSeparatable,
@@ -50,6 +48,7 @@ use {
5048
app_version,
5149
exchange::{self, *},
5250
metrics::{self, dp, MetricsConfig},
51+
notifier::*,
5352
priority_fee::{apply_priority_fee, PriorityFee},
5453
send_transaction_until_expired,
5554
token::*,

src/notifier.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ pub struct Notifier {
55
slack_webhook: Option<String>,
66
}
77

8-
impl Notifier {
9-
pub fn default() -> Self {
8+
impl Default for Notifier {
9+
fn default() -> Self {
1010
let slack_webhook = env::var("SLACK_WEBHOOK").ok();
1111
Notifier {
1212
client: Client::new(),
1313
slack_webhook,
1414
}
1515
}
16+
}
1617

18+
impl Notifier {
1719
pub async fn send(&self, msg: &str) {
1820
if let Some(ref slack_webhook) = self.slack_webhook {
1921
let data = json!({ "text": msg });

src/stake_spreader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
crate::{db::*, notifier::*, rpc_client_utils::get_signature_date},
2+
crate::{db::*, rpc_client_utils::get_signature_date},
33
log::*,
44
solana_client::{rpc_client::RpcClient, rpc_config::RpcBlockConfig, rpc_custom_error},
55
solana_sdk::{
@@ -21,7 +21,7 @@ use {
2121
},
2222
solana_transaction_status::Reward,
2323
std::collections::{BTreeMap, HashMap, HashSet},
24-
sys::{send_transaction_until_expired, token::*},
24+
sys::{notifier::*, send_transaction_until_expired, token::*},
2525
};
2626

2727
const MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY: usize = 5; // Remove once Solana 1.15 ships. Ref: https://github.com/solana-labs/solana/pull/28096

0 commit comments

Comments
 (0)