From 0bc3b8ddd67f88683f30a2de1b645dd056f34658 Mon Sep 17 00:00:00 2001 From: Grant Findlay Date: Thu, 22 Aug 2024 21:44:09 +0100 Subject: [PATCH 1/2] add ore utils --- Cargo.lock | 125 ++++++++++++++++++++++++++++++++--------------- Cargo.toml | 2 + src/main.rs | 31 +++++++----- src/ore_utils.rs | 26 ++++++++++ 4 files changed, 134 insertions(+), 50 deletions(-) create mode 100644 src/ore_utils.rs diff --git a/Cargo.lock b/Cargo.lock index 56d38ed..ab8642a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -970,6 +970,77 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "coal-api" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ea40c3c4609c7e86416222e329e2044f236aa8e6a0f0d957d4c2c8a8a4aa9c" +dependencies = [ + "array-const-fn-init", + "bytemuck", + "coal-utils", + "const-crypto", + "drillx_2", + "mpl-token-metadata", + "num_enum 0.7.3", + "solana-program", + "spl-associated-token-account", + "spl-token", + "static_assertions", + "thiserror", +] + +[[package]] +name = "coal-hq-server" +version = "0.1.0" +dependencies = [ + "axum", + "axum-extra", + "base64 0.22.1", + "bincode", + "bytemuck", + "chrono", + "clap 4.5.14", + "coal-api", + "coal-utils", + "crossbeam-channel", + "deadpool-diesel", + "diesel", + "dotenv", + "drillx_2", + "futures", + "futures-util", + "ore-api", + "ore-utils", + "rand 0.8.5", + "serde", + "serde_json", + "solana-account-decoder", + "solana-client", + "solana-sdk", + "solana-transaction-status", + "spl-associated-token-account", + "spl-token", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-appender", + "tracing-subscriber", +] + +[[package]] +name = "coal-utils" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb26b94f251538acc2605e4656652c37a86cf23490bad4b68c1c46308eb81f28" +dependencies = [ + "bytemuck", + "solana-program", + "spl-associated-token-account", + "spl-token", +] + [[package]] name = "colorchoice" version = "1.0.2" @@ -1424,9 +1495,22 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "drillx" -version = "2.0.0" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1b6097a8aeb360dc83cad60047b42cfabf54a56b81a75e254f5854211a7475" +dependencies = [ + "equix", + "serde", + "sha3 0.10.8", + "solana-program", + "strum", +] + +[[package]] +name = "drillx_2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c5fd3a8f11a6420d6efb1952c8c2e788627cb2c9e834537dc4b6bd036461646" +checksum = "af4e3aca4ae86ab0d0050f50b322adab7c0e93904896a5c60bdb33324ea1d36a" dependencies = [ "equix", "serde", @@ -2751,43 +2835,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "ore-hq-server" -version = "0.1.0" -dependencies = [ - "axum", - "axum-extra", - "base64 0.22.1", - "bincode", - "bytemuck", - "chrono", - "clap 4.5.14", - "crossbeam-channel", - "deadpool-diesel", - "diesel", - "dotenv", - "drillx", - "futures", - "futures-util", - "ore-api", - "ore-utils", - "rand 0.8.5", - "serde", - "serde_json", - "solana-account-decoder", - "solana-client", - "solana-sdk", - "solana-transaction-status", - "spl-associated-token-account", - "spl-token", - "tokio", - "tower", - "tower-http", - "tracing", - "tracing-appender", - "tracing-subscriber", -] - [[package]] name = "ore-utils" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index c382463..1c7a184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index 0ea84f2..82efb70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,10 @@ 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, + get_ore_reset_ix, ore_proof_pubkey +}; use rand::Rng; use serde::Deserialize; use solana_account_decoder::UiAccountEncoding; @@ -240,13 +244,17 @@ async fn main() -> Result<(), Box> { 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); @@ -552,11 +560,11 @@ async fn main() -> Result<(), Box> { 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 @@ -573,19 +581,20 @@ async fn main() -> Result<(), Box> { 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()) diff --git a/src/ore_utils.rs b/src/ore_utils.rs new file mode 100644 index 0000000..04dfa87 --- /dev/null +++ b/src/ore_utils.rs @@ -0,0 +1,26 @@ +use ore_api::{ + instruction, + ID as ORE_ID, +}; +use solana_sdk::{ + pubkey::Pubkey, + instruction::Instruction, +}; + + +pub fn get_ore_auth_ix(signer: Pubkey) -> Instruction { + let proof = proof_pubkey(signer); + instruction::auth(proof) +} + +pub fn get_mine_ix(signer: Pubkey, solution: Solution, bus: usize) -> Instruction { + instruction::mine(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 +} \ No newline at end of file From ddba57a6428393f50f34625a74517c70330caf1b Mon Sep 17 00:00:00 2001 From: Grant Findlay Date: Thu, 22 Aug 2024 22:09:07 +0100 Subject: [PATCH 2/2] fix imports --- src/main.rs | 6 ++---- src/ore_utils.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 82efb70..aa0a294 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,10 +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, - get_ore_reset_ix, ore_proof_pubkey -}; +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; @@ -123,6 +120,7 @@ pub struct Config { } mod coal_utils; +mod ore_utils; #[derive(Parser, Debug)] #[command(version, author, about, long_about = None)] diff --git a/src/ore_utils.rs b/src/ore_utils.rs index 04dfa87..9bfa9c8 100644 --- a/src/ore_utils.rs +++ b/src/ore_utils.rs @@ -1,7 +1,10 @@ +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, @@ -9,12 +12,12 @@ use solana_sdk::{ pub fn get_ore_auth_ix(signer: Pubkey) -> Instruction { - let proof = proof_pubkey(signer); + let proof = ore_proof_pubkey(signer); instruction::auth(proof) } -pub fn get_mine_ix(signer: Pubkey, solution: Solution, bus: usize) -> Instruction { - instruction::mine(signer, signer, BUS_ADDRESSES[bus], solution) +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 {