Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions aave-core/sources/aave-logic/validation_logic.move
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,40 @@ module aave_pool::validation_logic {
}

/// @notice Validates if an asset should be automatically activated as collateral in the following actions: supply,
/// transfer, mint unbacked, and liquidate
/// @dev This is used to ensure that isolated assets are not enabled as collateral automatically
/// @param user_config_map the user configuration map
/// @param reserve_config_map The reserve configuration map
/// @return True if the asset can be activated as collateral, false otherwise
/// transfer and liquidate
/// @dev Auto-collateralization is disabled to improve user control and protocol predictability.
/// Users must explicitly call set_user_use_reserve_as_collateral to enable collateral.
/// @param _user_config_map the user configuration map
/// @param _reserve_config_map The reserve configuration map
/// @return Always returns false. No asset will be automatically activated as collateral.
public fun validate_automatic_use_as_collateral(
user_config_map: &UserConfigurationMap,
reserve_config_map: &ReserveConfigurationMap
_user_config_map: &UserConfigurationMap,
_reserve_config_map: &ReserveConfigurationMap
): bool {
if (reserve_config::get_debt_ceiling(reserve_config_map) != 0) {
return false
};
return validate_use_as_collateral(user_config_map, reserve_config_map)
// [Code Logic Improvement]
//
// Background:
// - Previous logic allowed assets to be automatically enabled as collateral when supplied, transferred, or liquidated.
// - This auto-collateralization could potentially cause user experience issues and account state inconsistencies.
//
// Improvement:
// - Auto-collateralization is now disabled to improve protocol predictability and user control.
// - Users must explicitly call set_user_use_reserve_as_collateral to enable collateral for any asset.
//
// Benefits:
// - Provides users with full control over their collateral settings.
// - Reduces potential state inconsistencies and improves protocol reliability.
// - Slightly increases user operation steps, but greatly improves protocol safety and predictability.
//
// Original logic (disabled for improvement):
// if (reserve_config::get_debt_ceiling(reserve_config_map) != 0) {
// return false
// };
// return validate_use_as_collateral(user_config_map, reserve_config_map)

// Auto-collateralization is disabled to improve user control and protocol predictability.
// Users must explicitly enable collateral via set_user_use_reserve_as_collateral.
false
}

/// @notice Validates the action of activating the asset as collateral.
Expand Down
24 changes: 24 additions & 0 deletions aave-core/tests/aave-logic/borrow_logic_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
supply_user, underlying_u1_token_address, true
);

let a_token_address = pool::get_reserve_a_token_address(reserve_data);
let user1_balance =
a_token_factory::balance_of(supply_user_address, a_token_address);
Expand Down Expand Up @@ -379,6 +383,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set asset price for U_2
token_helper::set_asset_price(
aave_role_super_admin,
Expand Down Expand Up @@ -568,6 +576,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set asset price
token_helper::set_asset_price(
aave_role_super_admin,
Expand Down Expand Up @@ -746,6 +758,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set asset price
token_helper::set_asset_price(
aave_role_super_admin,
Expand Down Expand Up @@ -923,6 +939,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set asset price
token_helper::set_asset_price(
aave_role_super_admin,
Expand Down Expand Up @@ -1144,6 +1164,10 @@ module aave_pool::borrow_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set asset price
token_helper::set_asset_price(
aave_role_super_admin,
Expand Down
33 changes: 33 additions & 0 deletions aave-core/tests/aave-logic/borrow_validation_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -641,6 +645,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
aave_pool, underlying_u1_token_address, true
);

// set debt ceiling
let user_config_map = pool::get_user_configuration(aave_pool_address);
let reserve_config_map =
Expand Down Expand Up @@ -1109,6 +1117,11 @@ module aave_pool::borrow_validation_tests {
0
);

// User 1 set U_1 as collateral
supply_logic::set_user_use_reserve_as_collateral(
user1, underlying_u1_token_address, true
);

// User 2 mint 1000 U_2
let underlying_u2_token_address =
mock_underlying_token_factory::token_address(utf8(b"U_2"));
Expand Down Expand Up @@ -1136,6 +1149,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -1274,6 +1291,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -1411,6 +1432,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -1534,6 +1559,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -1690,6 +1719,10 @@ module aave_pool::borrow_validation_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user2, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down
4 changes: 4 additions & 0 deletions aave-core/tests/aave-logic/emode_logic_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ module aave_pool::emode_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
user0, underlying_u0_token_address, true
);

// User 1 supplies 100 U_1
supply_logic::supply(
user1,
Expand Down
40 changes: 40 additions & 0 deletions aave-core/tests/aave-logic/liquidation_logic_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// set global time
timestamp::update_global_time_for_test_secs(1000);

Expand Down Expand Up @@ -437,6 +441,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// set emode
pool_configurator::set_emode_category(
aave_pool, 1, 8500, 9000, 10500, utf8(b"EMODE")
Expand Down Expand Up @@ -732,6 +740,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -1003,6 +1015,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -1309,6 +1325,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -1633,6 +1653,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -1971,6 +1995,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -2275,6 +2303,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// set emode
pool_configurator::set_emode_category(
aave_pool, 1, 8500, 9000, 10500, utf8(b"EMODE")
Expand Down Expand Up @@ -2554,6 +2586,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down Expand Up @@ -2825,6 +2861,10 @@ module aave_pool::liquidation_logic_tests {
0
);

supply_logic::set_user_use_reserve_as_collateral(
borrower, underlying_u2_token_address, true
);

// mint 1 APT to the borrower_address
let mint_apt_amount = 100000000;
aptos_framework::aptos_coin_tests::mint_apt_fa_to_primary_fungible_store_for_test(
Expand Down
Loading
Loading