@@ -1080,6 +1080,8 @@ fn test_do_swap_success() {
1080
1080
let origin_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1081
1081
let destination_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1082
1082
1083
+ let fee = DefaultMinStake :: < Test > :: get ( ) ;
1084
+
1083
1085
let coldkey = U256 :: from ( 1 ) ;
1084
1086
let hotkey = U256 :: from ( 2 ) ;
1085
1087
let stake_amount = DefaultMinStake :: < Test > :: get ( ) * 10 ;
@@ -1114,7 +1116,11 @@ fn test_do_swap_success() {
1114
1116
& coldkey,
1115
1117
destination_netuid,
1116
1118
) ;
1117
- assert_abs_diff_eq ! ( alpha_after, stake_amount, epsilon = stake_amount / 1000 ) ;
1119
+ assert_abs_diff_eq ! (
1120
+ alpha_after,
1121
+ stake_amount - fee,
1122
+ epsilon = stake_amount / 1000
1123
+ ) ;
1118
1124
} ) ;
1119
1125
}
1120
1126
@@ -1259,6 +1265,8 @@ fn test_do_swap_same_subnet() {
1259
1265
let subnet_owner_hotkey = U256 :: from ( 1101 ) ;
1260
1266
let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1261
1267
1268
+ let fee = DefaultMinStake :: < Test > :: get ( ) ;
1269
+
1262
1270
let coldkey = U256 :: from ( 1 ) ;
1263
1271
let hotkey = U256 :: from ( 2 ) ;
1264
1272
let stake_amount = DefaultMinStake :: < Test > :: get ( ) * 10 ;
@@ -1268,6 +1276,7 @@ fn test_do_swap_same_subnet() {
1268
1276
1269
1277
let alpha_before =
1270
1278
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid) ;
1279
+ let fee_as_alpha = SubtensorModule :: swap_tao_for_alpha ( netuid, fee) ;
1271
1280
1272
1281
assert_ok ! ( SubtensorModule :: do_swap_stake(
1273
1282
RuntimeOrigin :: signed( coldkey) ,
@@ -1279,7 +1288,8 @@ fn test_do_swap_same_subnet() {
1279
1288
1280
1289
let alpha_after =
1281
1290
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid) ;
1282
- assert_abs_diff_eq ! ( alpha_after, alpha_before, epsilon = 5 ) ;
1291
+ assert_abs_diff_eq ! ( alpha_after, alpha_before - fee_as_alpha, epsilon = 15 ) ;
1292
+ // Some slippage due to fee on same subnet.
1283
1293
} ) ;
1284
1294
}
1285
1295
@@ -1291,13 +1301,16 @@ fn test_do_swap_partial_stake() {
1291
1301
let origin_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1292
1302
let destination_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1293
1303
1304
+ let fee = DefaultMinStake :: < Test > :: get ( ) ;
1305
+
1294
1306
let coldkey = U256 :: from ( 1 ) ;
1295
1307
let hotkey = U256 :: from ( 2 ) ;
1296
1308
let total_stake = DefaultMinStake :: < Test > :: get ( ) * 10 ;
1297
1309
1298
1310
SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
1299
1311
SubtensorModule :: stake_into_subnet ( & hotkey, & coldkey, origin_netuid, total_stake, 0 ) ;
1300
1312
1313
+ let fee_as_alpha2 = SubtensorModule :: swap_tao_for_alpha ( destination_netuid, fee) ;
1301
1314
let swap_amount = total_stake / 2 ;
1302
1315
assert_ok ! ( SubtensorModule :: do_swap_stake(
1303
1316
RuntimeOrigin :: signed( coldkey) ,
@@ -1322,7 +1335,7 @@ fn test_do_swap_partial_stake() {
1322
1335
& coldkey,
1323
1336
destination_netuid
1324
1337
) ,
1325
- swap_amount,
1338
+ swap_amount - fee_as_alpha2 ,
1326
1339
epsilon = total_stake / 1000
1327
1340
) ;
1328
1341
} ) ;
@@ -1336,6 +1349,8 @@ fn test_do_swap_storage_updates() {
1336
1349
let origin_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1337
1350
let destination_netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1338
1351
1352
+ let fee = DefaultMinStake :: < Test > :: get ( ) ;
1353
+
1339
1354
let coldkey = U256 :: from ( 1 ) ;
1340
1355
let hotkey = U256 :: from ( 2 ) ;
1341
1356
let stake_amount = DefaultMinStake :: < Test > :: get ( ) * 10 ;
@@ -1365,13 +1380,15 @@ fn test_do_swap_storage_updates() {
1365
1380
0
1366
1381
) ;
1367
1382
1383
+ let fee_as_alpha = SubtensorModule :: swap_tao_for_alpha ( destination_netuid, fee) ;
1384
+
1368
1385
assert_abs_diff_eq ! (
1369
1386
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
1370
1387
& hotkey,
1371
1388
& coldkey,
1372
1389
destination_netuid
1373
1390
) ,
1374
- alpha,
1391
+ alpha - fee_as_alpha ,
1375
1392
epsilon = 5
1376
1393
) ;
1377
1394
} ) ;
@@ -1385,13 +1402,16 @@ fn test_do_swap_multiple_times() {
1385
1402
let netuid1 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1386
1403
let netuid2 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1387
1404
1405
+ let fee = DefaultMinStake :: < Test > :: get ( ) ;
1406
+
1388
1407
let coldkey = U256 :: from ( 1 ) ;
1389
1408
let hotkey = U256 :: from ( 2 ) ;
1390
1409
let initial_stake = DefaultMinStake :: < Test > :: get ( ) * 10 ;
1391
1410
1392
1411
SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
1393
1412
SubtensorModule :: stake_into_subnet ( & hotkey, & coldkey, netuid1, initial_stake, 0 ) ;
1394
1413
1414
+ let mut total_alpha1_fee = 0 ;
1395
1415
for _ in 0 ..3 {
1396
1416
let alpha1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
1397
1417
& hotkey, & coldkey, netuid1,
@@ -1404,6 +1424,9 @@ fn test_do_swap_multiple_times() {
1404
1424
netuid2,
1405
1425
alpha1
1406
1426
) ) ;
1427
+
1428
+ let fee_as_alpha = SubtensorModule :: swap_tao_for_alpha ( netuid1, fee) ;
1429
+ total_alpha1_fee += fee_as_alpha;
1407
1430
}
1408
1431
let alpha2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
1409
1432
& hotkey, & coldkey, netuid2,
@@ -1416,17 +1439,21 @@ fn test_do_swap_multiple_times() {
1416
1439
netuid1,
1417
1440
alpha2
1418
1441
) ) ;
1442
+
1443
+ let fee_as_alpha = SubtensorModule :: swap_tao_for_alpha ( netuid1, fee) ;
1444
+ total_alpha1_fee += fee_as_alpha;
1419
1445
}
1420
1446
}
1421
1447
1422
- let final_stake_netuid1 =
1448
+ let final_stake_netuid1: u64 =
1423
1449
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid1) ;
1424
1450
let final_stake_netuid2 =
1425
1451
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid2) ;
1452
+ let expected_stake = initial_stake - total_alpha1_fee;
1426
1453
assert_abs_diff_eq ! (
1427
1454
final_stake_netuid1,
1428
- initial_stake ,
1429
- epsilon = initial_stake / 1000
1455
+ expected_stake ,
1456
+ epsilon = expected_stake / 1000
1430
1457
) ;
1431
1458
assert_eq ! ( final_stake_netuid2, 0 ) ;
1432
1459
} ) ;
0 commit comments