Skip to content

Commit

Permalink
feat: claim and staked jup locked voter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsource147 committed Jul 2, 2024
1 parent dbd72b6 commit 3a1473f
Show file tree
Hide file tree
Showing 16 changed files with 520 additions and 73 deletions.
45 changes: 45 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ tracing = { version = "0.1.37" }
tracing-core = "0.1.32"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
rust_decimal = "1.35.0"
locked-voter = { git = "https://github.com/TeamRaccoons/WAGMI", rev = "425ac5e3a51f15831c825874e531409d4dc12c71" }
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ serde = { workspace = true }
serde_json = { workspace = true }
zip = {version = "0.6.0", features = ["deflate"] }
rand = "0.7.3"
reqwest = { version = "0.11", features = ["blocking"] }
reqwest = { version = "0.11", features = ["blocking"] }
locked-voter = { workspace = true }
24 changes: 24 additions & 0 deletions cli/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ pub struct NewDistributorArgs {
/// Clawback receiver owner
#[clap(long, env)]
pub clawback_receiver_owner: Pubkey,

#[clap(long, env)]
pub locker: Pubkey,

#[clap(long, env)]
pub min_stake_duration: u64,
}

// NewDistributor subcommand args
Expand Down Expand Up @@ -281,6 +287,12 @@ pub struct NewDistributorWithBonusArgs {
#[clap(long, env)]
pub clawback_receiver_owner: Pubkey,

#[clap(long, env)]
pub locker: Pubkey,

#[clap(long, env)]
pub min_stake_duration: u64,

#[clap(long, env)]
pub bonus_vesting_duration: u64,

Expand All @@ -301,6 +313,8 @@ impl NewDistributorWithBonusArgs {
skip_verify: self.skip_verify,
base_path: self.base_path.clone(),
clawback_receiver_owner: self.clawback_receiver_owner,
locker: self.locker,
min_stake_duration: self.min_stake_duration,
}
}
}
Expand Down Expand Up @@ -620,6 +634,8 @@ fn check_distributor_onchain_matches(
new_distributor_args: &NewDistributorArgs,
total_bonus: u64,
bonus_vesting_duration: u64,
locker: Pubkey,
min_locked_duration: u64,
pubkey: Pubkey,
base: Pubkey,
args: &Args,
Expand Down Expand Up @@ -671,6 +687,14 @@ fn check_distributor_onchain_matches(
return Err("bonus_vesting_duration mismatch");
}

if distributor.locker != locker {
return Err("locker mismatch");
}

if distributor.min_locked_duration != min_locked_duration {
return Err("min_locked_duration mismatch");
}

// TODO fix code
let clawback_receiver_token_account =
spl_associated_token_account::get_associated_token_address(
Expand Down
14 changes: 14 additions & 0 deletions cli/src/bin/instructions/process_claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub fn process_claim(args: &Args, claim_args: &ClaimArgs) {
&args.mint,
merkle_tree.airdrop_version,
);
let program_client = args.get_program_client();
let distributor_state: MerkleDistributor = program_client.account(distributor).unwrap();
println!("distributor pubkey {}", distributor);

let (claim_status_pda, _bump) = get_claim_status_pda(&args.program_id, &claimant, &distributor);
Expand Down Expand Up @@ -46,6 +48,14 @@ pub fn process_claim(args: &Args, claim_args: &ClaimArgs) {

let claimant_ata = get_associated_token_address(&claimant, &args.mint);

let (escrow, _bump) = Pubkey::find_program_address(
&[
b"Escrow".as_ref(),
distributor_state.locker.as_ref(),
claimant.key().as_ref(),
],
&locked_voter::ID,
);
ixs.push(Instruction {
program_id: args.program_id,
accounts: merkle_distributor::accounts::ClaimLocked {
Expand All @@ -55,6 +65,10 @@ pub fn process_claim(args: &Args, claim_args: &ClaimArgs) {
to: claimant_ata,
claimant,
token_program: token::ID,
voter_program: locked_voter::ID,
locker: distributor_state.locker,
escrow,
escrow_tokens: get_associated_token_address(&escrow, &args.mint),
}
.to_account_metas(None),
data: merkle_distributor::instruction::ClaimLocked {}.data(),
Expand Down
15 changes: 15 additions & 0 deletions cli/src/bin/instructions/process_claim_from_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub fn process_claim_from_api(args: &Args, claim_args: &ClaimFromApiArgs) {

let distributor = Pubkey::from_str(&kv_proof.merkle_tree).unwrap();

let program_client = args.get_program_client();
let distributor_state: MerkleDistributor = program_client.account(distributor).unwrap();

let (claim_status_pda, _bump) = get_claim_status_pda(&args.program_id, &claimant, &distributor);

let client = RpcClient::new_with_commitment(&args.rpc_url, CommitmentConfig::confirmed());
Expand All @@ -45,6 +48,14 @@ pub fn process_claim_from_api(args: &Args, claim_args: &ClaimFromApiArgs) {
);
}

let (escrow, _bump) = Pubkey::find_program_address(
&[
b"Escrow".as_ref(),
distributor_state.locker.as_ref(),
claimant.key().as_ref(),
],
&locked_voter::ID,
);
ixs.push(Instruction {
program_id: args.program_id,
accounts: merkle_distributor::accounts::NewClaim {
Expand All @@ -55,6 +66,10 @@ pub fn process_claim_from_api(args: &Args, claim_args: &ClaimFromApiArgs) {
claimant,
token_program: token::ID,
system_program: solana_program::system_program::ID,
voter_program: locked_voter::ID,
locker: distributor_state.locker,
escrow,
escrow_tokens: get_associated_token_address(&escrow, &args.mint),
}
.to_account_metas(None),
data: merkle_distributor::instruction::NewClaim {
Expand Down
15 changes: 15 additions & 0 deletions cli/src/bin/instructions/process_new_claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::*;
pub fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
let keypair = read_keypair_file(&args.keypair_path.clone().unwrap())
.expect("Failed reading keypair file");
let program_client = args.get_program_client();
let claimant = keypair.pubkey();
println!("Claiming tokens for user {}...", claimant);

Expand All @@ -18,6 +19,8 @@ pub fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
merkle_tree.airdrop_version,
);

let distributor_state: MerkleDistributor = program_client.account(distributor).unwrap();

// Get user's node in claim
let node = merkle_tree.get_node(&claimant);

Expand Down Expand Up @@ -54,6 +57,14 @@ pub fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
}
}

let (escrow, _bump) = Pubkey::find_program_address(
&[
b"Escrow".as_ref(),
distributor_state.locker.as_ref(),
claimant.key().as_ref(),
],
&locked_voter::ID,
);
ixs.push(Instruction {
program_id: args.program_id,
accounts: merkle_distributor::accounts::NewClaim {
Expand All @@ -64,6 +75,10 @@ pub fn process_new_claim(args: &Args, claim_args: &ClaimArgs) {
claimant,
token_program: token::ID,
system_program: solana_program::system_program::ID,
voter_program: locked_voter::ID,
locker: distributor_state.locker,
escrow,
escrow_tokens: get_associated_token_address(&escrow, &args.mint),
}
.to_account_metas(None),
data: merkle_distributor::instruction::NewClaim {
Expand Down
8 changes: 8 additions & 0 deletions cli/src/bin/instructions/process_new_distributor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ fn create_new_distributor(
new_distributor_args,
total_bonus,
bonus_vesting_duration,
new_distributor_args.locker,
new_distributor_args.min_stake_duration,
keypair.pubkey(),
base.pubkey(),
&args,
Expand Down Expand Up @@ -190,6 +192,8 @@ fn create_new_distributor(
clawback_start_ts: new_distributor_args.clawback_start_ts,
enable_slot: new_distributor_args.enable_slot,
closable: new_distributor_args.closable,
locker: new_distributor_args.locker,
min_locked_duration: new_distributor_args.min_stake_duration,
}
.data(),
});
Expand Down Expand Up @@ -220,6 +224,8 @@ fn create_new_distributor(
closable: new_distributor_args.closable,
total_bonus,
bonus_vesting_slot_duration: bonus_vesting_duration,
locker: new_distributor_args.locker,
min_locked_duration: new_distributor_args.min_stake_duration,
}
.data(),
});
Expand Down Expand Up @@ -277,6 +283,8 @@ fn create_new_distributor(
new_distributor_args,
total_bonus,
bonus_vesting_duration,
new_distributor_args.locker,
new_distributor_args.min_stake_duration,
keypair.pubkey(),
base.pubkey(),
args,
Expand Down
4 changes: 4 additions & 0 deletions programs/merkle-distributor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ bytemuck = "1.14.0"
jito-merkle-verify = { path = "../../verify" }
solana-program = "1.16.16"
solana-security-txt = "1.1.1"
locked-voter = { git = "https://github.com/TeamRaccoons/WAGMI", features = [
"cpi",
"no-entrypoint",
], rev = "425ac5e3a51f15831c825874e531409d4dc12c71" }
2 changes: 2 additions & 0 deletions programs/merkle-distributor/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ pub enum ErrorCode {
CannotCloseDistributor,
#[msg("Cannot close claim status")]
CannotCloseClaimStatus,
#[msg("Remaning locked duration is too small")]
RemaningLockedDurationIsTooSmall,
}
Loading

0 comments on commit 3a1473f

Please sign in to comment.