15 contract architecture

Overview

This document provides detailed technical architecture for the smart contract system, focusing on the ERC-1155 semi-fungible implementation and integration with Project Records and PoAI.

A) ProjectRegistry (Project "NFT" Record)

Standard: ERC-721 or ERC-1155 (supply = 1 per project)

Purpose: Immutable project identity anchor

Stores:

  • Project metadata hash

  • PoAI proof hashes

  • Issuance cap

  • Project status


B) CarbonCredit1155 (Semi-Fungible Units)

Standard: ERC-1155 (Multi-Token Standard)

Purpose: Credit units that are fungible within project, non-fungible across projects

Stores:

  • Balances per user per tokenId

  • Caps per tokenId

  • Issued/retired totals per tokenId

  • Transfer policies per tokenId


C) Governance/Access (Roles)

Implementation: OpenZeppelin AccessControl or similar

Purpose: Role-based access control

Roles:

  • ISSUER_ROLE: Can mint credits

  • GOVERNANCE_ROLE: Can configure projects and execute governance

  • PAUSER_ROLE: Can pause contracts (emergency)


Token ID Strategy


Units & Decimals Implementation

Fixed-Point Units

Definition:

Conversion:

UI Display:


CarbonCredit1155 Contract Design

Storage Structure


Core Functions

setProjectConfig

Validations:

  • PoAI must be approved

  • Cap must be > 0

  • Caller must have GOVERNANCE_ROLE


mintCredits

Validations:

  • Project must be active

  • Issuance must not exceed cap

  • Caller must have ISSUER_ROLE


retire

Validations:

  • User must have sufficient balance

  • Burns credits permanently


_beforeTokenTransfer (Transfer Policy Enforcement)


PoAI Integration (Gating)

ProjectRegistry Integration

CarbonCredit1155 Gating

Result: No PoAI → no activation → no mint.


Complete On-Chain Flow

1

Step 1: Project Approved (PoAI + Governance)

  • Off-chain PoAI verification generates hashes

  • Governance approves project and sets issuance cap

  • ProjectRecord minted with cap and PoAI hashes

2

Step 2: Issue Credit Units

Enforces:

  • Project active

  • issued + amount <= cap

3

Step 3: User Holds Credits

4

Step 4: Retirement (Burn)

Contract Actions:

  • Burns units from user

  • Increments retired counter

  • Emits CreditsRetired event

5

Step 5: Certificate Generation (Off-Chain)

Indexer listens to CreditsRetired event:

  • Generates certificate

  • References tx hash + event details

  • Includes PoAI proof hash from ProjectRecord


Metadata Structure

uri(tokenId) Returns JSON


Security Considerations

circle-info

Access Control

  • Role-based access (OpenZeppelin AccessControl)

  • Multi-sig for critical operations (optional)

circle-exclamation
circle-info

Integer Safety

  • Solidity 0.8+ (built-in overflow protection)

  • Or SafeMath library

circle-info

Pausable

  • Emergency pause mechanism

  • whenNotPaused modifier on critical functions


Gas Optimization

Storage Optimization

  • Pack structs efficiently

  • Use events for historical data

  • Store only essential data on-chain

Function Optimization

  • Batch operations where possible

  • Minimize external calls

  • Use view functions for reads

Last updated