collateral check
Overview

isUsingCollateral
Transaction reverts on invalid
reserveIndex

Let's examine the bitwise manipulations with an example. In this example, we assume six bits for simplicity, w.r.t to self.data
Example: Check if the user has been using the reserve at index 2 as collateral:

It the result of the bitwise operations is not equal to 0, the function would return true. This indicates that the user has been using the reserve at reserveIndex = 2 as collateral.
setUsingAsCollateral
Set the collateral bit for a specific asset to either 0 or 1, depending on bool usingAsCollateral.

(reserveIndex << 1) + 1
(reserveIndex << 1) + 1This bitwise operation doubles the index and increments it by 1
Creates the necessary offset to manipulate the relevant bits to the asset of specified index
For more in-depth explanation see: isUsingCollateral
bit = 1 << offset
bit = 1 << offsetIf usingAsCollateral is true, indicating that the reserve should be marked as used for collateral,
bitwise OR operation between
dataand thebitvalue (self.data |= bit).sets the corresponding bit in the
self.datavariable to1
If usingAsCollateral is false, indicating that the reserve should NOT be marked as collateral
bitwise AND operation between
dataand thebitvalue (self.data &= bit).sets the corresponding bit in the
self.datavariable to0
Last updated
Was this helpful?