@@ -1061,3 +1061,72 @@ fn sell_with_all_fees_and_extra_withdrawal_works() {
10611061 assert_eq ! ( initial_reserve, omnipool_200_reserve + buy_amount + fee_collector) ;
10621062 } ) ;
10631063}
1064+
1065+ #[ test]
1066+ fn sell_allows_tolerance_when_part_of_fee_is_taken ( ) {
1067+ ExtBuilder :: default ( )
1068+ . with_endowed_accounts ( vec ! [
1069+ ( Omnipool :: protocol_account( ) , DAI , 1000 * ONE ) ,
1070+ ( Omnipool :: protocol_account( ) , HDX , NATIVE_AMOUNT ) ,
1071+ ( LP2 , 100 , 2000 * ONE ) ,
1072+ ( LP3 , 200 , 2000 * ONE ) ,
1073+ ( LP1 , 100 , 1000 * ONE ) ,
1074+ ] )
1075+ . with_registered_asset ( 100 )
1076+ . with_registered_asset ( 200 )
1077+ . with_asset_fee ( Permill :: from_percent ( 10 ) )
1078+ . with_protocol_fee ( Permill :: from_percent ( 3 ) )
1079+ . with_burn_fee ( Permill :: from_percent ( 50 ) )
1080+ . with_on_trade_withdrawal ( Permill :: from_percent ( 100 ) )
1081+ . with_on_trade_withdrawal_extra ( 1 )
1082+ . with_initial_pool ( FixedU128 :: from ( 1 ) , FixedU128 :: from ( 1 ) )
1083+ . with_token ( 100 , FixedU128 :: one ( ) , LP2 , 2000 * ONE )
1084+ . with_token ( 200 , FixedU128 :: one ( ) , LP3 , 2000 * ONE )
1085+ . build ( )
1086+ . execute_with ( || {
1087+ let sell_amount = 50 * ONE ;
1088+ let min_limit = 10 * ONE ;
1089+
1090+ assert_ok ! ( Omnipool :: sell(
1091+ RuntimeOrigin :: signed( LP1 ) ,
1092+ 100 ,
1093+ 200 ,
1094+ sell_amount,
1095+ min_limit
1096+ ) ) ;
1097+
1098+ assert_asset_state ! (
1099+ 100 ,
1100+ AssetReserveState {
1101+ reserve: 2000 * ONE + sell_amount,
1102+ hub_reserve: 1951219512195122 ,
1103+ shares: 2000000000000000 ,
1104+ protocol_shares: Balance :: zero( ) ,
1105+ cap: DEFAULT_WEIGHT_CAP ,
1106+ tradable: Tradability :: default ( ) ,
1107+ }
1108+ ) ;
1109+ assert_asset_state ! (
1110+ 200 ,
1111+ AssetReserveState {
1112+ reserve: 1953776507028830 ,
1113+ hub_reserve: 2047317073170732 ,
1114+ shares: 2000 * ONE ,
1115+ protocol_shares: Balance :: zero( ) ,
1116+ cap: DEFAULT_WEIGHT_CAP ,
1117+ tradable: Tradability :: default ( ) ,
1118+ }
1119+ ) ;
1120+
1121+ assert_eq ! ( Tokens :: free_balance( 100 , & LP1 ) , 950_000_000_000_000 ) ;
1122+ assert_eq ! ( Tokens :: free_balance( 200 , & LP1 ) , 41601143674053 ) ;
1123+ assert_eq ! ( Tokens :: free_balance( 200 , & TRADE_FEE_COLLECTOR ) , 4622349297117 ) ;
1124+ assert_eq ! ( Tokens :: free_balance( LRNA , & PROTOCOL_FEE_COLLECTOR ) , 731707317073 ) ;
1125+ // Account for 200 asset
1126+ let initial_reserve = 2000 * ONE ;
1127+ let omnipool_200_reserve = Tokens :: free_balance ( 200 , & Omnipool :: protocol_account ( ) ) ;
1128+ let fee_collector = Tokens :: free_balance ( 200 , & TRADE_FEE_COLLECTOR ) ;
1129+ let buy_amount = Tokens :: free_balance ( 200 , & LP1 ) ;
1130+ assert_eq ! ( initial_reserve, omnipool_200_reserve + buy_amount + fee_collector) ;
1131+ } ) ;
1132+ }
0 commit comments