/* Copyright 2021 Set Labs Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. SPDX-License-Identifier: Apache License, Version 2.0 */ pragma solidity 0.6.10; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IController } from "../../interfaces/IController.sol"; import { ISetToken } from "../../interfaces/ISetToken.sol"; /** * @title SetTokenAccessible * @author Set Protocol * * Abstract class that houses permissioning of module for SetTokens. */ abstract contract SetTokenAccessible is Ownable { /* ============ Events ============ */ /** * @dev Emitted on updateAllowedSetToken() * @param _setToken SetToken being whose allowance to initialize this module is being updated * @param _added true if added false if removed */ event SetTokenStatusUpdated( ISetToken indexed _setToken, bool indexed _added ); /** * @dev Emitted on updateAnySetAllowed() * @param _anySetAllowed true if any set is allowed to initialize this module, false otherwise */ event AnySetAllowedUpdated( bool indexed _anySetAllowed ); /* ============ Modifiers ============ */ // @dev If anySetAllowed is true or _setToken is registered in allowedSetTokens, modifier succeeds. // Reverts otherwise. modifier onlyAllowedSet(ISetToken _setToken) { if (!anySetAllowed) { require(allowedSetTokens[_setToken], "Not allowed SetToken"); } _; } /* ============ State Variables ============ */ // Address of the controller IController private controller; // Mapping of SetToken to boolean indicating if SetToken is on allow list. Updateable by governance mapping(ISetToken => bool) public allowedSetTokens; // Boolean that returns if any SetToken can initialize this module. If false, then subject to allow list. // Updateable by governance. bool public anySetAllowed; /* ============ Constructor ============ */ /** * Set controller state variable * * @param _controller Address of controller contract */ constructor(IController _controller) public { controller = _controller; } /* ============ External Functions ============ */ /** * @dev GOVERNANCE ONLY: Enable/disable ability of a SetToken to initialize this module. * * @param _setToken Instance of the SetToken * @param _status Bool indicating if _setToken is allowed to initialize this module */ function updateAllowedSetToken(ISetToken _setToken, bool _status) public onlyOwner { require(controller.isSet(address(_setToken)) || allowedSetTokens[_setToken], "Invalid SetToken"); allowedSetTokens[_setToken] = _status; emit SetTokenStatusUpdated(_setToken, _status); } /** * @dev GOVERNANCE ONLY: Toggle whether ANY SetToken is allowed to initialize this module. * * @param _anySetAllowed Bool indicating if ANY SetToken is allowed to initialize this module */ function updateAnySetAllowed(bool _anySetAllowed) public onlyOwner { anySetAllowed = _anySetAllowed; emit AnySetAllowedUpdated(_anySetAllowed); } }