all files / contracts/core/internal/ DAOEvents.sol

57.89% Statements 11/19
0% Branches 0/4
73.33% Functions 11/15
64.71% Lines 11/17
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172                                                    72×                         46×                                                                                                                                               66×       50×                                                                                                  
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
 
import "../interfaces/IDAOBase.sol";
import "../interfaces/IDAOEvents.sol";
import "../interfaces/IDAOModule.sol";
 
/**
 * @title DAOEvents
 * @dev Library for handling DAO event emissions
 * Uses events defined in IDAOEvents interface
 * Provides helper functions for emitting events with proper parameters
 */
library DAOEvents {
    // Mapping for module type strings to avoid repeated string comparisons
    // Note: Solidity doesn't support constant mappings, so we'll use a function
    function _getModuleTypeString(IDAOModule.ModuleType moduleType) private pure returns (string memory) {
        if (moduleType == IDAOModule.ModuleType.Presale) return "presale";
        if (moduleType == IDAOModule.ModuleType.Vesting) return "vesting";
        revert("Unknown module type");
    }
    function emitProposalCreated(
        uint256 proposalId,
        IDAOBase.ProposalType proposalType,
        uint256 endTime
    ) internal {
        emit IDAOEvents.ProposalCreated(
            proposalId,
            proposalType,
            endTime
        );
    }
 
    function emitTransferProposalCreated(
        uint256 proposalId,
        address token,
        address recipient,
        uint256 amount
    ) internal {
        emit IDAOEvents.TransferProposalCreated(
            proposalId,
            token,
            recipient,
            amount
        );
    }
 
    function emitPresaleProposalCreated(
        uint256 proposalId,
        address token,
        uint256 amount,
        uint256 initialPrice
    ) internal {
        emit IDAOEvents.PresaleProposalCreated(
            proposalId,
            token,
            amount,
            initialPrice
        );
    }
 
    function emitPresalePauseProposalCreated(
        uint256 proposalId,
        address presaleContract,
        bool pause
    ) internal {
        emit IDAOEvents.PresalePauseProposalCreated(
            proposalId,
            presaleContract,
            pause
        );
    }
 
    function emitPresaleWithdrawProposalCreated(
        uint256 proposalId,
        address presaleContract
    ) internal {
        emit IDAOEvents.PresaleWithdrawProposalCreated(
            proposalId,
            presaleContract
        );
    }
 
    function emitUpgradeProposalCreated(
        uint256 proposalId,
        address[] memory newImplementations,
        string memory version
    ) internal {
        emit IDAOEvents.UpgradeProposalCreated(
            proposalId,
            newImplementations,
            version
        );
    }
 
    function emitModuleUpgradeProposalCreated(
        uint256 proposalId,
        IDAOModule.ModuleType moduleType,
        address moduleAddress,
        string memory version
    ) internal {
        emit IDAOEvents.ModuleUpgradeProposalCreated(
            proposalId,
            moduleType,
            moduleAddress,
            version
        );
    }
 
    function emitVoted(
        uint256 proposalId,
        address voter,
        bool support,
        uint256 votingPower
    ) internal {
        emit IDAOEvents.Voted(proposalId, voter, support, votingPower);
    }
 
    function emitProposalExecuted(uint256 proposalId) internal {
        emit IDAOEvents.ProposalExecuted(proposalId);
    }
 
    function emitDAOPaused(address account) internal {
        emit IDAOEvents.DAOPaused(account);
    }
 
    function emitDAOUnpaused(address account) internal {
        emit IDAOEvents.DAOUnpaused(account);
    }
 
    // function emitEmergencyWithdraw(
    //     address token,
    //     address recipient,
    //     uint256 amount
    // ) internal {
    //     emit IDAOEvents.EmergencyWithdraw(token, recipient, amount);
    // }
 
    function emitPresaleDeployed(
        uint256 proposalId,
        address presaleContract,
        uint256 amount,
        uint256 initialPrice
    ) internal {
        emit IDAOEvents.PresaleDeployed(proposalId, presaleContract, amount, initialPrice);
    }
 
    function emitModuleUpgraded(
        uint256 proposalId,
        address moduleAddress,
        IDAOModule.ModuleType moduleType,
        string memory version
    ) internal {
        emit IDAOEvents.ModuleUpgraded(
            proposalId,
            moduleAddress,
            moduleTypeToString(moduleType),
            version
        );
    }
 
    /**
     * @dev Converts a module type enum to its string representation
     * @param moduleType The module type to convert
     * @return The string representation of the module type
     */
    function moduleTypeToString(IDAOModule.ModuleType moduleType) internal pure returns (string memory) {
        return _getModuleTypeString(moduleType);
    }
 
}