Skip to content

m374-crypt0/nifty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

127 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nifty - Advanced NFT Smart Contract Suite

CI Coverage Slither no High Vulnerabilities

A comprehensive, NFT implementation featuring crowdsale mechanics, upgradeable architecture, and extensive functionality built on Ethereum.

🌟 Key Features

Core NFT Implementation (Nifty.sol)

  • Full ERC721 Compliance: Complete implementation of the ERC721 standard with metadata and enumerable extensions
  • Advanced Minting: Flexible minting system with controlled supply management
  • Burnable Tokens: Secure token burning functionality with proper event emission
  • Pausable Operations: Emergency pause functionality for security and maintenance
  • Revealable Metadata: Support for hidden/revealed NFT mechanics common in modern drops
  • 2-Step Ownership: Enhanced ownership transfer security using OpenZeppelin's 2-step pattern
  • ERC165 Introspection: Full interface detection support for maximum compatibility
  • Basic Permit feature: non typed permit implementation. Kept simple for demonstration purpose

Crowdsale System (Crowdsale.sol)

  • Flexible Sale Mechanics: Configurable pricing, timing, and allocation limits
  • Multi-phase Sales: Support for different sale phases with varying conditions
  • Whitelist Support: Built-in allowlist functionality for exclusive access
  • Payment Processing: Secure ETH handling with withdrawal mechanisms
  • Supply Management: Automatic tracking and enforcement of mint limits
  • Event Logging: Comprehensive event system for transparency and indexing

Upgradeable Architecture

  • Transparent Proxy Pattern: Implementation of OpenZeppelin's transparent upgradeable proxy
  • Secure Upgrades: Admin-controlled upgrade mechanism with role separation
  • Storage Safety: Careful storage layout management to prevent upgrade conflicts
  • Initialization Support: Proper initialization patterns for proxy deployments

🏗️ Architecture

The project follows a modular architecture with clear separation of concerns:

src/
├── contracts/
│   ├── Nifty.sol                  # Main NFT contract
│   ├── Crowdsale.sol              # Sale management contract
│   ├── Ownable2Steps.sol          # Enhanced ownership pattern
│   ├── interfaces/                # Contract interfaces
│   │   ├── INifty.sol             # Main contract interface
│   │   ├── ICrowdsaleable.sol     # Crowdsale interface
│   │   ├── IRevealable.sol        # Metadata reveal interface
│   │   └── token/                 # ERC721 related interfaces
│   ├── proxy/                     # Proxy implementation
│   │   └── TransparentUpgradeableProxy.sol
│   └── introspection/             # ERC165 implementation
│       └── ERC165.sol
├── backend/
│   └── test/                      # tests

🧪 Testing & Coverage

The project maintains 100% test coverage across all critical components:

  • 15 comprehensive test suites covering every contract function
  • 100% line coverage on core contracts (Nifty.sol: 151/151 lines, Crowdsale.sol: 58/58 lines)
  • 100% branch coverage ensuring all conditional paths are tested
  • 100% function coverage validating every public/external function
  • Edge case testing including overflow, underflow, and boundary conditions
  • Access control testing verifying proper permission management
  • Integration tests ensuring contracts work together seamlessly

Test Categories

  • ERC721 compliance tests
  • Minting and burning functionality
  • Crowdsale mechanics and edge cases
  • Proxy upgrade scenarios
  • Access control and permissions
  • Pausable functionality
  • Metadata reveal mechanics
  • Token enumeration features
  • ERC721Permit permit feature for token approval

🛠️ OpenZeppelin Integration

The project leverages battle-tested OpenZeppelin primitives:

  • ERC721: Foundation for NFT functionality
  • Ownable: Access control with 2-step transfer enhancement
  • Pausable: Emergency stop mechanism
  • ReentrancyGuard: Protection against reentrancy attacks
  • Proxy Patterns: Upgradeable contract architecture
  • AccessControl: Role-based permission management
  • SafeMath: Automatic overflow protection (Solidity 0.8+)

🚀 Deployment & Usage

Disclaimer

This is not a project to be used in a real production system. There are several improvement rooms to be implemented

Prerequisites

  • Foundry installed
  • Ethereum wallet with testnet ETH for Sepolia deployment
  • Environment variables configured (see .env.sample)

Local Development

cd contracts

# Compile contracts
make build

# Run full test suite
make test

# Generate coverage report
make coverage

# Deploy locally
make local_deploy

Sepolia Testnet Deployment

cd contracts

# Deploy to Sepolia testnet
make sepolia_deploy

Available Make Commands

  • make build - Compile all contracts
  • make test - Run complete test suite
  • make coverage - Generate detailed coverage report
  • make local_deploy - Deploy to local Anvil network
  • make sepolia_deploy - Deploy to Sepolia testnet

📁 Project Structure

├── src/                    # Smart contracts source code
├── test/                   # Comprehensive test suites
├── script/                 # Deployment scripts
│   ├── LocalDeploy.s.sol  # Local deployment script
│   └── SepoliaDeploy.s.sol # Sepolia deployment script
├── lib/                    # External dependencies (OpenZeppelin)
├── Makefile               # Build and deployment automation
└── foundry.toml           # Foundry configuration

🔧 Configuration

The project uses Foundry's configuration system with sensible defaults:

  • Solidity version: 0.8.30
  • Optimizer: Enabled
  • Gas reporting: Enabled
  • Coverage: Comprehensive reporting
  • Remappings: Configured for OpenZeppelin imports

📈 Contract Metrics

  • Gas Optimized: Efficient implementations minimizing deployment and transaction costs
  • Security Focused: Comprehensive access controls and safety mechanisms
  • Upgrade Safe: Proper storage layouts and initialization patterns
  • Event Rich: Detailed event emission for off-chain indexing and monitoring

🛡️ Security Features

  • Reentrancy Protection: Guards against reentrancy attacks through battle-tested patterns
  • Access Control: Multi-level permission system
  • Integer Overflow Protection: Built-in Solidity 0.8+ protections
  • Pausable Operations: Emergency stop functionality
  • Upgrade Safety: Transparent proxy pattern with admin controls
  • Input Validation: Comprehensive parameter checking

🎯 Use Cases

This NFT suite is ideal for:

  • Art Collections: High-quality NFT drops with reveal mechanics
  • Gaming Assets: In-game items with upgrade capabilities
  • Membership Tokens: Access control and utility tokens
  • Collectibles: Trading cards, sports memorabilia, etc.
  • Utility NFTs: Tokens providing real-world benefits

What is not deliberately covered in Nifty

  • No frontend at all. In a real production project, some front would have been implemented facilitating minting and trading of these NFT
  • There is no functional backend, only a test suite In a real production project, some routes could be eventually created to reconstruct data off-chain if necessary
  • The token has been done from scratch In a real production project, I would have relied on OpenZeppelin ERC1155 or ERC721 depending on the needs to ensure battle tested use cases of NFT are already implemented, adding only tested Nifty specific features
  • The permit facility is basic. In a real production project, I would have implemented Typed structured data hashing and signing from EIP-712 and eventually the permit extension for signed approvals (ERC-2612)
  • TransparentUpgradeableProxy are used though it's not the standard anymore. However, it has been used to demonstrate storage slot collision issues and how to remediate. Two articles have been written on these: Understanding Solidity Transparent Upgradeable Proxy Pattern - A Practical Guide Deep Dive in Transparent Proxy Code In a real production project, I would have use UUPSProxy that is more gas efficient, get rid off storage collision issues and is more widespread. Of course it would require to adapt existing implementation contracts.

🤝 Contributing

Contributions should maintain the high standards of:

  • 100% test coverage
  • Comprehensive documentation
  • Gas optimization
  • Security best practices

Crafted with ❤️ using Foundry, OpenZeppelin, and modern Solidity practices.

About

An up-gradable digital deed

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published