From 9042d13d2452728d3dc9ece11d3d38c5c8971c6e Mon Sep 17 00:00:00 2001 From: Jean Marchand Date: Mon, 28 Oct 2024 16:14:47 +0700 Subject: [PATCH 1/6] Add resolve staking rounds --- src/lib.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 294eafa..d611d13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,6 +87,10 @@ mod adrena_abi { ) -> Result<()> { Ok(()) } + + pub(crate) fn resolve_staking_round(cx: Context) -> Result<()> { + Ok(()) + } } #[derive(Accounts)] @@ -460,3 +464,64 @@ pub struct CleanupPositionTakeProfit<'info> { #[account(address = SABLIER_THREAD_PROGRAM_ID)] sablier_program: AccountInfo<'info>, } + +#[derive(Accounts)] +pub(crate) struct ResolveStakingRound<'info> { + /// #1 + #[account(mut)] + pub caller: Signer<'info>, + + /// #2 + #[account(mut)] + pub payer: Signer<'info>, + + /// #3 + /// CHECKS: only for CPI + #[account(mut)] + pub staking_staked_token_vault: UncheckedAccount<'info>, + + /// #4 + /// CHECKS: only for CPI + #[account(mut)] + pub staking_reward_token_vault: UncheckedAccount<'info>, + + /// #5 + /// CHECKS: only for CPI + #[account(mut)] + pub staking_lm_reward_token_vault: UncheckedAccount<'info>, + + /// #6 + /// CHECKS: only for CPI + pub transfer_authority: UncheckedAccount<'info>, + + /// #7 + /// CHECKS: only for CPI + #[account(mut)] + pub staking: UncheckedAccount<'info>, + + /// #8 + /// CHECKS: only for CPI + #[account(mut)] + pub cortex: UncheckedAccount<'info>, + + /// #9 + /// CHECKS: only for CPI + #[account(mut)] + pub lm_token_mint: UncheckedAccount<'info>, + + /// #10 + /// CHECKS: only for CPI + pub fee_redistribution_mint: UncheckedAccount<'info>, + + /// #11 + /// CHECKS: only for CPI + pub adrena_program: UncheckedAccount<'info>, + + /// #12 + /// CHECKS: only for CPI + pub system_program: UncheckedAccount<'info>, + + /// #13 + /// CHECKS: only for CPI + pub token_program: UncheckedAccount<'info>, +} From bdd8a6af935fd68e243b0353ba68be6f19f16e5c Mon Sep 17 00:00:00 2001 From: Jean Marchand Date: Mon, 28 Oct 2024 18:45:07 +0700 Subject: [PATCH 2/6] Add claim stakes instruction --- src/lib.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d611d13..5479870 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,6 +91,10 @@ mod adrena_abi { pub(crate) fn resolve_staking_round(cx: Context) -> Result<()> { Ok(()) } + + pub(crate) fn claim_stakes(cx: Context) -> Result<()> { + Ok(()) + } } #[derive(Accounts)] @@ -470,58 +474,115 @@ pub(crate) struct ResolveStakingRound<'info> { /// #1 #[account(mut)] pub caller: Signer<'info>, - /// #2 #[account(mut)] pub payer: Signer<'info>, - /// #3 /// CHECKS: only for CPI #[account(mut)] pub staking_staked_token_vault: UncheckedAccount<'info>, - /// #4 /// CHECKS: only for CPI #[account(mut)] pub staking_reward_token_vault: UncheckedAccount<'info>, - /// #5 /// CHECKS: only for CPI #[account(mut)] pub staking_lm_reward_token_vault: UncheckedAccount<'info>, - /// #6 /// CHECKS: only for CPI pub transfer_authority: UncheckedAccount<'info>, - /// #7 /// CHECKS: only for CPI #[account(mut)] pub staking: UncheckedAccount<'info>, - /// #8 /// CHECKS: only for CPI #[account(mut)] pub cortex: UncheckedAccount<'info>, - /// #9 /// CHECKS: only for CPI #[account(mut)] pub lm_token_mint: UncheckedAccount<'info>, - /// #10 /// CHECKS: only for CPI pub fee_redistribution_mint: UncheckedAccount<'info>, - /// #11 /// CHECKS: only for CPI pub adrena_program: UncheckedAccount<'info>, - /// #12 /// CHECKS: only for CPI pub system_program: UncheckedAccount<'info>, - /// #13 /// CHECKS: only for CPI pub token_program: UncheckedAccount<'info>, } + +#[derive(Accounts)] +pub(crate) struct ClaimStakes<'info> { + /// #1 + #[account(mut)] + pub caller: Signer<'info>, + /// #2 + #[account(mut)] + pub payer: Signer<'info>, + /// #3 + /// CHECKS: only for CPI + #[account(mut)] + pub owner: UncheckedAccount<'info>, + /// #4 + /// CHECKS: only for CPI + #[account(mut)] + pub reward_token_account: UncheckedAccount<'info>, + /// #5 + /// CHECKS: only for CPI + #[account(mut)] + pub lm_token_account: UncheckedAccount<'info>, + /// #6 + /// CHECKS: only for CPI + #[account(mut)] + pub staking_reward_token_vault: UncheckedAccount<'info>, + /// #7 + /// CHECKS: only for CPI + #[account(mut)] + pub staking_lm_reward_token_vault: UncheckedAccount<'info>, + /// #8 + /// CHECKS: only for CPI + pub transfer_authority: UncheckedAccount<'info>, + /// #9 + /// CHECKS: only for CPI + #[account(mut)] + pub user_staking: UncheckedAccount<'info>, + /// #10 + /// CHECKS: only for CPI + #[account(mut)] + pub staking: UncheckedAccount<'info>, + /// #11 + /// CHECKS: only for CPI + #[account(mut)] + pub cortex: UncheckedAccount<'info>, + /// #12 + /// CHECKS: only for CPI + #[account(mut)] + pub pool: UncheckedAccount<'info>, + /// #13 + /// CHECKS: only for CPI + #[account(mut)] + pub genesis_lock: UncheckedAccount<'info>, + /// #14 + /// CHECKS: only for CPI + #[account(mut)] + pub lm_token_mint: UncheckedAccount<'info>, + /// #15 + /// CHECKS: only for CPI + pub fee_redistribution_mint: UncheckedAccount<'info>, + /// #16 + /// CHECKS: only for CPI + adrena_program: UncheckedAccount<'info>, + /// #17 + /// CHECKS: only for CPI + system_program: UncheckedAccount<'info>, + /// #18 + /// CHECKS: only for CPI + token_program: UncheckedAccount<'info>, +} From 2217098684e9fa2757afed4fa8a6ca8aa9ab7362 Mon Sep 17 00:00:00 2001 From: Jean Marchand Date: Tue, 29 Oct 2024 12:47:22 +0700 Subject: [PATCH 3/6] Add UserStaking type --- src/types.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/types.rs b/src/types.rs index b47862b..245c865 100644 --- a/src/types.rs +++ b/src/types.rs @@ -10,6 +10,8 @@ pub const MAX_CUSTODIES: usize = 10; pub const MAX_STABLE_CUSTODY: usize = 2; +pub const MAX_LOCKED_STAKE_COUNT: usize = 32; + #[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy)] pub struct ClosePositionLongParams { pub price: Option, @@ -514,3 +516,54 @@ impl TryFrom for Side { }) } } + +#[account(zero_copy)] +#[derive(Default, Debug, PartialEq, AnchorSerialize, AnchorDeserialize)] +#[repr(C)] +pub struct UserStaking { + pub bump: u8, + pub thread_authority_bump: u8, + pub _padding: [u8; 6], + pub stakes_claim_cron_thread_id: u64, + pub liquid_stake: LiquidStake, + pub locked_stakes: [LockedStake; MAX_LOCKED_STAKE_COUNT], +} + +#[derive( + Copy, Clone, PartialEq, AnchorSerialize, AnchorDeserialize, Default, Debug, Zeroable, Pod, +)] +#[repr(C)] +pub struct LiquidStake { + pub amount: u64, + pub stake_time: i64, + pub claim_time: i64, + pub overlap_time: i64, + pub overlap_amount: u64, +} + +#[derive( + Copy, Clone, PartialEq, AnchorSerialize, AnchorDeserialize, Default, Debug, Zeroable, Pod, +)] +#[repr(C)] +pub struct LockedStake { + pub amount: u64, + pub stake_time: i64, + pub claim_time: i64, + pub end_time: i64, + pub lock_duration: u64, + pub reward_multiplier: u32, + pub lm_reward_multiplier: u32, + pub vote_multiplier: u32, + pub qualified_for_rewards_in_resolved_round_count: u32, + pub amount_with_reward_multiplier: u64, + pub amount_with_lm_reward_multiplier: u64, + pub resolved: u8, + pub _padding2: [u8; 7], + pub stake_resolution_thread_id: u64, + pub early_exit: u8, + pub _padding3: [u8; 7], + pub early_exit_fee: u64, + pub is_genesis: u8, + pub _padding4: [u8; 7], + pub genesis_claim_time: i64, +} From 7891b2e87863a7f46503a46e96335ef58adf6752 Mon Sep 17 00:00:00 2001 From: Corto Date: Thu, 31 Oct 2024 07:03:39 +0800 Subject: [PATCH 4/6] Add staking constants --- src/types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types.rs b/src/types.rs index 245c865..055f781 100644 --- a/src/types.rs +++ b/src/types.rs @@ -5,6 +5,10 @@ use { }; pub const MAX_RESOLVED_ROUNDS: usize = 32; +pub const ROUND_MIN_DURATION_HOURS: i64 = 6; +pub const ROUND_MIN_DURATION_SECONDS: i64 = ROUND_MIN_DURATION_HOURS * SECONDS_PER_HOURS; +pub const SECONDS_PER_MONTH: i64 = 30 * SECONDS_PER_HOURS * 24; +pub const MAX_ROUNDS_PER_MONTH: u64 = SECONDS_PER_MONTH as u64 / ROUND_MIN_DURATION_SECONDS as u64;s pub const MAX_CUSTODIES: usize = 10; From 7b14dd00ff81f2e83e547e3b281311799ab14718 Mon Sep 17 00:00:00 2001 From: Corto Date: Thu, 31 Oct 2024 07:03:48 +0800 Subject: [PATCH 5/6] Add staking constants --- src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.rs b/src/types.rs index 055f781..44b2bb0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -8,7 +8,7 @@ pub const MAX_RESOLVED_ROUNDS: usize = 32; pub const ROUND_MIN_DURATION_HOURS: i64 = 6; pub const ROUND_MIN_DURATION_SECONDS: i64 = ROUND_MIN_DURATION_HOURS * SECONDS_PER_HOURS; pub const SECONDS_PER_MONTH: i64 = 30 * SECONDS_PER_HOURS * 24; -pub const MAX_ROUNDS_PER_MONTH: u64 = SECONDS_PER_MONTH as u64 / ROUND_MIN_DURATION_SECONDS as u64;s +pub const MAX_ROUNDS_PER_MONTH: u64 = SECONDS_PER_MONTH as u64 / ROUND_MIN_DURATION_SECONDS as u64; pub const MAX_CUSTODIES: usize = 10; From dbc2b0508dfbcbcc893781b7c15416592fd45818 Mon Sep 17 00:00:00 2001 From: Corto Date: Thu, 31 Oct 2024 07:05:15 +0800 Subject: [PATCH 6/6] Add missing consts --- src/types.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types.rs b/src/types.rs index 44b2bb0..dec4197 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,6 +4,9 @@ use { bytemuck::{Pod, Zeroable}, }; +pub const HOURS_PER_DAY: i64 = 24; +pub const SECONDS_PER_HOURS: i64 = 3600; + pub const MAX_RESOLVED_ROUNDS: usize = 32; pub const ROUND_MIN_DURATION_HOURS: i64 = 6; pub const ROUND_MIN_DURATION_SECONDS: i64 = ROUND_MIN_DURATION_HOURS * SECONDS_PER_HOURS;