Module 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::user_config
@title UserConfiguration library @author Aave @notice Implements the bitmap logic to handle the user configuration
- Struct
UserConfigurationMap
- Constants
- Function
get_interest_rate_mode_none
- Function
get_interest_rate_mode_variable
- Function
get_borrowing_mask
- Function
get_collateral_mask
- Function
get_minimum_health_factor_liquidation_threshold
- Function
get_health_factor_liquidation_threshold
- Function
is_using_as_collateral_or_borrowing
- Function
is_borrowing
- Function
is_using_as_collateral
- Function
is_using_as_collateral_one
- Function
is_using_as_collateral_any
- Function
is_borrowing_one
- Function
is_borrowing_any
- Function
is_empty
- Function
get_first_asset_id_by_mask
- Function
init
- Function
set_borrowing
- Function
set_using_as_collateral
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::error_config;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::helper;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::reserve_config;
Struct UserConfigurationMap
@notice Structure that stores the user configuration as a bitmap
struct UserConfigurationMap has copy, drop, store
Constants
@notice Bitmap mask for borrowing bits
const BORROWING_MASK: u256 = 38597363079105398474523661669562635951089994888546854679819194669304376546645;
@notice Bitmap mask for collateral bits
const COLLATERAL_MASK: u256 = 77194726158210796949047323339125271902179989777093709359638389338608753093290;
@notice Minimum health factor to consider a user position healthy @dev A value of 1e18 results in 1 @dev 1 * 10 ** 18
const HEALTH_FACTOR_LIQUIDATION_THRESHOLD: u256 = 1000000000000000000;
@notice Interest rate mode constant indicating no interest rate
const INTEREST_RATE_MODE_NONE: u8 = 0;
@notice Interest rate mode constant for variable rate @dev 1 = Stable Rate, 2 = Variable Rate, Since the Stable Rate service has been removed, only the Variable Rate service is retained.
const INTEREST_RATE_MODE_VARIABLE: u8 = 2;
@notice Minimum health factor allowed under any circumstance @dev A value of 0.95e18 results in 0.95 @dev 0.95 * 10 ** 18
const MINIMUM_HEALTH_FACTOR_LIQUIDATION_THRESHOLD: u256 = 950000000000000000;
Function get_interest_rate_mode_none
@notice Returns the interest rate mode none constant @return The interest rate mode none value
public fun get_interest_rate_mode_none(): u8
Function get_interest_rate_mode_variable
@notice Returns the interest rate mode variable constant @return The interest rate mode variable value
public fun get_interest_rate_mode_variable(): u8
Function get_borrowing_mask
@notice Returns the borrowing mask constant @return The borrowing mask value
public fun get_borrowing_mask(): u256
Function get_collateral_mask
@notice Returns the collateral mask constant @return The collateral mask value
public fun get_collateral_mask(): u256
Function get_minimum_health_factor_liquidation_threshold
@notice Returns the minimum health factor liquidation threshold constant @return The minimum health factor liquidation threshold value
public fun get_minimum_health_factor_liquidation_threshold(): u256
Function get_health_factor_liquidation_threshold
@notice Returns the health factor liquidation threshold constant @return The health factor liquidation threshold value
public fun get_health_factor_liquidation_threshold(): u256
Function is_using_as_collateral_or_borrowing
@notice Returns if a user has been using the reserve for borrowing or as collateral @param self The configuration object @param reserve_index The index of the reserve in the bitmap @return True if the user has been using a reserve for borrowing or as collateral, false otherwise
public fun is_using_as_collateral_or_borrowing(self: &user_config::UserConfigurationMap, reserve_index: u256): bool
Function is_borrowing
@notice Validate a user has been using the reserve for borrowing @param self The configuration object @param reserve_index The index of the reserve in the bitmap @return True if the user has been using a reserve for borrowing, false otherwise
public fun is_borrowing(self: &user_config::UserConfigurationMap, reserve_index: u256): bool
Function is_using_as_collateral
@notice Validate a user has been using the reserve as collateral @param self The configuration object @param reserve_index The index of the reserve in the bitmap @return True if the user has been using a reserve as collateral, false otherwise
public fun is_using_as_collateral(self: &user_config::UserConfigurationMap, reserve_index: u256): bool
Function is_using_as_collateral_one
@notice Checks if a user has been supplying only one reserve as collateral @dev This uses a simple trick - a number is a power of two (only one bit set) if and only if n & (n - 1) == 0 @param self The configuration object @return True if the user has been supplying as collateral one reserve, false otherwise
public fun is_using_as_collateral_one(self: &user_config::UserConfigurationMap): bool
Function is_using_as_collateral_any
@notice Checks if a user has been supplying any reserve as collateral @param self The configuration object @return True if the user has been supplying as collateral any reserve, false otherwise
public fun is_using_as_collateral_any(self: &user_config::UserConfigurationMap): bool
Function is_borrowing_one
@notice Checks if a user has been borrowing only one asset @dev This uses a simple trick - a number is a power of two (only one bit set) if and only if n & (n - 1) == 0 @param self The configuration object @return True if the user has been supplying as collateral one reserve, false otherwise
public fun is_borrowing_one(self: &user_config::UserConfigurationMap): bool
Function is_borrowing_any
@notice Checks if a user has been borrowing from any reserve @param self The configuration object @return True if the user has been borrowing any reserve, false otherwise
public fun is_borrowing_any(self: &user_config::UserConfigurationMap): bool
Function is_empty
@notice Checks if a user has not been using any reserve for borrowing or supply @param self The configuration object @return True if the user has not been borrowing or supplying any reserve, false otherwise
public fun is_empty(self: &user_config::UserConfigurationMap): bool
Function get_first_asset_id_by_mask
@notice Returns the address of the first asset flagged in the bitmap given the corresponding bitmask @param self The configuration object @param mask The mask to apply to the bitmap @return The index of the first asset flagged in the bitmap once the corresponding mask is applied
public fun get_first_asset_id_by_mask(self: &user_config::UserConfigurationMap, mask: u256): u256
Function init
@notice Initializes the user configuration map @return A new UserConfigurationMap with zero data
public fun init(): user_config::UserConfigurationMap
Function set_borrowing
@notice Sets if the user is borrowing the reserve identified by reserve_index @param self The configuration object @param reserve_index The index of the reserve in the bitmap @param borrowing True if the user is borrowing the reserve, false otherwise
public fun set_borrowing(self: &mut user_config::UserConfigurationMap, reserve_index: u256, borrowing: bool)
Function set_using_as_collateral
@notice Sets if the user is using as collateral the reserve identified by reserve_index @param self The configuration object @param reserve_index The index of the reserve in the bitmap @param using_as_collateral True if the user is using the reserve as collateral, false otherwise
public fun set_using_as_collateral(self: &mut user_config::UserConfigurationMap, reserve_index: u256, using_as_collateral: bool)