Skip to content

An open-source Hardhat project providing a boilerplate and reference implementation for tokenizing Community Supported Agriculture (CSA) programs as Real-World Assets (RWAs). This repository is a developer tool designed to accelerate the creation of ReFi applications on EVM chains.

License

Notifications You must be signed in to change notification settings

ecolab-web3/csa-rwa-solidity

Repository files navigation

CSA as RWA: A Smart Contract Prototype in Solidity

If you find our work valuable, please consider giving us a star on GitHub!

Language Blockchain Verified Contract License Solidity Version Framework


Quick Start

This repository is a Hardhat-based boilerplate for CSA RWAs. To get started and scaffold your own project from this template, follow these steps:

  1. Clone & Install:

    git clone https://github.com/ecolab-web3/csa-rwa-solidity.git
    cd csa-rwa-solidity
    npm install
  2. Configure Your Environment:

    • This project requires an .env file with a private key and RPC URL.
    • Rename the .env.example file in the root directory to .env.
    • Open the new .env file and add your test wallet's private key.
  3. Understand the Contract (Recommended):

    • Before deploying, take a moment to read the rest of this README and browse the contracts/ folder.
    • Understanding the smart contract's logic, its functions, and its purpose is a critical step for any developer.
  4. Deploy the Contract:

    • Fund your test wallet with some Fuji AVAX from a faucet.
    • Run the deployment script:
    npx hardhat run scripts/deploy.ts --network fuji

The script will deploy the contract and print its address to your terminal.


Official E-co.lab Links


About The Project

This repository contains a smart contract prototype that tokenizes a Community Supported Agriculture (CSA) membership share as a Real World Asset (RWA) on the blockchain.

This project has been successfully migrated to a professional Hardhat environment, rigorously tested, deployed, and verified on the Avalanche Fuji Testnet.


Live Demo & dApps

Frontend dApp

  • Wallet Integration: Connects seamlessly to browser wallets like MetaMask.
  • Auto-Connection & Network Validation: Remembers connected wallets and verifies the correct network.
  • Dynamic Season Display: Robustly fetches and displays all available seasons from the contract.
  • Multi-language Support: Available in both English and Portuguese.

Smart Contract

  • Season Management: Owner can create new harvest seasons with specific names, prices, and member capacity.
  • NFT Membership: Users can purchase a membership (buyMembership()), which mints an ERC721 NFT to their wallet.
  • Weekly Redemption: NFT owners can redeem their weekly product box, with the contract enforcing one redemption per week per share.
  • Standards-Based: Built on OpenZeppelin's ERC721Enumerable and Ownable contracts.

You can interact with the live version of this project using the dApp prototypes below. Please make sure your wallet (e.g., MetaMask) is connected to the Avalanche Fuji Testnet.

dApp Prototypes

Contract Details


Development Environment & Testing

This project was migrated from Remix IDE to a professional Hardhat environment to ensure quality and reproducibility.

  • Framework: Hardhat
  • Solidity Version: 0.8.20
  • Testing: A comprehensive test suite was developed using ethers.js and Chai. The suite consists of 26 passing tests covering all contract functions and logic paths.

Test Coverage

The project achieved the following test coverage:

File % Stmts % Branch % Funcs % Lines
CSA_RWA.sol 96.67 89.29 100 100
All files 96.67 89.29 100 100

Note on Code Coverage: The coverage tool correctly identifies a redundant require statement in the buyMembership function. A preceding line (uint256 seasonId = seasons.length - 1;) already prevents execution with an empty seasons array due to an arithmetic underflow, making the require check's failure path unreachable. Since the contract is already deployed and immutable, this code will not be altered in this version. The optimization is listed as a next step for future versions.


Overview

The core idea is to transform a CSA "membership share" into an ERC721Enumerable Non-Fungible Token (NFT). Each NFT represents a member's right to receive a weekly product box for a specific harvest season, turning this right into a liquid, transferable, and transparent digital asset.

Key Concepts Implemented

  • Season Management: The contract owner can create new harvest seasons via a dedicated admin panel.
  • Share Purchase (Minting): Community members can purchase a share through the dApp, which "mints" an NFT.
  • Weekly Redemption: The NFT owner can redeem their weekly product box.
  • Automated Token ID Discovery: The dApp automatically detects if a user is a member and retrieves their Token ID.
  • Security and Transparency: The contract is Ownable and the code is publicly verified.

Next Steps

This is a functional prototype. For a production-ready project, the next steps focus on code optimization, upgradability, user experience, and security.

1. Contract Refinement (Code Optimization)

As identified during the test coverage analysis, the next version of the contract will remove the redundant require statement in the buyMembership function. This will make the code cleaner and slightly more gas-efficient, allowing the test suite to achieve 100% branch coverage.

2. Implement an Upgradable Contract using the Proxy Pattern

To allow for future feature additions or bug fixes without forcing users to migrate to a new contract, the next logical step is to implement an upgradable contract using OpenZeppelin's Upgrades Contracts. This would enable future evolution, such as transforming the contract into a multi-farmer platform.

3. Enhance dApp and Admin Panel UI/UX

The current dApps are functional prototypes. A production version would require enhancing them with a modern framework and adding features like an NFT gallery, redemption history, and a more comprehensive admin dashboard.

4. Undergo a Professional Security Audit

Before deploying to a mainnet and handling real value, a full audit by a reputable third-party security firm is essential to ensure the safety of the system.


Ecosystem Recognition

E-co.lab is a recognized participant in the Avalanche Retro9000 program, a retroactive public goods funding initiative by the Avalanche Foundation. Our project has been approved for the "L1s & Infrastructure Tooling" round and is currently live for community voting by participants in the Avalanche ecosystem.

You can view our official submission and support our mission here: E-co.lab on Retro9000


Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

Please feel free to fork the repo and create a pull request, or open an issue with the tag "enhancement".


License

This project is licensed under the MIT License. See the LICENSE file for details.

About

An open-source Hardhat project providing a boilerplate and reference implementation for tokenizing Community Supported Agriculture (CSA) programs as Real-World Assets (RWAs). This repository is a developer tool designed to accelerate the creation of ReFi applications on EVM chains.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published