diff --git a/src/main.rs b/src/main.rs index c65244d1..7cb4e784 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ struct Miner { pub dynamic_fee: bool, pub rpc_client: Arc, pub fee_payer_filepath: Option, + pub discord_webhook: Option pub jito_client: Arc, pub tip: Arc>, } @@ -143,6 +144,9 @@ struct Args { #[arg(long, help = "Enable dynamic priority fees", global = true)] dynamic_fee: bool, + #[arg(long, value_name = "DISCORD_WEBHOOK", global = true)] + discord_webhook: Option, + #[arg( long, value_name = "JITO", @@ -209,6 +213,7 @@ async fn main() { args.dynamic_fee_url, args.dynamic_fee, Some(fee_payer_filepath), + args.discord_webhook, Arc::new(jito_client), tip, )); @@ -266,6 +271,7 @@ impl Miner { dynamic_fee_url: Option, dynamic_fee: bool, fee_payer_filepath: Option, + discord_webhook: Option, jito_client: Arc, tip: Arc>, ) -> Self { @@ -276,6 +282,7 @@ impl Miner { dynamic_fee_url, dynamic_fee, fee_payer_filepath, + discord_webhook, jito_client, tip, } diff --git a/src/mine.rs b/src/mine.rs index 90e597a1..c26817d6 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -13,6 +13,8 @@ use rand::Rng; use solana_program::pubkey::Pubkey; use solana_rpc_client::spinner; use solana_sdk::signer::Signer; +use reqwest::Client; +use serde_json::json; use crate::{ args::MineArgs, @@ -35,12 +37,16 @@ impl Miner { // Start mining loop let mut last_hash_at = 0; let mut last_balance = 0; + loop { // Fetch proof let config = get_config(&self.rpc_client).await; let proof = get_updated_proof_with_authority(&self.rpc_client, signer.pubkey(), last_hash_at) .await; + + let ore_gained = proof.balance.saturating_sub(last_balance); + println!( "\n\nStake: {} ORE\n{} Multiplier: {:12}x", amount_u64_to_string(proof.balance), @@ -55,6 +61,7 @@ impl Miner { calculate_multiplier(proof.balance, config.top_balance) ); last_hash_at = proof.last_hash_at; + last_balance = proof.balance; // Calculate cutoff time @@ -85,6 +92,19 @@ impl Miner { self.send_and_confirm(&ixs, ComputeBudget::Fixed(compute_budget), false) .await .ok(); + + let http_client = Client::new(); + + let payload = json!({ + "content": format!("Ore Gained: {}, Current Balance: {}", amount_u64_to_string(ore_gained), amount_u64_to_string(proof.balance)), + }); + + let discord_webhook_url = self.discord_webhook.as_deref().expect("Discord webhook URL must be set"); + + let _ = http_client.post(discord_webhook_url) + .json(&payload) + .send() + .await; } } @@ -173,7 +193,6 @@ impl Miner { // Increment nonce nonce += 1; } - // Return the best nonce (best_nonce, best_difficulty, best_hash) }