Safety Module Deposits

Assets deposited into a Safety Module are available to payout handlers for slashing if the Safety Module is triggered (see Safety Module Slashing). In return, depositors are minted receipt tokens which may be used to earn rewards (see Stake into a Rewards Manager) and withdraw their assets.

To deposit assets, SafetyModule.depositReserveAssets or SafetyModule.depositReserveAssetsWithoutTransfer can be used:

/// @notice Deposits reserve assets into the SafetyModule and mints deposit receipt tokens.
/// @dev Expects `msg.sender` to have approved this SafetyModule for `reserveAssetAmount_` of
/// `reservePools[reservePoolId_].asset` so it can `transferFrom` the assets to this SafetyModule.
/// @param reservePoolId_ The ID of the reserve pool to deposit assets into.
/// @param reserveAssetAmount_ The amount of reserve assets to deposit.
/// @param receiver_ The address to receive the deposit receipt tokens.
function depositReserveAssets(uint8 reservePoolId_, uint256 reserveAssetAmount_, address receiver_)
    external
    returns (uint256 depositReceiptTokenAmount_);
    
/// @notice Deposits reserve assets into the SafetyModule and mints deposit receipt tokens.
/// @dev Expects depositer to transfer assets to the SafetyModule beforehand.
/// @param reservePoolId_ The ID of the reserve pool to deposit assets into.
/// @param reserveAssetAmount_ The amount of reserve assets to deposit.
/// @param receiver_ The address to receive the deposit receipt tokens.
function depositReserveAssetsWithoutTransfer(uint8 reservePoolId_, uint256 reserveAssetAmount_, address receiver_)
    external
    returns (uint256 depositReceiptTokenAmount_);

SafetyModule.depositReserveAssets requires msg.sender to have approved SafetyModule to a spend sufficient amount of their SafetyModule.reservePools(reservePoolId).asset balance.

SafetyModule.depositReserveAssetsWithoutTransfer requires the SafetyModule.reservePools(reservePoolId).asset amount being deposited to be transferred to the Safety Module beforehand.

Using CozyRouter to deposit assets

Using the CozyRouter may be preferable in cases where integrators would like to batch several Safety Module related function calls into a single transaction (e.g. wrap ETH to WETH and deposit).

To deposit assets using the CozyRouter, integrators can use CozyRouter.depositReserveAssets:

/// @notice Deposits assets into a `safetyModule_` reserve pool. Mints `depositReceiptTokenAmount_` to `receiver_` by
/// depositing exactly `reserveAssetAmount_` of the reserve pool's underlying tokens into the `safetyModule_`. The
/// specified amount of assets are transferred from the caller to the Safety Module.
/// @dev The CozyRouter must be approved to spend the underlying asset of the reserve pool.
function depositReserveAssets(
    ISafetyModule safetyModule_,
    uint8 reservePoolId_,
    uint256 reserveAssetAmount_,
    address receiver_
) public payable returns (uint256 depositReceiptTokenAmount_);

This method will:

  • Transfer the underlying reserve assets from the msg.sender to the Safety Module.

  • Call SafetyModule.depositReserveAssetsWithoutTransfer.

CozyRouter.depositReserveAssets requires the depositor to have approved CozyRouter to a spend sufficient amount of their SafetyModule.reservePools(reservePoolId).asset balance.

Deposit mechanics

On deposit, high-level the Safety Module does the following:

  • Check if the Safety Module is PAUSED. If so, revert.

  • Check the Safety Module's asset balance to determine if the total deposit amount was transferred to it. If not, revert.

  • Update the relevant reserve pool's internal accounting.

  • Mint the receiver_ address deposit receipt tokens.

  • Emit a Deposited event.

Last updated