Skip to content

Commit 59c953f

Browse files
committed
hotfix for user claim
1 parent b73ee1b commit 59c953f

File tree

2 files changed

+129
-18
lines changed

2 files changed

+129
-18
lines changed

api/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,23 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
170170
max_total_claim: single_tree.max_total_claim,
171171
});
172172
for node in single_tree.tree_nodes.iter() {
173-
tree_clone
173+
let tree_has = tree_clone
174174
.lock()
175175
.await
176-
.insert(node.claimant, (distributor_pubkey, node.clone()));
176+
.contains_key(&node.claimant);
177+
if tree_has && node.claimant == Pubkey::from_str("FJWKx31QCW7yCwsVBihqx9QH5FzexbkpHgaaGrj8cbi5").unwrap() {
178+
let placeholder = Pubkey::from_str("BUZn6J1R6FEKNMptvKVmYiyn4U4cvxBRswBfeKBMKMm1").unwrap();
179+
println!("user was in tree already, insert the second claim in tree {}, amt: {}, ph: {}", single_tree.airdrop_version, node.amount, placeholder);
180+
tree_clone
181+
.lock()
182+
.await
183+
.insert(placeholder, (distributor_pubkey, node.clone()));
184+
} else {
185+
tree_clone
186+
.lock()
187+
.await
188+
.insert(node.claimant, (distributor_pubkey, node.clone()));
189+
}
177190
}
178191
let duration_single_tree = start_single_tree.elapsed();
179192
println!(

api/src/router.rs

Lines changed: 114 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ async fn get_eligibility(
288288
) -> Result<impl IntoResponse> {
289289
let merkle_tree = &state.tree;
290290
let proof = get_user_proof(merkle_tree, user_pubkey.clone())?;
291+
291292
let distributor = state.cache.get_distributor(&proof.merkle_tree);
292293
let curr_ts = SystemTime::now()
293294
.duration_since(UNIX_EPOCH)
@@ -361,22 +362,119 @@ async fn get_eligibility(
361362
err
362363
})?;
363364

364-
Ok(Json(EligibilityResp {
365-
claimant: user_pubkey.clone(),
366-
merkle_tree: proof.merkle_tree,
367-
start_ts,
368-
end_ts,
369-
mint,
370-
proof: proof.proof,
371-
start_amount,
372-
end_amount: proof.amount as u128,
373-
locked_amount: proof.locked_amount as u128,
374-
claimable_amount: claimable_amount as u128,
375-
unvested_amount: state.cache.get_unvested_amount(user_pubkey),
376-
claimed_amount: (unlocked_amount_claimed + locked_amount_withdrawn) as u128,
377-
unlocked_amount_claimed: unlocked_amount_claimed as u128,
378-
locked_amount_withdrawn: locked_amount_withdrawn as u128,
379-
}))
365+
let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("epoch time").as_secs() as i64;
366+
if user_pubkey.as_str() == "FJWKx31QCW7yCwsVBihqx9QH5FzexbkpHgaaGrj8cbi5" && now % 10 == 0 /*unlocked_amount_claimed == proof.amount*/ {
367+
let proof = get_user_proof(merkle_tree, "BUZn6J1R6FEKNMptvKVmYiyn4U4cvxBRswBfeKBMKMm1".to_string())?;
368+
369+
println!("user FJWKx31QCW7yCwsVBihqx9QH5FzexbkpHgaaGrj8cbi5 had full claim, loading second proof: {:?}", proof.amount);
370+
371+
let distributor = state.cache.get_distributor(&proof.merkle_tree);
372+
let curr_ts = SystemTime::now()
373+
.duration_since(UNIX_EPOCH)
374+
.expect("epoch time")
375+
.as_secs() as i64;
376+
377+
let (start_ts, end_ts, mint) = match distributor {
378+
Some(distributor) => (
379+
distributor.start_ts,
380+
distributor.end_ts,
381+
distributor.mint.to_string(),
382+
),
383+
None => (
384+
state.cache.default_start_ts,
385+
state.cache.default_end_ts,
386+
state.cache.default_mint.clone(),
387+
),
388+
};
389+
let (unlocked_amount_claimed, locked_amount_withdrawn, claimable_amount) = state
390+
.cache
391+
.get_claim_status(&user_pubkey)
392+
.map(|r| {
393+
(
394+
r.data.unlocked_amount_claimed,
395+
r.data.locked_amount_withdrawn,
396+
r.data
397+
.amount_withdrawable(curr_ts, start_ts, end_ts)
398+
.unwrap_or(0),
399+
)
400+
})
401+
.unwrap_or_else(|| {
402+
// No ClaimStatus exists - calculate what would be claimable
403+
// For unlocked amounts (proof.amount), use vesting with 50% start
404+
let unlocked_claimable = calculate_claimable_amount_for_new_user(
405+
proof.amount as u64,
406+
curr_ts,
407+
start_ts,
408+
end_ts,
409+
state.start_amount_pct,
410+
);
411+
412+
// For locked amounts, calculate linear vesting (no 50% start)
413+
let locked_claimable = calculate_locked_amount_claimable(
414+
proof.locked_amount as u64,
415+
curr_ts,
416+
start_ts,
417+
end_ts,
418+
);
419+
420+
(0, 0, unlocked_claimable + locked_claimable)
421+
});
422+
423+
let start_amount_pct_num = state.start_amount_pct * START_AMOUNT_PCT_PRECISION;
424+
let start_amount = (proof.amount as u128)
425+
.checked_mul(start_amount_pct_num)
426+
.ok_or_else(|| {
427+
let err = ApiError::MathError();
428+
error!(
429+
"Math error occurred (1), amount: {}, START_AMOUNT_PCT_NUM: {}, START_AMOUNT_PCT_DENOM: {}",
430+
proof.amount, start_amount_pct_num, START_AMOUNT_PCT_DENOM
431+
);
432+
err
433+
})?
434+
.checked_div(START_AMOUNT_PCT_DENOM)
435+
.ok_or_else(|| {
436+
let err = ApiError::MathError();
437+
error!(
438+
"Math error occurred (2), amount: {}, START_AMOUNT_PCT_NUM: {}, START_AMOUNT_PCT_DENOM: {}",
439+
proof.amount, start_amount_pct_num, START_AMOUNT_PCT_DENOM
440+
);
441+
err
442+
})?;
443+
Ok(Json(EligibilityResp {
444+
claimant: user_pubkey.clone(),
445+
merkle_tree: proof.merkle_tree,
446+
start_ts,
447+
end_ts,
448+
mint,
449+
proof: proof.proof,
450+
start_amount,
451+
end_amount: proof.amount as u128,
452+
locked_amount: proof.locked_amount as u128,
453+
claimable_amount: claimable_amount as u128,
454+
unvested_amount: state.cache.get_unvested_amount(user_pubkey),
455+
claimed_amount: (unlocked_amount_claimed + locked_amount_withdrawn) as u128,
456+
unlocked_amount_claimed: unlocked_amount_claimed as u128,
457+
locked_amount_withdrawn: locked_amount_withdrawn as u128,
458+
}))
459+
} else {
460+
Ok(Json(EligibilityResp {
461+
claimant: user_pubkey.clone(),
462+
merkle_tree: proof.merkle_tree,
463+
start_ts,
464+
end_ts,
465+
mint,
466+
proof: proof.proof,
467+
start_amount,
468+
end_amount: proof.amount as u128,
469+
locked_amount: proof.locked_amount as u128,
470+
claimable_amount: claimable_amount as u128,
471+
unvested_amount: state.cache.get_unvested_amount(user_pubkey),
472+
claimed_amount: (unlocked_amount_claimed + locked_amount_withdrawn) as u128,
473+
unlocked_amount_claimed: unlocked_amount_claimed as u128,
474+
locked_amount_withdrawn: locked_amount_withdrawn as u128,
475+
}))
476+
}
477+
380478
}
381479

382480
#[derive(Serialize, Deserialize, Clone)]

0 commit comments

Comments
 (0)