all files / contracts/risk/ RiskStrategyFactory.sol

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                                                    22× 21×                                                                                                                    
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.6;
 
import "../utils/Governable.sol";
import "../utils/Factory.sol";
import "./RiskStrategy.sol";
import "./RiskManager.sol";
import "../interfaces/risk/IRiskStrategyFactory.sol";
 
/**
 * @title RiskStrategyFactory
 * @author solace.fi
 * @notice The **RiskStrategyFactory** manages the creation of new products.
 */
contract RiskStrategyFactory is Factory, IRiskStrategyFactory, Governable {
 
    /// @notice `Registry` contract.
    /// @dev It is immutable for gas savings.
    IRegistry internal immutable _registry;
 
    /**
     * @notice Constructs the `RiskStrategyFactory` contract.
     * @param governance_ The address of the [governor](/docs/protocol/governance).
     * @param registry_ Address of registry.
     */
    constructor(address registry_, address governance_) Governable(governance_) {
        require(registry_ != address(0x0), "zero address registry");
        _registry = IRegistry(registry_);
    }
 
    /**
     * @notice Creates a new `Risk Strategy`.
     * @param base_ The strategy's source code.
     * @param products_ The strategy products.
     * @param weights_  The weights of the strategy products.
     * @param prices_   The prices of the strategy products.
     * @param divisors_ The divisors(max cover per policy divisor) of the strategy products. 
     * @return strategy The address of newly created strategy.
    */
    function createRiskStrategy(
        address base_,
        address[] memory products_, 
        uint32[] memory weights_, 
        uint24[] memory prices_,
        uint16[] memory divisors_
    ) external override returns (address strategy) {
        strategy = _deployMinimalProxy(base_);
        RiskStrategy(strategy).initialize(
            this.governance(),
            _registry.get("riskManager"),
            msg.sender,
            products_,
            weights_,
            prices_,
            divisors_
        );
        emit StrategyCreated(strategy, msg.sender);
        return strategy;
   
    }
 
    /**
     * @notice Creates a new `Risk Strategy`.
     * @param base_  The strategy's source code.
     * @param salt_ The salt for CREATE2.
     * @param products_ The strategy products.
     * @param weights_  The weights of the strategy products.
     * @param prices_   The prices of the strategy products.
     * @param divisors_ The divisors(max cover per policy divisor) of the strategy products. 
     * @return strategy The address of newly created strategy.
    */
    function create2RiskStrategy(
        address base_,
        bytes32 salt_,
        address[] memory products_, 
        uint32[] memory weights_, 
        uint24[] memory prices_,
        uint16[] memory divisors_
    ) external override returns (address strategy) {
        strategy = _deployMinimalProxy(base_, salt_);                                                                                                                
        RiskStrategy(strategy).initialize(
            this.governance(),
            _registry.get("riskManager"),
            msg.sender,
            products_,
            weights_,
            prices_,
            divisors_
        );
        emit StrategyCreated(strategy, msg.sender);
        return strategy;
    }
}