CollateralAuctionHouse

Git Source

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

NameTypeDescription
_auctionIduint256Id of the auction

Returns

NameTypeDescription
_auctionAuctionAuction data struct

params

Getter for the contract parameters struct

function params() external view returns (CollateralAuctionHouseParams memory _cahParams);

Returns

NameTypeDescription
_cahParamsCollateralAuctionHouseParamsAuction house parameters struct

constructor

constructor(
  address _safeEngine,
  address __liquidationEngine,
  address __oracleRelayer,
  bytes32 _cType,
  CollateralAuctionHouseParams memory _cahParams
) Authorizable(msg.sender) validParams;

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine contract
__liquidationEngineaddressAddress of the LiquidationEngine contract
__oracleRelayeraddressAddress of the OracleRelayer contract
_cTypebytes32Bytes32 representation of the collateral type
_cahParamsCollateralAuctionHouseParamsInitial 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

NameTypeDescription
_collateralPriceuint256The collateral price fetched from the Oracle
_systemCoinPriceuint256The system coin redemption price fetched from the OracleRelayer
_amountToSelluint256The amount of collateral being auctioned
_adjustedBiduint256The limited system coin bid
_customDiscountuint256The discount offered

Returns

NameTypeDescription
_boughtCollateraluint256Amount of collateral bought for given parameters
_readjustedBiduint256Amount 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

NameTypeDescription
_collateralPriceuint256The 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

NameTypeDescription
_iduint256The ID of the auction to calculate the upcoming discount for

Returns

NameTypeDescription
_auctionDiscountuint256The 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

NameTypeDescription
_iduint256The id of the auction to calculate the adjusted bid for
_waduint256The initial bid submitted

Returns

NameTypeDescription
_adjustedBiduint256The 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

NameTypeDescription
_forgoneCollateralReceiveraddressWho receives leftover collateral that is not sold in the auction (usually the liquidated SAFE)
_auctionIncomeRecipientaddress
_amountToRaiseuint256Total/max amount of coins to raise [rad]
_amountToSelluint256

Returns

NameTypeDescription
_iduint256Id of the started auction

getAuctionDiscount

Calculates the current discount of an auction

function getAuctionDiscount(uint256 _id) external view returns (uint256 _auctionDiscount);

Parameters

NameTypeDescription
_iduint256Id of the auction

Returns

NameTypeDescription
_auctionDiscountuint256Current 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

NameTypeDescription
_iduint256Id of the auction
_waduint256Bid amount [wad]

Returns

NameTypeDescription
_boughtCollateraluint256_collateralBought Amount of collateral that will be bought [wad]
_adjustedBiduint256Adjusted bid amount [wad]

buyCollateral

Buys collateral from an auction

function buyCollateral(
  uint256 _id,
  uint256 _wad
) external whenEnabled returns (uint256 _boughtCollateral, uint256 _adjustedBid);

Parameters

NameTypeDescription
_iduint256Id of the auction
_waduint256Bid amount [wad]

Returns

NameTypeDescription
_boughtCollateraluint256Amount of collateral that was bought [wad]
_adjustedBiduint256Adjusted bid amount [wad]

settleAuction

Deprecated

Current CollateralAuctionHouse implementation automatically settles auctions

function settleAuction(uint256) external pure;

terminateAuctionPrematurely

Terminates an auction prematurely

Transfers collateral and coins to the authorized caller address

function terminateAuctionPrematurely(uint256 _id) external isAuthorized;

Parameters

NameTypeDescription
_iduint256

_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;