Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve token account related #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ impl Miner {
let jito_tip = self.priority_fee.expect("jito tip is required");

let beneficiary_ata = utils::get_ore_ata(args.beneficiary);

info!(ata = %beneficiary_ata, recipient = %args.beneficiary);
if let Ok(Some(_ata)) = client.get_token_account(&beneficiary_ata).await {
info!("Token account already exists: {:?}, continue to claim", beneficiary_ata);
} else {
error!("Token account does not exist: {:?}", beneficiary_ata);
return;
}

let owner_proof_pdas = accounts
.iter()
Expand Down
58 changes: 58 additions & 0 deletions src/init_claim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use clap::Parser;
use crate::Miner;
use solana_sdk::{
signature::{Keypair, Signer},
signer::EncodableKey,
transaction::Transaction,
};

use tracing::{info, error};


#[derive(Parser, Debug, Clone)]
pub struct InitClaimArgs {
#[arg(long, help = "The keypair to initalize the $ORE token account with.")]
pub keypair: String
}

impl Miner {
pub async fn init_claim(&self, args: &InitClaimArgs) {
let client = Miner::get_client_confirmed(&self.rpc);
// initalize the token account
let keypair = Keypair::read_from_file(&args.keypair).unwrap();

// build instructions.
let token_account_pubkey = spl_associated_token_account::get_associated_token_address(
&keypair.pubkey(),
&ore::MINT_ADDRESS,
);

// Check if ata already exists
if let Ok(Some(_ata)) = client.get_token_account(&token_account_pubkey).await {
info!("Token account already exists: {:?}", token_account_pubkey);
}

// Sign and send transaction.
let instruction = spl_associated_token_account::instruction::create_associated_token_account(
&keypair.pubkey(),
&keypair.pubkey(),
&ore::MINT_ADDRESS,
&spl_token::id(),
);

let recent_blockhash = client
.get_latest_blockhash()
.await
.expect("Failed to get recent blockhash");

let transaction = Transaction::new_signed_with_payer(&[instruction],
Some(&keypair.pubkey()),
&[&keypair], recent_blockhash);

println!("Creating token account {} for {}...", token_account_pubkey, keypair.pubkey());
match client.send_and_confirm_transaction(&transaction).await {
Ok(_sig) => info!("Created token account {:?} for {}", token_account_pubkey, keypair.pubkey()),
Err(e) => error!("Transaction failed: {:?}", e),
}
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod generate_wallet;
mod jito;
mod register;
mod utils;
mod init_claim;

#[tokio::main(flavor = "multi_thread")]
async fn main() {
Expand All @@ -60,6 +61,7 @@ async fn main() {
Command::JitoTipStream => miner.jito_tip_stream().await,
Command::GenerateWallet(args) => miner.generate_wallet(args),
Command::Collect(args) => miner.collect(args).await,
Command::InitClaim(args) => miner.init_claim(args).await,
}
}

Expand All @@ -86,6 +88,7 @@ pub enum Command {
GenerateWallet(crate::generate_wallet::GenerateWalletArgs),
BatchTransfer(crate::batch_transfer::BatchTransferArgs),
Collect(crate::collect::CollectArgs),
InitClaim(crate::init_claim::InitClaimArgs),
}

impl Miner {
Expand Down