Skip to content

SatsBridge/play-with-dao

Repository files navigation

Play with DAO - Create a DAO in TVM Networks

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:


1. Imports and Dependencies

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, and IProposer define the interaction points for proposals, staking accounts, and upgradability.
  • Utilities: Additional utilities (Delegate, DaoCellEncoder) support encoding, delegation, and managing data.

2. Contract Constants

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.

3. State Variables

Key state variables manage the configuration and current status of the DAO:

  • Addresses: stakingRoot points to the staking system, admin and pendingAdmin manage DAO administration.
  • Proposals: proposalCount, proposalConfiguration, and proposalCode handle the state of proposals.
  • Deployment: deployEventValue manages the value required for Ethereum event deployments.

4. Modifiers

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.

5. Constructor

The constructor initializes the DAO:

  • Parameters: Platform code, initial proposal configuration, and the admin address.
  • Validation: Ensures the admin address and configuration are valid.

6. Getter Functions

Read-only functions provide public access to key data like admin, proposalCount, and expected addresses for proposals or staking accounts.


7. Proposal Functions

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).

8. Admin Functions

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.

9. Internal Utilities

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.

10. Event Emissions

The contract emits events for key actions, such as proposal creation, admin transfer, configuration updates, and upgrades, ensuring transparency.


11. Security and Gas Management

The contract uses tvm.rawReserve to optimize gas usage and prevent attacks by reserving the required balance for operations.


12. Upgradability

The upgrade function facilitates contract upgrades by accepting new code and reinitializing the contract state.


Key Features Summary:

  1. Proposal Management: Create, deploy, and execute proposals with strict validation.
  2. Configuration Flexibility: Update DAO parameters through admin functions.
  3. Staking Integration: Tightly coupled with staking accounts for proposal submission.
  4. Access Control: Multiple levels of restrictions ensure secure operations.
  5. Upgradability: Future-proof design with support for logic upgrades.

This modular structure ensures scalability, security, and flexibility for a DAO system.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published