How mrgnlabs/marginfi-v2 works
Main Components to Highlight
• On-Chain Programs: Indicate the various Solana programs such as the core marginfi program, liquidity incentive program, mocks, and test transfer hooks. (These are in the “programs/…” directory and are built with Anchor and Cargo.)
• Marginfi Group & Lending Pool: Represent the marginfi group as a central component that manages lending pools. Within these pools, you have multiple banks (each with its own mint and oracle configuration).
• Banks & Oracles: For each bank, show its relationship with its custom oracle (currently Pyth, with plans for Switchboard). This communicates the external data dependency that feeds into the risk engine.
• Marginfi Accounts and Users (Signers): Illustrate that users (signers) interact with the system via marginfi accounts, which allow multiple asset interactions.
• Client Interfaces and Tools: Include supporting components such as the command-line client in “clients/rust/marginfi-cli”, automated tests (both Rust and TS tests in “tests/…”), and deployment/observability tooling (in “observability”, “scripts”, “tools”).
Relationships & Interactions
• For each Bank, include a bidirectional relationship with a Price Oracle since banks use real-time price feeds (Pyth) to determine LTVs and risk.
• Risk engine monitoring data flows from user accounts and banks to the risk-management logic, with possible feedback loops (e.g., triggering liquidations).
Architectural Patterns and Technologies
• Modular and layered structure: on-chain programs for the business logic, client libraries (Rust CLI), and observability modules (indexer, ETL in Python and Rust).
• Use the microservices or modular components concept since many directories indicate separate concerns, such as “programs”, “observability”, “clients”, and “tools”.
• Mention use of Anchor (as observed in Anchor.toml, tests, and deployment docs) for program development.
• Testing framework structure and CI/CD tooling (GitHub actions, workflow YAMLs) that streamline build, deploy, and verification processes.