From 3925ffd2639d7c08645a1dfd6d274108db02f96b Mon Sep 17 00:00:00 2001 From: JesusRGil <108557695+JRGIL12@users.noreply.github.com> Date: Sat, 22 Mar 2025 06:03:42 -0400 Subject: [PATCH 1/2] initialize project structure with environment, ignore, and configuration files; add project contract and README --- .env | 1 + .gitignore | 1 + .prettierrc.json | 38 +++++++++++++ README.md | 32 +++++++++++ contracts/project.sol | 122 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 .env create mode 100644 .gitignore create mode 100644 .prettierrc.json create mode 100644 README.md create mode 100644 contracts/project.sol diff --git a/.env b/.env new file mode 100644 index 0000000..82789f2 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +# This file is intentionally left blank. \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..b2a56f2 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,38 @@ +{ + "overrides": [ + { + "files": "*.sol", + "options": { + "printWidth": 80, + "tabWidth": 4, + "useTabs": false, + "singleQuote": false, + "bracketSpacing": false + } + }, + { + "files": "*.yml", + "options": {} + }, + { + "files": "*.yaml", + "options": {} + }, + { + "files": "*.toml", + "options": {} + }, + { + "files": "*.json", + "options": {} + }, + { + "files": "*.js", + "options": {} + }, + { + "files": "*.ts", + "options": {} + } + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..0869054 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Project + +## Testing Branch for Project Contract + +This branch is used to create a project contract, serving as an example for how to set up and manage project contracts within the repository. + +## Project Contract Structure + +### Project Name +Enter project name + +### Project Description +Describe your project in detail + +### Developer Avalanche Address +0x... +Enter the Avalanche address of the developer who will work on this project + +### Project Milestones +#### Add Milestone +##### Milestone 1 +**Title** +Milestone title + +**Amount (USDC)** +0.0 + +**Due Date** +dd/mm/yyyy + +**Description** +Describe what should be delivered in this milestone \ No newline at end of file diff --git a/contracts/project.sol b/contracts/project.sol new file mode 100644 index 0000000..b4d25cd --- /dev/null +++ b/contracts/project.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +/** + * @title Project + * @dev A contract to manage project milestones, allowing the owner to add, complete, and approve milestones. + */ +contract Project { + struct Milestone { + string title; // Title of the milestone + uint256 tentativeDate; // Tentative date for the milestone + string description; // Description of the milestone + uint256 amount; // Amount allocated for the milestone + bool completed; // Status of the milestone completion + } + + address public owner; // Owner of the project + string public projectName; // Name of the project + string public projectDescription; // Description of the project + address payable public developerAddress; // Address of the developer + uint256 public totalCapital; // Total capital received + Milestone[] public milestones; // List of milestones + + /** + * @dev Emitted when a new milestone is added. + * @param milestoneId The ID of the milestone. + * @param title The title of the milestone. + * @param amount The amount allocated for the milestone. + */ + event MilestoneAdded(uint256 indexed milestoneId, string title, uint256 amount); + + /** + * @dev Emitted when a milestone is completed. + * @param milestoneId The ID of the milestone. + * @param proof The proof of completion. + */ + event MilestoneCompleted(uint256 indexed milestoneId, string proof); + + /** + * @dev Emitted when a milestone is approved. + * @param milestoneId The ID of the milestone. + * @param amount The amount transferred to the developer. + */ + event MilestoneApproved(uint256 indexed milestoneId, uint256 amount); + + /** + * @dev Modifier to restrict functions to the owner. + */ + modifier onlyOwner() { + require(msg.sender == owner, "Solo el owner puede ejecutar esta funcion"); + _; + } + + /** + * @dev Constructor to initialize the project. + * @param _projectName The name of the project. + * @param _projectDescription The description of the project. + * @param _developerAddress The address of the developer. + */ + constructor( + string memory _projectName, + string memory _projectDescription, + address payable _developerAddress + ) { + owner = msg.sender; + projectName = _projectName; + projectDescription = _projectDescription; + developerAddress = _developerAddress; + } + + /** + * @dev Adds a new milestone to the project. + * @param _title The title of the milestone. + * @param _tentativeDate The tentative date for the milestone. + * @param _description The description of the milestone. + * @param _amount The amount allocated for the milestone. + */ + function addMilestone( + string memory _title, + uint256 _tentativeDate, + string memory _description, + uint256 _amount + ) public onlyOwner { + milestones.push(Milestone({ + title: _title, + tentativeDate: _tentativeDate, + description: _description, + amount: _amount, + completed: false + })); + emit MilestoneAdded(milestones.length - 1, _title, _amount); + } + + /** + * @dev Marks a milestone as completed. + * @param _milestoneId The ID of the milestone. + * @param _proof The proof of completion. + */ + function completeMilestone(uint256 _milestoneId, string memory _proof) public onlyOwner { + require(_milestoneId < milestones.length, "Milestone no existe"); + milestones[_milestoneId].completed = true; + emit MilestoneCompleted(_milestoneId, _proof); + } + + /** + * @dev Approves a completed milestone and transfers the allocated amount to the developer. + * @param _milestoneId The ID of the milestone. + */ + function approveMilestone(uint256 _milestoneId) public onlyOwner { + require(_milestoneId < milestones.length, "Milestone no existe"); + require(milestones[_milestoneId].completed, "Milestone no esta completado"); + developerAddress.transfer(milestones[_milestoneId].amount); + emit MilestoneApproved(_milestoneId, milestones[_milestoneId].amount); + } + + /** + * @dev Fallback function to receive funds and update total capital. + */ + receive() external payable { + totalCapital += msg.value; + } +} \ No newline at end of file From 23eca6e82f8447aa74331ebd3864d83523bc4ef3 Mon Sep 17 00:00:00 2001 From: JesusRGil <108557695+JRGIL12@users.noreply.github.com> Date: Sat, 22 Mar 2025 06:06:28 -0400 Subject: [PATCH 2/2] add documentation for Solidity API and project milestone management contract --- docs/factory.md | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 docs/factory.md diff --git a/docs/factory.md b/docs/factory.md new file mode 100644 index 0000000..9d8e7cb --- /dev/null +++ b/docs/factory.md @@ -0,0 +1,141 @@ +# Solidity API + +## Project + +_A contract to manage project milestones, allowing the owner to add, complete, and approve milestones._ + +### Contract +Project : contracts/factory.sol + +A contract to manage project milestones, allowing the owner to add, complete, and approve milestones. + + --- +### Modifiers: +### onlyOwner + +```solidity +modifier onlyOwner() +``` + +_Modifier to restrict functions to the owner._ + + --- +### Functions: +### constructor + +```solidity +constructor(string _projectName, string _projectDescription, address payable _developerAddress) public +``` + +_Constructor to initialize the project._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _projectName | string | The name of the project. | +| _projectDescription | string | The description of the project. | +| _developerAddress | address payable | The address of the developer. | + +### addMilestone + +```solidity +function addMilestone(string _title, uint256 _tentativeDate, string _description, uint256 _amount) public +``` + +_Adds a new milestone to the project._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _title | string | The title of the milestone. | +| _tentativeDate | uint256 | The tentative date for the milestone. | +| _description | string | The description of the milestone. | +| _amount | uint256 | The amount allocated for the milestone. | + +### completeMilestone + +```solidity +function completeMilestone(uint256 _milestoneId, string _proof) public +``` + +_Marks a milestone as completed._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _milestoneId | uint256 | The ID of the milestone. | +| _proof | string | The proof of completion. | + +### approveMilestone + +```solidity +function approveMilestone(uint256 _milestoneId) public +``` + +_Approves a completed milestone and transfers the allocated amount to the developer._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _milestoneId | uint256 | The ID of the milestone. | + +### receive + +```solidity +receive() external payable +``` + +_Fallback function to receive funds and update total capital._ + + --- +### Events: +### MilestoneAdded + +```solidity +event MilestoneAdded(uint256 milestoneId, string title, uint256 amount) +``` + +_Emitted when a new milestone is added._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| milestoneId | uint256 | The ID of the milestone. | +| title | string | The title of the milestone. | +| amount | uint256 | The amount allocated for the milestone. | + +### MilestoneCompleted + +```solidity +event MilestoneCompleted(uint256 milestoneId, string proof) +``` + +_Emitted when a milestone is completed._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| milestoneId | uint256 | The ID of the milestone. | +| proof | string | The proof of completion. | + +### MilestoneApproved + +```solidity +event MilestoneApproved(uint256 milestoneId, uint256 amount) +``` + +_Emitted when a milestone is approved._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| milestoneId | uint256 | The ID of the milestone. | +| amount | uint256 | The amount transferred to the developer. | +