@@ -20,8 +20,10 @@ use crate::{
2020 ConstituentTargetBaseFixed , LPPool , TargetsDatum , WeightValidationFlags ,
2121 } ,
2222 oracle:: OraclePriceData ,
23+ oracle_map:: OracleMap ,
2324 perp_market:: { AmmCacheFixed , CacheInfo , AMM_POSITIONS_CACHE } ,
2425 perp_market_map:: MarketSet ,
26+ spot_market:: SpotMarket ,
2527 spot_market_map:: get_writable_spot_market_set_from_many,
2628 state:: State ,
2729 user:: MarketType ,
@@ -912,6 +914,46 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>(
912914 Ok ( ( ) )
913915}
914916
917+ pub fn handle_update_constituent_oracle_info < ' c : ' info , ' info > (
918+ ctx : Context < ' _ , ' _ , ' c , ' info , UpdateConstituentOracleInfo < ' info > > ,
919+ ) -> Result < ( ) > {
920+ let clock = Clock :: get ( ) ?;
921+ let mut constituent = ctx. accounts . constituent . load_mut ( ) ?;
922+ let spot_market = ctx. accounts . spot_market . load ( ) ?;
923+
924+ let oracle_id = spot_market. oracle_id ( ) ;
925+ let mut oracle_map = OracleMap :: load_one (
926+ & ctx. accounts . oracle ,
927+ clock. slot ,
928+ Some ( ctx. accounts . state . oracle_guard_rails ) ,
929+ ) ?;
930+
931+ let oracle_data = oracle_map. get_price_data ( & oracle_id) ?;
932+ let oracle_data_slot = clock. slot - oracle_data. delay . max ( 0i64 ) . cast :: < u64 > ( ) ?;
933+ if constituent. last_oracle_slot < oracle_data_slot {
934+ constituent. last_oracle_price = oracle_data. price ;
935+ constituent. last_oracle_slot = oracle_data_slot;
936+ }
937+
938+ Ok ( ( ) )
939+ }
940+
941+ #[ derive( Accounts ) ]
942+ pub struct UpdateConstituentOracleInfo < ' info > {
943+ pub state : Box < Account < ' info , State > > ,
944+ #[ account( mut ) ]
945+ pub keeper : Signer < ' info > ,
946+ #[ account( mut ) ]
947+ pub constituent : AccountLoader < ' info , Constituent > ,
948+ #[ account(
949+ owner = crate :: ID ,
950+ constraint = spot_market. load( ) ?. market_index == constituent. load( ) ?. spot_market_index
951+ ) ]
952+ pub spot_market : AccountLoader < ' info , SpotMarket > ,
953+ /// CHECK: checked when loading oracle in oracle map
954+ pub oracle : AccountInfo < ' info > ,
955+ }
956+
915957#[ derive( Accounts ) ]
916958pub struct UpdateConstituentTargetBase < ' info > {
917959 pub state : Box < Account < ' info , State > > ,
0 commit comments