@@ -2179,6 +2179,7 @@ pub mod fulfill_order_with_maker_order {
21792179 market. amm . historical_oracle_data . last_oracle_price_twap ,
21802180 market. get_max_confidence_interval_multiplier ( ) . unwrap ( ) ,
21812181 0 ,
2182+ 0 ,
21822183 )
21832184 . unwrap ( ) ;
21842185
@@ -3107,6 +3108,32 @@ pub mod fulfill_order {
31073108 assert ! ( validate_market_within_price_band( & market, & state, oracle_price) . is_err( ) ) ;
31083109 }
31093110
3111+ #[ test]
3112+ fn test_order_is_low_risk_for_amm ( ) {
3113+ let mut order = Order {
3114+ market_index : 0 ,
3115+ order_type : OrderType :: Market ,
3116+ direction : PositionDirection :: Long ,
3117+ base_asset_amount : 1000 ,
3118+ ..Order :: default ( )
3119+ } ;
3120+
3121+ // True if no oracle delay and no auction duration
3122+ assert ! ( order. is_low_risk_for_amm( 0 , 0 , 500 ) . unwrap( ) ) ;
3123+
3124+ // True if oracle delay but order older than auction duration
3125+ order. slot = 95 ;
3126+ assert ! ( order. is_low_risk_for_amm( 20 , 3 , 100 ) . unwrap( ) ) ;
3127+
3128+ // True if order is new but the order slot is older than the oracle delay
3129+ order. slot = 97 ;
3130+ assert ! ( order. is_low_risk_for_amm( 2 , 3 , 100 ) . unwrap( ) ) ;
3131+
3132+ // False if order is newer than auction duration and oracle delay
3133+ order. slot = 98 ;
3134+ assert ! ( !order. is_low_risk_for_amm( 4 , 3 , 100 ) . unwrap( ) ) ;
3135+ }
3136+
31103137 #[ test]
31113138 fn fulfill_with_amm_skip_auction_duration ( ) {
31123139 let mut oracle_price = get_pyth_price ( 100 , 6 ) ;
@@ -3159,17 +3186,25 @@ pub mod fulfill_order {
31593186 ..State :: default ( )
31603187 } ;
31613188
3162- assert ! ( !market. can_skip_auction_duration( & state, false ) . unwrap( ) ) ;
3189+ assert ! ( !market
3190+ . can_skip_auction_duration( & state, false , false )
3191+ . unwrap( ) ) ;
31633192
31643193 market. amm . net_revenue_since_last_funding = 1 ;
3165- assert ! ( !market. can_skip_auction_duration( & state, false ) . unwrap( ) ) ;
3166- assert ! ( market. can_skip_auction_duration( & state, true ) . unwrap( ) ) ;
3194+ assert ! ( !market
3195+ . can_skip_auction_duration( & state, false , false )
3196+ . unwrap( ) ) ;
3197+ assert ! ( market
3198+ . can_skip_auction_duration( & state, true , false )
3199+ . unwrap( ) ) ;
31673200
31683201 assert ! ( !state. amm_immediate_fill_paused( ) . unwrap( ) ) ;
31693202 state. exchange_status = 0b10000000 ;
31703203 assert ! ( state. amm_immediate_fill_paused( ) . unwrap( ) ) ;
31713204
3172- assert ! ( !market. can_skip_auction_duration( & state, true ) . unwrap( ) ) ;
3205+ assert ! ( !market
3206+ . can_skip_auction_duration( & state, true , false )
3207+ . unwrap( ) ) ;
31733208 }
31743209
31753210 #[ test]
0 commit comments