How morpho-org/morpho-blue works
Main Components
• Core Contract: The heart of the protocol is in src/Morpho.sol, which encompasses the business logic for lending.
• Internal Libraries: Found in src/libraries, these provide essential functions; note that the subdirectory src/libraries/periphery includes helper libraries for integrators.
• Interfaces: In src/interfaces, these specify the contracts’ API, such as IMorpho.sol, which lists important market dependency requirements.
• Mock Contracts: The src/mocks directory isolates test contracts used to simulate external behaviors during testing.
• Testing Frameworks: There are separate test suites for Forge (via test/forge) and Hardhat (via test/hardhat), reflecting diverse testing strategies.
• Formal Verification: The certora folder contains configurations and specifications (conf and specs directories) for running formal verification; it helps ensure properties like reentrancy-safety, accurate math, correct state, and more.
• Audits and Documentation: The audits folder and the whitepaper (morpho-blue-whitepaper.pdf) provide external validation and detailed protocol descriptions.
• CI/CD Pipelines: The .github/workflows folder with multiple YAML files (e.g., foundry.yml, hardhat.yml, halmos.yml) shows automated testing, formatting, and release processes. Other configuration files such as foundry.toml, tsconfig.json, and hardhat.config.ts also coordinate build and deployment setups.
Relationships and Interactions
• Core Contract to its test environments (forge and Hardhat tests) to indicate how the code is verified via both simulation (mock contracts) and formal proofs (Certora specifications).
• CI/CD workflows as a side component that continuously integrates and tests the codebase.
• Tie in the audits and whitepaper as external validation and documentation sources.
• That the protocol is designed to be augmentable (through periphery libraries) and to interact with external financial primitives (flash loans, oracles).
Architectural Patterns and Design Principles
• Modular design: separate concerns in core logic, reusable libraries, mock/test contracts, and formal verification specs.
• Separation of environments: production contracts vs. testing (Forge and Hardhat) vs. verification tools, which ensures robust development via multiple layers of quality assurance.
• CI/CD integration: automated workflows based on GitHub Actions ensure quality and standardized deployment.
Technology, Frameworks, and Tools
• Solidity for smart contract development.
• Foundry and Hardhat for testing frameworks.
• Certora formal verification tools as evidenced by the certora folder.
• GitHub Actions for automated testing, formatting, and releases.
• Dependency management via package.json and Yarn (as indicated through installation instructions).
Specific Elements
• Each major directory’s purpose should be represented (e.g., “src” for contracts and libraries, “test” for test suites, “certora” for verification).
• Visual markers to denote components that are external to the logic (like audits and whitepaper documentation) along with CI/CD workflows.