From 6b24ec9b64df1340042b5f896feea4a52e6f41a1 Mon Sep 17 00:00:00 2001 From: Cook Spam Date: Wed, 8 May 2024 00:18:00 +0900 Subject: [PATCH] initial commit of spam-cli --- Cargo.lock | 94 +++++++++++++++++----------------------- Cargo.toml | 8 ++-- README.md | 8 ++-- src/balance.rs | 4 +- src/busses.rs | 4 +- src/claim.rs | 14 +++--- src/initialize.rs | 4 +- src/main.rs | 4 +- src/mine.rs | 26 +++++------ src/register.rs | 2 +- src/rewards.rs | 4 +- src/treasury.rs | 10 ++--- src/update_admin.rs | 2 +- src/update_difficulty.rs | 2 +- src/utils.rs | 4 +- 15 files changed, 88 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed75c0b..f8c3512 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2182,19 +2182,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "mpl-token-metadata" -version = "4.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf0f61b553e424a6234af1268456972ee66c2222e1da89079242251fa7479e5" -dependencies = [ - "borsh 0.10.3", - "num-derive 0.3.3", - "num-traits", - "solana-program", - "thiserror", -] - [[package]] name = "nix" version = "0.26.4" @@ -2422,47 +2409,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "ore-cli" -version = "0.4.11" -dependencies = [ - "bincode", - "bs58 0.5.1", - "cached", - "chrono", - "clap 4.4.12", - "futures", - "log", - "ore-program", - "rand 0.8.5", - "solana-cli-config", - "solana-client", - "solana-program", - "solana-sdk", - "solana-transaction-status", - "spl-associated-token-account", - "spl-token", - "tokio", -] - -[[package]] -name = "ore-program" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf2aafa6b257df0f423042e69eb7dd5dbc90a03f2469b986b14401dc6570246" -dependencies = [ - "bs58 0.5.1", - "bytemuck", - "mpl-token-metadata", - "num_enum 0.7.2", - "shank", - "solana-program", - "spl-associated-token-account", - "spl-token", - "static_assertions", - "thiserror", -] - [[package]] name = "os_str_bytes" version = "6.6.1" @@ -4166,6 +4112,46 @@ dependencies = [ "winapi", ] +[[package]] +name = "spam-cli" +version = "0.4.11" +dependencies = [ + "bincode", + "bs58 0.5.1", + "cached", + "chrono", + "clap 4.4.12", + "futures", + "log", + "rand 0.8.5", + "solana-cli-config", + "solana-client", + "solana-program", + "solana-sdk", + "solana-transaction-status", + "spam-program", + "spl-associated-token-account", + "spl-token", + "tokio", +] + +[[package]] +name = "spam-program" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f015959c8cc242fde4564ee209da2a8e54b0dfb4adeb5eed99c9c7c8c01f8589" +dependencies = [ + "bs58 0.5.1", + "bytemuck", + "num_enum 0.7.2", + "shank", + "solana-program", + "spl-associated-token-account", + "spl-token", + "static_assertions", + "thiserror", +] + [[package]] name = "spin" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 4ec9f54..7ef5ba6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "ore-cli" +name = "spam-cli" version = "0.4.11" -description = "A command line interface for the Ore program." +description = "A command line interface for the Spam program." license = "Apache-2.0" edition = "2021" [[bin]] -name = "ore" +name = "spam" path = "src/main.rs" [features] @@ -21,7 +21,7 @@ chrono = "0.4.34" clap = { version = "4.4.12", features = ["derive"] } futures = "0.3.30" log = "0.4" -ore = { version = "1.2.1", package = "ore-program" } +spam = { version = "1.2.0", package = "spam-program" } rand = "0.8.4" solana-cli-config = "1.18.5" solana-client = "^1.16" diff --git a/README.md b/README.md index b332eed..7ce098f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Ore CLI +# Spam CLI -A command line interface for the Ore program. +A command line interface for the Spam program. ## Building -To build the Ore CLI, you will need to have the Rust programming language installed. You can install Rust by following the instructions on the [Rust website](https://www.rust-lang.org/tools/install). +To build the Spam CLI, you will need to have the Rust programming language installed. You can install Rust by following the instructions on the [Rust website](https://www.rust-lang.org/tools/install). -Once you have Rust installed, you can build the Ore CLI by running the following command: +Once you have Rust installed, you can build the Spam CLI by running the following command: ```sh cargo build --release diff --git a/src/balance.rs b/src/balance.rs index d492a6a..a3c6881 100644 --- a/src/balance.rs +++ b/src/balance.rs @@ -21,12 +21,12 @@ impl Miner { let client = self.rpc_client.clone(); let token_account_address = spl_associated_token_account::get_associated_token_address( &address, - &ore::MINT_ADDRESS, + &spam::MINT_ADDRESS, ); match client.get_token_account(&token_account_address).await { Ok(token_account) => { if let Some(token_account) = token_account { - println!("{:} ORE", token_account.token_amount.ui_amount_string); + println!("{:} SPAM", token_account.token_amount.ui_amount_string); } else { println!("Account not found"); } diff --git a/src/busses.rs b/src/busses.rs index 945423c..3ca4971 100644 --- a/src/busses.rs +++ b/src/busses.rs @@ -1,4 +1,4 @@ -use ore::{state::Bus, utils::AccountDeserialize, BUS_ADDRESSES, TOKEN_DECIMALS}; +use spam::{state::Bus, utils::AccountDeserialize, BUS_ADDRESSES, TOKEN_DECIMALS}; use solana_client::client_error::Result; use crate::Miner; @@ -11,7 +11,7 @@ impl Miner { match Bus::try_from_bytes(&data) { Ok(bus) => { let rewards = (bus.rewards as f64) / 10f64.powf(TOKEN_DECIMALS as f64); - println!("Bus {}: {:} ORE", bus.id, rewards); + println!("Bus {}: {:} SPAM", bus.id, rewards); } Err(_) => {} } diff --git a/src/claim.rs b/src/claim.rs index 548a5a3..8e78d7e 100644 --- a/src/claim.rs +++ b/src/claim.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use ore::{self, state::Proof, utils::AccountDeserialize}; +use spam::{self, state::Proof, utils::AccountDeserialize}; use solana_program::pubkey::Pubkey; use solana_sdk::{ compute_budget::ComputeBudgetInstruction, @@ -21,7 +21,7 @@ impl Miner { None => self.initialize_ata().await, }; let amount = if let Some(amount) = amount { - (amount * 10f64.powf(ore::TOKEN_DECIMALS as f64)) as u64 + (amount * 10f64.powf(spam::TOKEN_DECIMALS as f64)) as u64 } else { match client.get_account(&proof_pubkey(pubkey)).await { Ok(proof_account) => { @@ -34,17 +34,17 @@ impl Miner { } } }; - let amountf = (amount as f64) / (10f64.powf(ore::TOKEN_DECIMALS as f64)); + let amountf = (amount as f64) / (10f64.powf(spam::TOKEN_DECIMALS as f64)); let cu_limit_ix = ComputeBudgetInstruction::set_compute_unit_limit(CU_LIMIT_CLAIM); let cu_price_ix = ComputeBudgetInstruction::set_compute_unit_price(self.priority_fee); - let ix = ore::instruction::claim(pubkey, beneficiary, amount); + let ix = spam::instruction::claim(pubkey, beneficiary, amount); println!("Submitting claim transaction..."); match self .send_and_confirm(&[cu_limit_ix, cu_price_ix, ix], false, false) .await { Ok(sig) => { - println!("Claimed {:} ORE to account {:}", amountf, beneficiary); + println!("Claimed {:} SPAM to account {:}", amountf, beneficiary); println!("{:?}", sig); } Err(err) => { @@ -61,7 +61,7 @@ impl Miner { // Build instructions. let token_account_pubkey = spl_associated_token_account::get_associated_token_address( &signer.pubkey(), - &ore::MINT_ADDRESS, + &spam::MINT_ADDRESS, ); // Check if ata already exists @@ -73,7 +73,7 @@ impl Miner { let ix = spl_associated_token_account::instruction::create_associated_token_account( &signer.pubkey(), &signer.pubkey(), - &ore::MINT_ADDRESS, + &spam::MINT_ADDRESS, &spl_token::id(), ); println!("Creating token account {}...", token_account_pubkey); diff --git a/src/initialize.rs b/src/initialize.rs index d7e01d7..b242d85 100644 --- a/src/initialize.rs +++ b/src/initialize.rs @@ -1,4 +1,4 @@ -use ore::TREASURY_ADDRESS; +use spam::TREASURY_ADDRESS; use solana_sdk::signature::Signer; @@ -14,7 +14,7 @@ impl Miner { } // Sign and send transaction. - let ix = ore::instruction::initialize(signer.pubkey()); + let ix = spam::instruction::initialize(signer.pubkey()); self.send_and_confirm(&[ix], false, false) .await .expect("Transaction failed"); diff --git a/src/main.rs b/src/main.rs index ce2723e..7179793 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,13 +73,13 @@ struct Args { #[derive(Subcommand, Debug)] enum Commands { - #[command(about = "Fetch the Ore balance of an account")] + #[command(about = "Fetch the Spam balance of an account")] Balance(BalanceArgs), #[command(about = "Fetch the distributable rewards of the busses")] Busses(BussesArgs), - #[command(about = "Mine Ore using local compute")] + #[command(about = "Mine Spam using local compute")] Mine(MineArgs), #[command(about = "Claim available mining rewards")] diff --git a/src/mine.rs b/src/mine.rs index a6f72bb..e0f11c2 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -3,7 +3,7 @@ use std::{ sync::{atomic::AtomicBool, Arc, Mutex}, }; -use ore::{self, state::Bus, BUS_ADDRESSES, BUS_COUNT, EPOCH_DURATION}; +use spam::{self, state::Bus, BUS_ADDRESSES, BUS_COUNT, EPOCH_DURATION}; use rand::Rng; use solana_program::{keccak::HASH_BYTES, program_memory::sol_memcmp, pubkey::Pubkey}; use solana_sdk::{ @@ -32,17 +32,17 @@ impl Miner { // Start mining loop loop { // Fetch account state - let balance = self.get_ore_display_balance().await; + let balance = self.get_spam_display_balance().await; let treasury = get_treasury(&self.rpc_client).await; let proof = get_proof(&self.rpc_client, signer.pubkey()).await; let rewards = - (proof.claimable_rewards as f64) / (10f64.powf(ore::TOKEN_DECIMALS as f64)); + (proof.claimable_rewards as f64) / (10f64.powf(spam::TOKEN_DECIMALS as f64)); let reward_rate = - (treasury.reward_rate as f64) / (10f64.powf(ore::TOKEN_DECIMALS as f64)); + (treasury.reward_rate as f64) / (10f64.powf(spam::TOKEN_DECIMALS as f64)); stdout.write_all(b"\x1b[2J\x1b[3J\x1b[H").ok(); - println!("Balance: {} ORE", balance); - println!("Claimable: {} ORE", rewards); - println!("Reward rate: {} ORE", reward_rate); + println!("Balance: {} SPAM", balance); + println!("Claimable: {} SPAM", rewards); + println!("Reward rate: {} SPAM", reward_rate); // Escape sequence that clears the screen and the scrollback buffer println!("\nMining for a valid hash..."); @@ -78,7 +78,7 @@ impl Miner { ComputeBudgetInstruction::set_compute_unit_limit(CU_LIMIT_RESET); let cu_price_ix = ComputeBudgetInstruction::set_compute_unit_price(self.priority_fee); - let reset_ix = ore::instruction::reset(signer.pubkey()); + let reset_ix = spam::instruction::reset(signer.pubkey()); self.send_and_confirm(&[cu_limit_ix, cu_price_ix, reset_ix], false, true) .await .ok(); @@ -87,12 +87,12 @@ impl Miner { // Submit request. let bus = self.find_bus_id(treasury.reward_rate).await; - let bus_rewards = (bus.rewards as f64) / (10f64.powf(ore::TOKEN_DECIMALS as f64)); - println!("Sending on bus {} ({} ORE)", bus.id, bus_rewards); + let bus_rewards = (bus.rewards as f64) / (10f64.powf(spam::TOKEN_DECIMALS as f64)); + println!("Sending on bus {} ({} SPAM)", bus.id, bus_rewards); let cu_limit_ix = ComputeBudgetInstruction::set_compute_unit_limit(CU_LIMIT_MINE); let cu_price_ix = ComputeBudgetInstruction::set_compute_unit_price(self.priority_fee); - let ix_mine = ore::instruction::mine( + let ix_mine = spam::instruction::mine( signer.pubkey(), BUS_ADDRESSES[bus.id as usize], next_hash.into(), @@ -237,12 +237,12 @@ impl Miner { true } - pub async fn get_ore_display_balance(&self) -> String { + pub async fn get_spam_display_balance(&self) -> String { let client = self.rpc_client.clone(); let signer = self.signer(); let token_account_address = spl_associated_token_account::get_associated_token_address( &signer.pubkey(), - &ore::MINT_ADDRESS, + &spam::MINT_ADDRESS, ); match client.get_token_account(&token_account_address).await { Ok(token_account) => { diff --git a/src/register.rs b/src/register.rs index 704b079..0d6d820 100644 --- a/src/register.rs +++ b/src/register.rs @@ -15,7 +15,7 @@ impl Miner { // Sign and send transaction. println!("Generating challenge..."); 'send: loop { - let ix = ore::instruction::register(signer.pubkey()); + let ix = spam::instruction::register(signer.pubkey()); if self.send_and_confirm(&[ix], true, false).await.is_ok() { break 'send; } diff --git a/src/rewards.rs b/src/rewards.rs index 8a8deaa..e608bef 100644 --- a/src/rewards.rs +++ b/src/rewards.rs @@ -18,7 +18,7 @@ impl Miner { self.signer().pubkey() }; let proof = get_proof(&self.rpc_client, address).await; - let amount = (proof.claimable_rewards as f64) / 10f64.powf(ore::TOKEN_DECIMALS as f64); - println!("{:} ORE", amount); + let amount = (proof.claimable_rewards as f64) / 10f64.powf(spam::TOKEN_DECIMALS as f64); + println!("{:} SPAM", amount); } } diff --git a/src/treasury.rs b/src/treasury.rs index 47bc856..d24991a 100644 --- a/src/treasury.rs +++ b/src/treasury.rs @@ -10,17 +10,17 @@ impl Miner { { let treasury = get_treasury(&self.rpc_client).await; let balance = treasury_tokens.token_amount.ui_amount_string; - println!("{:} ORE", balance); + println!("{:} SPAM", balance); println!("Admin: {}", treasury.admin); println!("Difficulty: {}", treasury.difficulty.to_string()); println!("Last reset at: {}", treasury.last_reset_at); println!( - "Reward rate: {} ORE", - (treasury.reward_rate as f64) / 10f64.powf(ore::TOKEN_DECIMALS as f64) + "Reward rate: {} SPAM", + (treasury.reward_rate as f64) / 10f64.powf(spam::TOKEN_DECIMALS as f64) ); println!( - "Total claimed rewards: {} ORE", - (treasury.total_claimed_rewards as f64) / 10f64.powf(ore::TOKEN_DECIMALS as f64) + "Total claimed rewards: {} SPAM", + (treasury.total_claimed_rewards as f64) / 10f64.powf(spam::TOKEN_DECIMALS as f64) ); } } diff --git a/src/update_admin.rs b/src/update_admin.rs index d30be15..309724d 100644 --- a/src/update_admin.rs +++ b/src/update_admin.rs @@ -9,7 +9,7 @@ impl Miner { pub async fn update_admin(&self, new_admin: String) { let signer = self.signer(); let new_admin = Pubkey::from_str(new_admin.as_str()).unwrap(); - let ix = ore::instruction::update_admin(signer.pubkey(), new_admin); + let ix = spam::instruction::update_admin(signer.pubkey(), new_admin); self.send_and_confirm(&[ix], false, false) .await .expect("Transaction failed"); diff --git a/src/update_difficulty.rs b/src/update_difficulty.rs index 101b5ba..681256f 100644 --- a/src/update_difficulty.rs +++ b/src/update_difficulty.rs @@ -14,7 +14,7 @@ impl Miner { 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, ]); - let ix = ore::instruction::update_difficulty(signer.pubkey(), new_difficulty.into()); + let ix = spam::instruction::update_difficulty(signer.pubkey(), new_difficulty.into()); // let bs58data = bs58::encode(ix.data).into_string(); // println!("Data: {:?}", bs58data); self.send_and_confirm(&[ix], false, false) diff --git a/src/utils.rs b/src/utils.rs index 455d1e9..f05853d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ use cached::proc_macro::cached; -use ore::{ +use spam::{ self, state::{Proof, Treasury}, utils::AccountDeserialize, @@ -37,7 +37,7 @@ pub async fn get_clock_account(client: &RpcClient) -> Clock { #[cached] pub fn proof_pubkey(authority: Pubkey) -> Pubkey { - Pubkey::find_program_address(&[PROOF, authority.as_ref()], &ore::ID).0 + Pubkey::find_program_address(&[PROOF, authority.as_ref()], &spam::ID).0 } #[cached]