Skip to content

Commit

Permalink
Merge pull request #71 from HardhatChad/revert-70-hardhat/clockrate
Browse files Browse the repository at this point in the history
Revert "Rounds"
  • Loading branch information
HardhatChad authored May 13, 2024
2 parents 0e4bf1e + d61104e commit ad99a33
Show file tree
Hide file tree
Showing 20 changed files with 665 additions and 950 deletions.
258 changes: 79 additions & 179 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ore-cli"
version = "0.5.0"
version = "0.4.12-alpha"
description = "A command line interface for the Ore program."
license = "Apache-2.0"
edition = "2021"
Expand All @@ -12,26 +12,22 @@ path = "src/main.rs"
[features]
default = []
admin = []
gpu = ["drillx/gpu"]

[dependencies]
bincode = "1.3.3"
bs58 = "0.5.1"
bytemuck = "1.15.0"
cached = "0.46.1"
chrono = "0.4.38"
chrono = "0.4.34"
clap = { version = "4.4.12", features = ["derive"] }
drillx = { path = "../drillx/drillx", optional = false }
futures = "0.3.30"
num_cpus = "1.16.0"
ore = { path = "../ore", package = "ore-program" }
log = "0.4"
ore = { version = "1.2.1", package = "ore-program" }
rand = "0.8.4"
solana-cli-config = "^1.18"
solana-client = "^1.18"
solana-program = "^1.18"
solana-rpc-client = "^1.18"
solana-sdk = "^1.18"
solana-transaction-status = "^1.18"
solana-cli-config = "1.18.5"
solana-client = "^1.16"
solana-program = "^1.16"
solana-sdk = "^1.16"
solana-transaction-status = "^1.16"
spl-token = { version = "^4", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "^2.2", features = [ "no-entrypoint" ] }
tokio = "1.35.1"
120 changes: 0 additions & 120 deletions src/args.rs

This file was deleted.

38 changes: 16 additions & 22 deletions src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ use std::str::FromStr;
use solana_program::pubkey::Pubkey;
use solana_sdk::signature::Signer;

use crate::{
args::BalanceArgs,
utils::{amount_u64_to_string, get_proof},
Miner,
};
use crate::Miner;

impl Miner {
pub async fn balance(&self, args: BalanceArgs) {
pub async fn balance(&self, address: Option<String>) {
let signer = self.signer();
let address = if let Some(address) = args.address {
let address = if let Some(address) = address {
if let Ok(address) = Pubkey::from_str(&address) {
address
} else {
Expand All @@ -22,24 +18,22 @@ impl Miner {
} else {
signer.pubkey()
};
let proof = get_proof(&self.rpc_client, address).await;
let client = self.rpc_client.clone();
let token_account_address = spl_associated_token_account::get_associated_token_address(
&address,
&ore::MINT_ADDRESS,
);
let token_balance = if let Ok(Some(token_account)) = self
.rpc_client
.get_token_account(&token_account_address)
.await
{
token_account.token_amount.ui_amount_string
} else {
"0".to_string()
};
println!(
"Balance: {} ORE\nStake: {} ORE",
token_balance,
amount_u64_to_string(proof.balance)
)
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);
} else {
println!("Account not found");
}
}
Err(err) => {
println!("{:?}", err);
}
}
}
}
62 changes: 0 additions & 62 deletions src/benchmark.rs

This file was deleted.

7 changes: 7 additions & 0 deletions src/busses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ore::{state::Bus, utils::AccountDeserialize, BUS_ADDRESSES, TOKEN_DECIMALS};
use solana_client::client_error::Result;

use crate::Miner;

Expand All @@ -16,4 +17,10 @@ impl Miner {
}
}
}

pub async fn get_bus(&self, id: usize) -> Result<Bus> {
let client = self.rpc_client.clone();
let data = client.get_account_data(&BUS_ADDRESSES[id]).await?;
Ok(*Bus::try_from_bytes(&data).unwrap())
}
}
47 changes: 27 additions & 20 deletions src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,52 @@ use std::str::FromStr;

use ore::{self, state::Proof, utils::AccountDeserialize};
use solana_program::pubkey::Pubkey;
use solana_sdk::signature::Signer;
use solana_sdk::{compute_budget::ComputeBudgetInstruction, signature::Signer};

use crate::{
args::ClaimArgs,
cu_limits::CU_LIMIT_CLAIM,
send_and_confirm::ComputeBudget,
utils::{amount_f64_to_u64, proof_pubkey},
Miner,
};

// TODO Burn warning
use crate::{cu_limits::CU_LIMIT_CLAIM, utils::proof_pubkey, Miner};

impl Miner {
pub async fn claim(&self, args: ClaimArgs) {
pub async fn claim(&self, beneficiary: Option<String>, amount: Option<f64>) {
let signer = self.signer();
let pubkey = signer.pubkey();
let client = self.rpc_client.clone();
let beneficiary = match args.beneficiary {
let beneficiary = match beneficiary {
Some(beneficiary) => {
Pubkey::from_str(&beneficiary).expect("Failed to parse beneficiary address")
}
None => self.initialize_ata().await,
};
let amount = if let Some(amount) = args.amount {
amount_f64_to_u64(amount)
let amount = if let Some(amount) = amount {
(amount * 10f64.powf(ore::TOKEN_DECIMALS as f64)) as u64
} else {
match client.get_account(&proof_pubkey(pubkey)).await {
Ok(proof_account) => {
let proof = Proof::try_from_bytes(&proof_account.data).unwrap();
proof.balance
proof.claimable_rewards
}
Err(err) => {
println!("Error looking up claimable rewards: {:?}", err);
return;
}
}
};
let amountf = (amount as f64) / (10f64.powf(ore::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);
self.send_and_confirm(&[ix], ComputeBudget::Fixed(CU_LIMIT_CLAIM), false)
println!("Submitting claim transaction...");
match self
.send_and_confirm(&[cu_limit_ix, cu_price_ix, ix], false, false)
.await
.ok();
{
Ok(sig) => {
println!("Claimed {:} ORE to account {:}", amountf, beneficiary);
println!("{:?}", sig);
}
Err(err) => {
println!("Error: {:?}", err);
}
}
}

async fn initialize_ata(&self) -> Pubkey {
Expand All @@ -68,9 +73,11 @@ impl Miner {
&ore::MINT_ADDRESS,
&spl_token::id(),
);
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false)
.await
.ok();
println!("Creating token account {}...", token_account_pubkey);
match self.send_and_confirm(&[ix], true, false).await {
Ok(_sig) => println!("Created token account {:?}", token_account_pubkey),
Err(e) => println!("Transaction failed: {:?}", e),
}

// Return token account address
token_account_pubkey
Expand Down
Loading

0 comments on commit ad99a33

Please sign in to comment.