HaiSafeManager
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) internal _usrSafes;
_usrSafesPerCollat
Mapping of user addresses to their enumerable set of safes per collateral type
mapping(address _safeOwner => mapping(bytes32 _cType => EnumerableSet.UintSet)) internal _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 => bool _ok))) public safeCan;
handlerCan
Mapping of handler to a caller permissions
mapping(address _safeHandler => mapping(address _caller => bool _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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id 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
Name | Type | Description |
---|---|---|
_handler | address | Address of the handler to check if msg.sender has permissions for |
constructor
constructor(address _safeEngine);
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address 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
Name | Type | Description |
---|---|---|
_usr | address | Address of the user |
Returns
Name | Type | Description |
---|---|---|
_safes | uint256[] | 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
Name | Type | Description |
---|---|---|
_usr | address | Address of the user |
_cType | bytes32 |
Returns
Name | Type | Description |
---|---|---|
_safes | uint256[] | 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
Name | Type | Description |
---|---|---|
_usr | address | Address of the user |
Returns
Name | Type | Description |
---|---|---|
_safes | uint256[] | List of safe ids owned by the user |
_safeHandlers | address[] | List of safe handlers addresses owned by the user |
_cTypes | bytes32[] | 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
Returns
Name | Type | Description |
---|---|---|
_sData | SAFEData | Struct with the safe data |
allowSAFE
Allow/disallow a user address to manage the safe
function allowSAFE(uint256 _safe, address _usr, bool _ok) external safeAllowed(_safe);
Parameters
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_usr | address | Address of the user to allow/disallow |
_ok | bool | Boolean state to allow/disallow |
allowHandler
Allow/disallow a handler address to manage the safe
function allowHandler(address _usr, bool _ok) external;
Parameters
Name | Type | Description |
---|---|---|
_usr | address | Address of the user to allow/disallow |
_ok | bool | Boolean state to allow/disallow |
openSAFE
Open a new safe for a user address
function openSAFE(bytes32 _cType, address _usr) external returns (uint256 _id);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_usr | address | Address of the user to open the safe for |
Returns
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the new SAFE |
transferSAFEOwnership
Initiate the transfer of the ownership of a safe to a dst address
function transferSAFEOwnership(uint256 _safe, address _dst) external safeAllowed(_safe);
Parameters
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_dst | address | Address of the dst address |
acceptSAFEOwnership
Accept the transfer of the ownership of a safe
function acceptSAFEOwnership(uint256 _safe) external;
Parameters
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_deltaCollateral | int256 | Delta of collateral to add/remove [wad] |
_deltaDebt | int256 | Delta 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_dst | address | Address of the dst address |
_wad | uint256 | Amount 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | |
_safe | uint256 | Id of the SAFE |
_dst | address | Address of the dst address |
_wad | uint256 | Amount 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_dst | address | Address of the dst address |
_rad | uint256 | Amount 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_dst | address | Address 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
Name | Type | Description |
---|---|---|
_src | address | Address of the src handler |
_safe | uint256 | Id 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
Name | Type | Description |
---|---|---|
_safeSrc | uint256 | Id of the source SAFE |
_safeDst | uint256 | Id 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id 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
Name | Type | Description |
---|---|---|
_safe | uint256 | Id of the SAFE |
_liquidationEngine | address | Address of the LiquidationEngine |
_saviour | address | Address of the saviour |