all files / contracts/ DAO.sol

100% Statements 14/14
64.29% Branches 9/14
100% Functions 5/5
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                                                                                                      28×                   14× 14× 14× 14× 14×   14× 14×   14× 14× 14×     14× 14× 14× 14×     14× 14× 14×                                                    
// SPDX-License-Identifier: MIT
//   _____          ____           _____ ____  _   _ _______ _____            _____ _______ 
//  |  __ \   /\   / __ \         / ____/ __ \| \ | |__   __|  __ \     /\   / ____|__   __|
//  | |  | | /  \ | |  | |       | |   | |  | |  \| |  | |  | |__) |   /  \ | |       | |   
//  | |  | |/ /\ \| |  | |       | |   | |  | | . ` |  | |  |  _  /   / /\ \| |       | |   
//  | |__| / ____ \ |__| |       | |___| |__| | |\  |  | |  | | \ \  / ____ \ |____   | |   
//  |_____/_/    \_\____/         \_____\____/|_| \_|  |_|  |_|  \_\/_/    \_\_____|  |_|   
//                                                                                         
//                                                                                         
// Deployed by createDAO.org -  Main DAO Implementation
// GitHub: https://github.com/createdao
// 
// 🌍 This code is free. Like speech. Like people should be.
// Use it, learn from it, build with it. Share what you make.
// But remember what this is for: not greed, not ego — but freedom, creativity, and unity.
// 
// Inspired by Chaplin's call in The Great Dictator:
// “You, the people, have the power — the power to create happiness!”
// 
// So build not for domination, but for decentralization.
// Not for walls, but bridges. Not for power, but empowerment.
// 
// Licensed under the MIT License — short, sweet, and to the point.
// No restrictions, no delays. Just create. Just be human. ✌️
// — Diornov
 
 
 
pragma solidity ^0.8.20;
 
import "./core/DAOProposals.sol";
import "./core/DAOExecutor.sol";
import "./core/storage/CoreStorage.sol";
import "./core/storage/ProposalStorage.sol";
 
/**
 * @title DAO
 * @dev Main DAO contract that combines all functionality through inheritance
 * Uses ERC-7201 namespaced storage pattern for better storage management
 * and safer upgrades
 * 
 * Inheritance chain:
 * - DAOProposals (IDAOProposals): Proposal creation and voting
 * - DAOExecutor (IDAOExecutor): Proposal execution and emergency functions
 * Both inherit from:
 * - DAOStorage (IDAOBase): Shared storage and base functionality with ERC-7201
 * - DAOEvents: Shared events
 */
contract DAO is DAOProposals, DAOExecutor {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
 
    function initialize(
        string memory _name,
        address _treasury,
        address _stakingContract,
        address _token,
        address _factory
    ) external initializer {
        Erequire(bytes(_name).length > 0, "Empty name");
        Erequire(_treasury != address(0), "Zero treasury");
        Erequire(_stakingContract != address(0), "Zero staking");
        Erequire(_token != address(0), "Zero token");
        Erequire(_factory != address(0), "Zero factory");
 
        __Ownable_init(_factory);
        __UUPSUpgradeable_init();
 
        CoreStorage.Layout storage core = _getCore();
        core.name = _name;
        core.factory = _factory;
 
        // Initialize upgradeable contract addresses
        core.upgradeableContracts[IDAOBase.UpgradeableContract.DAO] = address(this);
        core.upgradeableContracts[IDAOBase.UpgradeableContract.Treasury] = _treasury;
        core.upgradeableContracts[IDAOBase.UpgradeableContract.Staking] = _stakingContract;
        core.upgradeableContracts[IDAOBase.UpgradeableContract.Token] = _token;
 
        // Initialize governance parameters
        core.votingPeriod = 3 days;
        core.minProposalStake = 1e18; // 1 token
        core.quorum = 5000; // 50%
    }
 
    string private constant VERSION = "1.0.0";
 
    function version() external pure virtual returns (string memory) {
        return VERSION;
    }
 
    function getPresaleContract(uint256 proposalId) external view returns (address) {
        return _getProposals().presaleContracts[proposalId];
    }
 
    // Required override for UUPS proxy
    function _authorizeUpgrade(
        address
    ) internal override view {
        CoreStorage.Layout storage core = _getCore();
        if (!core.executingProposal) {
            // Only allow owner for direct upgrades (initialization)
            _checkOwner();
        }
        // If _executingProposal is true, allow the upgrade
        // This means it's being called during proposal execution
        // which has already gone through governance checks:
        // - Proposer has enough stake
        // - Community voted in favor
        // - Quorum was reached
        // - Voting period has ended
    }
}