View Source: contracts/HintHelpers.sol
↗ Extends: LiquityBase, HintHelpersStorage, CheckContract
HintHelpers
Events
event SortedTrovesAddressChanged(address _sortedTrovesAddress);
event TroveManagerAddressChanged(address _troveManagerAddress);
- setAddresses(address _liquityBaseParamsAddress, address _sortedTrovesAddress, address _troveManagerAddress)
- getRedemptionHints(uint256 _ZUSDamount, uint256 _price, uint256 _maxIterations)
- getApproxHint(uint256 _CR, uint256 _numTrials, uint256 _inputRandomSeed)
- computeNominalCR(uint256 _coll, uint256 _debt)
- computeCR(uint256 _coll, uint256 _debt, uint256 _price)
function setAddresses(address _liquityBaseParamsAddress, address _sortedTrovesAddress, address _troveManagerAddress) external nonpayable onlyOwner
Arguments
Name | Type | Description |
---|---|---|
_liquityBaseParamsAddress | address | |
_sortedTrovesAddress | address | |
_troveManagerAddress | address |
Source Code
function setAddresses(
address _liquityBaseParamsAddress,
address _sortedTrovesAddress,
address _troveManagerAddress
)
external
onlyOwner
{
checkContract(_liquityBaseParamsAddress);
checkContract(_sortedTrovesAddress);
checkContract(_troveManagerAddress);
liquityBaseParams = ILiquityBaseParams(_liquityBaseParamsAddress);
sortedTroves = ISortedTroves(_sortedTrovesAddress);
troveManager = ITroveManager(_troveManagerAddress);
emit SortedTrovesAddressChanged(_sortedTrovesAddress);
emit TroveManagerAddressChanged(_troveManagerAddress);
}
function getRedemptionHints(uint256 _ZUSDamount, uint256 _price, uint256 _maxIterations) external view
returns(firstRedemptionHint address, partialRedemptionHintNICR uint256, truncatedZUSDamount uint256)
Arguments
Name | Type | Description |
---|---|---|
_ZUSDamount | uint256 | |
_price | uint256 | |
_maxIterations | uint256 |
Source Code
function getRedemptionHints(
uint _ZUSDamount,
uint _price,
uint _maxIterations
)
external
view
returns (
address firstRedemptionHint,
uint partialRedemptionHintNICR,
uint truncatedZUSDamount
)
{
ISortedTroves sortedTrovesCached = sortedTroves;
uint remainingZUSD = _ZUSDamount;
address currentTroveuser = sortedTrovesCached.getLast();
while (currentTroveuser != address(0) && troveManager.getCurrentICR(currentTroveuser, _price) < liquityBaseParams.MCR()) {
currentTroveuser = sortedTrovesCached.getPrev(currentTroveuser);
}
firstRedemptionHint = currentTroveuser;
if (_maxIterations == 0) {
_maxIterations = uint(-1);
}
while (currentTroveuser != address(0) && remainingZUSD > 0 && _maxIterations-- > 0) {
uint netZUSDDebt = _getNetDebt(troveManager.getTroveDebt(currentTroveuser))
.add(troveManager.getPendingZUSDDebtReward(currentTroveuser));
if (netZUSDDebt > remainingZUSD) {
if (netZUSDDebt > MIN_NET_DEBT) {
uint maxRedeemableZUSD = LiquityMath._min(remainingZUSD, netZUSDDebt.sub(MIN_NET_DEBT));
uint ETH = troveManager.getTroveColl(currentTroveuser)
.add(troveManager.getPendingETHReward(currentTroveuser));
uint newColl = ETH.sub(maxRedeemableZUSD.mul(DECIMAL_PRECISION).div(_price));
uint newDebt = netZUSDDebt.sub(maxRedeemableZUSD);
uint compositeDebt = _getCompositeDebt(newDebt);
partialRedemptionHintNICR = LiquityMath._computeNominalCR(newColl, compositeDebt);
remainingZUSD = remainingZUSD.sub(maxRedeemableZUSD);
}
break;
} else {
remainingZUSD = remainingZUSD.sub(netZUSDDebt);
}
currentTroveuser = sortedTrovesCached.getPrev(currentTroveuser);
}
truncatedZUSDamount = _ZUSDamount.sub(remainingZUSD);
}
function getApproxHint(uint256 _CR, uint256 _numTrials, uint256 _inputRandomSeed) external view
returns(hintAddress address, diff uint256, latestRandomSeed uint256)
Arguments
Name | Type | Description |
---|---|---|
_CR | uint256 | |
_numTrials | uint256 | |
_inputRandomSeed | uint256 |
Source Code
function getApproxHint(uint _CR, uint _numTrials, uint _inputRandomSeed)
external
view
returns (address hintAddress, uint diff, uint latestRandomSeed)
{
uint arrayLength = troveManager.getTroveOwnersCount();
if (arrayLength == 0) {
return (address(0), 0, _inputRandomSeed);
}
hintAddress = sortedTroves.getLast();
diff = LiquityMath._getAbsoluteDifference(_CR, troveManager.getNominalICR(hintAddress));
latestRandomSeed = _inputRandomSeed;
uint i = 1;
while (i < _numTrials) {
latestRandomSeed = uint(keccak256(abi.encodePacked(latestRandomSeed)));
uint arrayIndex = latestRandomSeed % arrayLength;
address currentAddress = troveManager.getTroveFromTroveOwnersArray(arrayIndex);
uint currentNICR = troveManager.getNominalICR(currentAddress);
// check if abs(current - CR) > abs(closest - CR), and update closest if current is closer
uint currentDiff = LiquityMath._getAbsoluteDifference(currentNICR, _CR);
if (currentDiff < diff) {
diff = currentDiff;
hintAddress = currentAddress;
}
i++;
}
}
function computeNominalCR(uint256 _coll, uint256 _debt) external pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_coll | uint256 | |
_debt | uint256 |
Source Code
function computeNominalCR(uint _coll, uint _debt) external pure returns (uint) {
return LiquityMath._computeNominalCR(_coll, _debt);
}
function computeCR(uint256 _coll, uint256 _debt, uint256 _price) external pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
_coll | uint256 | |
_debt | uint256 | |
_price | uint256 |
Source Code
function computeCR(uint _coll, uint _debt, uint _price) external pure returns (uint) {
return LiquityMath._computeCR(_coll, _debt, _price);
}
- 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