Skip to content

Commit

Permalink
Merge pull request #3 from AdrenaFoundation/misc/sablier-removal
Browse files Browse the repository at this point in the history
Untested (to test with MrSablier/staking)
  • Loading branch information
Adrena-Corto authored Nov 9, 2024
2 parents 7d2ce64 + 60e926d commit cb6b69c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 161 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"kwtpr",
"Nxhc",
"pyth",
"pythnet",
"sablier",
"Tokenkeg",
"Zeroable"
Expand Down
130 changes: 7 additions & 123 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ declare_id!("13gDzEXCdocbj8iAiqrScGo47NiSuYENGsRqi3SEAwet");
pub static SPL_TOKEN_PROGRAM_ID: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
pub static SPL_ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey =
pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
pub static SABLIER_THREAD_PROGRAM_ID: Pubkey =
pubkey!("sabGLGXfBiUCkwtprPMtatG6tCNxhcWWs1hjQAvDqEE");
pub static SABLIER_NETWORK_PROGRAM_ID: Pubkey =
pubkey!("H6CTDj7ewA6PT1jGt2WTnkhWb2RwwuoQkAsgzRuSsnaV");
pub static SPL_GOVERNANCE_PROGRAM_ID: Pubkey =
pubkey!("GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw");

Expand Down Expand Up @@ -90,16 +86,6 @@ mod adrena_abi {
Ok(())
}

pub(crate) fn cleanup_position_stop_loss(cx: Context<CleanupPositionStopLoss>) -> Result<()> {
Ok(())
}

pub(crate) fn cleanup_position_take_profit(
cx: Context<CleanupPositionTakeProfit>,
) -> Result<()> {
Ok(())
}

pub(crate) fn resolve_staking_round(cx: Context<ResolveStakingRound>) -> Result<()> {
Ok(())
}
Expand Down Expand Up @@ -178,20 +164,11 @@ pub struct ClosePositionLong<'info> {
#[account(mut)]
pub user_profile: Option<AccountLoader<'info, UserProfile>>,
/// #22
#[account(mut)]
pub take_profit_thread: UncheckedAccount<'info>,
/// #23
#[account(mut)]
pub stop_loss_thread: UncheckedAccount<'info>,
/// #24
#[account(address = SPL_TOKEN_PROGRAM_ID)]
token_program: AccountInfo<'info>,
/// #25
/// #23
#[account(address = ADRENA_PROGRAM_ID)]
adrena_program: AccountInfo<'info>,
/// #26
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
Expand Down Expand Up @@ -259,20 +236,11 @@ pub struct ClosePositionShort<'info> {
#[account(mut)]
pub user_profile: Option<AccountLoader<'info, UserProfile>>,
/// #23
#[account(mut)]
pub take_profit_thread: UncheckedAccount<'info>,
/// #24
#[account(mut)]
pub stop_loss_thread: UncheckedAccount<'info>,
/// #25
#[account(address = SPL_TOKEN_PROGRAM_ID)]
token_program: AccountInfo<'info>,
/// #26
/// #24
#[account(address = ADRENA_PROGRAM_ID)]
adrena_program: AccountInfo<'info>,
/// #27
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
Expand Down Expand Up @@ -337,20 +305,11 @@ pub struct LiquidateShort<'info> {
#[account(mut)]
pub user_profile: Option<AccountLoader<'info, UserProfile>>,
/// #22
#[account(mut)]
pub take_profit_thread: UncheckedAccount<'info>,
/// #23
#[account(mut)]
pub stop_loss_thread: UncheckedAccount<'info>,
/// #24
#[account(address = SPL_TOKEN_PROGRAM_ID)]
token_program: AccountInfo<'info>,
/// #25
/// #23
#[account(address = ADRENA_PROGRAM_ID)]
adrena_program: AccountInfo<'info>,
/// #26
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
Expand Down Expand Up @@ -412,80 +371,11 @@ pub struct LiquidateLong<'info> {
#[account(mut)]
pub user_profile: Option<AccountLoader<'info, UserProfile>>,
/// #21
#[account(mut)]
pub take_profit_thread: UncheckedAccount<'info>,
/// #22
#[account(mut)]
pub stop_loss_thread: UncheckedAccount<'info>,
/// #23
#[account(address = SPL_TOKEN_PROGRAM_ID)]
token_program: AccountInfo<'info>,
/// #24
/// #22
#[account(address = ADRENA_PROGRAM_ID)]
adrena_program: AccountInfo<'info>,
/// #25
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CleanupPositionStopLoss<'info> {
/// #1
#[account(mut)]
pub caller: Signer<'info>,
/// #2
#[account(mut)]
pub owner: AccountInfo<'info>,
/// #3
pub transfer_authority: AccountInfo<'info>,
/// #4
pub cortex: AccountLoader<'info, Cortex>,
/// #5
pub pool: AccountLoader<'info, Pool>,
/// #6
#[account(mut)]
pub position: AccountLoader<'info, Position>,
/// #7
pub custody: AccountLoader<'info, Custody>,
/// #8
#[account(mut)]
pub stop_loss_thread: AccountInfo<'info>,
/// #9
#[account(mut)]
pub take_profit_thread: UncheckedAccount<'info>,
/// #10
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CleanupPositionTakeProfit<'info> {
/// #1
#[account(mut)]
pub caller: Signer<'info>,
/// #2
#[account(mut)]
pub owner: AccountInfo<'info>,
/// #3
pub transfer_authority: AccountInfo<'info>,
/// #4
pub cortex: AccountLoader<'info, Cortex>,
/// #5
pub pool: AccountLoader<'info, Pool>,
/// #6
#[account(mut)]
pub position: AccountLoader<'info, Position>,
/// #7
pub custody: AccountLoader<'info, Custody>,
/// #8
#[account(mut)]
pub take_profit_thread: AccountInfo<'info>,
/// #9
#[account(mut)]
pub stop_loss_thread: UncheckedAccount<'info>,
/// #10
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
}

#[derive(Accounts)]
Expand Down Expand Up @@ -642,21 +532,15 @@ pub struct FinalizeLockedStake<'info> {
#[account(mut)]
pub governance_governing_token_owner_record: UncheckedAccount<'info>,
/// #13
#[account(mut)]
pub stake_resolution_thread: UncheckedAccount<'info>,
/// #14
#[account(address = SABLIER_THREAD_PROGRAM_ID)]
sablier_program: AccountInfo<'info>,
/// #15
#[account(address = SPL_GOVERNANCE_PROGRAM_ID)]
governance_program: AccountInfo<'info>,
/// #16
/// #14
#[account(address = ADRENA_PROGRAM_ID)]
adrena_program: AccountInfo<'info>,
/// #17
/// #15
#[account(address = solana_sdk::system_program::ID)]
system_program: AccountInfo<'info>,
/// #18
/// #16
#[account(address = SPL_TOKEN_PROGRAM_ID)]
token_program: AccountInfo<'info>,
}
20 changes: 1 addition & 19 deletions src/pda.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
crate::{Side, GOVERNANCE_PROGRAM_ID, SABLIER_THREAD_PROGRAM_ID},
crate::{Side, GOVERNANCE_PROGRAM_ID},
anchor_lang::prelude::*,
};

#[constant]
pub const SEED_THREAD: &[u8] = b"thread";

#[constant]
pub const SEED_CONFIG: &[u8] = b"config";
Expand All @@ -29,22 +27,6 @@ pub fn get_lm_token_mint_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&["lm_token_mint".as_ref()], &crate::id())
}

pub fn get_sablier_thread_pda(
thread_authority: &Pubkey,
thread_id: Vec<u8>,
domain: Option<Vec<u8>>,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[
SEED_THREAD,
thread_authority.as_ref(),
thread_id.as_slice(),
domain.unwrap_or_default().as_slice(),
],
&SABLIER_THREAD_PROGRAM_ID,
)
}

pub fn get_governance_token_mint_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&["governance_token_mint".as_ref()], &crate::id())
}
Expand Down
2 changes: 1 addition & 1 deletion src/pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct PriceFeedMessage {
/// (which we can do once publishers have migrated over).
///
/// Additionally, this field may be equal to publish_time if the message is sent on a slot where
/// where the aggregation was unsuccesful. This problem will go away once all publishers have
/// where the aggregation was unsuccessful. This problem will go away once all publishers have
/// migrated over to a recent version of pyth-agent.
pub prev_publish_time: i64,
pub ema_price: i64,
Expand Down
32 changes: 14 additions & 18 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct LiquidateShortParams {}

#[derive(AnchorSerialize, AnchorDeserialize, Copy, Clone)]
pub struct FinalizeLockedStakeParams {
pub thread_id: u64,
pub locked_stake_id: u64,
pub early_exit: bool,
}

Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct Staking {
pub _padding: [u8; 3],
pub lm_emission_potentiometer_bps: u16,
pub months_elapsed_since_inception: u16,
pub resolve_round_cron_thread_id: u64,
pub _padding_unsafe: [u8; 8],
pub emission_amount_per_round_last_update: i64,
pub current_month_emission_amount_per_round: u64,
}
Expand Down Expand Up @@ -154,7 +154,7 @@ pub struct Cortex {
pub ecosystem_bucket_vested_amount: u64,
pub ecosystem_bucket_minted_amount: u64,
pub genesis_liquidity_alp_amount: u64,
pub unique_position_automation_thread_id_counter: u64,
pub unique_position_id_counter: u64,
}

impl Cortex {
Expand Down Expand Up @@ -217,9 +217,9 @@ pub struct Pool {
pub struct Position {
pub bump: u8,
pub side: u8,
pub take_profit_thread_is_set: u8,
pub stop_loss_thread_is_set: u8,
pub pending_cleanup_and_close: u8,
pub take_profit_is_set: u8,
pub stop_loss_is_set: u8,
pub _padding_unsafe: [u8; 1],
pub _padding: [u8; 3],
pub owner: Pubkey,
pub pool: Pubkey,
Expand All @@ -237,31 +237,26 @@ pub struct Position {
pub collateral_amount: u64,
pub exit_fee_usd: u64,
pub liquidation_fee_usd: u64,
pub take_profit_thread_id: u64,
pub id: u64,
pub take_profit_limit_price: u64,
pub stop_loss_thread_id: u64,
pub _padding_unsafe3: [u8; 8],
pub stop_loss_limit_price: u64,
pub stop_loss_close_position_price: u64,
}

impl Position {
pub const LEN: usize = 8 + std::mem::size_of::<Position>();

pub fn is_pending_cleanup_and_close(&self) -> bool {
self.pending_cleanup_and_close != 0
}

pub fn get_side(&self) -> Side {
// Consider value in the struct always good
Side::try_from(self.side).unwrap()
}

pub fn take_profit_is_set(&self) -> bool {
self.take_profit_thread_is_set != 0
self.take_profit_is_set != 0
}

pub fn stop_loss_is_set(&self) -> bool {
self.stop_loss_thread_is_set != 0
self.stop_loss_is_set != 0
}

pub fn take_profit_reached(&self, price: u64) -> bool {
Expand Down Expand Up @@ -557,10 +552,10 @@ impl TryFrom<u8> for StakingType {
#[repr(C)]
pub struct UserStaking {
pub bump: u8,
pub thread_authority_bump: u8,
pub _unused_unsafe: [u8; 1],
pub staking_type: u8,
pub _padding: [u8; 5],
pub stakes_claim_cron_thread_id: u64,
pub locked_stake_id_counter: u64,
pub liquid_stake: LiquidStake,
pub locked_stakes: [LockedStake; MAX_LOCKED_STAKE_COUNT],
}
Expand Down Expand Up @@ -601,7 +596,8 @@ pub struct LockedStake {
pub amount_with_lm_reward_multiplier: u64,
pub resolved: u8,
pub _padding2: [u8; 7],
pub stake_resolution_thread_id: u64,
// History: was a thread id before while using Sablier, now used as a unique random id for each stake
pub id: u64,
pub early_exit: u8,
pub _padding3: [u8; 7],
pub early_exit_fee: u64,
Expand Down

0 comments on commit cb6b69c

Please sign in to comment.