@@ -17,7 +17,7 @@ use crate::{
17
17
casting:: Cast ,
18
18
constants:: {
19
19
PERCENTAGE_PRECISION , PERCENTAGE_PRECISION_I128 , PERCENTAGE_PRECISION_I64 ,
20
- PERCENTAGE_PRECISION_U64 , PRICE_PRECISION_I128 , QUOTE_PRECISION_I128 ,
20
+ PERCENTAGE_PRECISION_U64 , PRICE_PRECISION , PRICE_PRECISION_I128 , QUOTE_PRECISION_I128 ,
21
21
} ,
22
22
oracle:: { is_oracle_valid_for_action, oracle_validity, DriftAction } ,
23
23
safe_math:: SafeMath ,
@@ -30,7 +30,7 @@ use crate::{
30
30
calculate_target_weight, AmmConstituentDatum , AmmConstituentMappingFixed , Constituent ,
31
31
ConstituentCorrelationsFixed , ConstituentTargetBaseFixed , LPPool , TargetsDatum ,
32
32
WeightValidationFlags , LP_POOL_SWAP_AUM_UPDATE_DELAY ,
33
- MAX_AMM_CACHE_STALENESS_FOR_TARGET_CALC , MAX_CONSTITUENT_ORACLE_SLOT_STALENESS_FOR_AUM ,
33
+ MAX_AMM_CACHE_STALENESS_FOR_TARGET_CALC ,
34
34
} ,
35
35
oracle:: OraclePriceData ,
36
36
oracle_map:: OracleMap ,
@@ -258,7 +258,7 @@ pub fn handle_update_lp_pool_aum<'c: 'info, 'info>(
258
258
for i in 0 ..lp_pool. constituents as usize {
259
259
let constituent = constituent_map. get_ref ( & ( i as u16 ) ) ?;
260
260
if slot. saturating_sub ( constituent. last_oracle_slot )
261
- > MAX_CONSTITUENT_ORACLE_SLOT_STALENESS_FOR_AUM
261
+ > constituent . oracle_staleness_threshold
262
262
{
263
263
msg ! (
264
264
"Constituent {} oracle slot is too stale: {}, current slot: {}" ,
@@ -490,13 +490,13 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>(
490
490
} = load_maps (
491
491
& mut ctx. remaining_accounts . iter ( ) . peekable ( ) ,
492
492
& MarketSet :: new ( ) ,
493
- & get_writable_spot_market_set_from_many ( vec ! [ in_market_index , out_market_index ] ) ,
493
+ & MarketSet :: new ( ) ,
494
494
slot,
495
495
Some ( state. oracle_guard_rails ) ,
496
496
) ?;
497
497
498
- let mut in_spot_market = spot_market_map. get_ref_mut ( & in_market_index) ?;
499
- let mut out_spot_market = spot_market_map. get_ref_mut ( & out_market_index) ?;
498
+ let in_spot_market = spot_market_map. get_ref ( & in_market_index) ?;
499
+ let out_spot_market = spot_market_map. get_ref ( & out_market_index) ?;
500
500
501
501
let in_oracle_id = in_spot_market. oracle_id ( ) ;
502
502
let out_oracle_id = out_spot_market. oracle_id ( ) ;
@@ -538,9 +538,6 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>(
538
538
return Err ( ErrorCode :: InvalidOracle . into ( ) ) ;
539
539
}
540
540
541
- update_spot_market_cumulative_interest ( & mut in_spot_market, Some ( & in_oracle) , now) ?;
542
- update_spot_market_cumulative_interest ( & mut out_spot_market, Some ( & out_oracle) , now) ?;
543
-
544
541
let in_target_weight = constituent_target_base. get_target_weight (
545
542
in_constituent. constituent_index ,
546
543
& in_spot_market,
@@ -622,8 +619,6 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>(
622
619
in_constituent_index : in_constituent. constituent_index ,
623
620
out_oracle_price : out_oracle. price ,
624
621
in_oracle_price : in_oracle. price ,
625
- out_mint : out_constituent. mint ,
626
- in_mint : in_constituent. mint ,
627
622
last_aum : lp_pool. last_aum ,
628
623
last_aum_slot : lp_pool. last_aum_slot ,
629
624
in_market_current_weight : in_constituent. get_weight (
@@ -833,7 +828,10 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>(
833
828
834
829
let dlp_total_supply = ctx. accounts . lp_mint . supply ;
835
830
let lp_price = if dlp_total_supply > 0 {
836
- lp_pool. last_aum . safe_div ( dlp_total_supply as u128 ) ?
831
+ lp_pool
832
+ . last_aum
833
+ . safe_mul ( PRICE_PRECISION ) ?
834
+ . safe_div ( dlp_total_supply as u128 ) ?
837
835
} else {
838
836
0
839
837
} ;
@@ -850,7 +848,6 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>(
850
848
constituent_index : in_constituent. constituent_index ,
851
849
oracle_price : in_oracle. price ,
852
850
mint : in_constituent. mint ,
853
- lp_mint : lp_pool. mint ,
854
851
lp_amount,
855
852
lp_fee : lp_fee_amount,
856
853
lp_price,
@@ -1032,7 +1029,10 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>(
1032
1029
1033
1030
let dlp_total_supply = ctx. accounts . lp_mint . supply ;
1034
1031
let lp_price = if dlp_total_supply > 0 {
1035
- lp_pool. last_aum . safe_div ( dlp_total_supply as u128 ) ?
1032
+ lp_pool
1033
+ . last_aum
1034
+ . safe_mul ( PRICE_PRECISION ) ?
1035
+ . safe_div ( dlp_total_supply as u128 ) ?
1036
1036
} else {
1037
1037
0
1038
1038
} ;
@@ -1049,7 +1049,6 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>(
1049
1049
constituent_index : out_constituent. constituent_index ,
1050
1050
oracle_price : out_oracle. price ,
1051
1051
mint : out_constituent. mint ,
1052
- lp_mint : lp_pool. mint ,
1053
1052
lp_amount : lp_burn_amount,
1054
1053
lp_fee : lp_fee_amount,
1055
1054
lp_price,
@@ -1112,6 +1111,8 @@ pub fn handle_deposit_to_program_vault<'c: 'info, 'info>(
1112
1111
return Err ( ErrorCode :: InsufficientDeposit . into ( ) ) ;
1113
1112
}
1114
1113
1114
+ let deposit_plus_token_amount_before = amount. safe_add ( spot_market_vault. amount ) ?;
1115
+
1115
1116
let oracle_data = oracle_map. get_price_data ( & oracle_id) ?;
1116
1117
let oracle_data_slot = clock. slot - oracle_data. delay . max ( 0i64 ) . cast :: < u64 > ( ) ?;
1117
1118
if constituent. last_oracle_slot < oracle_data_slot {
@@ -1150,6 +1151,12 @@ pub fn handle_deposit_to_program_vault<'c: 'info, 'info>(
1150
1151
ctx. accounts . spot_market_vault . reload ( ) ?;
1151
1152
spot_market. validate_max_token_deposits_and_borrows ( false ) ?;
1152
1153
1154
+ validate ! (
1155
+ ctx. accounts. spot_market_vault. amount == deposit_plus_token_amount_before,
1156
+ ErrorCode :: LpInvariantFailed ,
1157
+ "Spot market vault amount mismatch after deposit"
1158
+ ) ?;
1159
+
1153
1160
Ok ( ( ) )
1154
1161
}
1155
1162
0 commit comments