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
125 changes: 86 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ futures = "0.3.30"
futures-util = { version = "0.3.30", default-features = false, features = ["sink", "std"] }
coal-api = "2.3.0"
coal-utils = "2.3.0"
ore-api = "2.1.0"
ore-utils = "2.1.0"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.122"
solana-sdk = "1.18.12"
Expand Down
29 changes: 18 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use coal_utils::{
get_proof_and_config_with_busses, get_register_ix, get_reset_ix, proof_pubkey,
COAL_TOKEN_DECIMALS,
};
use ore_utils::{get_ore_auth_ix, get_ore_mine_ix, get_ore_register_ix};
use rand::Rng;
use serde::Deserialize;
use solana_account_decoder::UiAccountEncoding;
Expand Down Expand Up @@ -119,6 +120,7 @@ pub struct Config {
}

mod coal_utils;
mod ore_utils;

#[derive(Parser, Debug)]
#[command(version, author, about, long_about = None)]
Expand Down Expand Up @@ -240,13 +242,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
error!("Failed to load proof.");
info!("Creating proof account...");

let ix = get_register_ix(wallet.pubkey());
let coal_register_ix = get_register_ix(wallet.pubkey());
let ore_register_ix = get_ore_register_ix(wallet.pubkey());

if let Ok((hash, _slot)) = rpc_client
.get_latest_blockhash_with_commitment(rpc_client.commitment())
.await
{
let mut tx = Transaction::new_with_payer(&[ix], Some(&wallet.pubkey()));
let mut tx = Transaction::new_with_payer(
&[coal_register_ix, ore_register_ix],
Some(&wallet.pubkey())
);

tx.sign(&[&wallet], hash);

Expand Down Expand Up @@ -552,11 +558,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
text: String::from("Sending mine transaction..."),
});

let mut cu_limit = 485_000;
let mut cu_limit = 980_000;
let should_add_reset_ix = if let Some(config) = loaded_config {
let time_until_reset = (config.last_reset_at + 300) - now as i64;
if time_until_reset <= 5 {
cu_limit = 500_000;
cu_limit += 20_000;
true
} else {
false
Expand All @@ -573,19 +579,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
ComputeBudgetInstruction::set_compute_unit_price(prio_fee);
ixs.push(prio_fee_ix);

let noop_ix = get_auth_ix(signer.pubkey());
let noop_ix_clone = noop_ix.clone();
ixs.push(noop_ix);
ixs.push(noop_ix_clone);
let ore_noop_ix = get_ore_auth_ix(signer.pubkey());
let coal_apinoop_ix = get_auth_ix(signer.pubkey());
ixs.push(ore_noop_ix);
ixs.push(coal_apinoop_ix);

if should_add_reset_ix {
let reset_ix = get_reset_ix(signer.pubkey());
ixs.push(reset_ix);
}


let ix_mine = get_mine_ix(signer.pubkey(), best_solution, bus);
ixs.push(ix_mine);
let coal_mine_ix = get_mine_ix(signer.pubkey(), best_solution, bus);
let ore_mine_ix = get_ore_mine_ix(signer.pubkey(), best_solution, bus);
ixs.push(coal_mine_ix);
ixs.push(ore_mine_ix);

if let Ok((hash, _slot)) = rpc_client
.get_latest_blockhash_with_commitment(rpc_client.commitment())
Expand Down
29 changes: 29 additions & 0 deletions src/ore_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use drillx_2::Solution;
use ore_api::{
consts::{PROOF, BUS_ADDRESSES},
instruction,
ID as ORE_ID,
};
use coal_api::instruction::mine_ore;
use solana_sdk::{
pubkey::Pubkey,
instruction::Instruction,
};


pub fn get_ore_auth_ix(signer: Pubkey) -> Instruction {
let proof = ore_proof_pubkey(signer);
instruction::auth(proof)
}

pub fn get_ore_mine_ix(signer: Pubkey, solution: Solution, bus: usize) -> Instruction {
mine_ore(signer, signer, BUS_ADDRESSES[bus], solution)
}

pub fn get_ore_register_ix(signer: Pubkey) -> Instruction {
instruction::open(signer, signer, signer)
}

pub fn ore_proof_pubkey(authority: Pubkey) -> Pubkey {
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &ORE_ID).0
}