The DaoRoot
contract is a core component of a decentralized autonomous organization (DAO) system written in Ever-Solidity. It serves as the root contract managing proposals, configurations, staking accounts, and interactions with other modules within the DAO. Here's a structured explanation:
The contract imports libraries, interfaces, and utility components to provide essential functionality:
- Structures:
PlatformTypes
defines types used within the DAO system. - Libraries: Includes utility libraries for gas management (
Gas
), error handling (DaoErrors
), and message flag operations (MsgFlag
). - Interfaces: Interfaces like
IDaoRoot
,IStakingAccount
, andIProposer
define the interaction points for proposals, staking accounts, and upgradability. - Utilities: Additional utilities (
Delegate
,DaoCellEncoder
) support encoding, delegation, and managing data.
These constants define the operational limits and parameters of the DAO:
- Proposal Limits: Maximum operations per proposal, description length, and thresholds for proposal quorum, voting period, delay, time lock, and grace period.
- Static Variables:
_nonce
is a unique identifier.
Key state variables manage the configuration and current status of the DAO:
- Addresses:
stakingRoot
points to the staking system,admin
andpendingAdmin
manage DAO administration. - Proposals:
proposalCount
,proposalConfiguration
, andproposalCode
handle the state of proposals. - Deployment:
deployEventValue
manages the value required for Ethereum event deployments.
Modifiers enforce access control and validation:
onlyAdmin
: Restricts functions to the admin or delegated roles.onlyProposal
: Ensures that only valid proposals can call certain functions.onlyStakingAccount
: Restricts calls to authorized staking accounts.
The constructor initializes the DAO:
- Parameters: Platform code, initial proposal configuration, and the admin address.
- Validation: Ensures the admin address and configuration are valid.
Read-only functions provide public access to key data like admin
, proposalCount
, and expected addresses for proposals or staking accounts.
Core functionality for managing proposals:
- Propose: Accepts new proposals, validates actions, and interacts with the staking account for submission.
- DeployProposal: Deploys proposals with unique IDs and initializes platform state.
- Proposal Actions:
onProposalSucceeded
executes proposal actions (Ton and Ethereum-based) when approved. - Helpers: Functions to calculate gas costs for actions (
calcTvmActionsValue
,calcBtcActionsValue
).
Administrative operations manage configurations and upgrades:
- Configuration Updates: Modify parameters like voting delay, quorum, thresholds, and event configurations.
- Admin Management: Transfer or accept admin rights.
- Code Upgrades: Allows upgrading the contract logic and proposals through the
upgrade
function.
Internal functions handle lower-level tasks:
- State Initialization: Functions like
buildProposalStateInit
prepare the state for proposals. - Validation: Ensures that configurations (e.g., voting periods, thresholds) meet predefined limits.
- Delegation: Manage delegation for certain operations.
The contract emits events for key actions, such as proposal creation, admin transfer, configuration updates, and upgrades, ensuring transparency.
The contract uses tvm.rawReserve
to optimize gas usage and prevent attacks by reserving the required balance for operations.
The upgrade
function facilitates contract upgrades by accepting new code and reinitializing the contract state.
- Proposal Management: Create, deploy, and execute proposals with strict validation.
- Configuration Flexibility: Update DAO parameters through admin functions.
- Staking Integration: Tightly coupled with staking accounts for proposal submission.
- Access Control: Multiple levels of restrictions ensure secure operations.
- Upgradability: Future-proof design with support for logic upgrades.
This modular structure ensures scalability, security, and flexibility for a DAO system.