From 60e926dceea759dac4fa4cb7c419f83711087a1a Mon Sep 17 00:00:00 2001 From: Corto Date: Wed, 6 Nov 2024 22:30:54 +0800 Subject: [PATCH] Untested (to test with MrSablier/staking) --- .vscode/settings.json | 1 + src/lib.rs | 130 +++--------------------------------------- src/pda.rs | 20 +------ src/pyth.rs | 2 +- src/types.rs | 32 +++++------ 5 files changed, 24 insertions(+), 161 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ee9a638..e4bf17f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "kwtpr", "Nxhc", "pyth", + "pythnet", "sablier", "Tokenkeg", "Zeroable" diff --git a/src/lib.rs b/src/lib.rs index 7c1d22e..908b921 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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"); @@ -90,16 +86,6 @@ mod adrena_abi { Ok(()) } - pub(crate) fn cleanup_position_stop_loss(cx: Context) -> Result<()> { - Ok(()) - } - - pub(crate) fn cleanup_position_take_profit( - cx: Context, - ) -> Result<()> { - Ok(()) - } - pub(crate) fn resolve_staking_round(cx: Context) -> Result<()> { Ok(()) } @@ -178,20 +164,11 @@ pub struct ClosePositionLong<'info> { #[account(mut)] pub user_profile: Option>, /// #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)] @@ -259,20 +236,11 @@ pub struct ClosePositionShort<'info> { #[account(mut)] pub user_profile: Option>, /// #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)] @@ -337,20 +305,11 @@ pub struct LiquidateShort<'info> { #[account(mut)] pub user_profile: Option>, /// #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)] @@ -412,80 +371,11 @@ pub struct LiquidateLong<'info> { #[account(mut)] pub user_profile: Option>, /// #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)] @@ -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>, } diff --git a/src/pda.rs b/src/pda.rs index 6e70bee..e6180d8 100644 --- a/src/pda.rs +++ b/src/pda.rs @@ -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"; @@ -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, - domain: Option>, -) -> (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()) } diff --git a/src/pyth.rs b/src/pyth.rs index 7779a7f..214f8ca 100644 --- a/src/pyth.rs +++ b/src/pyth.rs @@ -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, diff --git a/src/types.rs b/src/types.rs index 8b70086..0e3b4a0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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, } @@ -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, } @@ -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 { @@ -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, @@ -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::(); - - 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 { @@ -557,10 +552,10 @@ impl TryFrom 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], } @@ -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,