DexCalcs ​
implements calculation methods used for Fluid Dex such as updated withdrawal / borrow limits.
State Variables ​
DEFAULT_EXPONENT_SIZE ​
uint256 internal constant DEFAULT_EXPONENT_SIZE = 8;DEFAULT_EXPONENT_MASK ​
uint256 internal constant DEFAULT_EXPONENT_MASK = 0xFF;FOUR_DECIMALS ​
uint256 internal constant FOUR_DECIMALS = 1e4;X14 ​
uint256 internal constant X14 = 0x3fff;X18 ​
uint256 internal constant X18 = 0x3ffff;X24 ​
uint256 internal constant X24 = 0xffffff;X33 ​
uint256 internal constant X33 = 0x1ffffffff;X64 ​
uint256 internal constant X64 = 0xffffffffffffffff;Functions ​
calcWithdrawalLimitBeforeOperate ​
calculates withdrawal limit before an operate execution: amount of user supply that must stay supplied (not amount that can be withdrawn). i.e. if user has supplied 100m and can withdraw 5M, this method returns the 95M, not the withdrawable amount 5M
function calcWithdrawalLimitBeforeOperate(uint256 userSupplyData_, uint256 userSupply_)
    internal
    view
    returns (uint256 currentWithdrawalLimit_);Parameters
| Name | Type | Description | 
|---|---|---|
userSupplyData_ | uint256 | user supply data packed uint256 from storage | 
userSupply_ | uint256 | current user supply amount already extracted from userSupplyData_ and converted from BigMath | 
Returns
| Name | Type | Description | 
|---|---|---|
currentWithdrawalLimit_ | uint256 | current withdrawal limit updated for expansion since last interaction. returned value is in raw for with interest mode, normal amount for interest free mode! | 
calcWithdrawalLimitAfterOperate ​
calculates withdrawal limit after an operate execution: amount of user supply that must stay supplied (not amount that can be withdrawn). i.e. if user has supplied 100m and can withdraw 5M, this method returns the 95M, not the withdrawable amount 5M
function calcWithdrawalLimitAfterOperate(uint256 userSupplyData_, uint256 userSupply_, uint256 newWithdrawalLimit_)
    internal
    pure
    returns (uint256);Parameters
| Name | Type | Description | 
|---|---|---|
userSupplyData_ | uint256 | user supply data packed uint256 from storage | 
userSupply_ | uint256 | current user supply amount already extracted from userSupplyData_ and added / subtracted with the executed operate amount | 
newWithdrawalLimit_ | uint256 | current withdrawal limit updated for expansion since last interaction, result from calcWithdrawalLimitBeforeOperate | 
Returns
| Name | Type | Description | 
|---|---|---|
<none> | uint256 | withdrawalLimit_ updated withdrawal limit that should be written to storage. returned value is in raw for with interest mode, normal amount for interest free mode! | 
calcBorrowLimitBeforeOperate ​
calculates borrow limit before an operate execution: total amount user borrow can reach (not borrowable amount in current operation). i.e. if user has borrowed 50M and can still borrow 5M, this method returns the total 55M, not the borrowable amount 5M
function calcBorrowLimitBeforeOperate(uint256 userBorrowData_, uint256 userBorrow_)
    internal
    view
    returns (uint256 currentBorrowLimit_);Parameters
| Name | Type | Description | 
|---|---|---|
userBorrowData_ | uint256 | user borrow data packed uint256 from storage | 
userBorrow_ | uint256 | current user borrow amount already extracted from userBorrowData_ | 
Returns
| Name | Type | Description | 
|---|---|---|
currentBorrowLimit_ | uint256 | current borrow limit updated for expansion since last interaction. returned value is in raw for with interest mode, normal amount for interest free mode! | 
calcBorrowLimitAfterOperate ​
calculates borrow limit after an operate execution: total amount user borrow can reach (not borrowable amount in current operation). i.e. if user has borrowed 50M and can still borrow 5M, this method returns the total 55M, not the borrowable amount 5M
function calcBorrowLimitAfterOperate(uint256 userBorrowData_, uint256 userBorrow_, uint256 newBorrowLimit_)
    internal
    pure
    returns (uint256 borrowLimit_);Parameters
| Name | Type | Description | 
|---|---|---|
userBorrowData_ | uint256 | user borrow data packed uint256 from storage | 
userBorrow_ | uint256 | current user borrow amount already extracted from userBorrowData_ and added / subtracted with the executed operate amount | 
newBorrowLimit_ | uint256 | current borrow limit updated for expansion since last interaction, result from calcBorrowLimitBeforeOperate | 
Returns
| Name | Type | Description | 
|---|---|---|
borrowLimit_ | uint256 | updated borrow limit that should be written to storage. returned value is in raw for with interest mode, normal amount for interest free mode! | 

