Skip to content

NexTechArchitect/FundMe-Contract

Repository files navigation



Oracle-Pegged Crowdfunding

A decentralized financial infrastructure mitigating volatility via Chainlink Data Feeds.
Enforces USD-denominated funding thresholds on ETH transactions with gas-optimized architecture.

   



📑 Table of Contents


🧠 Executive Summary

FundMe is a decentralized application (dApp) designed to solve the volatility problem in crypto crowdfunding.

Traditional crowdfunding accepts fixed ETH amounts (e.g., "Send 1 ETH"). However, if the price of ETH crashes, the project fails. This protocol enforces a Minimum USD Contribution (e.g., $50) by performing real-time cryptographic conversion using Chainlink Aggregators.

Core Value: "Fund in Crypto, Denominate in Fiat."


💱 Oracle Integration Logic

The core innovation is the Dynamic Price Conversion Library. We utilize modular arithmetic to handle precision loss between Ethereum (18 decimals) and Chainlink Oracles (8 decimals).

📐 Data Flow Architecture

graph LR
    User((Funder))
    Contract[FundMe Contract]
    Oracle{Chainlink Oracle}
    Logic{Validation}

    User -- "1. Send ETH (wei)" --> Contract
    Contract -- "2. Request Price" --> Oracle
    Oracle -- "3. Return ETH/USD (8 dec)" --> Contract
    
    Contract -- "4. Normalize to 18 dec" --> Logic
    Logic -- "Check Value >= $50" --> Valid{Result}
    
    Valid -- "Pass" --> Accept[✅ State Update]
    Valid -- "Fail" --> Revert[❌ Revert Tx]

    style Oracle fill:#2d1b4e,stroke:#9d4edd,stroke-width:2px
    style Contract fill:#1a1a1a,stroke:#b298dc
    style Logic fill:#1a1a1a,stroke:#fff

Loading

🧮 Precision Math Specification

To ensure accuracy, we perform the following conversion:

$$ \text{USD Value} = \frac{\text{ETH Amount (wei)} \times \text{ETH Price (8 decimals)} \times 10^{10}}{10^{18}} $$

  • Adjustment: We multiply Chainlink's price by to match Ethereum's 18-decimal standard (wei).

⚡ Gas Optimization Engineering

This contract is engineered to minimize OpCode execution costs, saving users significantly on transaction fees.

Technique Implementation Details Gas Impact
Bytecode Constants MINIMUM_USD is declared as constant. ~2,100 Gas Saved (No SLOAD).
Immutable Variables i_owner is set once at deployment and stored in bytecode. ~2,100 Gas Saved per call.
Custom Errors error FundMe__NotOwner(); vs require(). Cheaper Reverts (No string storage).
Memory Caching Reading funders array length from memory during loops. Massive Savings on large arrays by avoiding repeated storage reads (SLOAD).

🛡 Security & Access Control

Unlike simple wallets, FundMe implements strict State Management patterns to prevent re-entrancy or fund theft.

🛡️ Secure Withdrawal Pattern

sequenceDiagram
    participant Attacker
    participant Owner
    participant Contract

    Attacker->>Contract: withdraw()
    Note right of Contract: ❌ Revert: NotOwner Error
    Contract-->>Attacker: Transaction Failed

    Owner->>Contract: withdraw()
    Note right of Contract: ✅ Check: i_owner == msg.sender
    
    Contract->>Owner: Transfer All ETH
    Contract->>Contract: Reset Funders Array (New)
    Contract->>Contract: Reset Mappings (0)
    Note left of Contract: State Cleaned Atomically

Loading

🚀 Deployment & Testing

A clean, modular layout optimized for Foundry development. We support Forked Testing to simulate real Chainlink Oracles on a local blockchain.

FundMe-Contract/
├── src/
│   ├── FundMe.sol           // [CORE] Main crowdfunding logic
│   └── PriceConverter.sol   // [LIB]  Math library for 1e18 precision
├── script/
│   ├── DeployFundMe.s.sol   // [OPS]  Network-aware deployment
│   └── HelperConfig.s.sol   // [CONF] Mocks for local Anvil chains
└── test/
    ├── unit/                // [TEST] Isolated logic checks
    └── integration/         // [TEST] Full funding/withdrawal simulation

🛠 Automated Workflow

Command Action Performed
make build Compiles smart contracts and generates ABI artifacts.
make test Executes the full test suite (Unit + Integration).
make snapshot Generates a gas usage report for optimization analysis.
make anvil Starts a local Ethereum node for rapid debugging.

Engineered by NEXTECHARHITECT

Smart Contract Developer · Solidity · Foundry · Web3 Engineering

GitHubTwitter


About

A minimalistic smart contract built with Solidity and Foundry, enabling decentralized funding contributions with transparent logic.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors