From b54673f7fb077524a58b559a9a30e037b9de2755 Mon Sep 17 00:00:00 2001 From: Punitkumar756 Date: Sat, 13 Dec 2025 17:18:50 +0530 Subject: [PATCH 1/2] chore: update README.md for improved organization and clarity --- README.md | 415 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 400 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9d9c471..213d1b4 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,20 @@ **Treee** is the smart contract layer of the *Treee tree-planting protocol*, enabling on-chain verification, organization management, and NFT issuance for planted trees. It powers transparent and auditable sustainability tracking within the **Stability Nexus** ecosystem. +## ๐Ÿ“‹ Table of Contents + +- [Tech Stack](#tech-stack) +- [Architecture Overview](#architecture-overview) +- [Getting Started](#getting-started) +- [Developer Workflow](#developer-workflow) +- [Testing](#testing) +- [Deployment](#deployment) +- [Common Commands](#common-commands) +- [Project Structure](#project-structure) +- [Security](#security) +- [Contributing](#contributing) +- [License](#license) + --- ## Tech Stack @@ -58,12 +72,50 @@ It powers transparent and auditable sustainability tracking within the **Stabili - **Foundry (forge, anvil, cast)** โ€” Testing, simulation & deployment - **OpenZeppelin Contracts** โ€” Token standards and access control -### Contracts +### Libraries & Dependencies + +- **foundry-devops** โ€” Deployment utilities +- **forge-std** โ€” Foundry standard library for testing + +--- + +## Architecture Overview + +### Core Contracts + +#### ๐ŸŒณ TreeNft.sol +The main NFT contract representing planted trees. Each NFT contains: +- **Metadata** โ€” Tree species, location, planting date +- **Verification status** โ€” On-chain proof of planting +- **Organization tracking** โ€” Links to the planting organization + +#### ๐Ÿข Organisation.sol +Manages individual organizations that plant trees: +- **Role management** โ€” Admin, verifier, and planter roles +- **Tree tracking** โ€” Records trees planted by the organization +- **Token distribution** โ€” Manages incentive token allocation + +#### ๐Ÿญ OrganisationFactory.sol +Factory contract for deploying and managing organizations: +- **Organization deployment** โ€” Creates new organization contracts +- **Registry** โ€” Maintains a list of all active organizations +- **Access control** โ€” Manages who can create organizations + +### Token Contracts -- `TreeNft.sol` โ€” NFT for planted trees -- `Organisation.sol` โ€” Handles organization logic -- `OrganisationFactory.sol` โ€” Deploys and tracks organizations -- `CareToken.sol`, `PlanterToken.sol`, `LegacyToken.sol` โ€” Incentive ERC-20 tokens +#### ๐Ÿ’š CareToken.sol +ERC-20 token rewarding tree care and maintenance activities. + +#### ๐ŸŒฑ PlanterToken.sol +ERC-20 token incentivizing tree planting activities. + +#### ๐Ÿ† LegacyToken.sol +ERC-20 token for long-term sustainability contributions. + +### Utilities + +- **errors.sol** โ€” Custom error definitions for gas-efficient reverts +- **structs.sol** โ€” Shared data structures across contracts --- @@ -71,32 +123,365 @@ It powers transparent and auditable sustainability tracking within the **Stabili ### Prerequisites -- [Foundry](https://book.getfoundry.sh/getting-started/installation) -- Rust toolchain (`rustup`) -- Node.js (optional, for deployment scripting) +Ensure you have the following installed: ---- +- **[Foundry](https://book.getfoundry.sh/getting-started/installation)** โ€” Ethereum development toolkit + ```bash + curl -L https://foundry.paradigm.xyz | bash + foundryup + ``` +- **Git** โ€” Version control +- **Rust toolchain** โ€” Required by Foundry (`rustup`) +- **Node.js** (optional) โ€” For additional tooling -### Quickstart +### Environment Setup + +Create a `.env` file in the root directory: +Install dependencies -#### 1. Clone the repository ```bash -git clone https://github.com/StabilityNexus/Treee-Solidity.git -cd Treee-Solidity +forge install ``` -#### 2. Build contracts +#### 3. Build contracts ```bash forge build ``` -#### 3. Run tests +#### 4. Run tests + +```bash +forge test +``` + +#### 5. Start a local node + +```bash +anvil +``` + +#### 6. Deploy locally + +```bash +# In a new terminal, deploy to local Anvil node +forge script script/DeployAllContracts.s.sol:DeployAllContractsAtOnce \ + --rpc-url http://127.0.0.1:8545 \ + --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +### Local Development + +#### Start local blockchain: + +```bash +anvil +``` + +#### Test in watch mode: + +```bash +forge test --watch +``` + +#### Run specific tests: + +```bash +# Test a specific contract +forge test --match-contract TreeNftTest + +# Test a specific function +forge test --match-test testMintTree + +# Verbose output +forge test -vvv +``` + +#### Gas reporting: + +```bash +forge test --gas-report +``` + +#### Check test coverage: + +```bash +forge coverage +``` + +### Interacting with Contracts + +#### Using Cast (Command Line): + +```bash +# Call a view function +cast call "getOrganisationCount()(uint256)" --rpc-url http://127.0.0.1:8545 + +# Send a transaction +cast send "mintTree(address,string)" "ipfs://metadata" \ + --private-key \ + --rpc-url http://127.0.0.1:8545 + | Description | +| -------------------------- | ---------------------------------------- | +| `forge build` | Compile contracts | +| `forge test` | Run all tests | +| `forge test -vvvv` | Run tests with detailed traces | +| `forge fmt` | Format Solidity code | +| `forge clean` | Remove build artifacts | +| `forge snapshot` | Create gas usage snapshot | +| `forge coverage` | Generate test coverage report | +| `anvil` | Start local blockchain node | +| `cast call` | Call a contract function (read-only) | +| `cast send` | Send a transaction to a contract | +| `forge script