View Source: contracts/Dependencies/LiquityMath.sol
LiquityMath
Constants & Variables
uint256 internal constant DECIMAL_PRECISION;
uint256 internal constant NICR_PRECISION;
- _min(uint256 _a, uint256 _b)
- _max(uint256 _a, uint256 _b)
- decMul(uint256 x, uint256 y)
- _decPow(uint256 _base, uint256 _minutes)
- _getAbsoluteDifference(uint256 _a, uint256 _b)
- _computeNominalCR(uint256 _coll, uint256 _debt)
- _computeCR(uint256 _coll, uint256 _debt, uint256 _price)
function _min(uint256 _a, uint256 _b) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_a | uint256 | |
_b | uint256 |
Source Code
_min(uint _a, uint _b) internal pure returns (uint) {
return (_a < _b) ? _a : _b;
}
fu
function _max(uint256 _a, uint256 _b) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_a | uint256 | |
_b | uint256 |
Source Code
_max(uint _a, uint _b) internal pure returns (uint) {
return (_a >= _b) ? _a : _b;
}
/*
function decMul(uint256 x, uint256 y) internal pure
returns(decProd uint256)
Arguments
Name | Type | Description |
---|---|---|
x | uint256 | |
y | uint256 |
Source Code
decMul(uint x, uint y) internal pure returns (uint decProd) {
uint prod_xy = x.mul(y);
decProd = prod_xy.add(DECIMAL_PRECISION / 2).div(DECIMAL_PRECISION);
}
/*
function _decPow(uint256 _base, uint256 _minutes) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_base | uint256 | |
_minutes | uint256 |
Source Code
_decPow(uint _base, uint _minutes) internal pure returns (uint) {
if (_minutes > 525600000) {_minutes = 525600000;} // cap to avoid overflow
if (_minutes == 0) {return DECIMAL_PRECISION;}
uint y = DECIMAL_PRECISION;
uint x = _base;
uint n = _minutes;
// Exponentiation-by-squaring
while (n > 1) {
if (n % 2 == 0) {
x = decMul(x, x);
n = n.div(2);
} else { // if (n % 2 != 0)
y = decMul(x, y);
x = decMul(x, x);
n = (n.sub(1)).div(2);
}
}
return decMul(x, y);
}
fu
function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_a | uint256 | |
_b | uint256 |
Source Code
_getAbsoluteDifference(uint _a, uint _b) internal pure returns (uint) {
return (_a >= _b) ? _a.sub(_b) : _b.sub(_a);
}
fu
function _computeNominalCR(uint256 _coll, uint256 _debt) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_coll | uint256 | |
_debt | uint256 |
Source Code
_computeNominalCR(uint _coll, uint _debt) internal pure returns (uint) {
if (_debt > 0) {
return _coll.mul(NICR_PRECISION).div(_debt);
}
// Return the maximal value for uint256 if the Trove has a debt of 0. Represents "infinite" CR.
else { // if (_debt == 0)
return 2**256 - 1;
}
}
fu
function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_coll | uint256 | |
_debt | uint256 | |
_price | uint256 |
Source Code
_computeCR(uint _coll, uint _debt, uint _price) internal pure returns (uint) {
if (_debt > 0) {
uint newCollRatio = _coll.mul(_price).div(_debt);
return newCollRatio;
}
// Return the maximal value for uint256 if the Trove has a debt of 0. Represents "infinite" CR.
else { // if (_debt == 0)
return 2**256 - 1;
}
}
}
- ActivePool
- ActivePoolStorage
- BaseMath
- BorrowerOperations
- BorrowerOperationsScript
- BorrowerOperationsStorage
- BorrowerWrappersScript
- CheckContract
- CollSurplusPool
- CollSurplusPoolStorage
- console
- Context
- DefaultPool
- DefaultPoolStorage
- DocsCover
- DSAuth
- DSAuthEvents
- DSAuthority
- DSNote
- DSProxy
- DSProxyCache
- DSProxyFactory
- ERC20
- ETHTransferScript
- FeeDistributor
- FeeDistributorStorage
- GasPool
- HintHelpers
- HintHelpersStorage
- IActivePool
- IBalanceRedirectPresale
- IBorrowerOperations
- ICollSurplusPool
- IDefaultPool
- IERC20
- IERC2612
- IExternalPriceFeed
- IFeeDistributor
- IFeeSharingProxy
- ILiquityBase
- ILiquityBaseParams
- IMasset
- IMoCBaseOracle
- Initializable
- IPool
- IPriceFeed
- IRSKOracle
- ISortedTroves
- IStabilityPool
- ITroveManager
- IWrbtc
- IZUSDToken
- LiquityBase
- LiquityBaseParams
- LiquityMath
- LiquitySafeMath128
- MoCMedianizer
- MultiTroveGetter
- MultiTroveGetterStorage
- NueToken
- Ownable
- PriceFeed
- PriceFeedStorage
- ProxiableContract
- ProxiableContract2
- Proxy
- RskOracle
- SafeMath
- SortedTroves
- SortedTrovesStorage
- StabilityPool
- StabilityPoolScript
- StabilityPoolStorage
- Storage
- Storage2
- TokenScript
- TroveManager
- TroveManagerBase
- TroveManagerBase1MinuteBootstrap
- TroveManagerRedeemOps
- TroveManagerScript
- TroveManagerStorage
- UpgradableProxy
- ZUSDToken
- ZUSDTokenStorage