Liquidation Engine
1. Summary
The LiquidationEngine enables external actors to liquidate SAFEs and send their collateral to the CollateralAuctionHouse as well as send a portion of their debt to the AccountingEngine.
2. Contract Variables & Functions
Variables
contractEnabled- must be1for theLiquidationEnginetoliquidateSAFEs. **** Used **** to indicate whether the contract is enabled.authorizedAccounts[usr: address]- addresses allowed to callmodifyParameters()anddisableContract()safeEngine- address that conforms to aSAFEEngineLikeinterface. It cannot be changed after the contract is instantiated.accountingEngine- address that conforms to anAccountingEngineLikeinterface.chosenSAFESaviour[collateralType: bytes32, safe: address]- stores theSAFESaviourchosen by asafeuser in order to save their position from liquidation.safeSaviours[saviour: address]- stores contract addresses that can be used asSAFESaviours.- A
SAFESaviourcan be "attached" to asafeby its owner. When an external actor callsliquidateSAFE, theSAFESaviourwill try to add more collateral in the targetedsafeand thus (potentially) save it from liquidation.
- A
mutex[collatralType: bytes32, safe: address]- helps with preventing re-entrancy whenliquidateSAFEcalls aSAFESaviourin order to add more collateral to a position.collateralTypes- storesCollateralTypestructsonAuctionSystemCoinLimit- total amount of system coins that can be requested across all collateral auctions at any timecurrentOnAuctionSystemCoins- amount of system coins requested across all current collateral auctions
Data Structures
CollateralType:collateralAuctionHouse- the address of the contract that auctions a specific collateral type.liquidationPenalty- penalty applied to a SAFE when it is liquidated (extra amount of debt that must be covered by an auction).liquidationQuantity- maximum amount of system coins to be requested in one collateral auction.
Modifiers
isAuthorized**** - checks whether an address is part ofauthorizedAddresses(and thus can call authed functions).
Functions
disableContract()- disable the liquidation engine.connectSAFESaviour(saviour: address)- governance controlled address that whitelists aSAFESaviour.disconnectSAFESaviour(saviour: address)- governance controlled address that blacklists aSAFESaviour.addAuthorization(usr: address)- add an address toauthorizedAddresses.removeAuthorization(usr: address)- remove an address fromauthorizedAddresses.modifyParameters(parameter: bytes32,data: address)- modify anaddressvariable.modifyParameters(collateralType: bytes32,parameter: bytes32,data: uint256)- modify a collateral specificuint256parameter.modifyParameters(collateralType: bytes32,parameter: bytes32,data: address)- modify a collateral specificaddressparameter.liquidateSAFE(collateralType: bytes32,safe: address)- will revert iflockedCollateralorgeneratedDebtare larger than or equal to 2^255.protectSAFE(collateralType: bytes32, address, address)will revert if the proposedSAFESaviouraddress was not whitelisted by governanceremoveCoinsFromAuction(rad: uint256)- signal that an amount of system coins has been covered by a collateral auction and it can now be subtracted fromcurrentOnAuctionSystemCoinsgetLimitAdjustedDebtToCover(collateralType: bytes32,safe: address)- returns the amount of debt that can currently be covered by a collateral auction for a specific safe
Events
-
AddAuthorization- emitted when a new address becomes authorized. Contains:account- the new authorized account
-
RemoveAuthorization- emitted when an address is de-authorized. Contains:- account - the address that was de-authorized
-
ConnectSAFESaviour- emitted when a new SAFE savior becomes available to protect SAFEs from liquidation. Contains:saviour- the savior's address
-
DisconnectSAFESaviour- emitted when a SAFE savior is not available anymore to protect SAFEs. Contains:saviour- the savior's address
-
UpdateCurrentOnAuctionSystemCoins- emitted whencurrentOnAuctionSystemCoinsis updated. Contains:currentOnAuctionSystemCoins- the current amount of system coins being requested across all active collateral auctions
-
ModifyParameters- emitted when a parameter is updated by an authorized account -
DisableContract- emitted after the contract is disabled -
Liquidate- emitted when aliquidateSAFE(bytes32, address)is successfully executed. Contains:collateralType- collateralsafe- SAFE addresscollateralAmount- seecollateralToSellinliquidateSAFEdebtAmount- seesafeDebtinliquidateSAFEamountToRaise- seeamountToRaiseinliquidateSAFEcollateralAuctioneer- address of theCollateralAuctionHousecontractauctionId- ID of the auction in theCollateralAuctionHouse
-
SaveSAFE- emitted when the liquidated SAFE has aSAFESaviourattached to it and an external actor callsliquidateSAFE(bytes32, address).Contains:
collateralType- The collateral type of the saved SAFEsafe- SAFE addresscollateralAdded- amount of collateral added in the SAFE
-
FailedSAFESave- emitted when a savior fails to rescue a SAFE. Contains:failReason- the reason for failure
-
ProtectSAFE- emitted when a SAFE user chooses a SAFE savior for their position. Contains:collateralType- the collateral type locked in the protected SAFEsafe- the SAFE's addresssaviour- the savior's address
Notes
liquidateSAFEwill not leave a SAFE with debt and no collateralliquidateSAFEwill not leave a SAFE dustyliquidateSAFEwill not start a new auction ifamountToRaise + currentOnAuctionSystemCoinsexceedsonAuctionSystemCoinLimitprotectSAFEwill revert if the chosenSAFESaviouraddress was not whitelisted by governance.
3. Walkthrough
liquidateSAFE can be called at any time but will only succeed if the target SAFE is underwater. A SAFE is underwater when the result of its collateral (lockedCollateral) multiplied by the collateral's liquidation price (liquidationPrice) is smaller than its present value debt (generatedDebt times the collateral's accumulatedRates).
liquidationPrice is the oracle-reported price scaled by the collateral's liquidation ratio. There is a clear distinction between liquidation and safety ratios (even though the two can be equal in value):
- Safety ratios are the minimum collateralization ratios used when generating debt against a SAFE's collateral. They can be more conservative (higher) than liquidation ratios
- Liquidation ratios are the minimum collateralization ratios under which SAFEs are liquidated
liquidateSAFE may terminate early if the owner of the SAFE that's being targeted protected their position with a saviour that manages to save it from liquidation.