Skip to content
Merged
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
64 changes: 45 additions & 19 deletions cli/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ use merkle_distributor::state::merkle_distributor::MerkleDistributor;
use solana_program::instruction::Instruction;
use solana_rpc_client::rpc_client::RpcClient;
use solana_sdk::{
account::Account, bs58, commitment_config::CommitmentConfig, compute_budget::ComputeBudgetInstruction, signature::{read_keypair_file, Keypair}, signer::Signer, transaction::Transaction
account::Account,
bs58,
commitment_config::CommitmentConfig,
compute_budget::ComputeBudgetInstruction,
signature::{read_keypair_file, Keypair},
signer::Signer,
transaction::Transaction,
};
use spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
Expand Down Expand Up @@ -137,7 +143,6 @@ pub struct SetStakingArgs {

#[clap(long)]
pub duration: i64,

}

fn main() {
Expand All @@ -148,7 +153,13 @@ fn main() {
process_new_distributor(&args, new_distributor_args);
}
Commands::AdminNewClaim => {
process_admin_claim(&args, Pubkey::from_str(&"5pT9ijgv2Qpxn4ux4u4crCCJhgAe4w7GoeaCPJKgP4NW").unwrap(), 1500, 1500, 1);
process_admin_claim(
&args,
Pubkey::from_str(&"5pT9ijgv2Qpxn4ux4u4crCCJhgAe4w7GoeaCPJKgP4NW").unwrap(),
1500,
1500,
1,
);
}
Commands::Claim(claim_args) => {
process_claim(&args, claim_args);
Expand All @@ -170,7 +181,8 @@ fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand Down Expand Up @@ -248,13 +260,19 @@ fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
println!("successfully created new claim with signature {signature:#?}");
}

pub fn call_process_admin_claim(claimant: Pubkey, amount_unlocked: u64, amount_locked: u64, page_index: u8){
pub fn call_process_admin_claim(
claimant: Pubkey,
amount_unlocked: u64,
amount_locked: u64,
page_index: u8,
) {
use dotenv::dotenv;
dotenv().ok();
let mint = std::env::var("WHITELIST_MINT").expect("WHITELIST_MINT must be set.");
let vesting_program = std::env::var("VESTING_PROGRAM_ID").expect("VESTING_PROGRAM_ID must be set.");
let vesting_program =
std::env::var("VESTING_PROGRAM_ID").expect("VESTING_PROGRAM_ID must be set.");
let solana_rpc_url = std::env::var("SOLANA_RPC_URL").expect("SOLANA_RPC_URL must be set.");
let args: Args = Args{
let args: Args = Args {
command: Commands::AdminNewClaim,
airdrop_version: 0,
mint: Pubkey::from_str(&mint).unwrap(),
Expand All @@ -267,12 +285,18 @@ pub fn call_process_admin_claim(claimant: Pubkey, amount_unlocked: u64, amount_l
process_admin_claim(&args, claimant, amount_unlocked, amount_locked, page_index);
}


fn process_admin_claim(args: &Args, claimant: Pubkey, amount_unlocked: u64, amount_locked: u64, page_index: u8) {
fn process_admin_claim(
args: &Args,
claimant: Pubkey,
amount_unlocked: u64,
amount_locked: u64,
page_index: u8,
) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let admin_private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&admin_private_key_bytes).unwrap();
Expand All @@ -281,7 +305,6 @@ fn process_admin_claim(args: &Args, claimant: Pubkey, amount_unlocked: u64, amou
let (distributor, _bump) =
get_merkle_distributor_pda(&args.program_id, &args.mint, args.airdrop_version);


let (page_account_pda, _bump) = get_page_account_pda(&args.program_id, 1);

let client = RpcClient::new_with_commitment(&args.rpc_url, CommitmentConfig::confirmed());
Expand Down Expand Up @@ -346,7 +369,8 @@ fn process_claim(args: &Args, claim_args: &ClaimArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand Down Expand Up @@ -465,7 +489,8 @@ fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArg
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand All @@ -481,7 +506,7 @@ fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArg
// &args.mint,
// );
// let ret_back = Pubkey::from_str("PYsq43ovMAvj3yuiF7jgfcfbCgASapELHKAQPDS6WfU").unwrap();

// let keypair = read_keypair_file(&args.keypair_path).expect("Failed reading keypair file");

let client = RpcClient::new_with_commitment(&args.rpc_url, CommitmentConfig::finalized());
Expand All @@ -508,8 +533,6 @@ fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArg

println!("creating new distributor with args: {new_distributor_args:#?}");



let new_distributor_ix = Instruction {
program_id: args.program_id,
accounts: merkle_distributor::accounts::NewDistributor {
Expand Down Expand Up @@ -621,7 +644,8 @@ fn process_set_admin(args: &Args, set_admin_args: &SetAdminArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand Down Expand Up @@ -660,7 +684,8 @@ fn process_set_staking(args: &Args, set_admin_args: &SetStakingArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand All @@ -681,7 +706,8 @@ fn process_set_staking(args: &Args, set_admin_args: &SetStakingArgs) {
data: merkle_distributor::instruction::SetStaking {
staking: Some(set_admin_args.staking_contract),
duration: set_admin_args.duration,
}.data(),
}
.data(),
};

let tx = Transaction::new_signed_with_payer(
Expand Down
61 changes: 40 additions & 21 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ use merkle_distributor::state::merkle_distributor::MerkleDistributor;
use solana_program::instruction::Instruction;
use solana_rpc_client::rpc_client::RpcClient;
use solana_sdk::{
account::Account, bs58, commitment_config::CommitmentConfig, compute_budget::ComputeBudgetInstruction, signature::{read_keypair_file, Keypair}, signer::Signer, transaction::Transaction
account::Account,
bs58,
commitment_config::CommitmentConfig,
compute_budget::ComputeBudgetInstruction,
signature::{read_keypair_file, Keypair},
signer::Signer,
transaction::Transaction,
};
use spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
Expand Down Expand Up @@ -133,7 +139,8 @@ fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand Down Expand Up @@ -211,13 +218,19 @@ fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
println!("successfully created new claim with signature {signature:#?}");
}

pub fn call_process_admin_claim(claimant: Pubkey, amount_unlocked: u64, amount_locked: u64, page_index: u8) -> (bool, String) {
pub fn call_process_admin_claim(
claimant: Pubkey,
amount_unlocked: u64,
amount_locked: u64,
page_index: u8,
) -> (bool, String) {
use dotenv::dotenv;
dotenv().ok();
let mint = std::env::var("WHITELIST_MINT").expect("WHITELIST_MINT must be set.");
let vesting_program = std::env::var("VESTING_PROGRAM_ID").expect("VESTING_PROGRAM_ID must be set.");
let vesting_program =
std::env::var("VESTING_PROGRAM_ID").expect("VESTING_PROGRAM_ID must be set.");
let solana_rpc_url = std::env::var("SOLANA_RPC_URL").expect("SOLANA_RPC_URL must be set.");
let args: Args = Args{
let args: Args = Args {
command: Commands::AdminNewClaim,
airdrop_version: 0,
mint: Pubkey::from_str(&mint).unwrap(),
Expand All @@ -230,12 +243,18 @@ pub fn call_process_admin_claim(claimant: Pubkey, amount_unlocked: u64, amount_l
return process_admin_claim(&args, claimant, amount_unlocked, amount_locked, page_index);
}


fn process_admin_claim(args: &Args, claimant: Pubkey, amount_unlocked: u64, amount_locked: u64, page_index: u8) -> (bool, String) {
fn process_admin_claim(
args: &Args,
claimant: Pubkey,
amount_unlocked: u64,
amount_locked: u64,
page_index: u8,
) -> (bool, String) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let admin_private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&admin_private_key_bytes).unwrap();
Expand Down Expand Up @@ -295,11 +314,14 @@ fn process_admin_claim(args: &Args, claimant: Pubkey, amount_unlocked: u64, amou
ixs.push(new_claim_ix);

let blockhash = client.get_latest_blockhash().unwrap();
let tx =
Transaction::new_signed_with_payer(&ixs, Some(&keypair.pubkey().key()), &[&keypair], blockhash);
let tx = Transaction::new_signed_with_payer(
&ixs,
Some(&keypair.pubkey().key()),
&[&keypair],
blockhash,
);

let signature = client
.send_and_confirm_transaction_with_spinner(&tx);
let signature = client.send_and_confirm_transaction_with_spinner(&tx);
let msg_signature = format!("{:?}", signature);
println!("{}", msg_signature);
if signature.is_err() {
Expand All @@ -312,7 +334,8 @@ fn process_claim(args: &Args, claim_args: &ClaimArgs) {
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
Expand Down Expand Up @@ -431,17 +454,15 @@ fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArg
use dotenv::dotenv;
dotenv().ok();

let env_siner_private_key = std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let env_siner_private_key =
std::env::var("SIGNER_PRIV_KEY").expect("SIGNER_PRIV_KEY must be set.");
let private_key_bytes = bs58::decode(env_siner_private_key).into_vec().unwrap();

let keypair = Keypair::from_bytes(&private_key_bytes).unwrap();
println!("This is pubkey {}", keypair.pubkey().to_string());

let ret_back = get_associated_token_address(
&keypair.pubkey(),
&args.mint,
);

let ret_back = get_associated_token_address(&keypair.pubkey(), &args.mint);

// let keypair = read_keypair_file(&args.keypair_path).expect("Failed reading keypair file");

let client = RpcClient::new_with_commitment(&args.rpc_url, CommitmentConfig::finalized());
Expand All @@ -468,8 +489,6 @@ fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArg

println!("creating new distributor with args: {new_distributor_args:#?}");



let new_distributor_ix = Instruction {
program_id: args.program_id,
accounts: merkle_distributor::accounts::NewDistributor {
Expand Down
56 changes: 26 additions & 30 deletions common/cf-guest/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,27 @@ impl<PK: guestchain::PubKey> ClientState<PK> {
this
}

pub fn frozen(&self) -> Self { Self { is_frozen: true, ..self.clone() } }
pub fn frozen(&self) -> Self {
Self {
is_frozen: true,
..self.clone()
}
}
}

impl<PK: guestchain::PubKey> From<ClientState<PK>> for proto::ClientState {
fn from(state: ClientState<PK>) -> Self { Self::from(&state) }
fn from(state: ClientState<PK>) -> Self {
Self::from(&state)
}
}

impl<PK: guestchain::PubKey> From<&ClientState<PK>> for proto::ClientState {
fn from(state: &ClientState<PK>) -> Self {
let prev_epoch_commitment =
if state.prev_epoch_commitment == state.epoch_commitment {
alloc::vec::Vec::new()
} else {
state.prev_epoch_commitment.to_vec()
};
let prev_epoch_commitment = if state.prev_epoch_commitment == state.epoch_commitment {
alloc::vec::Vec::new()
} else {
state.prev_epoch_commitment.to_vec()
};
Self {
genesis_hash: state.genesis_hash.to_vec(),
latest_height: state.latest_height.into(),
Expand All @@ -132,9 +138,7 @@ impl<PK: guestchain::PubKey> TryFrom<proto::ClientState> for ClientState<PK> {
impl<PK: guestchain::PubKey> TryFrom<&proto::ClientState> for ClientState<PK> {
type Error = proto::BadMessage;
fn try_from(msg: &proto::ClientState) -> Result<Self, Self::Error> {
let make_hash = |hash: &[u8]| {
CryptoHash::try_from(hash).map_err(|_| proto::BadMessage)
};
let make_hash = |hash: &[u8]| CryptoHash::try_from(hash).map_err(|_| proto::BadMessage);

let genesis_hash = make_hash(&msg.genesis_hash)?;
let epoch_commitment = make_hash(&msg.epoch_commitment)?;
Expand Down Expand Up @@ -167,23 +171,19 @@ fn test_decode() {
use prost::Message;

const MESSAGE: [u8; 79] = [
10u8, 32, 51, 149, 5, 79, 50, 53, 152, 49, 180, 107, 202, 134, 169,
136, 236, 63, 188, 148, 223, 47, 72, 42, 1, 239, 198, 197, 0, 114, 147,
202, 130, 249, 16, 211, 7, 24, 128, 128, 144, 202, 210, 198, 14, 34,
32, 86, 12, 131, 131, 127, 125, 82, 54, 32, 207, 121, 149, 204, 11,
121, 102, 180, 211, 111, 54, 0, 207, 247, 125, 195, 57, 10, 10, 80, 84,
86, 152,
10u8, 32, 51, 149, 5, 79, 50, 53, 152, 49, 180, 107, 202, 134, 169, 136, 236, 63, 188, 148,
223, 47, 72, 42, 1, 239, 198, 197, 0, 114, 147, 202, 130, 249, 16, 211, 7, 24, 128, 128,
144, 202, 210, 198, 14, 34, 32, 86, 12, 131, 131, 127, 125, 82, 54, 32, 207, 121, 149, 204,
11, 121, 102, 180, 211, 111, 54, 0, 207, 247, 125, 195, 57, 10, 10, 80, 84, 86, 152,
];

const GENESIS_HASH: [u8; 32] = [
51, 149, 5, 79, 50, 53, 152, 49, 180, 107, 202, 134, 169, 136, 236, 63,
188, 148, 223, 47, 72, 42, 1, 239, 198, 197, 0, 114, 147, 202, 130,
249,
51, 149, 5, 79, 50, 53, 152, 49, 180, 107, 202, 134, 169, 136, 236, 63, 188, 148, 223, 47,
72, 42, 1, 239, 198, 197, 0, 114, 147, 202, 130, 249,
];
const EPOCH_COMMITMENT: [u8; 32] = [
86, 12, 131, 131, 127, 125, 82, 54, 32, 207, 121, 149, 204, 11, 121,
102, 180, 211, 111, 54, 0, 207, 247, 125, 195, 57, 10, 10, 80, 84, 86,
152,
86, 12, 131, 131, 127, 125, 82, 54, 32, 207, 121, 149, 204, 11, 121, 102, 180, 211, 111,
54, 0, 207, 247, 125, 195, 57, 10, 10, 80, 84, 86, 152,
];

let want_proto = proto::ClientState {
Expand All @@ -208,14 +208,10 @@ fn test_decode() {
let proto = proto::ClientState::decode(MESSAGE.as_slice()).unwrap();
assert_eq!(want_proto, proto);

let state =
ClientState::<guestchain::validators::MockPubKey>::try_from(proto)
.unwrap();
let state = ClientState::<guestchain::validators::MockPubKey>::try_from(proto).unwrap();
assert_eq!(want_state, state);

let state = ClientState::<guestchain::validators::MockPubKey>::decode(
MESSAGE.as_slice(),
)
.unwrap();
let state =
ClientState::<guestchain::validators::MockPubKey>::decode(MESSAGE.as_slice()).unwrap();
assert_eq!(want_state, state);
}
Loading