A decentralized financial infrastructure mitigating volatility via Chainlink Data Feeds.
Enforces USD-denominated funding thresholds on ETH transactions with gas-optimized architecture.
- 🧠 Executive Summary
- 💱 Oracle Integration Logic
- ⚡ Gas Optimization Engineering
- 🛡 Security & Access Control
- 🚀 Deployment & Testing
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."
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).
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
To ensure accuracy, we perform the following conversion:
- Adjustment: We multiply Chainlink's price by to match Ethereum's 18-decimal standard (
wei).
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). |
Unlike simple wallets, FundMe implements strict State Management patterns to prevent re-entrancy or fund theft.
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
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
| 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