Skip to content

DexCalcs ​

implements calculation methods used for Fluid Dex such as updated withdrawal / borrow limits.

DEFAULT_EXPONENT_SIZE ​

solidity
uint256 DEFAULT_EXPONENT_SIZE

DEFAULT_EXPONENT_MASK ​

solidity
uint256 DEFAULT_EXPONENT_MASK

FOUR_DECIMALS ​

solidity
uint256 FOUR_DECIMALS

X14 ​

solidity
uint256 X14

X18 ​

solidity
uint256 X18

X24 ​

solidity
uint256 X24

X33 ​

solidity
uint256 X33

X64 ​

solidity
uint256 X64

calcWithdrawalLimitBeforeOperate ​

solidity
function calcWithdrawalLimitBeforeOperate(uint256 userSupplyData_, uint256 userSupply_) internal view returns (uint256 currentWithdrawalLimit_)

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

Parameters ​

NameTypeDescription
userSupplyData_uint256user supply data packed uint256 from storage
userSupply_uint256current user supply amount already extracted from userSupplyData_ and converted from BigMath

Return Values ​

NameTypeDescription
currentWithdrawalLimit_uint256current withdrawal limit updated for expansion since last interaction. returned value is in raw for with interest mode, normal amount for interest free mode!

calcWithdrawalLimitAfterOperate ​

solidity
function calcWithdrawalLimitAfterOperate(uint256 userSupplyData_, uint256 userSupply_, uint256 newWithdrawalLimit_) internal pure returns (uint256)

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

Parameters ​

NameTypeDescription
userSupplyData_uint256user supply data packed uint256 from storage
userSupply_uint256current user supply amount already extracted from userSupplyData_ and added / subtracted with the executed operate amount
newWithdrawalLimit_uint256current withdrawal limit updated for expansion since last interaction, result from calcWithdrawalLimitBeforeOperate

Return Values ​

NameTypeDescription
[0]uint256withdrawalLimit_ 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 ​

solidity
function calcBorrowLimitBeforeOperate(uint256 userBorrowData_, uint256 userBorrow_) internal view returns (uint256 currentBorrowLimit_)

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

Parameters ​

NameTypeDescription
userBorrowData_uint256user borrow data packed uint256 from storage
userBorrow_uint256current user borrow amount already extracted from userBorrowData_

Return Values ​

NameTypeDescription
currentBorrowLimit_uint256current borrow limit updated for expansion since last interaction. returned value is in raw for with interest mode, normal amount for interest free mode!

calcBorrowLimitAfterOperate ​

solidity
function calcBorrowLimitAfterOperate(uint256 userBorrowData_, uint256 userBorrow_, uint256 newBorrowLimit_) internal pure returns (uint256 borrowLimit_)

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

Parameters ​

NameTypeDescription
userBorrowData_uint256user borrow data packed uint256 from storage
userBorrow_uint256current user borrow amount already extracted from userBorrowData_ and added / subtracted with the executed operate amount
newBorrowLimit_uint256current borrow limit updated for expansion since last interaction, result from calcBorrowLimitBeforeOperate

Return Values ​

NameTypeDescription
borrowLimit_uint256updated borrow limit that should be written to storage. returned value is in raw for with interest mode, normal amount for interest free mode!