Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions project-crowdfunding/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests/** linguist-vendored
vitest.config.js linguist-vendored
* text=lf
13 changes: 13 additions & 0 deletions project-crowdfunding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

**/settings/Mainnet.toml
**/settings/Testnet.toml
.cache/**
history.txt

logs
*.log
npm-debug.log*
coverage
*.info
costs-reports.json
node_modules
4 changes: 4 additions & 0 deletions project-crowdfunding/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{
"files.eol": "\n"
}
19 changes: 19 additions & 0 deletions project-crowdfunding/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
"version": "2.0.0",
"tasks": [
{
"label": "check contracts",
"group": "test",
"type": "shell",
"command": "clarinet check"
},
{
"type": "npm",
"script": "test",
"group": "test",
"problemMatcher": [],
"label": "npm test"
}
]
}
19 changes: 19 additions & 0 deletions project-crowdfunding/Clarinet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[project]
name = 'project-crowdfunding'
description = ''
authors = []
telemetry = true
cache_dir = '.\.cache'
requirements = []
[contracts.stx-project-funding]
path = 'contracts/stx-project-funding.clar'
clarity_version = 2
epoch = 2.5
[repl.analysis]
passes = ['check_checker']

[repl.analysis.check_checker]
strict = false
trusted_sender = false
trusted_caller = false
callee_filter = false
211 changes: 211 additions & 0 deletions project-crowdfunding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Open Source Project Funding Smart Contract

## About
This Clarity smart contract enables decentralized funding for open-source projects on the Stacks blockchain. It provides a comprehensive system for creating, funding, and managing open-source projects with milestone-based development tracking and automated fund distribution.

## Features

### Project Management
- Create new open-source projects with detailed information
- Track project status and funding progress
- Milestone-based development tracking
- Automated fund distribution upon milestone completion

### Funding Mechanism
- Secure STX token contributions
- Individual contributor tracking
- Prevention of over-funding
- Automatic milestone-based fund distribution

### Access Control
- Project creator authorization
- Contract administrator controls
- Secure fund management
- Milestone completion verification

## Contract Functions

### Administrative Functions

#### `initialize-contract`
Initializes the contract with the deployer as the administrator.
```clarity
(define-public (initialize-contract))
```

### Project Management Functions

#### `create-open-source-project`
Creates a new open-source project.
```clarity
(define-public (create-open-source-project
(project-title (string-ascii 100))
(project-description (string-utf8 500))
(target-funding-amount uint)))
```
Parameters:
- `project-title`: Name of the project (max 100 characters)
- `project-description`: Detailed project description (max 500 characters)
- `target-funding-amount`: Total funding goal in microSTX

#### `add-project-milestone`
Adds a development milestone to an existing project.
```clarity
(define-public (add-project-milestone
(project-identifier uint)
(milestone-title (string-ascii 100))
(milestone-description (string-utf8 500))
(milestone-deadline uint)
(milestone-funding-amount uint)))
```
Parameters:
- `project-identifier`: Unique project ID
- `milestone-title`: Name of the milestone
- `milestone-description`: Detailed milestone description
- `milestone-deadline`: Block height deadline
- `milestone-funding-amount`: Funding amount for this milestone

### Funding Functions

#### `contribute-project-funding`
Contributes STX tokens to a project.
```clarity
(define-public (contribute-project-funding
(project-identifier uint)
(funding-amount uint)))
```
Parameters:
- `project-identifier`: Project ID to fund
- `funding-amount`: Amount of STX tokens to contribute

#### `complete-project-milestone`
Marks a milestone as complete and releases funds.
```clarity
(define-public (complete-project-milestone
(project-identifier uint)
(milestone-identifier uint)))
```
Parameters:
- `project-identifier`: Project ID
- `milestone-identifier`: Milestone ID to complete

### Read-Only Functions

#### `get-project-details`
Retrieves project information.
```clarity
(define-read-only (get-project-details
(project-identifier uint)))
```

#### `get-milestone-details`
Retrieves milestone information.
```clarity
(define-read-only (get-milestone-details
(project-identifier uint)
(milestone-identifier uint)))
```

#### `get-contributor-funding-amount`
Gets the total contribution amount from a specific contributor.
```clarity
(define-read-only (get-contributor-funding-amount
(project-identifier uint)
(funding-contributor principal)))
```

#### `is-project-fully-funded`
Checks if a project has reached its funding goal.
```clarity
(define-read-only (is-project-fully-funded
(project-identifier uint)))
```

## Error Codes

| Code | Description |
|------|-------------|
| ERR-UNAUTHORIZED-ACCESS | User not authorized for the operation |
| ERR-PROJECT-DOES-NOT-EXIST | Project ID not found |
| ERR-PROJECT-ALREADY-FUNDED | Project has already reached funding goal |
| ERR-INSUFFICIENT-BALANCE | Insufficient funds for operation |
| ERR-INVALID-FUNDING-AMOUNT | Invalid funding amount specified |
| ERR-MILESTONE-DOES-NOT-EXIST | Milestone ID not found |
| ERR-MILESTONE-INCOMPLETE | Milestone completion conditions not met |

## Data Structures

### Open Source Projects
```clarity
{
project-creator: principal,
project-title: (string-ascii 100),
project-description: (string-utf8 500),
target-funding-amount: uint,
total-funds-raised: uint,
project-status: (string-ascii 20),
project-creation-block: uint
}
```

### Project Development Milestones
```clarity
{
milestone-title: (string-ascii 100),
milestone-description: (string-utf8 500),
milestone-completion-deadline: uint,
milestone-funding-amount: uint,
milestone-status: (string-ascii 20)
}
```

### Project Funding Contributors
```clarity
{
contribution-amount: uint
}
```

## Security Considerations

1. **Access Control**
- Only project creators can add milestones and mark them as complete
- Only contract administrator can initialize the contract
- Public functions have appropriate authorization checks

2. **Fund Safety**
- Automatic fund distribution upon milestone completion
- Prevention of over-funding
- Secure STX token transfers using contract principal

3. **Input Validation**
- All numeric inputs are validated
- String lengths are constrained
- Milestone deadlines are verified

## Usage Examples

### Creating a New Project
```clarity
(contract-call? .open-source-funding create-open-source-project
"My Open Source Project"
"A detailed description of the project"
u1000000)
```

### Contributing Funds
```clarity
(contract-call? .open-source-funding contribute-project-funding
u1
u500000)
```

### Adding a Milestone
```clarity
(contract-call? .open-source-funding add-project-milestone
u1
"First Release"
"Complete core functionality"
u100000
u500000)
```
7 changes: 7 additions & 0 deletions project-crowdfunding/Testnet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[network]
name = "testnet"
stacks_node_rpc_address = "https://api.testnet.hiro.so"
deployment_fee_rate = 10

[accounts.deployer]
mnemonic = "<YOUR PRIVATE TESTNET MNEMONIC HERE>"
Loading