Skip to content

Commit

Permalink
docs: Add comprehensive DAO documentation structure
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Dec 24, 2024
1 parent 294b017 commit ca8f608
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/dao/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# aibtcdev DAO Documentation

This directory contains documentation for the aibtcdev DAO smart contracts.

## Core Components

- [Base DAO](base-dao.md) - The main DAO contract that manages extensions and proposal execution
- [Extensions](extensions/README.md) - Modular components that add functionality to the DAO
- [Proposals](proposals/README.md) - Contracts that can be executed by the DAO

## Architecture Overview

The aibtcdev DAO follows an "executor DAO" pattern where:

1. The base DAO contract manages a set of extensions and can execute proposals
2. Extensions provide specific functionality (payments, messaging, etc)
3. Proposals are contracts that can be executed by the DAO to make changes

This modular architecture allows:

- Adding new functionality through extensions
- Upgrading components independently
- Fine-grained access control
- Clear separation of concerns

## Error Codes

Each contract uses a distinct error code range to make debugging easier:

- Base DAO: 900-999
- Actions Extension: 1000-1999
- Bank Account Extension: 2000-2999
- Direct Execute Extension: 3000-3999
- Messaging Extension: 4000-4999
- Payments Extension: 5000-5999
- Treasury Extension: 6000-6999

## Getting Started

See the individual component documentation for details on:

- Contract interfaces and functions
- Extension capabilities
- Creating and executing proposals
- Managing DAO settings
96 changes: 96 additions & 0 deletions docs/dao/base-dao.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Base DAO Contract

The base DAO contract (`aibtcdev-base-dao.clar`) is the core contract that manages extensions and proposal execution.

## Key Features

- Manages enabled/disabled status of extensions
- Executes proposals that can modify DAO state
- Controls access to extension functionality
- Maintains record of executed proposals

## Constants

- `ERR_UNAUTHORIZED (900)` - Caller not authorized
- `ERR_ALREADY_EXECUTED (901)` - Proposal already executed
- `ERR_INVALID_EXTENSION (902)` - Extension validation failed
- `ERR_NO_EMPTY_LISTS (903)` - Empty list provided

## Storage

### Data Variables

- `executive` - Principal that can construct the DAO, set to contract itself after construction

### Maps

- `ExecutedProposals` - Tracks block height when proposals were executed
- `Extensions` - Tracks enabled/disabled status of extensions

## Functions

### Public Functions

#### construct
```clarity
(define-public (construct (proposal <proposal-trait>)))
```
Initial construction of the DAO. Can only be called once by the executive.

#### execute
```clarity
(define-public (execute (proposal <proposal-trait>) (sender principal)))
```
Executes a proposal contract. Can only be called by the DAO or enabled extensions.

#### set-extension
```clarity
(define-public (set-extension (extension principal) (enabled bool)))
```
Enables or disables an extension. Can only be called by the DAO or enabled extensions.

#### set-extensions
```clarity
(define-public (set-extensions (extensionList (list 200 {extension: principal, enabled: bool}))))
```
Enables or disables multiple extensions. Can only be called by the DAO or enabled extensions.

#### request-extension-callback
```clarity
(define-public (request-extension-callback (extension <extension-trait>) (memo (buff 34))))
```
Requests a callback from an extension. Can only be called by enabled extensions.

### Read-Only Functions

#### is-extension
```clarity
(define-read-only (is-extension (extension principal)))
```
Returns whether an extension is enabled.

#### executed-at
```clarity
(define-read-only (executed-at (proposal <proposal-trait>)))
```
Returns the block height when a proposal was executed, if it was.

## Usage Examples

### Enabling an Extension

```clarity
(contract-call? .aibtcdev-base-dao set-extension .aibtc-ext001-actions true)
```

### Executing a Proposal

```clarity
(contract-call? .aibtcdev-base-dao execute .aibtc-prop001-bootstrap tx-sender)
```

### Checking Extension Status

```clarity
(contract-call? .aibtcdev-base-dao is-extension .aibtc-ext001-actions)
```
70 changes: 70 additions & 0 deletions docs/dao/extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# DAO Extensions

Extensions are modular components that add functionality to the DAO. Each extension implements specific traits and can only be called by the DAO or other enabled extensions.

## Available Extensions

- [Actions](actions.md) - Voting on predefined actions
- [Bank Account](bank-account.md) - Managed STX withdrawals
- [Direct Execute](direct-execute.md) - Voting on arbitrary code execution
- [Messaging](messaging.md) - On-chain messaging
- [Payments](payments.md) - Payment processing
- [Treasury](treasury.md) - Asset management

## Extension Architecture

Each extension:

1. Implements the base extension trait
2. Implements additional specialized traits
3. Uses a unique error code range
4. Can only be called by the DAO or other extensions
5. Can request callbacks from other extensions

## Common Patterns

### Authorization Check

All extensions use this pattern to verify calls:

```clarity
(define-private (is-dao-or-extension)
(ok (asserts! (or (is-eq tx-sender .aibtcdev-dao)
(contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED
))
)
```

### Callback Support

Extensions implement a callback function:

```clarity
(define-public (callback (sender principal) (memo (buff 34)))
(ok true)
)
```

### Event Logging

Extensions log events with consistent format:

```clarity
(print {
notification: "event-name",
payload: {
key1: value1,
key2: value2
}
})
```

## Adding New Extensions

To add a new extension:

1. Create contract implementing required traits
2. Use unique error code range
3. Add authorization checks
4. Implement callback support
5. Add to bootstrap proposal

0 comments on commit ca8f608

Please sign in to comment.