Skip to content

Commit

Permalink
initial commit of spam-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
cookspam committed May 26, 2024
1 parent db79a19 commit 6b24ec9
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 102 deletions.
94 changes: 40 additions & 54 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions src/busses.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(_) => {}
}
Expand Down
14 changes: 7 additions & 7 deletions src/claim.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ore::TREASURY_ADDRESS;
use spam::TREASURY_ADDRESS;

use solana_sdk::signature::Signer;

Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
26 changes: 13 additions & 13 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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();
Expand All @@ -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(),
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/update_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading

0 comments on commit 6b24ec9

Please sign in to comment.