Skip to content

Latest commit

 

History

History
1271 lines (912 loc) · 31.4 KB

ITroveManager.md

File metadata and controls

1271 lines (912 loc) · 31.4 KB

ITroveManager.sol

View Source: contracts/Interfaces/ITroveManager.sol

↗ Extends: ILiquityBase ↘ Derived Contracts: TroveManager

ITroveManager

Events

event FeeDistributorAddressChanged(address  _feeDistributorAddress);
event TroveManagerRedeemOpsAddressChanged(address  _troveManagerRedeemOps);
event LiquityBaseParamsAddressChanges(address  _borrowerOperationsAddress);
event BorrowerOperationsAddressChanged(address  _newBorrowerOperationsAddress);
event PriceFeedAddressChanged(address  _newPriceFeedAddress);
event ZUSDTokenAddressChanged(address  _newZUSDTokenAddress);
event ActivePoolAddressChanged(address  _activePoolAddress);
event DefaultPoolAddressChanged(address  _defaultPoolAddress);
event StabilityPoolAddressChanged(address  _stabilityPoolAddress);
event GasPoolAddressChanged(address  _gasPoolAddress);
event CollSurplusPoolAddressChanged(address  _collSurplusPoolAddress);
event SortedTrovesAddressChanged(address  _sortedTrovesAddress);
event ZEROTokenAddressChanged(address  _zeroTokenAddress);
event ZEROStakingAddressChanged(address  _zeroStakingAddress);
event Liquidation(uint256  _liquidatedDebt, uint256  _liquidatedColl, uint256  _collGasCompensation, uint256  _ZUSDGasCompensation);
event Redemption(uint256  _attemptedZUSDAmount, uint256  _actualZUSDAmount, uint256  _ETHSent, uint256  _ETHFee);
event TroveUpdated(address indexed _borrower, uint256  _debt, uint256  _coll, uint256  stake, uint8  operation);
event TroveLiquidated(address indexed _borrower, uint256  _debt, uint256  _coll, uint8  operation);
event BaseRateUpdated(uint256  _baseRate);
event LastFeeOpTimeUpdated(uint256  _lastFeeOpTime);
event TotalStakesUpdated(uint256  _newTotalStakes);
event SystemSnapshotsUpdated(uint256  _totalStakesSnapshot, uint256  _totalCollateralSnapshot);
event LTermsUpdated(uint256  _L_ETH, uint256  _L_ZUSDDebt);
event TroveSnapshotsUpdated(uint256  _L_ETH, uint256  _L_ZUSDDebt);
event TroveIndexUpdated(address  _borrower, uint256  _newIndex);

Functions


setAddresses

Called only once on init, to set addresses of other Zero contracts. Callable only by owner

function setAddresses(address _feeDistributorAddress, address _troveManagerRedeemOps, address _liquityBaseParamsAddress, address _borrowerOperationsAddress, address _activePoolAddress, address _defaultPoolAddress, address _stabilityPoolAddress, address _gasPoolAddress, address _collSurplusPoolAddress, address _priceFeedAddress, address _zusdTokenAddress, address _sortedTrovesAddress, address _zeroTokenAddress, address _zeroStakingAddress) external nonpayable

Arguments

Name Type Description
_feeDistributorAddress address feeDistributor contract address
_troveManagerRedeemOps address TroveManagerRedeemOps contract address
_liquityBaseParamsAddress address LiquityBaseParams contract address
_borrowerOperationsAddress address BorrowerOperations contract address
_activePoolAddress address ActivePool contract address
_defaultPoolAddress address DefaultPool contract address
_stabilityPoolAddress address StabilityPool contract address
_gasPoolAddress address GasPool contract address
_collSurplusPoolAddress address CollSurplusPool contract address
_priceFeedAddress address PriceFeed contract address
_zusdTokenAddress address ZUSDToken contract address
_sortedTrovesAddress address SortedTroves contract address
_zeroTokenAddress address ZEROToken contract address
_zeroStakingAddress address ZEROStaking contract address
Source Code
function setAddresses(
        address _feeDistributorAddress,
        address _troveManagerRedeemOps,
        address _liquityBaseParamsAddress,
        address _borrowerOperationsAddress,
        address _activePoolAddress,
        address _defaultPoolAddress,
        address _stabilityPoolAddress,
        address _gasPoolAddress,
        address _collSurplusPoolAddress,
        address _priceFeedAddress,
        address _zusdTokenAddress,
        address _sortedTrovesAddress,
        address _zeroTokenAddress,
        address _zeroStakingAddress
    ) external;

getTroveOwnersCount

function getTroveOwnersCount() external view
returns(uint256)
Source Code
function getTroveOwnersCount() external view returns (uint256);

getTroveFromTroveOwnersArray

function getTroveFromTroveOwnersArray(uint256 _index) external view
returns(address)

Arguments

Name Type Description
_index uint256 Trove owner index

Returns

Trove from TroveOwners array in given index

Source Code
function getTroveFromTroveOwnersArray(uint256 _index) external view returns (address);

getNominalICR

function getNominalICR(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

the nominal collateral ratio (ICR) of a given Trove, without the price. Takes a trove's pending coll and debt rewards from redistributions into account.

Source Code
function getNominalICR(address _borrower) external view returns (uint256);

getCurrentICR

computes the user’s individual collateralization ratio (ICR) based on their total collateral and total ZUSD debt. Returns 2^256 -1 if they have 0 debt.

function getCurrentICR(address _borrower, uint256 _price) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
_price uint256 ETH price

Returns

the current collateral ratio (ICR) of a given Trove. Takes a trove's pending coll and debt rewards from redistributions into account.

Source Code
nction getCurrentICR(address _borrower, uint256 _price) external view returns (uint256);

liquidate

Closes the trove if its ICR is lower than the minimum collateral ratio.

function liquidate(address _borrower) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
Source Code
nction liquidate(address _borrower) external;

liquidateTroves

Liquidate a sequence of troves. Closes a maximum number of n under-collateralized Troves, starting from the one with the lowest collateral ratio in the system, and moving upwards

function liquidateTroves(uint256 _n) external nonpayable

Arguments

Name Type Description
_n uint256 max number of under-collateralized Troves to liquidate
Source Code
nction liquidateTroves(uint256 _n) external;

batchLiquidateTroves

Attempt to liquidate a custom list of troves provided by the caller.

function batchLiquidateTroves(address[] _troveArray) external nonpayable

Arguments

Name Type Description
_troveArray address[] list of trove addresses
Source Code
nction batchLiquidateTroves(address[] calldata _troveArray) external;

redeemCollateral

Send _ZUSDamount ZUSD to the system and redeem the corresponding amount of collateral from as many Troves as are needed to fill the redemption request. Applies pending rewards to a Trove before reducing its debt and coll. Note that if _amount is very large, this function can run out of gas, specially if traversed troves are small. This can be easily avoided by splitting the total _amount in appropriate chunks and calling the function multiple times. Param _maxIterations can also be provided, so the loop through Troves is capped (if it’s zero, it will be ignored).This makes it easier to avoid OOG for the frontend, as only knowing approximately the average cost of an iteration is enough, without needing to know the “topology” of the trove list. It also avoids the need to set the cap in stone in the contract, nor doing gas calculations, as both gas price and opcode costs can vary. All Troves that are redeemed from -- with the likely exception of the last one -- will end up with no debt left, therefore they will be closed. If the last Trove does have some remaining debt, it has a finite ICR, and the reinsertion could be anywhere in the list, therefore it requires a hint. A frontend should use getRedemptionHints() to calculate what the ICR of this Trove will be after redemption, and pass a hint for its position in the sortedTroves list along with the ICR value that the hint was found for. If another transaction modifies the list between calling getRedemptionHints() and passing the hints to redeemCollateral(), it is very likely that the last (partially) redeemed Trove would end up with a different ICR than what the hint is for. In this case the redemption will stop after the last completely redeemed Trove and the sender will keep the remaining ZUSD amount, which they can attempt to redeem later.

function redeemCollateral(uint256 _ZUSDAmount, address _firstRedemptionHint, address _upperPartialRedemptionHint, address _lowerPartialRedemptionHint, uint256 _partialRedemptionHintNICR, uint256 _maxIterations, uint256 _maxFee) external nonpayable

Arguments

Name Type Description
_ZUSDAmount uint256 ZUSD amount to send to the system
_firstRedemptionHint address calculated ICR hint of first trove after redemption
_upperPartialRedemptionHint address
_lowerPartialRedemptionHint address
_partialRedemptionHintNICR uint256
_maxIterations uint256 max Troves iterations (can be 0)
_maxFee uint256 max fee percentage to accept
Source Code
 redeemCollateral(
        uint256 _ZUSDAmount,
        address _firstRedemptionHint,
        address _upperPartialRedemptionHint,
        address _lowerPartialRedemptionHint,
        uint256 _partialRedemptionHintNICR,
        uint256 _maxIterations,
        uint256 _maxFee
    ) external;

    //

updateStakeAndTotalStakes

Update borrower's stake based on their latest collateral value

function updateStakeAndTotalStakes(address _borrower) external nonpayable
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
Source Code
 updateStakeAndTotalStakes(address _borrower) external returns (uint256);

    //

updateTroveRewardSnapshots

Update borrower's snapshots of L_ETH and L_ZUSDDebt to reflect the current values

function updateTroveRewardSnapshots(address _borrower) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
Source Code
 updateTroveRewardSnapshots(address _borrower) external;

    //

addTroveOwnerToArray

Push the owner's address to the Trove owners list, and record the corresponding array index on the Trove struct

function addTroveOwnerToArray(address _borrower) external nonpayable
returns(index uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

index where Trove was inserted

Source Code
 addTroveOwnerToArray(address _borrower) external returns (uint256 index);

    //

applyPendingRewards

Add the borrowers's coll and debt rewards earned from redistributions, to their Trove

function applyPendingRewards(address _borrower) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
Source Code
 applyPendingRewards(address _borrower) external;

    //

getPendingETHReward

function getPendingETHReward(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

the borrower's pending accumulated ETH reward, earned by their stake

Source Code
 getPendingETHReward(address _borrower) external view returns (uint256);

    //

getPendingZUSDDebtReward

function getPendingZUSDDebtReward(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

the borrower's pending accumulated ZUSD reward, earned by their stake

Source Code
 getPendingZUSDDebtReward(address _borrower) external view returns (uint256);

    /*

hasPendingRewards

function hasPendingRewards(address _borrower) external view
returns(bool)

Arguments

Name Type Description
_borrower address
Source Code
 hasPendingRewards(address _borrower) external view returns (bool);

    //

getEntireDebtAndColl

returns the Troves entire debt and coll, including pending rewards from redistributions.

function getEntireDebtAndColl(address _borrower) external view
returns(debt uint256, coll uint256, pendingZUSDDebtReward uint256, pendingETHReward uint256)

Arguments

Name Type Description
_borrower address borrower address
Source Code
 getEntireDebtAndColl(address _borrower)
        external
        view
        returns (
            uint256 debt,
            uint256 coll,
            uint256 pendingZUSDDebtReward,
            uint256 pendingETHReward
        );

    //

closeTrove

Close given trove. Called by BorrowerOperations.

function closeTrove(address _borrower) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
Source Code
 closeTrove(address _borrower) external;

    //

removeStake

Remove borrower's stake from the totalStakes sum, and set their stake to 0

function removeStake(address _borrower) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
Source Code
 removeStake(address _borrower) external;

    //

getRedemptionRate

function getRedemptionRate() external view
returns(uint256)
Source Code
 getRedemptionRate() external view returns (uint256);

    //

getRedemptionRateWithDecay

function getRedemptionRateWithDecay() external view
returns(uint256)
Source Code
 getRedemptionRateWithDecay() external view returns (uint256);

    //

getRedemptionFeeWithDecay

The redemption fee is taken as a cut of the total ETH drawn from the system in a redemption. It is based on the current redemption rate.

function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view
returns(uint256)

Arguments

Name Type Description
_ETHDrawn uint256 ETH drawn
Source Code
 getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view returns (uint256);

    //

getBorrowingRate

function getBorrowingRate() external view
returns(uint256)
Source Code
 getBorrowingRate() external view returns (uint256);

    //

getBorrowingRateWithDecay

function getBorrowingRateWithDecay() external view
returns(uint256)
Source Code
 getBorrowingRateWithDecay() external view returns (uint256);

    //

getBorrowingFee

function getBorrowingFee(uint256 ZUSDDebt) external view
returns(uint256)

Arguments

Name Type Description
ZUSDDebt uint256 ZUSD debt amount to calculate fee

Returns

borrowing fee using borrowing rate

Source Code
 getBorrowingFee(uint256 ZUSDDebt) external view returns (uint256);

    //

getBorrowingFeeWithDecay

function getBorrowingFeeWithDecay(uint256 _ZUSDDebt) external view
returns(uint256)

Arguments

Name Type Description
_ZUSDDebt uint256 ZUSD debt amount to calculate fee

Returns

borrowing fee using borrowing rate with decay

Source Code
 getBorrowingFeeWithDecay(uint256 _ZUSDDebt) external view returns (uint256);

    //

decayBaseRateFromBorrowing

Updates the baseRate state variable based on time elapsed since the last redemption or ZUSD borrowing operation.

function decayBaseRateFromBorrowing() external nonpayable
Source Code
 decayBaseRateFromBorrowing() external;

    //

getTroveStatus

function getTroveStatus(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

Trove status from given trove

Source Code
 getTroveStatus(address _borrower) external view returns (uint256);

    //

getTroveStake

function getTroveStake(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

Trove stake from given trove

Source Code
 getTroveStake(address _borrower) external view returns (uint256);

    //

getTroveDebt

function getTroveDebt(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

Trove debt from given trove

Source Code
 getTroveDebt(address _borrower) external view returns (uint256);

    //

getTroveColl

function getTroveColl(address _borrower) external view
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address

Returns

Trove collateral from given trove

Source Code
 getTroveColl(address _borrower) external view returns (uint256);

    //

setTroveStatus

function setTroveStatus(address _borrower, uint256 num) external nonpayable

Arguments

Name Type Description
_borrower address borrower address
num uint256 status to set
Source Code
 setTroveStatus(address _borrower, uint256 num) external;

    //

increaseTroveColl

function increaseTroveColl(address _borrower, uint256 _collIncrease) external nonpayable
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
_collIncrease uint256 amount of collateral to increase

Returns

new trove collateral

Source Code
 increaseTroveColl(address _borrower, uint256 _collIncrease) external returns (uint256);

    //

decreaseTroveColl

function decreaseTroveColl(address _borrower, uint256 _collDecrease) external nonpayable
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
_collDecrease uint256 amount of collateral to decrease

Returns

new trove collateral

Source Code
 decreaseTroveColl(address _borrower, uint256 _collDecrease) external returns (uint256);

    //

increaseTroveDebt

function increaseTroveDebt(address _borrower, uint256 _debtIncrease) external nonpayable
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
_debtIncrease uint256 amount of debt to increase

Returns

new trove debt

Source Code
 increaseTroveDebt(address _borrower, uint256 _debtIncrease) external returns (uint256);

    //

decreaseTroveDebt

function decreaseTroveDebt(address _borrower, uint256 _debtDecrease) external nonpayable
returns(uint256)

Arguments

Name Type Description
_borrower address borrower address
_debtDecrease uint256 amount of debt to decrease

Returns

new trove debt

Source Code
 decreaseTroveDebt(address _borrower, uint256 _debtDecrease) external returns (uint256);

    /*

getTCR

function getTCR(uint256 _price) external view
returns(uint256)

Arguments

Name Type Description
_price uint256 ETH price

Returns

the total collateralization ratio (TCR) of the system. The TCR is based on the the entire system debt and collateral (including pending rewards).

Source Code
 getTCR(uint256 _price) external view returns (uint256);

    fu

MCR

function MCR() external view
returns(uint256)
Source Code
 MCR() external view returns (uint256);

    fu

CCR

function CCR() external view
returns(uint256)
Source Code
 CCR() external view returns (uint256);

    //

checkRecoveryMode

reveals whether or not the system is in Recovery Mode (i.e. whether the Total Collateralization Ratio (TCR) is below the Critical Collateralization Ratio (CCR)).

function checkRecoveryMode(uint256 _price) external view
returns(bool)

Arguments

Name Type Description
_price uint256
Source Code
 checkRecoveryMode(uint256 _price) external view returns (bool);
}

Contracts