diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md new file mode 100644 index 00000000..6d2bda8e --- /dev/null +++ b/ASSIGNMENT.md @@ -0,0 +1,23 @@ +# Todo Contract Assignment + +## Overview +This is the Todo contract assignment (as-w3-d1). The Todo contract provides functionality for task management. + +## Setup +1. Install dependencies: `npm install` +2. Configure hardhat: See `hardhat.config.ts` +3. Run tests: `npm test` + +## Contract Details +- **Location**: `Assignment/solidity-assignment7/contracts/todo/` +- **Language**: Solidity + +## Testing +```bash +npm test +``` + +## Deployment +```bash +npx hardhat run scripts/deploy.ts +``` diff --git a/Assignment/solidity-assignment7/contracts/todo/contracts/Todo.sol b/Assignment/solidity-assignment7/contracts/todo/contracts/Todo.sol new file mode 100644 index 00000000..4904ac66 --- /dev/null +++ b/Assignment/solidity-assignment7/contracts/todo/contracts/Todo.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.28; + +contract Todo { + uint public todoCounter; + + enum TaskState { + Pending, + Completed, + Cancelled, + Defaulted + } + + struct Task { + uint id; + address admin; + string text; + TaskState status; + uint deadline; + } + + mapping(uint => Task) tasks; + event TaskCreated(string text, uint deadline); + + function createTask( + string memory text, + uint deadline + ) external returns (uint) { + require(bytes(text).length > 0, 'Text cannot be empty'); + require(deadline > (block.timestamp + 600), 'Invalid deadline'); + + todoCounter++; + + tasks[todoCounter] = Task( + todoCounter, + msg.sender, + text, + TaskState.Pending, + deadline + ); + + emit TaskCreated(text, deadline); + return todoCounter; + } + + function getTask(uint id) external view returns (Task memory) { + return tasks[id]; + } + + function updateTask( + uint id, + string memory text, + uint deadline + ) external returns (uint) { + require(bytes(text).length > 0, 'Text cannot be empty'); + require( + deadline > (block.timestamp + 600), + 'Deadline cannot be less than 10 minutes' + ); + require(tasks[id].admin == msg.sender, 'Only admin can update task'); + tasks[id] = Task(id, msg.sender, text, TaskState.Pending, deadline); + return id; + } + + function doneTask(uint id) external returns (uint) { + require(tasks[id].admin == msg.sender, 'Only admin can complete task'); + tasks[id].status = TaskState.Completed; + return id; + } +} diff --git a/Assignment/solidity-assignment7/contracts/todo/hardhat.config.ts b/Assignment/solidity-assignment7/contracts/todo/hardhat.config.ts new file mode 100644 index 00000000..5a11c3e9 --- /dev/null +++ b/Assignment/solidity-assignment7/contracts/todo/hardhat.config.ts @@ -0,0 +1,45 @@ +import dotenv from "dotenv"; +dotenv.config({ path: "../../.env" }); +import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem"; +import { configVariable, defineConfig } from "hardhat/config"; + +export default defineConfig({ + plugins: [hardhatToolboxViemPlugin], + solidity: { + profiles: { + default: { + version: "0.8.28", + }, + production: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + }, + }, + networks: { + hardhatMainnet: { + type: "edr-simulated", + chainType: "l1", + }, + hardhatOp: { + type: "edr-simulated", + chainType: "op", + }, + sepolia: { + type: "http", + chainType: "l1", + url: configVariable("SEPOLIA_RPC_URL"), + accounts: [configVariable("SEPOLIA_PRIVATE_KEY")], + }, + }, + verify: { + etherscan: { + apiKey: configVariable("ETHERSCAN_API_KEY"), + }, + }, +}); diff --git a/Assignment/solidity-assignment7/contracts/todo/ignition/modules/Todo.ts b/Assignment/solidity-assignment7/contracts/todo/ignition/modules/Todo.ts new file mode 100644 index 00000000..e342098e --- /dev/null +++ b/Assignment/solidity-assignment7/contracts/todo/ignition/modules/Todo.ts @@ -0,0 +1,7 @@ +import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; + +export default buildModule("TodoModule", (m) => { + const todo = m.contract("Todo"); + + return { todo }; +}); diff --git a/Assignment/solidity-assignment7/contracts/todo/package.json b/Assignment/solidity-assignment7/contracts/todo/package.json new file mode 100644 index 00000000..8327a2fb --- /dev/null +++ b/Assignment/solidity-assignment7/contracts/todo/package.json @@ -0,0 +1,17 @@ +{ + "name": "New Folder", + "version": "1.0.0", + "type": "module", + "devDependencies": { + "@nomicfoundation/hardhat-ignition": "^3.0.7", + "@nomicfoundation/hardhat-toolbox-viem": "^5.0.2", + "@types/node": "^22.19.8", + "forge-std": "github:foundry-rs/forge-std#v1.9.4", + "hardhat": "^3.1.6", + "typescript": "~5.8.0", + "viem": "^2.45.1" + }, + "dependencies": { + "dotenv": "^17.2.4" + } +} diff --git a/Assignment/solidity-assignment7/contracts/todo/tsconfig.json b/Assignment/solidity-assignment7/contracts/todo/tsconfig.json new file mode 100644 index 00000000..9b1380cc --- /dev/null +++ b/Assignment/solidity-assignment7/contracts/todo/tsconfig.json @@ -0,0 +1,13 @@ +/* Based on https://github.com/tsconfig/bases/blob/501da2bcd640cf95c95805783e1012b992338f28/bases/node22.json */ +{ + "compilerOptions": { + "lib": ["es2023"], + "module": "node16", + "target": "es2022", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "moduleResolution": "node16", + "outDir": "dist" + } +} diff --git a/template/.github/pull_request_template.md b/template/.github/pull_request_template.md new file mode 100644 index 00000000..60af44d0 --- /dev/null +++ b/template/.github/pull_request_template.md @@ -0,0 +1,9 @@ +## Summary +What does this PR implement? + +## Testing +- [ ] Unit tests added +- [ ] Tests passing locally + +## Notes +Any assumptions or trade-offs? \ No newline at end of file diff --git a/template/.github/workflows/.yml b/template/.github/workflows/.yml new file mode 100644 index 00000000..3aed9df2 --- /dev/null +++ b/template/.github/workflows/.yml @@ -0,0 +1,24 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + formatting: + name: Code Formatting (Prettier) + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Run Prettier check + run: npx prettier --check . diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 00000000..962c2511 --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,5 @@ +.env +.vscode/ + +package-lock.json +node_modules \ No newline at end of file diff --git a/template/.prettierignore b/template/.prettierignore new file mode 100644 index 00000000..2603b336 --- /dev/null +++ b/template/.prettierignore @@ -0,0 +1,4 @@ +node_modules +dist +build +.env* \ No newline at end of file diff --git a/template/.prettierrc b/template/.prettierrc new file mode 100644 index 00000000..d4fed1f5 --- /dev/null +++ b/template/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "singleQuote": true, + "trailingComma": "es5", + "printWidth": 80, + "tabWidth": 2 +} \ No newline at end of file diff --git a/template/CONTRIBUTING.md b/template/CONTRIBUTING.md new file mode 100644 index 00000000..cbd55a65 --- /dev/null +++ b/template/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# How to Contribute + +1. Getting Started + - Fork the repository + - Sync with upstream + - Create a feature branch + +2. Branch Naming Convention +Example: +`submission/assignment-01/` + +3. Commit Message Guidelines + +Example (Conventional Commits–lite): +``` +feat: implement token transfer logic +fix: handle zero-address edge case +test: add coverage for revert conditions +``` + +4. Pull Request Checklist +- [x] Code compiles +- [x] Tests pass +- [x] README included +- [x] No changes outside /submissions + +5. PR Review Process +- [x] Automated checks +- [x] Manual review by mentors +- [x] Required fixes before merge + +6. Common Mistakes to Avoid +- Editing assignment specs +- Submitting compiled artifacts +- Force-pushing after review \ No newline at end of file diff --git a/template/README.md b/template/README.md new file mode 100644 index 00000000..1f9b46e7 --- /dev/null +++ b/template/README.md @@ -0,0 +1,26 @@ +# Cohort 8 +Blockchain Development Bootcamp — Cohort 8 + +This repository contains official technical materials, specifications, assignments, and collaboration artifacts for the 8th edition of our blockchain program. Dev participants are expected to actively use this repository throughout the program for learning, development, version control, and peer collaboration. + +#### Repository Structure +The repository will evolve over time, but a typical structure looks like: +```cohort-8/ +├── README.md # Repository overview and instructions +├── assignments/ # Coding exercises and assessments +├── projects/ +│ ├── templates/ # Starter project templates +│ └── submissions/ # Participant or team submissions +└── resources/ # Technical references & reading material +``` + +#### Setup +Clone the repository: +``` +git clone https://github.com/BlockheaderWeb3-Community/cohort-8.git +cd cohort-8 +``` + +#### Code Formatting +This repository uses Prettier for formatting. Install the Prettier extension in your editor and enable Format on Save. +