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/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index b2a56f2..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "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 index f8a31ff..381e9c6 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ -# ProjectFactory +# Factory -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 Factory Contract -## Development +This branch is dedicated to creating a factory contract in Solidity. A factory contract is a smart contract that is capable of deploying other contracts. This pattern is useful for scenarios where you need to create multiple instances of a contract with the same code but different states. -The development of this project is planned and tracked in the testing branches. These branches contain the latest features and improvements under development. +### Key Features -## Contracts +- **Automated Deployment**: The factory contract can deploy new contracts automatically. +- **Centralized Management**: Manage all deployed contracts from a single factory contract. +- **Efficiency**: Reduce gas costs by reusing the same contract code. -- `Project`: Manages project milestones. -- `ProjectFactory`: Creates and manages multiple projects. +### Example -## Documentation +Here is a simple example of a factory contract in Solidity: -For detailed API documentation, refer to the [ProjectFactory Documentation](docs/ProjectFactory.md). +### Conclusion + +Using a factory contract can simplify the deployment and management of multiple contracts, making your Solidity projects more efficient and maintainable. diff --git a/contracts/factory.sol b/contracts/factory.sol new file mode 100644 index 0000000..29d3abd --- /dev/null +++ b/contracts/factory.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract SimpleContract { + address public owner; + string public phrase; + + constructor(address _owner, string memory _phrase) { + owner = _owner; + phrase = _phrase; + } + + function getPhrase() public view returns (string memory) { + return phrase; + } +} + +contract Factory { + SimpleContract[] public contracts; + + function createContract(string memory _phrase) public returns (address) { + SimpleContract newContract = new SimpleContract(msg.sender, _phrase); + contracts.push(newContract); + return address(newContract); + } +} \ 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..63b9735 --- /dev/null +++ b/docs/factory.md @@ -0,0 +1,33 @@ +# Solidity API + +## SimpleContract + +### Contract +SimpleContract : contracts/factory.sol + + --- +### Functions: +### constructor + +```solidity +constructor(address _owner, string _phrase) public +``` + +### getPhrase + +```solidity +function getPhrase() public view returns (string) +``` + +## Factory + +### Contract +Factory : contracts/factory.sol + + --- +### Functions: +### createContract + +```solidity +function createContract(string _phrase) public returns (address) +``` \ No newline at end of file diff --git a/scripts/deploy.js b/scripts/deploy.js new file mode 100644 index 0000000..9786a0c --- /dev/null +++ b/scripts/deploy.js @@ -0,0 +1,23 @@ +const hre = require("hardhat"); + +async function main() { + await hre.run("compile"); + + const [deployer] = await hre.ethers.getSigners(); + + console.log("Deploying contracts with the account:", deployer.address); + + const ProjectFactory = await hre.ethers.getContractFactory("ProjectFactory"); + const projectFactory = await ProjectFactory.deploy(); + + await projectFactory.deployed(); + + console.log("ProjectFactory deployed to:", projectFactory.address); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); 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