implements calculation methods used for Fluid liquidity such as updated exchange prices,
borrow rate, withdrawal / borrow limits, revenue amount.
error FluidLiquidityCalcsError ( uint256 errorId_)
Copy to clipboard event BorrowRateMaxCap ()
Copy to clipboard emitted if the calculated borrow rate surpassed max borrow rate (16 bits) and was capped at maximum value 65535
uint256 EXCHANGE_PRICES_PRECISION
Copy to clipboard constants as from Liquidity variables.sol
uint256 SECONDS_PER_YEAR
Copy to clipboard Ignoring leap years
uint256 DEFAULT_EXPONENT_SIZE
Copy to clipboard uint256 DEFAULT_EXPONENT_MASK
Copy to clipboard uint256 FOUR_DECIMALS
Copy to clipboard uint256 TWELVE_DECIMALS
Copy to clipboard uint256 X14
Copy to clipboard uint256 X15
Copy to clipboard uint256 X16
Copy to clipboard uint256 X18
Copy to clipboard uint256 X24
Copy to clipboard uint256 X33
Copy to clipboard uint256 X64
Copy to clipboard function calcExchangePrices ( uint256 exchangePricesAndConfig_ ) internal view returns ( uint256 supplyExchangePrice_ , uint256 borrowExchangePrice_ )
Copy to clipboard calculates interest (exchange prices) for a token given its' exchangePricesAndConfig from storage.
Name Type Description exchangePricesAndConfig_ uint256 exchange prices and config packed uint256 read from storage
Name Type Description supplyExchangePrice_ uint256 updated supplyExchangePrice borrowExchangePrice_ uint256 updated borrowExchangePrice
function calcRevenue ( uint256 totalAmounts_ , uint256 exchangePricesAndConfig_ , uint256 liquidityTokenBalance_ ) internal view returns ( uint256 revenueAmount_ )
Copy to clipboard _gets the revenueAmount_
for a token given its' totalAmounts and exchangePricesAndConfig from storage
and the current balance of the Fluid liquidity contract for the token._
Name Type Description totalAmounts_ uint256 total amounts packed uint256 read from storage exchangePricesAndConfig_ uint256 exchange prices and config packed uint256 read from storage liquidityTokenBalance_ uint256 current balance of Liquidity contract (IERC20(token_).balanceOf(address(this)))
Name Type Description revenueAmount_ uint256 collectable revenue amount
function calcWithdrawalLimitBeforeOperate ( uint256 userSupplyData_ , uint256 userSupply_ ) internal view returns ( uint256 currentWithdrawalLimit_ )
Copy to clipboard 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
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
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!
function calcWithdrawalLimitAfterOperate ( uint256 userSupplyData_ , uint256 userSupply_ , uint256 newWithdrawalLimit_ ) internal pure returns ( uint256 )
Copy to clipboard 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
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
Name Type Description 0 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!
function calcBorrowLimitBeforeOperate ( uint256 userBorrowData_ , uint256 userBorrow_ ) internal view returns ( uint256 currentBorrowLimit_ )
Copy to clipboard 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
Name Type Description userBorrowData_ uint256 user borrow data packed uint256 from storage userBorrow_ uint256 current user borrow amount already extracted from userBorrowData_
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!
function calcBorrowLimitAfterOperate ( uint256 userBorrowData_ , uint256 userBorrow_ , uint256 newBorrowLimit_ ) internal pure returns ( uint256 borrowLimit_ )
Copy to clipboard 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
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
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!
function calcBorrowRateFromUtilization ( uint256 rateData_ , uint256 utilization_ ) internal returns ( uint256 rate_ )
Copy to clipboard Calculates new borrow rate from utilization for a token
Name Type Description rateData_ uint256 rate data packed uint256 from storage for the token utilization_ uint256 totalBorrow / totalSupply. 1e4 = 100% utilization
Name Type Description rate_ uint256 rate for that particular token in 1e2 precision (e.g. 5% rate = 500)
function calcRateV1 ( uint256 rateData_ , uint256 utilization_ ) internal pure returns ( uint256 rate_ )
Copy to clipboard calculates the borrow rate based on utilization for rate data version 1 (with one kink) in 1e2 precision
Name Type Description rateData_ uint256 rate data packed uint256 from storage for the token utilization_ uint256 in 1e2 (100% = 1e4)
Name Type Description rate_ uint256 rate in 1e2 precision
function calcRateV2 ( uint256 rateData_ , uint256 utilization_ ) internal pure returns ( uint256 rate_ )
Copy to clipboard calculates the borrow rate based on utilization for rate data version 2 (with two kinks) in 1e4 precision
Name Type Description rateData_ uint256 rate data packed uint256 from storage for the token utilization_ uint256 in 1e2 (100% = 1e4)
Name Type Description rate_ uint256 rate in 1e4 precision
function getTotalSupply ( uint256 totalAmounts_ , uint256 supplyExchangePrice_ ) internal pure returns ( uint256 totalSupply_ )
Copy to clipboard _reads the total supply out of Liquidity packed storage totalAmounts_
forsupplyExchangePrice*
*
function getTotalBorrow ( uint256 totalAmounts_ , uint256 borrowExchangePrice_ ) internal pure returns ( uint256 totalBorrow_ )
Copy to clipboard _reads the total borrow out of Liquidity packed storage totalAmounts_
forborrowExchangePrice*
*