Liquidation Engine
The protocol's liquidation mechanism
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 be1
for theLiquidationEngine
toliquidateSAFE
s. Used to indicate whether the contract is enabled.authorizedAccounts[usr: address]
- addresses allowed to callmodifyParameters()
anddisableContract()
safeEngine
- address that conforms to aSAFEEngineLike
interface. It cannot be changed after the contract is instantiated.accountingEngine
- address that conforms to anAccountingEngineLike
interface.chosenSAFESaviour[collateralType: bytes32, safe: address]
- stores theSAFESaviour
chosen by asafe
user in order to save their position from liquidation.safeSaviours[saviour: address]
- stores contract addresses that can be used asSAFESaviour
s.A
SAFESaviour
can be "attached" to asafe
by its owner. When an external actor callsliquidateSAFE
, theSAFESaviour
will try to add more collateral in the targetedsafe
and thus (potentially) save it from liquidation.
mutex[collatralType: bytes32, safe: address]
- helps with preventing re-entrancy whenliquidateSAFE
calls aSAFESaviour
in order to add more collateral to a position.collateralTypes
- storesCollateralType
structsonAuctionSystemCoinLimit
- 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 anaddress
variable.modifyParameters(collateralType: bytes32
,parameter: bytes32
,data: uint256)
- modify a collateral specificuint256
parameter.modifyParameters(collateralType: bytes32
,parameter: bytes32
,data: address)
- modify a collateral specificaddress
parameter.liquidateSAFE(collateralType: bytes32
,safe: address)
- will revert iflockedCollateral
orgeneratedDebt
are larger than or equal to 2^255.protectSAFE(collateralType: bytes32, address, address)
will revert if the proposedSAFESaviour
address 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 fromcurrentOnAuctionSystemCoins
getLimitAdjustedDebtToCover(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 whencurrentOnAuctionSystemCoins
is 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 accountDisableContract
- emitted after the contract is disabledLiquidate
- emitted when aliquidateSAFE(bytes32, address)
is successfully executed. Contains:collateralType
- collateralsafe
- SAFE addresscollateralAmount
- seecollateralToSell
inliquidateSAFE
debtAmount
- seesafeDebt
inliquidateSAFE
amountToRaise
- seeamountToRaise
inliquidateSAFE
collateralAuctioneer
- address of theCollateralAuctionHouse
contractauctionId
- ID of the auction in theCollateralAuctionHouse
SaveSAFE
- emitted when the liquidated SAFE has aSAFESaviour
attached 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
liquidateSAFE
will not leave a SAFE with debt and no collateralliquidateSAFE
will not leave a SAFE dustyliquidateSAFE
will not start a new auction ifamountToRaise + currentOnAuctionSystemCoins
exceedsonAuctionSystemCoinLimit
protectSAFE
will revert if the chosenSAFESaviour
address 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.
Last updated