Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Miner {
pub dynamic_fee: bool,
pub rpc_client: Arc<RpcClient>,
pub fee_payer_filepath: Option<String>,
pub discord_webhook: Option<String>
pub jito_client: Arc<RpcClient>,
pub tip: Arc<std::sync::RwLock<u64>>,
}
Expand Down Expand Up @@ -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<String>,

#[arg(
long,
value_name = "JITO",
Expand Down Expand Up @@ -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,
));
Expand Down Expand Up @@ -266,6 +271,7 @@ impl Miner {
dynamic_fee_url: Option<String>,
dynamic_fee: bool,
fee_payer_filepath: Option<String>,
discord_webhook: Option<String>,
jito_client: Arc<RpcClient>,
tip: Arc<std::sync::RwLock<u64>>,
) -> Self {
Expand All @@ -276,6 +282,7 @@ impl Miner {
dynamic_fee_url,
dynamic_fee,
fee_payer_filepath,
discord_webhook,
jito_client,
tip,
}
Expand Down
21 changes: 20 additions & 1 deletion src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -173,7 +193,6 @@ impl Miner {
// Increment nonce
nonce += 1;
}

// Return the best nonce
(best_nonce, best_difficulty, best_hash)
}
Expand Down