UserConfiguration

Implements the bitmap logic to handle the user configuration

BORROWING_MASK

uint256 BORROWING_MASK

COLLATERAL_MASK

uint256 COLLATERAL_MASK

setBorrowing

function setBorrowing(struct DataTypes.UserConfigurationMap self, uint256 reserveIndex, bool borrowing) internal

Sets if the user is borrowing the reserve identified by reserveIndex

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reserveIndex

uint256

The index of the reserve in the bitmap

borrowing

bool

True if the user is borrowing the reserve, false otherwise

setUsingAsCollateral

function setUsingAsCollateral(struct DataTypes.UserConfigurationMap self, uint256 reserveIndex, bool usingAsCollateral) internal

Sets if the user is using as collateral the reserve identified by reserveIndex

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reserveIndex

uint256

The index of the reserve in the bitmap

usingAsCollateral

bool

True if the user is using the reserve as collateral, false otherwise

isUsingAsCollateralOrBorrowing

function isUsingAsCollateralOrBorrowing(struct DataTypes.UserConfigurationMap self, uint256 reserveIndex) internal pure returns (bool)

Returns if a user has been using the reserve for borrowing or as collateral

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reserveIndex

uint256

The index of the reserve in the bitmap

Return Values

NameTypeDescription

[0]

bool

True if the user has been using a reserve for borrowing or as collateral, false otherwise

isBorrowing

function isBorrowing(struct DataTypes.UserConfigurationMap self, uint256 reserveIndex) internal pure returns (bool)

Validate a user has been using the reserve for borrowing

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reserveIndex

uint256

The index of the reserve in the bitmap

Return Values

NameTypeDescription

[0]

bool

True if the user has been using a reserve for borrowing, false otherwise

isUsingAsCollateral

function isUsingAsCollateral(struct DataTypes.UserConfigurationMap self, uint256 reserveIndex) internal pure returns (bool)

Validate a user has been using the reserve as collateral

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reserveIndex

uint256

The index of the reserve in the bitmap

Return Values

NameTypeDescription

[0]

bool

True if the user has been using a reserve as collateral, false otherwise

isUsingAsCollateralOne

function isUsingAsCollateralOne(struct DataTypes.UserConfigurationMap self) internal pure returns (bool)

Checks if a user has been supplying only one reserve as collateral

this uses a simple trick - if a number is a power of two (only one bit set) then n & (n - 1) == 0

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

Return Values

NameTypeDescription

[0]

bool

True if the user has been supplying as collateral one reserve, false otherwise

isUsingAsCollateralAny

function isUsingAsCollateralAny(struct DataTypes.UserConfigurationMap self) internal pure returns (bool)

Checks if a user has been supplying any reserve as collateral

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

Return Values

NameTypeDescription

[0]

bool

True if the user has been supplying as collateral any reserve, false otherwise

isBorrowingOne

function isBorrowingOne(struct DataTypes.UserConfigurationMap self) internal pure returns (bool)

Checks if a user has been borrowing only one asset

this uses a simple trick - if a number is a power of two (only one bit set) then n & (n - 1) == 0

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

Return Values

NameTypeDescription

[0]

bool

True if the user has been supplying as collateral one reserve, false otherwise

isBorrowingAny

function isBorrowingAny(struct DataTypes.UserConfigurationMap self) internal pure returns (bool)

Checks if a user has been borrowing from any reserve

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

Return Values

NameTypeDescription

[0]

bool

True if the user has been borrowing any reserve, false otherwise

isEmpty

function isEmpty(struct DataTypes.UserConfigurationMap self) internal pure returns (bool)

Checks if a user has not been using any reserve for borrowing or supply

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

Return Values

NameTypeDescription

[0]

bool

True if the user has not been borrowing or supplying any reserve, false otherwise

getSiloedBorrowingState

function getSiloedBorrowingState(struct DataTypes.UserConfigurationMap self, mapping(address => struct DataTypes.ReserveData) reservesData, mapping(uint256 => address) reservesList) internal view returns (bool, address)

Returns the siloed borrowing state for the user

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

reservesData

mapping(address => struct DataTypes.ReserveData)

The data of all the reserves

reservesList

mapping(uint256 => address)

The reserve list

Return Values

NameTypeDescription

[0]

bool

True if the user has borrowed a siloed asset, false otherwise

[1]

address

The address of the only borrowed asset

_getFirstAssetIdByMask

function _getFirstAssetIdByMask(struct DataTypes.UserConfigurationMap self, uint256 mask) internal pure returns (uint256)

Returns the address of the first asset flagged in the bitmap given the corresponding bitmask

Parameters

NameTypeDescription

self

struct DataTypes.UserConfigurationMap

The configuration object

mask

uint256

Return Values

NameTypeDescription

[0]

uint256

The index of the first asset flagged in the bitmap once the corresponding mask is applied