contract KeepCreator is CloneFactory {
    // Holds the address of the keep contract that will be used as a master
    // contract for cloning.
    address public masterKeepAddress;

    // Keeps created by this factory.
    address[] public keeps;

    // Maps keep opened timestamp to each keep address
    mapping(address => uint256) keepOpenedTimestamp;

    constructor(address _masterKeepAddress) public {
        masterKeepAddress = _masterKeepAddress;
    }

    /// @notice Gets how many keeps have been opened by this contract.
    /// @dev    Checks the size of the keeps array.
    /// @return The number of keeps opened so far.
    function getKeepCount() external view returns (uint256) {
        return keeps.length;
    }

    /// @notice Gets a specific keep address at a given index.
    /// @return The address of the keep at the given index.
    function getKeepAtIndex(uint256 index) external view returns (address) {
        require(index < keeps.length, "Out of bounds.");
        return keeps[index];
    }

    /// @notice Gets the opened timestamp of the given keep.
    /// @return Timestamp the given keep was opened at or 0 if this keep
    /// was not created by this factory.
    function getKeepOpenedTimestamp(address _keep)
        external
        view
        returns (uint256)
    {
        return keepOpenedTimestamp[_keep];
    }

    /// @notice Creates a new keep instance with a clone factory.
    /// @dev It has to be called by a function implementing a keep opening mechanism.
    function createKeep() internal returns (address keepAddress) {
        keepAddress = createClone(masterKeepAddress);
        keeps.push(keepAddress);

        /* solium-disable-next-line security/no-block-members*/
        keepOpenedTimestamp[keepAddress] = block.timestamp;
    }
}
function getKeepOpenedTimestamp(address _keep)
    external
    view
    returns (uint256)
{
    return keepOpenedTimestamp[_keep];
}

/// @notice Gets the opened timestamp of the given keep.
/// @return Timestamp the given keep was opened at or 0 if this keep
/// was not created by this factory.