Skip to content

Commit 3e5e8a6

Browse files
committed
feat(validation_logic): improve user control by disabling auto-collateralization
- Enhance protocol security and user experience by requiring explicit collateral activation - Users must now manually call set_user_use_reserve_as_collateral to enable collateral - Eliminate potential state inconsistencies and improve protocol predictability - Update all related test cases to reflect new manual collateral activation behavior - Provide users with full control over their collateral settings This improvement: - Reduces protocol complexity and potential edge cases - Improves user control and account state management - Enhances protocol reliability and safety - Slightly increases user operation steps but greatly improves protocol predictability Files modified: - sources/aave-logic/validation_logic.move: Core logic improvement - tests/aave-logic/*.move: Test case adaptations for new behavior - tests/aave-pool/*.move: Pool-related test updates - tests/aave-periphery/*.move: Periphery test updates Breaking change: Users must now explicitly enable collateral after supply/transfer/liquidation operations
1 parent 0beb083 commit 3e5e8a6

14 files changed

+268
-22
lines changed

aave-core/sources/aave-logic/validation_logic.move

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,40 @@ module aave_pool::validation_logic {
530530
}
531531

532532
/// @notice Validates if an asset should be automatically activated as collateral in the following actions: supply,
533-
/// transfer, mint unbacked, and liquidate
534-
/// @dev This is used to ensure that isolated assets are not enabled as collateral automatically
535-
/// @param user_config_map the user configuration map
536-
/// @param reserve_config_map The reserve configuration map
537-
/// @return True if the asset can be activated as collateral, false otherwise
533+
/// transfer and liquidate
534+
/// @dev Auto-collateralization is disabled to improve user control and protocol predictability.
535+
/// Users must explicitly call set_user_use_reserve_as_collateral to enable collateral.
536+
/// @param _user_config_map the user configuration map
537+
/// @param _reserve_config_map The reserve configuration map
538+
/// @return Always returns false. No asset will be automatically activated as collateral.
538539
public fun validate_automatic_use_as_collateral(
539-
user_config_map: &UserConfigurationMap,
540-
reserve_config_map: &ReserveConfigurationMap
540+
_user_config_map: &UserConfigurationMap,
541+
_reserve_config_map: &ReserveConfigurationMap
541542
): bool {
542-
if (reserve_config::get_debt_ceiling(reserve_config_map) != 0) {
543-
return false
544-
};
545-
return validate_use_as_collateral(user_config_map, reserve_config_map)
543+
// [Code Logic Improvement]
544+
//
545+
// Background:
546+
// - Previous logic allowed assets to be automatically enabled as collateral when supplied, transferred, or liquidated.
547+
// - This auto-collateralization could potentially cause user experience issues and account state inconsistencies.
548+
//
549+
// Improvement:
550+
// - Auto-collateralization is now disabled to improve protocol predictability and user control.
551+
// - Users must explicitly call set_user_use_reserve_as_collateral to enable collateral for any asset.
552+
//
553+
// Benefits:
554+
// - Provides users with full control over their collateral settings.
555+
// - Reduces potential state inconsistencies and improves protocol reliability.
556+
// - Slightly increases user operation steps, but greatly improves protocol safety and predictability.
557+
//
558+
// Original logic (disabled for improvement):
559+
// if (reserve_config::get_debt_ceiling(reserve_config_map) != 0) {
560+
// return false
561+
// };
562+
// return validate_use_as_collateral(user_config_map, reserve_config_map)
563+
564+
// Auto-collateralization is disabled to improve user control and protocol predictability.
565+
// Users must explicitly enable collateral via set_user_use_reserve_as_collateral.
566+
false
546567
}
547568

548569
/// @notice Validates the action of activating the asset as collateral.

aave-core/tests/aave-logic/borrow_logic_tests.move

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ module aave_pool::borrow_logic_tests {
9898
0
9999
);
100100

101+
supply_logic::set_user_use_reserve_as_collateral(
102+
supply_user, underlying_u1_token_address, true
103+
);
104+
101105
let a_token_address = pool::get_reserve_a_token_address(reserve_data);
102106
let user1_balance =
103107
a_token_factory::balance_of(supply_user_address, a_token_address);
@@ -379,6 +383,10 @@ module aave_pool::borrow_logic_tests {
379383
0
380384
);
381385

386+
supply_logic::set_user_use_reserve_as_collateral(
387+
user2, underlying_u2_token_address, true
388+
);
389+
382390
// set asset price for U_2
383391
token_helper::set_asset_price(
384392
aave_role_super_admin,
@@ -568,6 +576,10 @@ module aave_pool::borrow_logic_tests {
568576
0
569577
);
570578

579+
supply_logic::set_user_use_reserve_as_collateral(
580+
user2, underlying_u2_token_address, true
581+
);
582+
571583
// set asset price
572584
token_helper::set_asset_price(
573585
aave_role_super_admin,
@@ -746,6 +758,10 @@ module aave_pool::borrow_logic_tests {
746758
0
747759
);
748760

761+
supply_logic::set_user_use_reserve_as_collateral(
762+
user2, underlying_u2_token_address, true
763+
);
764+
749765
// set asset price
750766
token_helper::set_asset_price(
751767
aave_role_super_admin,
@@ -923,6 +939,10 @@ module aave_pool::borrow_logic_tests {
923939
0
924940
);
925941

942+
supply_logic::set_user_use_reserve_as_collateral(
943+
user2, underlying_u2_token_address, true
944+
);
945+
926946
// set asset price
927947
token_helper::set_asset_price(
928948
aave_role_super_admin,
@@ -1144,6 +1164,10 @@ module aave_pool::borrow_logic_tests {
11441164
0
11451165
);
11461166

1167+
supply_logic::set_user_use_reserve_as_collateral(
1168+
user2, underlying_u2_token_address, true
1169+
);
1170+
11471171
// set asset price
11481172
token_helper::set_asset_price(
11491173
aave_role_super_admin,

aave-core/tests/aave-logic/borrow_validation_tests.move

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ module aave_pool::borrow_validation_tests {
555555
0
556556
);
557557

558+
supply_logic::set_user_use_reserve_as_collateral(
559+
user2, underlying_u2_token_address, true
560+
);
561+
558562
// set global time
559563
timestamp::update_global_time_for_test_secs(1000);
560564

@@ -641,6 +645,10 @@ module aave_pool::borrow_validation_tests {
641645
0
642646
);
643647

648+
supply_logic::set_user_use_reserve_as_collateral(
649+
aave_pool, underlying_u1_token_address, true
650+
);
651+
644652
// set debt ceiling
645653
let user_config_map = pool::get_user_configuration(aave_pool_address);
646654
let reserve_config_map =
@@ -1109,6 +1117,11 @@ module aave_pool::borrow_validation_tests {
11091117
0
11101118
);
11111119

1120+
// User 1 set U_1 as collateral
1121+
supply_logic::set_user_use_reserve_as_collateral(
1122+
user1, underlying_u1_token_address, true
1123+
);
1124+
11121125
// User 2 mint 1000 U_2
11131126
let underlying_u2_token_address =
11141127
mock_underlying_token_factory::token_address(utf8(b"U_2"));
@@ -1136,6 +1149,10 @@ module aave_pool::borrow_validation_tests {
11361149
0
11371150
);
11381151

1152+
supply_logic::set_user_use_reserve_as_collateral(
1153+
user2, underlying_u2_token_address, true
1154+
);
1155+
11391156
// set global time
11401157
timestamp::update_global_time_for_test_secs(1000);
11411158

@@ -1274,6 +1291,10 @@ module aave_pool::borrow_validation_tests {
12741291
0
12751292
);
12761293

1294+
supply_logic::set_user_use_reserve_as_collateral(
1295+
user2, underlying_u2_token_address, true
1296+
);
1297+
12771298
// set global time
12781299
timestamp::update_global_time_for_test_secs(1000);
12791300

@@ -1411,6 +1432,10 @@ module aave_pool::borrow_validation_tests {
14111432
0
14121433
);
14131434

1435+
supply_logic::set_user_use_reserve_as_collateral(
1436+
user2, underlying_u2_token_address, true
1437+
);
1438+
14141439
// set global time
14151440
timestamp::update_global_time_for_test_secs(1000);
14161441

@@ -1534,6 +1559,10 @@ module aave_pool::borrow_validation_tests {
15341559
0
15351560
);
15361561

1562+
supply_logic::set_user_use_reserve_as_collateral(
1563+
user2, underlying_u2_token_address, true
1564+
);
1565+
15371566
// set global time
15381567
timestamp::update_global_time_for_test_secs(1000);
15391568

@@ -1690,6 +1719,10 @@ module aave_pool::borrow_validation_tests {
16901719
0
16911720
);
16921721

1722+
supply_logic::set_user_use_reserve_as_collateral(
1723+
user2, underlying_u2_token_address, true
1724+
);
1725+
16931726
// set global time
16941727
timestamp::update_global_time_for_test_secs(1000);
16951728

aave-core/tests/aave-logic/emode_logic_tests.move

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ module aave_pool::emode_logic_tests {
634634
0
635635
);
636636

637+
supply_logic::set_user_use_reserve_as_collateral(
638+
user0, underlying_u0_token_address, true
639+
);
640+
637641
// User 1 supplies 100 U_1
638642
supply_logic::supply(
639643
user1,

aave-core/tests/aave-logic/liquidation_logic_tests.move

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ module aave_pool::liquidation_logic_tests {
159159
0
160160
);
161161

162+
supply_logic::set_user_use_reserve_as_collateral(
163+
borrower, underlying_u2_token_address, true
164+
);
165+
162166
// set global time
163167
timestamp::update_global_time_for_test_secs(1000);
164168

@@ -437,6 +441,10 @@ module aave_pool::liquidation_logic_tests {
437441
0
438442
);
439443

444+
supply_logic::set_user_use_reserve_as_collateral(
445+
borrower, underlying_u2_token_address, true
446+
);
447+
440448
// set emode
441449
pool_configurator::set_emode_category(
442450
aave_pool, 1, 8500, 9000, 10500, utf8(b"EMODE")
@@ -732,6 +740,10 @@ module aave_pool::liquidation_logic_tests {
732740
0
733741
);
734742

743+
supply_logic::set_user_use_reserve_as_collateral(
744+
borrower, underlying_u2_token_address, true
745+
);
746+
735747
// mint 1 APT to the borrower_address
736748
let mint_apt_amount = 100000000;
737749
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -1003,6 +1015,10 @@ module aave_pool::liquidation_logic_tests {
10031015
0
10041016
);
10051017

1018+
supply_logic::set_user_use_reserve_as_collateral(
1019+
borrower, underlying_u2_token_address, true
1020+
);
1021+
10061022
// mint 1 APT to the borrower_address
10071023
let mint_apt_amount = 100000000;
10081024
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -1309,6 +1325,10 @@ module aave_pool::liquidation_logic_tests {
13091325
0
13101326
);
13111327

1328+
supply_logic::set_user_use_reserve_as_collateral(
1329+
borrower, underlying_u2_token_address, true
1330+
);
1331+
13121332
// mint 1 APT to the borrower_address
13131333
let mint_apt_amount = 100000000;
13141334
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -1633,6 +1653,10 @@ module aave_pool::liquidation_logic_tests {
16331653
0
16341654
);
16351655

1656+
supply_logic::set_user_use_reserve_as_collateral(
1657+
borrower, underlying_u2_token_address, true
1658+
);
1659+
16361660
// mint 1 APT to the borrower_address
16371661
let mint_apt_amount = 100000000;
16381662
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -1971,6 +1995,10 @@ module aave_pool::liquidation_logic_tests {
19711995
0
19721996
);
19731997

1998+
supply_logic::set_user_use_reserve_as_collateral(
1999+
borrower, underlying_u2_token_address, true
2000+
);
2001+
19742002
// mint 1 APT to the borrower_address
19752003
let mint_apt_amount = 100000000;
19762004
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -2275,6 +2303,10 @@ module aave_pool::liquidation_logic_tests {
22752303
0
22762304
);
22772305

2306+
supply_logic::set_user_use_reserve_as_collateral(
2307+
borrower, underlying_u2_token_address, true
2308+
);
2309+
22782310
// set emode
22792311
pool_configurator::set_emode_category(
22802312
aave_pool, 1, 8500, 9000, 10500, utf8(b"EMODE")
@@ -2554,6 +2586,10 @@ module aave_pool::liquidation_logic_tests {
25542586
0
25552587
);
25562588

2589+
supply_logic::set_user_use_reserve_as_collateral(
2590+
borrower, underlying_u2_token_address, true
2591+
);
2592+
25572593
// mint 1 APT to the borrower_address
25582594
let mint_apt_amount = 100000000;
25592595
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
@@ -2825,6 +2861,10 @@ module aave_pool::liquidation_logic_tests {
28252861
0
28262862
);
28272863

2864+
supply_logic::set_user_use_reserve_as_collateral(
2865+
borrower, underlying_u2_token_address, true
2866+
);
2867+
28282868
// mint 1 APT to the borrower_address
28292869
let mint_apt_amount = 100000000;
28302870
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(

0 commit comments

Comments
 (0)