|
{
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"contracts/factories/DelegatedManagerFactory.sol": {
|
|
"content": "/*\n Copyright 2022 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\npragma experimental ABIEncoderV2;\n\nimport { Address } from \"@openzeppelin/contracts/utils/Address.sol\";\nimport { ISetToken } from \"@setprotocol/set-protocol-v2/contracts/interfaces/ISetToken.sol\";\n\nimport { AddressArrayUtils } from \"../lib/AddressArrayUtils.sol\";\nimport { DelegatedManager } from \"../manager/DelegatedManager.sol\";\nimport { IController } from \"../interfaces/IController.sol\";\nimport { IDelegatedManager } from \"../interfaces/IDelegatedManager.sol\";\nimport { IManagerCore } from \"../interfaces/IManagerCore.sol\";\nimport { ISetTokenCreator } from \"../interfaces/ISetTokenCreator.sol\";\n\n/**\n * @title DelegatedManagerFactory\n * @author Set Protocol\n *\n * Factory smart contract which gives asset managers the ability to:\n * > create a Set Token managed with a DelegatedManager contract\n * > create a DelegatedManager contract for an existing Set Token to migrate to\n * > initialize extensions and modules for SetTokens using the DelegatedManager system\n */\ncontract DelegatedManagerFactory {\n using AddressArrayUtils for address[];\n using Address for address;\n\n /* ============ Structs ============ */\n\n struct InitializeParams{\n address deployer;\n address owner;\n address methodologist;\n IDelegatedManager manager;\n bool isPending;\n }\n\n /* ============ Events ============ */\n\n /**\n * @dev Emitted on DelegatedManager creation\n * @param _setToken Instance of the SetToken being created\n * @param _manager Address of the DelegatedManager\n * @param _deployer Address of the deployer\n */\n event DelegatedManagerCreated(\n ISetToken indexed _setToken,\n DelegatedManager indexed _manager,\n address _deployer\n );\n\n /**\n * @dev Emitted on DelegatedManager initialization\n * @param _setToken Instance of the SetToken being initialized\n * @param _manager Address of the DelegatedManager owner\n */\n event DelegatedManagerInitialized(\n ISetToken indexed _setToken,\n IDelegatedManager indexed _manager\n );\n\n /* ============ State Variables ============ */\n\n // ManagerCore address\n IManagerCore public immutable managerCore;\n\n // Controller address\n IController public immutable controller;\n\n // SetTokenFactory address\n ISetTokenCreator public immutable setTokenFactory;\n\n // Mapping which stores manager creation metadata between creation and initialization steps\n mapping(ISetToken=>InitializeParams) public initializeState;\n\n /* ============ Constructor ============ */\n\n /**\n * @dev Sets managerCore and setTokenFactory address.\n * @param _managerCore Address of ManagerCore protocol contract\n * @param _controller Address of Controller protocol contract\n * @param _setTokenFactory Address of SetTokenFactory protocol contract\n */\n constructor(\n IManagerCore _managerCore,\n IController _controller,\n ISetTokenCreator _setTokenFactory\n )\n public\n {\n managerCore = _managerCore;\n controller = _controller;\n setTokenFactory = _setTokenFactory;\n }\n\n /* ============ External Functions ============ */\n\n /**\n * ANYONE CAN CALL: Deploys a new SetToken and DelegatedManager. Sets some temporary metadata about\n * the deployment which will be read during a subsequent intialization step which wires everything\n * together.\n *\n * @param _components List of addresses of components for initial Positions\n * @param _units List of units. Each unit is the # of components per 10^18 of a SetToken\n * @param _name Name of the SetToken\n * @param _symbol Symbol of the SetToken\n * @param _owner Address to set as the DelegateManager's `owner` role\n * @param _methodologist Address to set as the DelegateManager's methodologist role\n * @param _modules List of modules to enable. All modules must be approved by the Controller\n * @param _operators List of operators authorized for the DelegateManager\n * @param _assets List of assets DelegateManager can trade. When empty, asset allow list is not enforced\n * @param _extensions List of extensions authorized for the DelegateManager\n *\n * @return (ISetToken, address) The created SetToken and DelegatedManager addresses, respectively\n */\n function createSetAndManager(\n address[] memory _components,\n int256[] memory _units,\n string memory _name,\n string memory _symbol,\n address _owner,\n address _methodologist,\n address[] memory _modules,\n address[] memory _operators,\n address[] memory _assets,\n address[] memory _extensions\n )\n external\n returns (ISetToken, address)\n {\n _validateManagerParameters(_components, _extensions, _assets);\n\n ISetToken setToken = _deploySet(\n _components,\n _units,\n _modules,\n _name,\n _symbol\n );\n\n DelegatedManager manager = _deployManager(\n setToken,\n _extensions,\n _operators,\n _assets\n );\n\n _setInitializationState(setToken, address(manager), _owner, _methodologist);\n\n return (setToken, address(manager));\n }\n\n /**\n * ONLY SETTOKEN MANAGER: Deploys a DelegatedManager and sets some temporary metadata about the\n * deployment which will be read during a subsequent intialization step which wires everything together.\n * This method is used when migrating an existing SetToken to the DelegatedManager system.\n *\n * (Note: This flow should work well for SetTokens managed by an EOA. However, existing\n * contract-managed Sets may need to have their ownership temporarily transferred to an EOA when\n * migrating. We don't anticipate high demand for this migration case though.)\n *\n * @param _setToken Instance of SetToken to migrate to the DelegatedManager system\n * @param _owner Address to set as the DelegateManager's `owner` role\n * @param _methodologist Address to set as the DelegateManager's methodologist role\n * @param _operators List of operators authorized for the DelegateManager\n * @param _assets List of assets DelegateManager can trade. When empty, asset allow list is not enforced\n * @param _extensions List of extensions authorized for the DelegateManager\n *\n * @return (address) Address of the created DelegatedManager\n */\n function createManager(\n ISetToken _setToken,\n address _owner,\n address _methodologist,\n address[] memory _operators,\n address[] memory _assets,\n address[] memory _extensions\n )\n external\n returns (address)\n {\n require(controller.isSet(address(_setToken)), \"Must be controller-enabled SetToken\");\n require(msg.sender == _setToken.manager(), \"Must be manager\");\n\n _validateManagerParameters(_setToken.getComponents(), _extensions, _assets);\n\n DelegatedManager manager = _deployManager(\n _setToken,\n _extensions,\n _operators,\n _assets\n );\n\n _setInitializationState(_setToken, address(manager), _owner, _methodologist);\n\n return address(manager);\n }\n\n /**\n * ONLY DEPLOYER: Wires SetToken, DelegatedManager, global manager extensions, and modules together\n * into a functioning package.\n *\n * NOTE: When migrating to this manager system from an existing SetToken, the SetToken's current manager address\n * must be reset to point at the newly deployed DelegatedManager contract in a separate, final transaction.\n *\n * @param _setToken Instance of the SetToken\n * @param _ownerFeeSplit Percent of fees in precise units (10^16 = 1%) sent to owner, rest to methodologist\n * @param _ownerFeeRecipient Address which receives owner's share of fees when they're distributed\n * @param _extensions List of addresses of extensions which need to be initialized\n * @param _initializeBytecode List of bytecode encoded calls to relevant target's initialize function\n */\n function initialize(\n ISetToken _setToken,\n uint256 _ownerFeeSplit,\n address _ownerFeeRecipient,\n address[] memory _extensions,\n bytes[] memory _initializeBytecode\n )\n external\n {\n require(initializeState[_setToken].isPending, \"Manager must be awaiting initialization\");\n require(msg.sender == initializeState[_setToken].deployer, \"Only deployer can initialize manager\");\n _extensions.validatePairsWithArray(_initializeBytecode);\n\n IDelegatedManager manager = initializeState[_setToken].manager;\n\n // If the SetToken was factory-deployed & factory is its current `manager`, transfer\n // managership to the new DelegatedManager\n if (_setToken.manager() == address(this)) {\n _setToken.setManager(address(manager));\n }\n\n _initializeExtensions(manager, _extensions, _initializeBytecode);\n\n _setManagerState(\n manager,\n initializeState[_setToken].owner,\n initializeState[_setToken].methodologist,\n _ownerFeeSplit,\n _ownerFeeRecipient\n );\n\n delete initializeState[_setToken];\n\n emit DelegatedManagerInitialized(_setToken, manager);\n }\n\n /* ============ Internal Functions ============ */\n\n /**\n * Deploys a SetToken, setting this factory as its manager temporarily, pending initialization.\n * Managership is transferred to a newly created DelegatedManager during `initialize`\n *\n * @param _components List of addresses of components for initial Positions\n * @param _units List of units. Each unit is the # of components per 10^18 of a SetToken\n * @param _modules List of modules to enable. All modules must be approved by the Controller\n * @param _name Name of the SetToken\n * @param _symbol Symbol of the SetToken\n *\n * @return Address of created SetToken;\n */\n function _deploySet(\n address[] memory _components,\n int256[] memory _units,\n address[] memory _modules,\n string memory _name,\n string memory _symbol\n )\n internal\n returns (ISetToken)\n {\n address setToken = setTokenFactory.create(\n _components,\n _units,\n _modules,\n address(this),\n _name,\n _symbol\n );\n\n return ISetToken(setToken);\n }\n\n /**\n * Deploys a DelegatedManager. Sets owner and methodologist roles to address(this) and the resulting manager address is\n * saved to the ManagerCore.\n *\n * @param _setToken Instance of SetToken to migrate to the DelegatedManager system\n * @param _extensions List of extensions authorized for the DelegateManager\n * @param _operators List of operators authorized for the DelegateManager\n * @param _assets List of assets DelegateManager can trade. When empty, asset allow list is not enforced\n *\n * @return Address of created DelegatedManager\n */\n function _deployManager(\n ISetToken _setToken,\n address[] memory _extensions,\n address[] memory _operators,\n address[] memory _assets\n )\n internal\n returns (DelegatedManager)\n {\n // If asset array is empty, manager's useAssetAllowList will be set to false\n // and the asset allow list is not enforced\n bool useAssetAllowlist = _assets.length > 0;\n\n DelegatedManager newManager = new DelegatedManager(\n _setToken,\n address(this),\n address(this),\n _extensions,\n _operators,\n _assets,\n useAssetAllowlist\n );\n\n // Registers manager with ManagerCore\n managerCore.addManager(address(newManager));\n\n emit DelegatedManagerCreated(\n _setToken,\n newManager,\n msg.sender\n );\n\n return newManager;\n }\n\n /**\n * Initialize extensions on the DelegatedManager. Checks that extensions are tracked on the ManagerCore and that the\n * provided bytecode targets the input manager.\n *\n * @param _manager Instance of DelegatedManager\n * @param _extensions List of addresses of extensions to initialize\n * @param _initializeBytecode List of bytecode encoded calls to relevant extensions's initialize function\n */\n function _initializeExtensions(\n IDelegatedManager _manager,\n address[] memory _extensions,\n bytes[] memory _initializeBytecode\n ) internal {\n for (uint256 i = 0; i < _extensions.length; i++) {\n address extension = _extensions[i];\n require(managerCore.isExtension(extension), \"Target must be ManagerCore-enabled Extension\");\n\n bytes memory initializeBytecode = _initializeBytecode[i];\n\n // Each input initializeBytecode is a varible length bytes array which consists of a 32 byte prefix for the\n // length parameter, a 4 byte function selector, a 32 byte DelegatedManager address, and any additional parameters\n // as shown below:\n // [32 bytes - length parameter, 4 bytes - function selector, 32 bytes - DelegatedManager address, additional parameters]\n // It is required that the input DelegatedManager address is the DelegatedManager address corresponding to the caller\n address inputManager;\n assembly {\n inputManager := mload(add(initializeBytecode, 36))\n }\n require(inputManager == address(_manager), \"Must target correct DelegatedManager\");\n\n // Because we validate uniqueness of _extensions only one transaction can be sent to each extension during this\n // transaction. Due to this no extension can be used for any SetToken transactions other than initializing these contracts\n extension.functionCallWithValue(initializeBytecode, 0);\n }\n }\n\n /**\n * Stores temporary creation metadata during the contract creation step. Data is retrieved, read and\n * finally deleted during `initialize`.\n *\n * @param _setToken Instance of SetToken\n * @param _manager Address of DelegatedManager created for SetToken\n * @param _owner Address that will be given the `owner` DelegatedManager's role on initialization\n * @param _methodologist Address that will be given the `methodologist` DelegatedManager's role on initialization\n */\n function _setInitializationState(\n ISetToken _setToken,\n address _manager,\n address _owner,\n address _methodologist\n ) internal {\n initializeState[_setToken] = InitializeParams({\n deployer: msg.sender,\n owner: _owner,\n methodologist: _methodologist,\n manager: IDelegatedManager(_manager),\n isPending: true\n });\n }\n\n /**\n * Initialize fee settings on DelegatedManager and transfer `owner` and `methodologist` roles.\n *\n * @param _manager Instance of DelegatedManager\n * @param _owner Address that will be given the `owner` DelegatedManager's role\n * @param _methodologist Address that will be given the `methodologist` DelegatedManager's role\n * @param _ownerFeeSplit Percent of fees in precise units (10^16 = 1%) sent to owner, rest to methodologist\n * @param _ownerFeeRecipient Address which receives owner's share of fees when they're distributed\n */\n function _setManagerState(\n IDelegatedManager _manager,\n address _owner,\n address _methodologist,\n uint256 _ownerFeeSplit,\n address _ownerFeeRecipient\n ) internal {\n _manager.updateOwnerFeeSplit(_ownerFeeSplit);\n _manager.updateOwnerFeeRecipient(_ownerFeeRecipient);\n\n _manager.transferOwnership(_owner);\n _manager.setMethodologist(_methodologist);\n }\n\n /**\n * Validates that all components currently held by the Set are on the asset allow list. Validate that the manager is\n * deployed with at least one extension in the PENDING state.\n *\n * @param _components List of addresses of components for initial/current Set positions\n * @param _extensions List of extensions authorized for the DelegateManager\n * @param _assets List of assets DelegateManager can trade. When empty, asset allow list is not enforced\n */\n function _validateManagerParameters(\n address[] memory _components,\n address[] memory _extensions,\n address[] memory _assets\n )\n internal\n pure\n {\n require(_extensions.length > 0, \"Must have at least 1 extension\");\n\n if (_assets.length != 0) {\n _validateComponentsIncludedInAssetsList(_components, _assets);\n }\n }\n\n /**\n * Validates that all SetToken components are included in the assets whitelist. This prevents the\n * DelegatedManager from being initialized with some components in an untrade-able state.\n *\n * @param _components List of addresses of components for initial Positions\n * @param _assets List of assets DelegateManager can trade.\n */\n function _validateComponentsIncludedInAssetsList(\n address[] memory _components,\n address[] memory _assets\n ) internal pure {\n for (uint256 i = 0; i < _components.length; i++) {\n require(_assets.contains(_components[i]), \"Asset list must include all components\");\n }\n }\n}"
|
|
},
|
|
"@openzeppelin/contracts/utils/Address.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.2 <0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n // solhint-disable-next-line no-inline-assembly\n assembly { size := extcodesize(account) }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n (bool success, ) = recipient.call{ value: amount }(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain`call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.staticcall(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n // solhint-disable-next-line no-inline-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
|
|
},
|
|
"@setprotocol/set-protocol-v2/contracts/interfaces/ISetToken.sol": {
|
|
"content": "/*\n Copyright 2020 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\npragma solidity 0.6.10;\npragma experimental \"ABIEncoderV2\";\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/**\n * @title ISetToken\n * @author Set Protocol\n *\n * Interface for operating with SetTokens.\n */\ninterface ISetToken is IERC20 {\n\n /* ============ Enums ============ */\n\n enum ModuleState {\n NONE,\n PENDING,\n INITIALIZED\n }\n\n /* ============ Structs ============ */\n /**\n * The base definition of a SetToken Position\n *\n * @param component Address of token in the Position\n * @param module If not in default state, the address of associated module\n * @param unit Each unit is the # of components per 10^18 of a SetToken\n * @param positionState Position ENUM. Default is 0; External is 1\n * @param data Arbitrary data\n */\n struct Position {\n address component;\n address module;\n int256 unit;\n uint8 positionState;\n bytes data;\n }\n\n /**\n * A struct that stores a component's cash position details and external positions\n * This data structure allows O(1) access to a component's cash position units and \n * virtual units.\n *\n * @param virtualUnit Virtual value of a component's DEFAULT position. Stored as virtual for efficiency\n * updating all units at once via the position multiplier. Virtual units are achieved\n * by dividing a \"real\" value by the \"positionMultiplier\"\n * @param componentIndex \n * @param externalPositionModules List of external modules attached to each external position. Each module\n * maps to an external position\n * @param externalPositions Mapping of module => ExternalPosition struct for a given component\n */\n struct ComponentPosition {\n int256 virtualUnit;\n address[] externalPositionModules;\n mapping(address => ExternalPosition) externalPositions;\n }\n\n /**\n * A struct that stores a component's external position details including virtual unit and any\n * auxiliary data.\n *\n * @param virtualUnit Virtual value of a component's EXTERNAL position.\n * @param data Arbitrary data\n */\n struct ExternalPosition {\n int256 virtualUnit;\n bytes data;\n }\n\n\n /* ============ Functions ============ */\n \n function addComponent(address _component) external;\n function removeComponent(address _component) external;\n function editDefaultPositionUnit(address _component, int256 _realUnit) external;\n function addExternalPositionModule(address _component, address _positionModule) external;\n function removeExternalPositionModule(address _component, address _positionModule) external;\n function editExternalPositionUnit(address _component, address _positionModule, int256 _realUnit) external;\n function editExternalPositionData(address _component, address _positionModule, bytes calldata _data) external;\n\n function invoke(address _target, uint256 _value, bytes calldata _data) external returns(bytes memory);\n\n function editPositionMultiplier(int256 _newMultiplier) external;\n\n function mint(address _account, uint256 _quantity) external;\n function burn(address _account, uint256 _quantity) external;\n\n function lock() external;\n function unlock() external;\n\n function addModule(address _module) external;\n function removeModule(address _module) external;\n function initializeModule() external;\n\n function setManager(address _manager) external;\n\n function manager() external view returns (address);\n function moduleStates(address _module) external view returns (ModuleState);\n function getModules() external view returns (address[] memory);\n \n function getDefaultPositionRealUnit(address _component) external view returns(int256);\n function getExternalPositionRealUnit(address _component, address _positionModule) external view returns(int256);\n function getComponents() external view returns(address[] memory);\n function getExternalPositionModules(address _component) external view returns(address[] memory);\n function getExternalPositionData(address _component, address _positionModule) external view returns(bytes memory);\n function isExternalPositionModule(address _component, address _module) external view returns(bool);\n function isComponent(address _component) external view returns(bool);\n \n function positionMultiplier() external view returns (int256);\n function getPositions() external view returns (Position[] memory);\n function getTotalComponentRealUnits(address _component) external view returns(int256);\n\n function isInitializedModule(address _module) external view returns(bool);\n function isPendingModule(address _module) external view returns(bool);\n function isLocked() external view returns (bool);\n}"
|
|
},
|
|
"contracts/lib/AddressArrayUtils.sol": {
|
|
"content": "/*\n Copyright 2020 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\n\n/**\n * @title AddressArrayUtils\n * @author Set Protocol\n *\n * Utility functions to handle Address Arrays\n *\n * CHANGELOG:\n * - 4/27/21: Added validatePairsWithArray methods\n */\nlibrary AddressArrayUtils {\n\n /**\n * Finds the index of the first occurrence of the given element.\n * @param A The input array to search\n * @param a The value to find\n * @return Returns (index and isIn) for the first occurrence starting from index 0\n */\n function indexOf(address[] memory A, address a) internal pure returns (uint256, bool) {\n uint256 length = A.length;\n for (uint256 i = 0; i < length; i++) {\n if (A[i] == a) {\n return (i, true);\n }\n }\n return (uint256(-1), false);\n }\n\n /**\n * Returns true if the value is present in the list. Uses indexOf internally.\n * @param A The input array to search\n * @param a The value to find\n * @return Returns isIn for the first occurrence starting from index 0\n */\n function contains(address[] memory A, address a) internal pure returns (bool) {\n (, bool isIn) = indexOf(A, a);\n return isIn;\n }\n\n /**\n * Returns true if there are 2 elements that are the same in an array\n * @param A The input array to search\n * @return Returns boolean for the first occurrence of a duplicate\n */\n function hasDuplicate(address[] memory A) internal pure returns(bool) {\n require(A.length > 0, \"A is empty\");\n\n for (uint256 i = 0; i < A.length - 1; i++) {\n address current = A[i];\n for (uint256 j = i + 1; j < A.length; j++) {\n if (current == A[j]) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * @param A The input array to search\n * @param a The address to remove\n * @return Returns the array with the object removed.\n */\n function remove(address[] memory A, address a)\n internal\n pure\n returns (address[] memory)\n {\n (uint256 index, bool isIn) = indexOf(A, a);\n if (!isIn) {\n revert(\"Address not in array.\");\n } else {\n (address[] memory _A,) = pop(A, index);\n return _A;\n }\n }\n\n /**\n * @param A The input array to search\n * @param a The address to remove\n */\n function removeStorage(address[] storage A, address a)\n internal\n {\n (uint256 index, bool isIn) = indexOf(A, a);\n if (!isIn) {\n revert(\"Address not in array.\");\n } else {\n uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here\n if (index != lastIndex) { A[index] = A[lastIndex]; }\n A.pop();\n }\n }\n\n /**\n * Removes specified index from array\n * @param A The input array to search\n * @param index The index to remove\n * @return Returns the new array and the removed entry\n */\n function pop(address[] memory A, uint256 index)\n internal\n pure\n returns (address[] memory, address)\n {\n uint256 length = A.length;\n require(index < A.length, \"Index must be < A length\");\n address[] memory newAddresses = new address[](length - 1);\n for (uint256 i = 0; i < index; i++) {\n newAddresses[i] = A[i];\n }\n for (uint256 j = index + 1; j < length; j++) {\n newAddresses[j - 1] = A[j];\n }\n return (newAddresses, A[index]);\n }\n\n /**\n * Returns the combination of the two arrays\n * @param A The first array\n * @param B The second array\n * @return Returns A extended by B\n */\n function extend(address[] memory A, address[] memory B) internal pure returns (address[] memory) {\n uint256 aLength = A.length;\n uint256 bLength = B.length;\n address[] memory newAddresses = new address[](aLength + bLength);\n for (uint256 i = 0; i < aLength; i++) {\n newAddresses[i] = A[i];\n }\n for (uint256 j = 0; j < bLength; j++) {\n newAddresses[aLength + j] = B[j];\n }\n return newAddresses;\n }\n\n /**\n * Validate that address and uint array lengths match. Validate address array is not empty\n * and contains no duplicate elements.\n *\n * @param A Array of addresses\n * @param B Array of uint\n */\n function validatePairsWithArray(address[] memory A, uint[] memory B) internal pure {\n require(A.length == B.length, \"Array length mismatch\");\n _validateLengthAndUniqueness(A);\n }\n\n /**\n * Validate that address and bool array lengths match. Validate address array is not empty\n * and contains no duplicate elements.\n *\n * @param A Array of addresses\n * @param B Array of bool\n */\n function validatePairsWithArray(address[] memory A, bool[] memory B) internal pure {\n require(A.length == B.length, \"Array length mismatch\");\n _validateLengthAndUniqueness(A);\n }\n\n /**\n * Validate that address and string array lengths match. Validate address array is not empty\n * and contains no duplicate elements.\n *\n * @param A Array of addresses\n * @param B Array of strings\n */\n function validatePairsWithArray(address[] memory A, string[] memory B) internal pure {\n require(A.length == B.length, \"Array length mismatch\");\n _validateLengthAndUniqueness(A);\n }\n\n /**\n * Validate that address array lengths match, and calling address array are not empty\n * and contain no duplicate elements.\n *\n * @param A Array of addresses\n * @param B Array of addresses\n */\n function validatePairsWithArray(address[] memory A, address[] memory B) internal pure {\n require(A.length == B.length, \"Array length mismatch\");\n _validateLengthAndUniqueness(A);\n }\n\n /**\n * Validate that address and bytes array lengths match. Validate address array is not empty\n * and contains no duplicate elements.\n *\n * @param A Array of addresses\n * @param B Array of bytes\n */\n function validatePairsWithArray(address[] memory A, bytes[] memory B) internal pure {\n require(A.length == B.length, \"Array length mismatch\");\n _validateLengthAndUniqueness(A);\n }\n\n /**\n * Validate address array is not empty and contains no duplicate elements.\n *\n * @param A Array of addresses\n */\n function _validateLengthAndUniqueness(address[] memory A) internal pure {\n require(A.length > 0, \"Array length must be > 0\");\n require(!hasDuplicate(A), \"Cannot duplicate addresses\");\n }\n}\n"
|
|
},
|
|
"contracts/manager/DelegatedManager.sol": {
|
|
"content": "/*\n Copyright 2022 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\n\nimport { Address } from \"@openzeppelin/contracts/utils/Address.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\n\nimport { ISetToken } from \"@setprotocol/set-protocol-v2/contracts/interfaces/ISetToken.sol\";\nimport { PreciseUnitMath } from \"@setprotocol/set-protocol-v2/contracts/lib/PreciseUnitMath.sol\";\n\nimport { AddressArrayUtils } from \"../lib/AddressArrayUtils.sol\";\nimport { IGlobalExtension } from \"../interfaces/IGlobalExtension.sol\";\nimport { MutualUpgradeV2 } from \"../lib/MutualUpgradeV2.sol\";\n\n\n/**\n * @title DelegatedManager\n * @author Set Protocol\n *\n * Smart contract manager that maintains permissions and SetToken admin functionality via owner role. Owner\n * works alongside methodologist to ensure business agreements are kept. Owner is able to delegate maintenance\n * operations to operator(s). There can be more than one operator, however they have a global role so once\n * delegated to they can perform any operator delegated roles. The owner is able to set restrictions on what\n * operators can do in the form of asset whitelists. Operators cannot trade/wrap/claim/etc. an asset that is not\n * a part of the asset whitelist, hence they are a semi-trusted party. It is recommended that the owner address\n * be managed by a multi-sig or some form of permissioning system.\n */\ncontract DelegatedManager is Ownable, MutualUpgradeV2 {\n using Address for address;\n using AddressArrayUtils for address[];\n using SafeERC20 for IERC20;\n\n /* ============ Enums ============ */\n\n enum ExtensionState {\n NONE,\n PENDING,\n INITIALIZED\n }\n\n /* ============ Events ============ */\n\n event MethodologistChanged(\n address indexed _newMethodologist\n );\n\n event ExtensionAdded(\n address indexed _extension\n );\n\n event ExtensionRemoved(\n address indexed _extension\n );\n\n event ExtensionInitialized(\n address indexed _extension\n );\n\n event OperatorAdded(\n address indexed _operator\n );\n\n event OperatorRemoved(\n address indexed _operator\n );\n\n event AllowedAssetAdded(\n address indexed _asset\n );\n\n event AllowedAssetRemoved(\n address indexed _asset\n );\n\n event UseAssetAllowlistUpdated(\n bool _status\n );\n\n event OwnerFeeSplitUpdated(\n uint256 _newFeeSplit\n );\n\n event OwnerFeeRecipientUpdated(\n address indexed _newFeeRecipient\n );\n\n /* ============ Modifiers ============ */\n\n /**\n * Throws if the sender is not the SetToken methodologist\n */\n modifier onlyMethodologist() {\n require(msg.sender == methodologist, \"Must be methodologist\");\n _;\n }\n\n /**\n * Throws if the sender is not an initialized extension\n */\n modifier onlyExtension() {\n require(extensionAllowlist[msg.sender] == ExtensionState.INITIALIZED, \"Must be initialized extension\");\n _;\n }\n\n /* ============ State Variables ============ */\n\n // Instance of SetToken\n ISetToken public immutable setToken;\n\n // Address of factory contract used to deploy contract\n address public immutable factory;\n\n // Mapping to check which ExtensionState a given extension is in\n mapping(address => ExtensionState) public extensionAllowlist;\n\n // Array of initialized extensions\n address[] internal extensions;\n\n // Mapping indicating if address is an approved operator\n mapping(address=>bool) public operatorAllowlist;\n\n // List of approved operators\n address[] internal operators;\n\n // Mapping indicating if asset is approved to be traded for, wrapped into, claimed, etc.\n mapping(address=>bool) public assetAllowlist;\n\n // List of allowed assets\n address[] internal allowedAssets;\n\n // Toggle if asset allow list is being enforced\n bool public useAssetAllowlist;\n\n // Global owner fee split that can be referenced by Extensions\n uint256 public ownerFeeSplit;\n\n // Address owners portions of fees get sent to\n address public ownerFeeRecipient;\n\n // Address of methodologist which serves as providing methodology for the index and receives fee splits\n address public methodologist;\n\n /* ============ Constructor ============ */\n\n constructor(\n ISetToken _setToken,\n address _factory,\n address _methodologist,\n address[] memory _extensions,\n address[] memory _operators,\n address[] memory _allowedAssets,\n bool _useAssetAllowlist\n )\n public\n {\n setToken = _setToken;\n factory = _factory;\n methodologist = _methodologist;\n useAssetAllowlist = _useAssetAllowlist;\n emit UseAssetAllowlistUpdated(_useAssetAllowlist);\n\n _addExtensions(_extensions);\n _addOperators(_operators);\n _addAllowedAssets(_allowedAssets);\n }\n\n /* ============ External Functions ============ */\n\n /**\n * ONLY EXTENSION: Interact with a module registered on the SetToken. In order to ensure SetToken admin\n * functions can only be changed from this contract no calls to the SetToken can originate from Extensions.\n * To transfer SetTokens use the `transferTokens` function.\n *\n * @param _module Module to interact with\n * @param _data Byte data of function to call in module\n */\n function interactManager(address _module, bytes calldata _data) external onlyExtension {\n require(_module != address(setToken), \"Extensions cannot call SetToken\");\n // Invoke call to module, assume value will always be 0\n _module.functionCallWithValue(_data, 0);\n }\n\n /**\n * EXTENSION ONLY: Transfers _tokens held by the manager to _destination. Can be used to\n * distribute fees or recover anything sent here accidentally.\n *\n * @param _token ERC20 token to send\n * @param _destination Address receiving the tokens\n * @param _amount Quantity of tokens to send\n */\n function transferTokens(address _token, address _destination, uint256 _amount) external onlyExtension {\n IERC20(_token).safeTransfer(_destination, _amount);\n }\n\n /**\n * Initializes an added extension from PENDING to INITIALIZED state and adds to extension array. An\n * address can only enter a PENDING state if it is an enabled extension added by the manager. Only\n * callable by the extension itself, hence msg.sender is the subject of update.\n */\n function initializeExtension() external {\n require(extensionAllowlist[msg.sender] == ExtensionState.PENDING, \"Extension must be pending\");\n\n extensionAllowlist[msg.sender] = ExtensionState.INITIALIZED;\n extensions.push(msg.sender);\n\n emit ExtensionInitialized(msg.sender);\n }\n\n /**\n * ONLY OWNER: Add new extension(s) that the DelegatedManager can call. Puts extensions into PENDING\n * state, each must be initialized in order to be used.\n *\n * @param _extensions New extension(s) to add\n */\n function addExtensions(address[] memory _extensions) external onlyOwner {\n _addExtensions(_extensions);\n }\n\n /**\n * ONLY OWNER: Remove existing extension(s) tracked by the DelegatedManager. Removed extensions are\n * placed in NONE state.\n *\n * @param _extensions Old extension to remove\n */\n function removeExtensions(address[] memory _extensions) external onlyOwner {\n for (uint256 i = 0; i < _extensions.length; i++) {\n address extension = _extensions[i];\n\n require(extensionAllowlist[extension] == ExtensionState.INITIALIZED, \"Extension not initialized\");\n\n extensions.removeStorage(extension);\n\n extensionAllowlist[extension] = ExtensionState.NONE;\n\n IGlobalExtension(extension).removeExtension();\n\n emit ExtensionRemoved(extension);\n }\n }\n\n /**\n * ONLY OWNER: Add new operator(s) address(es)\n *\n * @param _operators New operator(s) to add\n */\n function addOperators(address[] memory _operators) external onlyOwner {\n _addOperators(_operators);\n }\n\n /**\n * ONLY OWNER: Remove operator(s) from the allowlist\n *\n * @param _operators New operator(s) to remove\n */\n function removeOperators(address[] memory _operators) external onlyOwner {\n for (uint256 i = 0; i < _operators.length; i++) {\n address operator = _operators[i];\n\n require(operatorAllowlist[operator], \"Operator not already added\");\n\n operators.removeStorage(operator);\n\n operatorAllowlist[operator] = false;\n\n emit OperatorRemoved(operator);\n }\n }\n\n /**\n * ONLY OWNER: Add new asset(s) that can be traded to, wrapped to, or claimed\n *\n * @param _assets New asset(s) to add\n */\n function addAllowedAssets(address[] memory _assets) external onlyOwner {\n _addAllowedAssets(_assets);\n }\n\n /**\n * ONLY OWNER: Remove asset(s) so that it/they can't be traded to, wrapped to, or claimed\n *\n * @param _assets Asset(s) to remove\n */\n function removeAllowedAssets(address[] memory _assets) external onlyOwner {\n for (uint256 i = 0; i < _assets.length; i++) {\n address asset = _assets[i];\n\n require(assetAllowlist[asset], \"Asset not already added\");\n\n allowedAssets.removeStorage(asset);\n\n assetAllowlist[asset] = false;\n\n emit AllowedAssetRemoved(asset);\n }\n }\n\n /**\n * ONLY OWNER: Toggle useAssetAllowlist on and off. When false asset allowlist is ignored\n * when true it is enforced.\n *\n * @param _useAssetAllowlist Bool indicating whether to use asset allow list\n */\n function updateUseAssetAllowlist(bool _useAssetAllowlist) external onlyOwner {\n useAssetAllowlist = _useAssetAllowlist;\n\n emit UseAssetAllowlistUpdated(_useAssetAllowlist);\n }\n\n /**\n * ONLY OWNER: Update percent of fees that are sent to owner\n *\n * @param _newFeeSplit Percent in precise units (100% = 10**18) of fees that accrue to owner\n */\n function updateOwnerFeeSplit(uint256 _newFeeSplit) external mutualUpgrade(owner(), methodologist) {\n require(_newFeeSplit <= PreciseUnitMath.preciseUnit(), \"Invalid fee split\");\n\n ownerFeeSplit = _newFeeSplit;\n\n emit OwnerFeeSplitUpdated(_newFeeSplit);\n }\n\n /**\n * ONLY OWNER: Update address owner receives fees at\n *\n * @param _newFeeRecipient Address to send owner fees to\n */\n function updateOwnerFeeRecipient(address _newFeeRecipient) external onlyOwner {\n require(_newFeeRecipient != address(0), \"Null address passed\");\n\n ownerFeeRecipient = _newFeeRecipient;\n\n emit OwnerFeeRecipientUpdated(_newFeeRecipient);\n }\n\n /**\n * ONLY METHODOLOGIST: Update the methodologist address\n *\n * @param _newMethodologist New methodologist address\n */\n function setMethodologist(address _newMethodologist) external onlyMethodologist {\n require(_newMethodologist != address(0), \"Null address passed\");\n\n methodologist = _newMethodologist;\n\n emit MethodologistChanged(_newMethodologist);\n }\n\n /**\n * ONLY OWNER: Update the SetToken manager address.\n *\n * @param _newManager New manager address\n */\n function setManager(address _newManager) external onlyOwner {\n require(_newManager != address(0), \"Zero address not valid\");\n require(extensions.length == 0, \"Must remove all extensions\");\n setToken.setManager(_newManager);\n }\n\n /**\n * ONLY OWNER: Add a new module to the SetToken.\n *\n * @param _module New module to add\n */\n function addModule(address _module) external onlyOwner {\n setToken.addModule(_module);\n }\n\n /**\n * ONLY OWNER: Remove a module from the SetToken.\n *\n * @param _module Module to remove\n */\n function removeModule(address _module) external onlyOwner {\n setToken.removeModule(_module);\n }\n\n /* ============ External View Functions ============ */\n\n function isAllowedAsset(address _asset) external view returns(bool) {\n return !useAssetAllowlist || assetAllowlist[_asset];\n }\n\n function isPendingExtension(address _extension) external view returns(bool) {\n return extensionAllowlist[_extension] == ExtensionState.PENDING;\n }\n\n function isInitializedExtension(address _extension) external view returns(bool) {\n return extensionAllowlist[_extension] == ExtensionState.INITIALIZED;\n }\n\n function getExtensions() external view returns(address[] memory) {\n return extensions;\n }\n\n function getOperators() external view returns(address[] memory) {\n return operators;\n }\n\n function getAllowedAssets() external view returns(address[] memory) {\n return allowedAssets;\n }\n\n /* ============ Internal Functions ============ */\n\n /**\n * Add extensions that the DelegatedManager can call.\n *\n * @param _extensions New extension to add\n */\n function _addExtensions(address[] memory _extensions) internal {\n for (uint256 i = 0; i < _extensions.length; i++) {\n address extension = _extensions[i];\n\n require(extensionAllowlist[extension] == ExtensionState.NONE , \"Extension already exists\");\n\n extensionAllowlist[extension] = ExtensionState.PENDING;\n\n emit ExtensionAdded(extension);\n }\n }\n\n /**\n * Add new operator(s) address(es)\n *\n * @param _operators New operator to add\n */\n function _addOperators(address[] memory _operators) internal {\n for (uint256 i = 0; i < _operators.length; i++) {\n address operator = _operators[i];\n\n require(!operatorAllowlist[operator], \"Operator already added\");\n\n operators.push(operator);\n\n operatorAllowlist[operator] = true;\n\n emit OperatorAdded(operator);\n }\n }\n\n /**\n * Add new assets that can be traded to, wrapped to, or claimed\n *\n * @param _assets New asset to add\n */\n function _addAllowedAssets(address[] memory _assets) internal {\n for (uint256 i = 0; i < _assets.length; i++) {\n address asset = _assets[i];\n\n require(!assetAllowlist[asset], \"Asset already added\");\n\n allowedAssets.push(asset);\n\n assetAllowlist[asset] = true;\n\n emit AllowedAssetAdded(asset);\n }\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IController.sol": {
|
|
"content": "/*\n Copyright 2020 Set Labs Inc.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n http://www.apache.org/licenses/LICENSE-2.0\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\npragma solidity 0.6.10;\n\ninterface IController {\n function addSet(address _setToken) external;\n function feeRecipient() external view returns(address);\n function getModuleFee(address _module, uint256 _feeType) external view returns(uint256);\n function isModule(address _module) external view returns(bool);\n function isSet(address _setToken) external view returns(bool);\n function isSystemContract(address _contractAddress) external view returns (bool);\n function resourceId(uint256 _id) external view returns(address);\n}\n"
|
|
},
|
|
"contracts/interfaces/IDelegatedManager.sol": {
|
|
"content": "/*\n Copyright 2021 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\npragma experimental \"ABIEncoderV2\";\n\nimport { ISetToken } from \"@setprotocol/set-protocol-v2/contracts/interfaces/ISetToken.sol\";\n\ninterface IDelegatedManager {\n function interactManager(address _module, bytes calldata _encoded) external;\n\n function initializeExtension() external;\n\n function transferTokens(address _token, address _destination, uint256 _amount) external;\n\n function updateOwnerFeeSplit(uint256 _newFeeSplit) external;\n\n function updateOwnerFeeRecipient(address _newFeeRecipient) external;\n\n function setMethodologist(address _newMethodologist) external;\n \n function transferOwnership(address _owner) external;\n\n function setToken() external view returns(ISetToken);\n function owner() external view returns(address);\n function methodologist() external view returns(address);\n function operatorAllowlist(address _operator) external view returns(bool);\n function assetAllowlist(address _asset) external view returns(bool);\n function isAllowedAsset(address _asset) external view returns(bool);\n function isPendingExtension(address _extension) external view returns(bool);\n function isInitializedExtension(address _extension) external view returns(bool);\n function getExtensions() external view returns(address[] memory);\n function getOperators() external view returns(address[] memory);\n function getAllowedAssets() external view returns(address[] memory);\n function ownerFeeRecipient() external view returns(address);\n function ownerFeeSplit() external view returns(uint256);\n}"
|
|
},
|
|
"contracts/interfaces/IManagerCore.sol": {
|
|
"content": "/*\n Copyright 2022 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\npragma solidity 0.6.10;\n\ninterface IManagerCore {\n function addManager(address _manager) external;\n function isExtension(address _extension) external view returns(bool);\n function isFactory(address _factory) external view returns(bool);\n function isManager(address _manager) external view returns(bool);\n}"
|
|
},
|
|
"contracts/interfaces/ISetTokenCreator.sol": {
|
|
"content": "/*\n Copyright 2021 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\n\ninterface ISetTokenCreator {\n function create(\n address[] memory _components,\n int256[] memory _units,\n address[] memory _modules,\n address _manager,\n string memory _name,\n string memory _symbol\n )\n external\n returns (address);\n}"
|
|
},
|
|
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/access/Ownable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../GSN/Context.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor () internal {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/token/ERC20/SafeERC20.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\nimport \"../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using SafeMath for uint256;\n using Address for address;\n\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n // solhint-disable-next-line max-line-length\n require((value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).add(value);\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) { // Return data is optional\n // solhint-disable-next-line max-line-length\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
|
|
},
|
|
"@setprotocol/set-protocol-v2/contracts/lib/PreciseUnitMath.sol": {
|
|
"content": "/*\n Copyright 2020 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\npragma experimental ABIEncoderV2;\n\nimport { SafeCast } from \"@openzeppelin/contracts/utils/SafeCast.sol\";\nimport { SafeMath } from \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport { SignedSafeMath } from \"@openzeppelin/contracts/math/SignedSafeMath.sol\";\n\n\n/**\n * @title PreciseUnitMath\n * @author Set Protocol\n *\n * Arithmetic for fixed-point numbers with 18 decimals of precision. Some functions taken from\n * dYdX's BaseMath library.\n *\n * CHANGELOG:\n * - 9/21/20: Added safePower function\n * - 4/21/21: Added approximatelyEquals function\n * - 12/13/21: Added preciseDivCeil (int overloads) function\n * - 12/13/21: Added abs function\n */\nlibrary PreciseUnitMath {\n using SafeMath for uint256;\n using SignedSafeMath for int256;\n using SafeCast for int256;\n\n // The number One in precise units.\n uint256 constant internal PRECISE_UNIT = 10 ** 18;\n int256 constant internal PRECISE_UNIT_INT = 10 ** 18;\n\n // Max unsigned integer value\n uint256 constant internal MAX_UINT_256 = type(uint256).max;\n // Max and min signed integer value\n int256 constant internal MAX_INT_256 = type(int256).max;\n int256 constant internal MIN_INT_256 = type(int256).min;\n\n /**\n * @dev Getter function since constants can't be read directly from libraries.\n */\n function preciseUnit() internal pure returns (uint256) {\n return PRECISE_UNIT;\n }\n\n /**\n * @dev Getter function since constants can't be read directly from libraries.\n */\n function preciseUnitInt() internal pure returns (int256) {\n return PRECISE_UNIT_INT;\n }\n\n /**\n * @dev Getter function since constants can't be read directly from libraries.\n */\n function maxUint256() internal pure returns (uint256) {\n return MAX_UINT_256;\n }\n\n /**\n * @dev Getter function since constants can't be read directly from libraries.\n */\n function maxInt256() internal pure returns (int256) {\n return MAX_INT_256;\n }\n\n /**\n * @dev Getter function since constants can't be read directly from libraries.\n */\n function minInt256() internal pure returns (int256) {\n return MIN_INT_256;\n }\n\n /**\n * @dev Multiplies value a by value b (result is rounded down). It's assumed that the value b is the significand\n * of a number with 18 decimals precision.\n */\n function preciseMul(uint256 a, uint256 b) internal pure returns (uint256) {\n return a.mul(b).div(PRECISE_UNIT);\n }\n\n /**\n * @dev Multiplies value a by value b (result is rounded towards zero). It's assumed that the value b is the\n * significand of a number with 18 decimals precision.\n */\n function preciseMul(int256 a, int256 b) internal pure returns (int256) {\n return a.mul(b).div(PRECISE_UNIT_INT);\n }\n\n /**\n * @dev Multiplies value a by value b (result is rounded up). It's assumed that the value b is the significand\n * of a number with 18 decimals precision.\n */\n function preciseMulCeil(uint256 a, uint256 b) internal pure returns (uint256) {\n if (a == 0 || b == 0) {\n return 0;\n }\n return a.mul(b).sub(1).div(PRECISE_UNIT).add(1);\n }\n\n /**\n * @dev Divides value a by value b (result is rounded down).\n */\n function preciseDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n return a.mul(PRECISE_UNIT).div(b);\n }\n\n\n /**\n * @dev Divides value a by value b (result is rounded towards 0).\n */\n function preciseDiv(int256 a, int256 b) internal pure returns (int256) {\n return a.mul(PRECISE_UNIT_INT).div(b);\n }\n\n /**\n * @dev Divides value a by value b (result is rounded up or away from 0).\n */\n function preciseDivCeil(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"Cant divide by 0\");\n\n return a > 0 ? a.mul(PRECISE_UNIT).sub(1).div(b).add(1) : 0;\n }\n\n /**\n * @dev Divides value a by value b (result is rounded up or away from 0). When `a` is 0, 0 is\n * returned. When `b` is 0, method reverts with divide-by-zero error.\n */\n function preciseDivCeil(int256 a, int256 b) internal pure returns (int256) {\n require(b != 0, \"Cant divide by 0\");\n \n a = a.mul(PRECISE_UNIT_INT);\n int256 c = a.div(b);\n\n if (a % b != 0) {\n // a ^ b == 0 case is covered by the previous if statement, hence it won't resolve to --c\n (a ^ b > 0) ? ++c : --c;\n }\n\n return c;\n }\n\n /**\n * @dev Divides value a by value b (result is rounded down - positive numbers toward 0 and negative away from 0).\n */\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n require(b != 0, \"Cant divide by 0\");\n require(a != MIN_INT_256 || b != -1, \"Invalid input\");\n\n int256 result = a.div(b);\n if (a ^ b < 0 && a % b != 0) {\n result -= 1;\n }\n\n return result;\n }\n\n /**\n * @dev Multiplies value a by value b where rounding is towards the lesser number.\n * (positive values are rounded towards zero and negative values are rounded away from 0).\n */\n function conservativePreciseMul(int256 a, int256 b) internal pure returns (int256) {\n return divDown(a.mul(b), PRECISE_UNIT_INT);\n }\n\n /**\n * @dev Divides value a by value b where rounding is towards the lesser number.\n * (positive values are rounded towards zero and negative values are rounded away from 0).\n */\n function conservativePreciseDiv(int256 a, int256 b) internal pure returns (int256) {\n return divDown(a.mul(PRECISE_UNIT_INT), b);\n }\n\n /**\n * @dev Performs the power on a specified value, reverts on overflow.\n */\n function safePower(\n uint256 a,\n uint256 pow\n )\n internal\n pure\n returns (uint256)\n {\n require(a > 0, \"Value must be positive\");\n\n uint256 result = 1;\n for (uint256 i = 0; i < pow; i++){\n uint256 previousResult = result;\n\n // Using safemath multiplication prevents overflows\n result = previousResult.mul(a);\n }\n\n return result;\n }\n\n /**\n * @dev Returns true if a =~ b within range, false otherwise.\n */\n function approximatelyEquals(uint256 a, uint256 b, uint256 range) internal pure returns (bool) {\n return a <= b.add(range) && a >= b.sub(range);\n }\n\n /**\n * Returns the absolute value of int256 `a` as a uint256\n */\n function abs(int256 a) internal pure returns (uint) {\n return a >= 0 ? a.toUint256() : a.mul(-1).toUint256();\n }\n\n /**\n * Returns the negation of a\n */\n function neg(int256 a) internal pure returns (int256) {\n require(a > MIN_INT_256, \"Inversion overflow\");\n return -a;\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IGlobalExtension.sol": {
|
|
"content": "/*\n Copyright 2021 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\npragma experimental \"ABIEncoderV2\";\n\nimport { ISetToken } from \"@setprotocol/set-protocol-v2/contracts/interfaces/ISetToken.sol\";\n\ninterface IGlobalExtension {\n function removeExtension() external;\n}"
|
|
},
|
|
"contracts/lib/MutualUpgradeV2.sol": {
|
|
"content": "/*\n Copyright 2022 Set Labs Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n SPDX-License-Identifier: Apache License, Version 2.0\n*/\n\npragma solidity 0.6.10;\n\n/**\n * @title MutualUpgradeV2\n * @author Set Protocol\n *\n * The MutualUpgradeV2 contract contains a modifier for handling mutual upgrades between two parties\n *\n * CHANGELOG:\n * - Update mutualUpgrade to allow single transaction execution if the two signing addresses are the same\n */\ncontract MutualUpgradeV2 {\n /* ============ State Variables ============ */\n\n // Mapping of upgradable units and if upgrade has been initialized by other party\n mapping(bytes32 => bool) public mutualUpgrades;\n\n /* ============ Events ============ */\n\n event MutualUpgradeRegistered(\n bytes32 _upgradeHash\n );\n\n /* ============ Modifiers ============ */\n\n modifier mutualUpgrade(address _signerOne, address _signerTwo) {\n require(\n msg.sender == _signerOne || msg.sender == _signerTwo,\n \"Must be authorized address\"\n );\n\n // If the two signing addresses are the same, skip upgrade hash step\n if (_signerOne == _signerTwo) {\n _;\n }\n\n address nonCaller = _getNonCaller(_signerOne, _signerTwo);\n\n // The upgrade hash is defined by the hash of the transaction call data and sender of msg,\n // which uniquely identifies the function, arguments, and sender.\n bytes32 expectedHash = keccak256(abi.encodePacked(msg.data, nonCaller));\n\n if (!mutualUpgrades[expectedHash]) {\n bytes32 newHash = keccak256(abi.encodePacked(msg.data, msg.sender));\n\n mutualUpgrades[newHash] = true;\n\n emit MutualUpgradeRegistered(newHash);\n\n return;\n }\n\n delete mutualUpgrades[expectedHash];\n\n // Run the rest of the upgrades\n _;\n }\n\n /* ============ Internal Functions ============ */\n\n function _getNonCaller(address _signerOne, address _signerTwo) internal view returns(address) {\n return msg.sender == _signerOne ? _signerTwo : _signerOne;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/GSN/Context.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/math/SafeMath.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts with custom message when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/utils/SafeCast.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n require(value < 2**128, \"SafeCast: value doesn\\'t fit in 128 bits\");\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n require(value < 2**64, \"SafeCast: value doesn\\'t fit in 64 bits\");\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n require(value < 2**32, \"SafeCast: value doesn\\'t fit in 32 bits\");\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n require(value < 2**16, \"SafeCast: value doesn\\'t fit in 16 bits\");\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits.\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n require(value < 2**8, \"SafeCast: value doesn\\'t fit in 8 bits\");\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n require(value >= 0, \"SafeCast: value must be positive\");\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n *\n * _Available since v3.1._\n */\n function toInt128(int256 value) internal pure returns (int128) {\n require(value >= -2**127 && value < 2**127, \"SafeCast: value doesn\\'t fit in 128 bits\");\n return int128(value);\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n *\n * _Available since v3.1._\n */\n function toInt64(int256 value) internal pure returns (int64) {\n require(value >= -2**63 && value < 2**63, \"SafeCast: value doesn\\'t fit in 64 bits\");\n return int64(value);\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n *\n * _Available since v3.1._\n */\n function toInt32(int256 value) internal pure returns (int32) {\n require(value >= -2**31 && value < 2**31, \"SafeCast: value doesn\\'t fit in 32 bits\");\n return int32(value);\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n *\n * _Available since v3.1._\n */\n function toInt16(int256 value) internal pure returns (int16) {\n require(value >= -2**15 && value < 2**15, \"SafeCast: value doesn\\'t fit in 16 bits\");\n return int16(value);\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits.\n *\n * _Available since v3.1._\n */\n function toInt8(int256 value) internal pure returns (int8) {\n require(value >= -2**7 && value < 2**7, \"SafeCast: value doesn\\'t fit in 8 bits\");\n return int8(value);\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n require(value < 2**255, \"SafeCast: value doesn't fit in an int256\");\n return int256(value);\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/math/SignedSafeMath.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @title SignedSafeMath\n * @dev Signed math operations with safety checks that revert on error.\n */\nlibrary SignedSafeMath {\n int256 constant private _INT256_MIN = -2**255;\n\n /**\n * @dev Returns the multiplication of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(int256 a, int256 b) internal pure returns (int256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n require(!(a == -1 && b == _INT256_MIN), \"SignedSafeMath: multiplication overflow\");\n\n int256 c = a * b;\n require(c / a == b, \"SignedSafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two signed integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(int256 a, int256 b) internal pure returns (int256) {\n require(b != 0, \"SignedSafeMath: division by zero\");\n require(!(b == -1 && a == _INT256_MIN), \"SignedSafeMath: division overflow\");\n\n int256 c = a / b;\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a - b;\n require((b >= 0 && c <= a) || (b < 0 && c > a), \"SignedSafeMath: subtraction overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the addition of two signed integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a + b;\n require((b >= 0 && c >= a) || (b < 0 && c < a), \"SignedSafeMath: addition overflow\");\n\n return c;\n }\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 200
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"metadata": {
|
|
"useLiteralContent": true
|
|
},
|
|
"libraries": {}
|
|
}
|
|
} |