How 0glabs/0g-storage-contracts works
Main Components
• Contracts Modules:
• Flow: Manages user data submissions and maintains the Merkle root of stored data.
• Market: Validates fee payment upon data submissions and supports different implementations (e.g., Cashier, FixedPrice).
• Reward: Distributes rewards based on the mining task results using various models (ChunkDecayReward, ChunkLinearReward, OnePoolReward).
• Miner: The component that validates mining submissions and requests corresponding rewards.
• Deployment and Upgrade Infrastructure:
• Deployment Scripts: Located in the src/deploy folder (deploy_blake2b_test.ts, deploy_fixed_price_flow.ts, etc.) used to deploy various contract configurations.
• Upgrade Tasks: Found under src/tasks/upgrade.ts and related tasks that manage upgrades following a detailed process (forceImportAll, upgrade:validate etc.).
• Network Configuration:
• Custom network configurations in src/networks (for example, zerog_contract_config.ts, zerog_testnet_contract_config_standard.ts) allowing for tailored deployments on local test networks or networks like Zero Gravity.
Relationships and Interactions
• Reward Distribution: After data submission is verified and the mining task is completed, Flow communicates with the Reward module to trigger reward calculations and releases.
• Contract Upgrades: Highlight the upgrade path via Hardhat tasks. Show how after initial deployments, artifacts are verified (via upgrade:validate) then upgraded, with deployments being stored and updated in the deployments folder.
• Deployment Options: Clearly demarcate between “market-enabled” and “non-market” deployments and illustrate how the different deployment scripts (FixedPrice, OnePoolReward, no-market, etc.) tie into that workflow.
Architectural Patterns & Design Principles
• Separation of Concerns: Differentiate between contract business logic, deployment scripts (in src/deploy), network configuration (in src/networks), and maintenance/upgrades (in src/tasks).
• Extensibility and Configuration: Emphasize that new networks can be added easily using the configuration files in the networks folder and that multiple economic models can be swapped in/out.
Relevant Technologies and Frameworks
• Hardhat Framework: Illustrate that the system is built and deployed using Hardhat (as evidenced by hardhat.config.ts) with specific tasks for deployment and upgrades.
• Testing Framework: Include Mocha configuration (.mocharc.json) showing that testing is robustly covered.
• Code Quality Tools: Mention ESLint (.eslintrc.js) and Prettier (.prettierrc) that enforce coding standards.
• Patch Files: Note the presence of patches that apply to third-party libraries (e.g., waffle-mock-contract) for enhanced functionality or bug fixes.