HaiSafeManager

Git Source

Inherits: IHaiSafeManager

This contract acts as interface to the SAFEEngine, facilitating the management of SAFEs

This contract is meant to be used by users that interact with the protocol through a proxy contract

State Variables

safeEngine

Address of the SAFEEngine

address public safeEngine;

_safeId

Nonce used to generate safe ids (autoincremental)

uint256 internal _safeId;

_usrSafes

Mapping of user addresses to their enumerable set of safes

mapping(address _safeOwner => EnumerableSet.UintSet) private _usrSafes;

_usrSafesPerCollat

Mapping of user addresses to their enumerable set of safes per collateral type

mapping(address _safeOwner => mapping(bytes32 _cType => EnumerableSet.UintSet)) private _usrSafesPerCollat;

_safeData

Mapping of safe ids to their data

mapping(uint256 _safeId => SAFEData) internal _safeData;

safeCan

Mapping of owner and safe permissions to a caller permissions

mapping(address _owner => mapping(uint256 _safeId => mapping(address _caller => uint256 _ok))) public safeCan;

handlerCan

Mapping of handler to a caller permissions

mapping(address _safeHandler => mapping(address _caller => uint256 _ok)) public handlerCan;

Functions

safeAllowed

Checks if the sender is the owner of the safe or the safe has permissions to call the function

modifier safeAllowed(uint256 _safe);

Parameters

NameTypeDescription
_safeuint256Id of the safe to check if msg.sender has permissions for

handlerAllowed

Checks if the sender is the safe handler has permissions to call the function

modifier handlerAllowed(address _handler);

Parameters

NameTypeDescription
_handleraddressAddress of the handler to check if msg.sender has permissions for

constructor

constructor(address _safeEngine);

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine

getSafes

Getter for the list of safes owned by a user

function getSafes(address _usr) external view returns (uint256[] memory _safes);

Parameters

NameTypeDescription
_usraddressAddress of the user

Returns

NameTypeDescription
_safesuint256[]List of safe ids owned by the user

getSafes

Getter for the list of safes owned by a user

function getSafes(address _usr, bytes32 _cType) external view returns (uint256[] memory _safes);

Parameters

NameTypeDescription
_usraddressAddress of the user
_cTypebytes32

Returns

NameTypeDescription
_safesuint256[]List of safe ids owned by the user

getSafesData

Getter for the details of the safes owned by a user

function getSafesData(address _usr)
  external
  view
  returns (uint256[] memory _safes, address[] memory _safeHandlers, bytes32[] memory _cTypes);

Parameters

NameTypeDescription
_usraddressAddress of the user

Returns

NameTypeDescription
_safesuint256[]List of safe ids owned by the user
_safeHandlersaddress[]List of safe handlers addresses owned by the user
_cTypesbytes32[]List of collateral types of the safes owned by the user

safeData

Getter for the details of a SAFE

function safeData(uint256 _safe) external view returns (SAFEData memory _sData);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE

Returns

NameTypeDescription
_sDataSAFEDataStruct with the safe data

allowSAFE

Allow/disallow a user address to manage the safe

function allowSAFE(uint256 _safe, address _usr, uint256 _ok) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_usraddressAddress of the user to allow/disallow
_okuint256Boolean state to allow/disallow

allowHandler

Allow/disallow a handler address to manage the safe

function allowHandler(address _usr, uint256 _ok) external;

Parameters

NameTypeDescription
_usraddressAddress of the user to allow/disallow
_okuint256Boolean state to allow/disallow

openSAFE

Open a new safe for a user address

function openSAFE(bytes32 _cType, address _usr) external returns (uint256 _id);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type
_usraddressAddress of the user to open the safe for

Returns

NameTypeDescription
_iduint256Id of the new SAFE

transferSAFEOwnership

Transfer the ownership of a safe to a dst address

function transferSAFEOwnership(uint256 _safe, address _dst) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_dstaddressAddress of the dst address

modifySAFECollateralization

Modify a SAFE's collateralization ratio while keeping the generated COIN or collateral freed in the safe handler address

function modifySAFECollateralization(
  uint256 _safe,
  int256 _deltaCollateral,
  int256 _deltaDebt
) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_deltaCollateralint256Delta of collateral to add/remove [wad]
_deltaDebtint256Delta of debt to add/remove [wad]

transferCollateral

Transfer wad amount of safe collateral from the safe address to a dst address

function transferCollateral(uint256 _safe, address _dst, uint256 _wad) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_dstaddressAddress of the dst address
_waduint256Amount of collateral to transfer [wad]

transferCollateral

Transfer wad amount of safe collateral from the safe address to a dst address

function transferCollateral(bytes32 _cType, uint256 _safe, address _dst, uint256 _wad) external safeAllowed(_safe);

Parameters

NameTypeDescription
_cTypebytes32
_safeuint256Id of the SAFE
_dstaddressAddress of the dst address
_waduint256Amount of collateral to transfer [wad]

transferInternalCoins

Transfer an amount of COIN from the safe address to a dst address [rad]

function transferInternalCoins(uint256 _safe, address _dst, uint256 _rad) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_dstaddressAddress of the dst address
_raduint256Amount of COIN to transfer [rad]

quitSystem

Quit the system, migrating the safe (lockedCollateral, generatedDebt) to a different dst handler

function quitSystem(uint256 _safe, address _dst) external safeAllowed(_safe) handlerAllowed(_dst);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_dstaddressAddress of the dst handler

enterSystem

Enter the system, migrating the safe (lockedCollateral, generatedDebt) from a src handler to the safe handler

function enterSystem(address _src, uint256 _safe) external handlerAllowed(_src) safeAllowed(_safe);

Parameters

NameTypeDescription
_srcaddressAddress of the src handler
_safeuint256Id of the SAFE

moveSAFE

Move a position from safeSrc handler to the safeDst handler

function moveSAFE(uint256 _safeSrc, uint256 _safeDst) external safeAllowed(_safeSrc) safeAllowed(_safeDst);

Parameters

NameTypeDescription
_safeSrcuint256Id of the source SAFE
_safeDstuint256Id of the destination SAFE

addSAFE

Add a safe to the user's list of safes (doesn't set safe ownership)

This function is meant to allow the user to add a safe to their list (if it was previously removed)

function addSAFE(uint256 _safe) external;

Parameters

NameTypeDescription
_safeuint256Id of the SAFE

removeSAFE

Remove a safe from the user's list of safes (doesn't erase safe ownership)

This function is meant to allow the user to remove a safe from their list (if it was added against their will)

function removeSAFE(uint256 _safe) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE

protectSAFE

Choose a safe saviour inside LiquidationEngine for the SAFE

function protectSAFE(uint256 _safe, address _liquidationEngine, address _saviour) external safeAllowed(_safe);

Parameters

NameTypeDescription
_safeuint256Id of the SAFE
_liquidationEngineaddressAddress of the LiquidationEngine
_saviouraddressAddress of the saviour