diff --git a/.deploys/pinned-contracts/43113/0x433e3b673b4edf8d02a3b7a38600eba1cd6c22c7.json b/.deploys/pinned-contracts/43113/0x433e3b673b4edf8d02a3b7a38600eba1cd6c22c7.json deleted file mode 100644 index 25050fd..0000000 --- a/.deploys/pinned-contracts/43113/0x433e3b673b4edf8d02a3b7a38600eba1cd6c22c7.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "name": "ProjectFactory", - "address": "0x433e3b673b4edf8d02a3b7a38600eba1cd6c22c7", - "abi": [ - { - "inputs": [ - { - "internalType": "string", - "name": "_projectName", - "type": "string" - }, - { - "internalType": "string", - "name": "_projectDescription", - "type": "string" - }, - { - "internalType": "address payable", - "name": "_developerAddress", - "type": "address" - } - ], - "name": "createProject", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_developer", - "type": "address" - } - ], - "name": "getProjectsByDeveloper", - "outputs": [ - { - "internalType": "contract Project[]", - "name": "", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_owner", - "type": "address" - } - ], - "name": "getProjectsByOwner", - "outputs": [ - { - "internalType": "contract Project[]", - "name": "", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "projects", - "outputs": [ - { - "internalType": "contract Project", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - } - ], - "filePath": "ProjectFactory/contracts/projectfactory.sol", - "pinnedAt": 1742680042033 -} \ No newline at end of file diff --git a/README.md b/README.md index f8a31ff..0869054 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,32 @@ -# ProjectFactory +# Project -ProjectFactory is a Solidity-based project management system that allows the creation and management of projects with milestones. Each project can have multiple milestones, and the owner can add, complete, and approve these milestones. +## Testing Branch for Project Contract -## Development +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. -The development of this project is planned and tracked in the testing branches. These branches contain the latest features and improvements under development. +## Project Contract Structure -## Contracts +### Project Name +Enter project name -- `Project`: Manages project milestones. -- `ProjectFactory`: Creates and manages multiple projects. +### Project Description +Describe your project in detail -## Documentation +### Developer Avalanche Address +0x... +Enter the Avalanche address of the developer who will work on this project -For detailed API documentation, refer to the [ProjectFactory Documentation](docs/ProjectFactory.md). +### 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 diff --git a/contracts/projectfactory.sol b/contracts/projectfactory.sol deleted file mode 100644 index 452f726..0000000 --- a/contracts/projectfactory.sol +++ /dev/null @@ -1,132 +0,0 @@ -// 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; - uint256 tentativeDate; - string description; - uint256 amount; - bool completed; - } - - address public owner; - string public projectName; - string public projectDescription; - address payable public developerAddress; - uint256 public totalCapital; - Milestone[] public milestones; - - event MilestoneAdded(uint256 indexed milestoneId, string title, uint256 amount); - event MilestoneCompleted(uint256 indexed milestoneId, string proof); - event MilestoneApproved(uint256 indexed milestoneId, uint256 amount); - - modifier onlyOwner() { - require(msg.sender == owner, "Solo el owner puede ejecutar esta funcion"); - _; - } - - constructor( - string memory _projectName, - string memory _projectDescription, - address payable _developerAddress, - address _owner - ) { - owner = _owner; - projectName = _projectName; - projectDescription = _projectDescription; - developerAddress = _developerAddress; - } - - 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); - } - - function completeMilestone(uint256 _milestoneId, string memory _proof) public onlyOwner { - require(_milestoneId < milestones.length, "Milestone no existe"); - milestones[_milestoneId].completed = true; - emit MilestoneCompleted(_milestoneId, _proof); - } - - 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); - } - - receive() external payable { - totalCapital += msg.value; - } -} - -contract ProjectFactory { - Project[] public projects; - - function createProject( - string memory _projectName, - string memory _projectDescription, - address payable _developerAddress - ) public returns (address) { - Project newProject = new Project( - _projectName, - _projectDescription, - _developerAddress, - msg.sender - ); - projects.push(newProject); - return address(newProject); - } - - function getProjectsByOwner(address _owner) public view returns (Project[] memory) { - uint count; - for (uint i = 0; i < projects.length; i++) { - if (projects[i].owner() == _owner) { - count++; - } - } - Project[] memory result = new Project[](count); - uint index; - for (uint j = 0; j < projects.length; j++) { - if (projects[j].owner() == _owner) { - result[index] = projects[j]; - index++; - } - } - return result; - } - - function getProjectsByDeveloper(address _developer) public view returns (Project[] memory) { - uint count; - for (uint i = 0; i < projects.length; i++) { - if (projects[i].developerAddress() == _developer) { - count++; - } - } - Project[] memory result = new Project[](count); - uint index; - for (uint j = 0; j < projects.length; j++) { - if (projects[j].developerAddress() == _developer) { - result[index] = projects[j]; - index++; - } - } - return result; - } -} \ No newline at end of file diff --git a/docs/ProjectFactory.md b/docs/ProjectFactory.md deleted file mode 100644 index 942c822..0000000 --- a/docs/ProjectFactory.md +++ /dev/null @@ -1,96 +0,0 @@ -# Solidity API - -## Project - -_A contract to manage project milestones, allowing the owner to add, complete, and approve milestones._ - -### Contract -Project : contracts/ProjectFactory.sol - -A contract to manage project milestones, allowing the owner to add, complete, and approve milestones. - - --- -### Modifiers: -### onlyOwner - -```solidity -modifier onlyOwner() -``` - - --- -### Functions: -### constructor - -```solidity -constructor(string _projectName, string _projectDescription, address payable _developerAddress) public -``` - -### addMilestone - -```solidity -function addMilestone(string _title, uint256 _tentativeDate, string _description, uint256 _amount) public -``` - -### completeMilestone - -```solidity -function completeMilestone(uint256 _milestoneId, string _proof) public -``` - -### approveMilestone - -```solidity -function approveMilestone(uint256 _milestoneId) public -``` - -### receive - -```solidity -receive() external payable -``` - - --- -### Events: -### MilestoneAdded - -```solidity -event MilestoneAdded(uint256 milestoneId, string title, uint256 amount) -``` - -### MilestoneCompleted - -```solidity -event MilestoneCompleted(uint256 milestoneId, string proof) -``` - -### MilestoneApproved - -```solidity -event MilestoneApproved(uint256 milestoneId, uint256 amount) -``` - -## ProjectFactory - -### Contract -ProjectFactory : contracts/ProjectFactory.sol - - --- -### Functions: -### createProject - -```solidity -function createProject(string _projectName, string _projectDescription, address payable _developerAddress) public -``` - -### getProjectsByOwner - -```solidity -function getProjectsByOwner(address _owner) public view returns (contract Project[]) -``` - -### getProjectsByDeveloper - -```solidity -function getProjectsByDeveloper(address _developer) public view returns (contract Project[]) -``` - 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. | + diff --git a/tests/tests/projectfactory_test.sol b/tests/tests/projectfactory_test.sol deleted file mode 100644 index e14dee1..0000000 --- a/tests/tests/projectfactory_test.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 - -pragma solidity >=0.4.22 <0.9.0; - -// This import is automatically injected by Remix -import "remix_tests.sol"; - -// This import is required to use custom transaction context -// Although it may fail compilation in 'Solidity Compiler' plugin -// But it will work fine in 'Solidity Unit Testing' plugin -import "remix_accounts.sol"; -import "../contracts/projectfactory.sol"; - -// File name has to end with '_test.sol', this file can contain more than one testSuite contracts -contract testSuite { - - /// 'beforeAll' runs before all other tests - /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll' - function beforeAll() public { - // - Assert.equal(uint(1), uint(1), "1 should be equal to 1"); - } - - function checkSuccess() public { - // Use 'Assert' methods: https://remix-ide.readthedocs.io/en/latest/assert_library.html - Assert.ok(2 == 2, 'should be true'); - Assert.greaterThan(uint(2), uint(1), "2 should be greater than to 1"); - Assert.lesserThan(uint(2), uint(3), "2 should be lesser than to 3"); - } - - function checkSuccess2() public pure returns (bool) { - // Use the return value (true or false) to test the contract - return true; - } - - function checkFailure() public { - Assert.notEqual(uint(1), uint(1), "1 should not be equal to 1"); - } - - /// Custom Transaction Context: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization - /// #sender: account-1 - /// #value: 100 - function checkSenderAndValue() public payable { - // account index varies 0-9, value is in wei - Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender"); - Assert.equal(msg.value, 100, "Invalid value"); - } -} - \ No newline at end of file