pragma solidity ^0.8.0; // SPDX-License-Identifier: MIT import "../core/DaoRegistry.sol"; import "../guards/AdapterGuard.sol"; import "./modifiers/Reimbursable.sol"; import "./interfaces/IConfiguration.sol"; import "../adapters/interfaces/IVoting.sol"; import "../helpers/DaoHelper.sol"; /** MIT License Copyright (c) 2020 Openlaw Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ contract ConfigurationContract is IConfiguration, AdapterGuard, Reimbursable { mapping(address => mapping(bytes32 => Configuration[])) private _configurations; /** * @notice Creates and sponsors a configuration proposal. * @param dao The DAO Address. * @param proposalId The proposal id. * @param configs The keys, type, numeric and address config values. * @param data Additional details about the financing proposal. */ // slither-disable-next-line reentrancy-benign function submitProposal( DaoRegistry dao, bytes32 proposalId, Configuration[] calldata configs, bytes calldata data ) external override reimbursable(dao) { require(configs.length > 0, "missing configs"); dao.submitProposal(proposalId); Configuration[] storage newConfigs = _configurations[address(dao)][ proposalId ]; for (uint256 i = 0; i < configs.length; i++) { Configuration memory config = configs[i]; newConfigs.push( Configuration({ key: config.key, configType: config.configType, numericValue: config.numericValue, addressValue: config.addressValue }) ); } IVoting votingContract = IVoting( dao.getAdapterAddress(DaoHelper.VOTING) ); address sponsoredBy = votingContract.getSenderAddress( dao, address(this), data, msg.sender ); dao.sponsorProposal(proposalId, sponsoredBy, address(votingContract)); votingContract.startNewVotingForProposal(dao, proposalId, data); } /** * @notice Processing a configuration proposal to update the DAO state. * @param dao The DAO Address. * @param proposalId The proposal id. */ // slither-disable-next-line reentrancy-benign function processProposal( DaoRegistry dao, bytes32 proposalId ) external override reimbursable(dao) { dao.processProposal(proposalId); IVoting votingContract = IVoting(dao.votingAdapter(proposalId)); require(address(votingContract) != address(0), "adapter not found"); require( votingContract.voteResult(dao, proposalId) == IVoting.VotingState.PASS, "proposal did not pass" ); Configuration[] memory configs = _configurations[address(dao)][ proposalId ]; for (uint256 i = 0; i < configs.length; i++) { Configuration memory config = configs[i]; if (ConfigType.NUMERIC == config.configType) { //slither-disable-next-line calls-loop dao.setConfiguration(config.key, config.numericValue); } else if (ConfigType.ADDRESS == config.configType) { //slither-disable-next-line calls-loop dao.setAddressConfiguration(config.key, config.addressValue); } } } }