@@ -2119,6 +2119,62 @@ mod omnipool {
21192119 assert_balance ! ( ALICE . into( ) , HDX , 0 ) ;
21202120 } ) ;
21212121 }
2122+
2123+ #[ test]
2124+ fn sell_schedule_should_use_slippage_limit_when_min_amount_out_is_zero ( ) {
2125+ TestNet :: reset ( ) ;
2126+ Hydra :: execute_with ( || {
2127+ //Arrange
2128+ init_omnipool_with_oracle_for_block_10 ( ) ;
2129+ let alice_init_hdx_balance = 5000 * UNITS ;
2130+ assert_ok ! ( Balances :: force_set_balance(
2131+ RuntimeOrigin :: root( ) ,
2132+ ALICE . into( ) ,
2133+ alice_init_hdx_balance,
2134+ ) ) ;
2135+
2136+ let dca_budget = 1100 * UNITS ;
2137+ let amount_to_sell = 100 * UNITS ;
2138+
2139+ // Create sell schedule with min_amount_out = 0
2140+ // This means last_block_slippage_min_limit will be used as the effective limit
2141+ let schedule = Schedule {
2142+ owner : AccountId :: from ( ALICE ) ,
2143+ period : 5u32 ,
2144+ total_amount : dca_budget,
2145+ max_retries : None ,
2146+ stability_threshold : None ,
2147+ slippage : Some ( Permill :: from_percent ( 5 ) ) ,
2148+ order : Order :: Sell {
2149+ asset_in : HDX ,
2150+ asset_out : DAI ,
2151+ amount_in : amount_to_sell,
2152+ min_amount_out : 0 ,
2153+ route : create_bounded_vec ( vec ! [ Trade {
2154+ pool: PoolType :: Omnipool ,
2155+ asset_in: HDX ,
2156+ asset_out: DAI ,
2157+ } ] ) ,
2158+ } ,
2159+ } ;
2160+ create_schedule ( ALICE , schedule) ;
2161+
2162+ let alice_dai_before = Currencies :: free_balance ( DAI , & ALICE . into ( ) ) ;
2163+
2164+ //Act
2165+ go_to_block ( 12 ) ;
2166+
2167+ //Assert - DCA executed successfully and schedule is still alive
2168+ let alice_dai_after = Currencies :: free_balance ( DAI , & ALICE . into ( ) ) ;
2169+ assert ! (
2170+ alice_dai_after > alice_dai_before,
2171+ "ALICE should have received DAI from the trade"
2172+ ) ;
2173+
2174+ let schedule = DCA :: schedules ( 0 ) ;
2175+ assert ! ( schedule. is_some( ) , "DCA schedule should still be alive after execution" ) ;
2176+ } ) ;
2177+ }
21222178}
21232179
21242180mod fee {
0 commit comments