Skip to content

Commit b780311

Browse files
committed
program: init-delegated-if-stake
1 parent 1e7e3b4 commit b780311

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use crate::instructions::optional_accounts::{load_maps, AccountMaps};
1818
use crate::math::casting::Cast;
1919
use crate::math::constants::{
2020
AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO, DEFAULT_LIQUIDATION_MARGIN_BUFFER_RATIO,
21-
FEE_POOL_TO_REVENUE_POOL_THRESHOLD, IF_FACTOR_PRECISION, INSURANCE_A_MAX, INSURANCE_B_MAX,
22-
INSURANCE_C_MAX, INSURANCE_SPECULATIVE_MAX, LIQUIDATION_FEE_PRECISION,
23-
MAX_CONCENTRATION_COEFFICIENT, MAX_SQRT_K, MAX_UPDATE_K_PRICE_CHANGE, PERCENTAGE_PRECISION,
24-
PERCENTAGE_PRECISION_I64, QUOTE_SPOT_MARKET_INDEX, SPOT_CUMULATIVE_INTEREST_PRECISION,
25-
SPOT_IMF_PRECISION, SPOT_WEIGHT_PRECISION, THIRTEEN_DAY, TWENTY_FOUR_HOUR,
21+
FEE_POOL_TO_REVENUE_POOL_THRESHOLD, GOV_SPOT_MARKET_INDEX, IF_FACTOR_PRECISION,
22+
INSURANCE_A_MAX, INSURANCE_B_MAX, INSURANCE_C_MAX, INSURANCE_SPECULATIVE_MAX,
23+
LIQUIDATION_FEE_PRECISION, MAX_CONCENTRATION_COEFFICIENT, MAX_SQRT_K,
24+
MAX_UPDATE_K_PRICE_CHANGE, PERCENTAGE_PRECISION, PERCENTAGE_PRECISION_I64,
25+
QUOTE_SPOT_MARKET_INDEX, SPOT_CUMULATIVE_INTEREST_PRECISION, SPOT_IMF_PRECISION,
26+
SPOT_WEIGHT_PRECISION, THIRTEEN_DAY, TWENTY_FOUR_HOUR,
2627
};
2728
use crate::math::cp_curve::get_update_k_result;
2829
use crate::math::helpers::get_proportion_u128;
@@ -45,6 +46,7 @@ use crate::state::fulfillment_params::serum::SerumContext;
4546
use crate::state::fulfillment_params::serum::SerumV3FulfillmentConfig;
4647
use crate::state::high_leverage_mode_config::HighLeverageModeConfig;
4748
use crate::state::if_rebalance_config::{IfRebalanceConfig, IfRebalanceConfigParams};
49+
use crate::state::insurance_fund_stake::InsuranceFundStake;
4850
use crate::state::insurance_fund_stake::ProtocolIfSharesTransferConfig;
4951
use crate::state::oracle::get_sb_on_demand_price;
5052
use crate::state::oracle::{
@@ -4915,6 +4917,39 @@ pub fn handle_update_feature_bit_flags_median_trigger_price(
49154917
Ok(())
49164918
}
49174919

4920+
pub fn handle_update_delegate_user_gov_token_insurance_stake(
4921+
ctx: Context<UpdateDelegateUserGovTokenInsuranceStake>,
4922+
) -> Result<()> {
4923+
let insurance_fund_stake = &mut load_mut!(ctx.accounts.insurance_fund_stake)?;
4924+
let user_stats = &mut load_mut!(ctx.accounts.user_stats)?;
4925+
let spot_market = &mut load_mut!(ctx.accounts.spot_market)?;
4926+
4927+
validate!(
4928+
insurance_fund_stake.market_index == GOV_SPOT_MARKET_INDEX,
4929+
ErrorCode::IncorrectSpotMarketAccountPassed,
4930+
"insurance_fund_stake is not for governance market index = {}",
4931+
GOV_SPOT_MARKET_INDEX
4932+
)?;
4933+
4934+
if insurance_fund_stake.market_index == GOV_SPOT_MARKET_INDEX
4935+
&& spot_market.market_index == GOV_SPOT_MARKET_INDEX
4936+
{
4937+
let clock = Clock::get()?;
4938+
let now = clock.unix_timestamp;
4939+
4940+
crate::controller::insurance::update_user_stats_if_stake_amount(
4941+
0,
4942+
ctx.accounts.insurance_fund_vault.amount,
4943+
insurance_fund_stake,
4944+
user_stats,
4945+
spot_market,
4946+
now,
4947+
)?;
4948+
}
4949+
4950+
Ok(())
4951+
}
4952+
49184953
#[derive(Accounts)]
49194954
pub struct Initialize<'info> {
49204955
#[account(mut)]
@@ -5754,3 +5789,27 @@ pub struct UpdateIfRebalanceConfig<'info> {
57545789
)]
57555790
pub state: Box<Account<'info, State>>,
57565791
}
5792+
5793+
#[derive(Accounts)]
5794+
pub struct UpdateDelegateUserGovTokenInsuranceStake<'info> {
5795+
#[account(
5796+
mut,
5797+
seeds = [b"spot_market", 15_u16.to_le_bytes().as_ref()],
5798+
bump
5799+
)]
5800+
pub spot_market: AccountLoader<'info, SpotMarket>,
5801+
pub insurance_fund_stake: AccountLoader<'info, InsuranceFundStake>,
5802+
#[account(mut)]
5803+
pub user_stats: AccountLoader<'info, UserStats>,
5804+
pub admin: Signer<'info>,
5805+
#[account(
5806+
mut,
5807+
seeds = [b"insurance_fund_vault".as_ref(), 15_u16.to_le_bytes().as_ref()],
5808+
bump,
5809+
)]
5810+
pub insurance_fund_vault: Box<InterfaceAccount<'info, TokenAccount>>,
5811+
#[account(
5812+
has_one = admin
5813+
)]
5814+
pub state: Box<Account<'info, State>>,
5815+
}

programs/drift/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ pub mod drift {
723723
handle_update_user_gov_token_insurance_stake(ctx)
724724
}
725725

726+
pub fn update_delegate_user_gov_token_insurance_stake(
727+
ctx: Context<UpdateDelegateUserGovTokenInsuranceStake>,
728+
) -> Result<()> {
729+
handle_update_delegate_user_gov_token_insurance_stake(ctx)
730+
}
731+
726732
pub fn update_user_gov_token_insurance_stake_devnet(
727733
ctx: Context<UpdateUserGovTokenInsuranceStakeDevnet>,
728734
gov_stake_amount: u64,

0 commit comments

Comments
 (0)