diff --git a/src/lib.rs b/src/lib.rs index 0e27783..72c98f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,6 +89,14 @@ mod adrena_abi { ) -> Result<()> { Ok(()) } + + pub(crate) fn resolve_staking_round(cx: Context) -> Result<()> { + Ok(()) + } + + pub(crate) fn claim_stakes(cx: Context) -> Result<()> { + Ok(()) + } } #[derive(Accounts)] @@ -462,3 +470,121 @@ 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>, +} + +#[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>, +} diff --git a/src/types.rs b/src/types.rs index 187cc97..11dfedc 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,12 +4,21 @@ 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; +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; 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, @@ -507,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, +}