CollateralAuctionHouse
Inherits: Authorizable, Modifiable, Disableable, ICollateralAuctionHouse
This contract enables the sell of a confiscated collateral in exchange for system coins to cover a SAFE's debt
State Variables
AUCTION_HOUSE_TYPE
Type of the auction house
bytes32 public constant AUCTION_HOUSE_TYPE = bytes32('COLLATERAL');
safeEngine
Address of the SAFEEngine contract
ISAFEEngine public safeEngine;
_liquidationEngine
Internal storage variable to allow overrides in child implementation contract
ILiquidationEngine internal _liquidationEngine;
_oracleRelayer
Internal storage variable to allow overrides in child implementation contract
IOracleRelayer internal _oracleRelayer;
collateralType
The collateral type of the auctions created by this contract
bytes32 public collateralType;
auctionsStarted
Total amount of collateral auctions created
uint256 public auctionsStarted;
_auctions
Unpacked data of an auction
mapping(uint256 _auctionId => Auction) public _auctions;
_params
Getter for the unpacked contract parameters struct
CollateralAuctionHouseParams public _params;
Functions
liquidationEngine
Address of the LiquidationEngine contract
function liquidationEngine() public view virtual returns (ILiquidationEngine __liquidationEngine);
oracleRelayer
Address of the OracleRelayer contract
function oracleRelayer() public view virtual returns (IOracleRelayer __oracleRelayer);
auctions
Data of an auction
function auctions(uint256 _auctionId) external view returns (Auction memory _auction);
Parameters
Name | Type | Description |
---|---|---|
_auctionId | uint256 | Id of the auction |
Returns
Name | Type | Description |
---|---|---|
_auction | Auction | Auction data struct |
params
Getter for the contract parameters struct
function params() external view returns (CollateralAuctionHouseParams memory _cahParams);
Returns
Name | Type | Description |
---|---|---|
_cahParams | CollateralAuctionHouseParams | Auction house parameters struct |
constructor
constructor(
address _safeEngine,
address __liquidationEngine,
address __oracleRelayer,
bytes32 _cType,
CollateralAuctionHouseParams memory _cahParams
) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address of the SAFEEngine contract |
__liquidationEngine | address | Address of the LiquidationEngine contract |
__oracleRelayer | address | Address of the OracleRelayer contract |
_cType | bytes32 | Bytes32 representation of the collateral type |
_cahParams | CollateralAuctionHouseParams | Initial valid CollateralAuctionHouse parameters struct |
_getBoughtCollateral
Get the amount of bought collateral from a specific auction using collateral and system coin prices, with a custom discount
The inputted bid is capped to the amount of system coins needed to buy all collateral
function _getBoughtCollateral(
uint256 _collateralPrice,
uint256 _systemCoinPrice,
uint256 _amountToSell,
uint256 _adjustedBid,
uint256 _customDiscount
) internal pure returns (uint256 _boughtCollateral, uint256 _readjustedBid);
Parameters
Name | Type | Description |
---|---|---|
_collateralPrice | uint256 | The collateral price fetched from the Oracle |
_systemCoinPrice | uint256 | The system coin redemption price fetched from the OracleRelayer |
_amountToSell | uint256 | The amount of collateral being auctioned |
_adjustedBid | uint256 | The limited system coin bid |
_customDiscount | uint256 | The discount offered |
Returns
Name | Type | Description |
---|---|---|
_boughtCollateral | uint256 | Amount of collateral bought for given parameters |
_readjustedBid | uint256 | Amount of system coins actually used to buy the collateral |
_getCollateralPrice
Get the collateral price from the oracle
function _getCollateralPrice() internal view returns (uint256 _collateralPrice);
Returns
Name | Type | Description |
---|---|---|
_collateralPrice | uint256 | The collateral price if valid [wad] |
_getAuctionDiscount
Get the upcoming discount that will be used in a specific auction
function _getAuctionDiscount(uint256 _id) internal view returns (uint256 _auctionDiscount);
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 | The ID of the auction to calculate the upcoming discount for |
Returns
Name | Type | Description |
---|---|---|
_auctionDiscount | uint256 | The upcoming discount that will be used in the targeted auction |
_getAdjustedBid
Get the actual bid that will be used in an auction (taking into account the bidder input)
The inputted bid is capped to the amount of system coins the auction needs to raise
function _getAdjustedBid(uint256 _id, uint256 _wad) internal view returns (uint256 _adjustedBid);
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 | The id of the auction to calculate the adjusted bid for |
_wad | uint256 | The initial bid submitted |
Returns
Name | Type | Description |
---|---|---|
_adjustedBid | uint256 | The adjusted bid |
startAuction
Starts a new collateral auction
function startAuction(
address _forgoneCollateralReceiver,
address _auctionIncomeRecipient,
uint256 _amountToRaise,
uint256 _amountToSell
) external isAuthorized whenEnabled returns (uint256 _id);
Parameters
Name | Type | Description |
---|---|---|
_forgoneCollateralReceiver | address | Who receives leftover collateral that is not sold in the auction (usually the liquidated SAFE) |
_auctionIncomeRecipient | address | Who receives the coins raised by the auction (usually the AccountingEngine) |
_amountToRaise | uint256 | Total/max amount of coins to raise [rad] |
_amountToSell | uint256 |
Returns
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the started auction |
getAuctionDiscount
Calculates the current discount of an auction
function getAuctionDiscount(uint256 _id) external view returns (uint256 _auctionDiscount);
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the auction |
Returns
Name | Type | Description |
---|---|---|
_auctionDiscount | uint256 | Current discount of the auction [wad %] |
getCollateralBought
Calculates the amount of collateral that will be bought with a given bid
function getCollateralBought(
uint256 _id,
uint256 _wad
) external view returns (uint256 _boughtCollateral, uint256 _adjustedBid);
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the auction |
_wad | uint256 | Bid amount [wad] |
Returns
Name | Type | Description |
---|---|---|
_boughtCollateral | uint256 | _collateralBought Amount of collateral that will be bought [wad] |
_adjustedBid | uint256 | Adjusted bid amount [wad] |
buyCollateral
Buys collateral from an auction
function buyCollateral(
uint256 _id,
uint256 _wad
) external whenEnabled returns (uint256 _boughtCollateral, uint256 _adjustedBid);
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the auction |
_wad | uint256 | Bid amount [wad] |
Returns
Name | Type | Description |
---|---|---|
_boughtCollateral | uint256 | Amount of collateral that was bought [wad] |
_adjustedBid | uint256 | Adjusted bid amount [wad] |
terminateAuctionPrematurely
Terminates an auction prematurely
Transfers collateral and coins to the authorized caller address
function terminateAuctionPrematurely(uint256 _id) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_id | uint256 |
_modifyParameters
Internal function to be overriden with custom logic to modify parameters
This function is set to revert if not overriden
function _modifyParameters(bytes32 _param, bytes memory _data) internal virtual override;
_setLiquidationEngine
Sets the LiquidationEngine contract address, revoking the previous, and granting the new one authorization
function _setLiquidationEngine(address _newLiquidationEngine) internal virtual;
_setOracleRelayer
Sets the OracleRelayer contract address
function _setOracleRelayer(address _newOracleRelayer) internal virtual;
_validateParameters
Internal function to be overriden with custom logic to validate parameters
function _validateParameters() internal view override;