-
Notifications
You must be signed in to change notification settings - Fork 199
Nour/expand lp status #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nour/expand lp status #1867
Changes from all commits
ae36c1d
5a67b95
d89b15a
cd23493
d9dd686
2f70648
76fd17f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; | |
|
|
||
| use crate::math::constants::{PERCENTAGE_PRECISION, PRICE_PRECISION_I64}; | ||
| use crate::math::oracle::OracleValidity; | ||
| use crate::state::paused_operations::ConstituentLpOperation; | ||
| use crate::validation::whitelist::validate_whitelist_token; | ||
| use crate::{ | ||
| controller::{ | ||
|
|
@@ -285,6 +286,9 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( | |
| let mut in_constituent = ctx.accounts.in_constituent.load_mut()?; | ||
| let mut out_constituent = ctx.accounts.out_constituent.load_mut()?; | ||
|
|
||
| in_constituent.does_constituent_allow_operation(ConstituentLpOperation::Swap)?; | ||
| out_constituent.does_constituent_allow_operation(ConstituentLpOperation::Swap)?; | ||
|
|
||
| let constituent_target_base_key = &ctx.accounts.constituent_target_base.key(); | ||
| let constituent_target_base: AccountZeroCopy<'_, TargetsDatum, ConstituentTargetBaseFixed> = | ||
| ctx.accounts.constituent_target_base.load_zc()?; | ||
|
|
@@ -320,6 +324,20 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( | |
| let in_spot_market = spot_market_map.get_ref(&in_market_index)?; | ||
| let out_spot_market = spot_market_map.get_ref(&out_market_index)?; | ||
|
|
||
| if in_constituent.is_reduce_only()? | ||
| && !in_constituent.is_operation_reducing(&in_spot_market, true)? | ||
| { | ||
| msg!("In constituent in reduce only mode"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging spot market index is nice to have |
||
| return Err(ErrorCode::InvalidConstituentOperation.into()); | ||
| } | ||
|
|
||
| if out_constituent.is_reduce_only()? | ||
| && !out_constituent.is_operation_reducing(&out_spot_market, false)? | ||
| { | ||
| msg!("Out constituent in reduce only mode"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging spot market index is nice to have |
||
| return Err(ErrorCode::InvalidConstituentOperation.into()); | ||
| } | ||
|
|
||
| let in_oracle_id = in_spot_market.oracle_id(); | ||
| let out_oracle_id = out_spot_market.oracle_id(); | ||
|
|
||
|
|
@@ -593,6 +611,9 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( | |
| "Mint/redeem LP pool is disabled" | ||
| )?; | ||
|
|
||
| let mut in_constituent = ctx.accounts.in_constituent.load_mut()?; | ||
| in_constituent.does_constituent_allow_operation(ConstituentLpOperation::Deposit)?; | ||
|
|
||
| let slot = Clock::get()?.slot; | ||
| let now = Clock::get()?.unix_timestamp; | ||
| let lp_pool_key = ctx.accounts.lp_pool.key(); | ||
|
|
@@ -611,8 +632,6 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( | |
|
|
||
| let remaining_accounts = &mut ctx.remaining_accounts.iter().peekable(); | ||
|
|
||
| let mut in_constituent = ctx.accounts.in_constituent.load_mut()?; | ||
|
|
||
| let constituent_target_base_key = &ctx.accounts.constituent_target_base.key(); | ||
| let constituent_target_base: AccountZeroCopy<'_, TargetsDatum, ConstituentTargetBaseFixed> = | ||
| ctx.accounts.constituent_target_base.load_zc()?; | ||
|
|
@@ -646,6 +665,13 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( | |
|
|
||
| let mut in_spot_market = spot_market_map.get_ref_mut(&in_market_index)?; | ||
|
|
||
| if in_constituent.is_reduce_only()? | ||
| && !in_constituent.is_operation_reducing(&in_spot_market, true)? | ||
| { | ||
| msg!("In constituent in reduce only mode"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging spot market index is nice to have |
||
| return Err(ErrorCode::InvalidConstituentOperation.into()); | ||
| } | ||
|
|
||
| let in_oracle_id = in_spot_market.oracle_id(); | ||
|
|
||
| let (in_oracle, in_oracle_validity) = oracle_map.get_price_data_and_validity( | ||
|
|
@@ -936,6 +962,9 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( | |
|
|
||
| let lp_price_before = lp_pool.get_price(ctx.accounts.lp_mint.supply)?; | ||
|
|
||
| let mut out_constituent = ctx.accounts.out_constituent.load_mut()?; | ||
| out_constituent.does_constituent_allow_operation(ConstituentLpOperation::Withdraw)?; | ||
|
|
||
| // Verify previous settle | ||
| let amm_cache: AccountZeroCopy<'_, CacheInfo, _> = ctx.accounts.amm_cache.load_zc()?; | ||
| for (i, _) in amm_cache.iter().enumerate() { | ||
|
|
@@ -959,8 +988,6 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( | |
| return Err(ErrorCode::LpPoolAumDelayed.into()); | ||
| } | ||
|
|
||
| let mut out_constituent = ctx.accounts.out_constituent.load_mut()?; | ||
|
|
||
| let constituent_target_base_key = &ctx.accounts.constituent_target_base.key(); | ||
| let constituent_target_base: AccountZeroCopy<'_, TargetsDatum, ConstituentTargetBaseFixed> = | ||
| ctx.accounts.constituent_target_base.load_zc()?; | ||
|
|
@@ -987,6 +1014,13 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( | |
|
|
||
| let mut out_spot_market = spot_market_map.get_ref_mut(&out_market_index)?; | ||
|
|
||
| if out_constituent.is_reduce_only()? | ||
| && !out_constituent.is_operation_reducing(&out_spot_market, false)? | ||
| { | ||
| msg!("Out constituent in reduce only mode"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging spot market index is nice to have |
||
| return Err(ErrorCode::InvalidConstituentOperation.into()); | ||
| } | ||
|
|
||
| let out_oracle_id = out_spot_market.oracle_id(); | ||
|
|
||
| let (out_oracle, out_oracle_validity) = oracle_map.get_price_data_and_validity( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add a
log_all_operations_pausedsimilar other market/if field