How bbayazit16/l2savings works
This project is a Next.js web application focused on demonstrating Ethereum Layer 2 fee savings. Its purpose is to show how much users can save by comparing the fees paid on different L2 solutions with those that would have been incurred on Ethereum Mainnet. The project leverages React components, custom hooks, context providers, and a series of utility libraries to fetch and process blockchain data.
Main components
• Frontend/UI Layer: Represented by the Next.js app. This includes pages (e.g., src/app/page.tsx, src/app/faq/page.tsx) and React components (e.g., Navbar, Footer, SavingsBox, various Buttons) that build the user interface.
• State Management & Context Providers: Illustrated by the AccountProvider, ChosenL2Provider, and SavingsProvider (in src/app/providers). These components manage shared state and context for user accounts, chosen L2 chains, and savings calculations.
• Business Logic & Calculation Layer: Found in the lib directory. It includes modules that encapsulate the logic to fetch transaction data (e.g., customfetch, ethfees, gethBatchCustomReceipts) and perform the fee savings calculations. The l2 subdirectory (with different files like Arbitrum.ts, Base.ts, Optimism.ts, ZkSyncLite.ts) is key in isolating logic for each Layer 2 chain.
• Utility & Helper Functions: Other lib modules (like chainToAssetSrc.ts, constants.ts, chunk.ts, and truncateTransactionHash.ts) that support data manipulation and UI presentation.
• Styling & Configuration: Tailwind CSS and configuration files (tailwind.config.ts, postcss.config.js, next.config.js) that set up the presentation style and build environment.
Out the relationships and interactions
• The UI components (in src/app/components) interact directly with the context providers to obtain data such as user accounts, selected L2, and saving information.
• The providers wrap the application (as seen in src/app/providers/index.tsx) to enable state sharing, so hooks (like useAccount, useSavings, and useChosenL2) can be used by the components.
• Hooks invoke functions from the lib directory, which handle data fetching from external Ethereum and L2 RPC endpoints. These functions compute fees based on the chain-specific logic.
• External blockchain interaction occurs behind the scenes – the lib functions (especially in the l2 directory) use endpoints to query transaction receipts and fee histories.
• The custom fetch utilities and constants ensure that the calculations (for Optimism, Arbitrum, ZkSync Lite, Linea, and Base) adhere to blockchain-specific data structures and formulas.
Important architectural patterns
• Separation of Concerns: UI, state management, and business logic are clearly separated into distinct directories (components vs. providers vs. lib), which encourages modularity and easier maintenance.
• Context-Driven State Management: The use of providers and custom hooks demonstrates a pattern where state is centralized and shared across components.
• Chain-Specific Logic Modules: The use of separate files for each L2 (e.g., Arbitrum.ts, Base.ts) shows a plug-in-like approach that makes it easier to extend support for additional chains.
• Next.js Page Routing & Layout: The project uses Next.js conventions (with pages and app directories) to manage routing and global layouts.
External and internal technologies
• Frameworks/Libraries: Next.js, React, Tailwind CSS, TypeScript.
• External Services: Ethereum Mainnet and L2 (Optimism, Arbitrum, ZkSync Lite, Linea, Base) RPC endpoints used to fetch blockchain data.
• Build & Linting Tools: ESLint, Prettier, and TypeScript configurations ensure code quality.