SAFE Manager
A central hub for all SAFEs
Smart contract code: GebSafeManager
1. Summary
The SAFE Manager is an abstraction around the SAFEEngine that allows anyone to easily manage their GEB positions.
2. Contract Variables & Functions
Variables
safeEngine- the address of theSAFEEnginesafei- auto incrementing noncecdps[safeId: uint256]- mapping between SAFE ids and SAFEcdpList[safeId: uint256]- double linked list indicating the previous and next SAFE ids of a provided SAFEownsCDP[cdpId: uint256]- indicates the owner of a SAFEcollateralTypes[cdpId: uint256]- the collateral type backing the SAFE with idsafeIdfirstSAFEID[owner: address]- the firstsafeIdof an ownerlastSAFEID[owner: address]- the lastsafeIdor an ownersafeCount[owner: address]- the amount of SAFEs and address hassafeCan[owner: address,safeId: uint256,allowedAddr: address]- whether an address is allowed to interact with a SAFEhandlerCan[safeHandler: address,allowedAddr: address]- whether an address is allowed to interact with a SAFE's handler
Data Structures
List- a struct containing the previous and the next SAFE ids of a specific SAFE. Contains:prev- the previous SAFE idnext- the next SAFE id
Functions
allowSAFE(safe: uint256,usr: address,ok: uint256)- allow an address to interact with a SAFE with a specific idallowHandler(usr: address,ok: uint256)- allow an address to interact with a SAFE handleropenSAFE(collateralType: bytes32,usr: address)- create a new SAFE id and handlertransferSAFEOwnership(safe: uint256,dst: address)- transfer a SAFE to another addressmodifySAFECollateralization(safe: uint256,deltaCollateral: int256,deltaDebt:int256)- add/remove collateral to and from a SAFE or generate/repay debttransferCollateral(safe: uint256,dst: address,wad: uint256)- transfer collateral from a SAFE to another addresstransferInternalCoins(safe: uint256,dst: address,rad: uint256)- transferSAFEEngine.coinBalancesystem coins between addressesquitSystem(safe: uint256,dst: address)- migrate the SAFE to a destination addressenterSystem(safe: address,src: uint256)- import a SAFE to the handler owned by an addressmoveSAFE(safeSrc: uint256,safeDst: uint256)- move a position between SAFE handlersprotectSAFE(safe: uint256,liquidationEngine: address,saviour: address)- choose aSAFESaviourfor a SAFE
Events
AllowSAFE- emitted whenallowSafeis called. Contains:sender- themsg.sendersafe- the SAFE idusr- the address of the user that is allowed/forbidden from managing the SAFEok- whether theusris allowed or not to manage the SAFE
AllowHandler- emitted whenallowHandleris called. Contains:sender- themsg.senderusr- the handlerok- whether it is allowed or not
TransferSAFEOwnership- emitted whentransferSAFEOwnershipis called. Contains:sender- themsg.sendersafe- the SAFE iddst- the new owner
OpenSAFE- emitted when a new SAFE is created usingopenSAFE. Contains:sender- themsg.senderown- the SAFE ownersafe- SAFE id
ModifySAFECollateralization- emitted whenmodifySAFECollateralizationis called. Contains:sender- themsg.sendersafe- the SAFE iddeltaCollateral- the amount of collateral to add/removedeltaDebt- the amount of debt to repay/withdraw
TransferCollateral- emitted whentransferCollateralis called. Contains:sender- themsg.sendersafe- the SAFE iddst- the destination SAFE idwad- amount of collateral to transfer
TransferInternalCoins- emitted whentransferInternalCoinsis called. Contains:sender- themsg.sendersafe- the SAFE iddst- destination for internal coinsrad- amount of internal coins to transfer
QuitSystem- emitted whenquitSystemis called. Contains:sender- themsg.sendersafe- the SAFE iddst- the destination handler for the SAFE
EnterSystem- emitted whenenterSystemis called. Contains:sender- themsg.sendersrc- the source handler for the SAFEsafe- the SAFE id
MoveSAFE- emitted whenmoveSAFEis called. Contains:safe- the SAFE idsafeSrc- the source ID that has the current handler controlling the SAFEsafeDst- the destination SAFE id that has the handler which will control thesafefrom now on
ProtectSAFE- emitted whenprotectSAFEis called. Contains:sender- themsg.sendersafe- the SAFE idliquidationEngine- theLiquidationEnginewheresaviouris and that can liquidatesafesaviour- the saviour that will protect the SAFE
3. Risks
When openSAFE is executed, a new safeHandler is created and a safeId is assigned to it for a specific owner. If the user calls CollateralJoin.join to add collateral to the safeHandler immediately after the SAFE creation transaction is mined, there is a chance that a chain reorg occurs. This would result in the user losing the ownership of the safeHandler and therefore lose their collateral. Users can avoid this issue when using proxy actions.
Last updated