Appearance
Protocol v2.1 Flow Diagrams
This directory contains Mermaid flow diagrams documenting the Textile Protocol v2.1 architecture and core flows.
Diagram Files
01. Architecture Overview
File: 01-architecture-overview.mmd
Complete system architecture showing:
- Protocol infrastructure layer (Registry, WithdrawalRegistry, ProtocolConfiguration, etc.)
- Pool instance components (StructuredPool, Tranche, Reserve, CreditLineController)
- External actor interactions
- Component relationships and data flows
02. Deposit Flow
File: 02-deposit-flow.mmd
Liquidity provider deposit flow:
- Pre-flight checks (pause state, limits, shutdown)
- Share calculation (ERC4626 standard)
- Fund custody transfer to Reserve
- Virtual accounting updates
- Share token minting
03. Drawdown Flow
File: 03-drawdown-flow.mmd
Borrower capital deployment flow:
- Authorization checks (onlyBorrower)
- Forced interest accrual
- Credit limit validation
- Tranche selection
- Capital deployment from Reserve to borrower
- Virtual accounting updates (virtualBalance → virtualDeployed)
04. Repayment Flow
File: 04-repayment-flow.mmd
Borrower repayment processing:
- Forced interest accrual
- Payment split (interest vs principal)
- Interest routing to Reserve → Tranche
- Principal routing to Reserve → Tranche
- Virtual accounting updates
- Credit line adjustment
05. Approval-Based Withdrawal Flow
File: 05-withdrawal-approval-flow.mmd
Three-step withdrawal process when approval required:
- Request: LP submits withdrawal request to WithdrawalRegistry
- Approve: Pool manager approves specific share amount (shares become reserved)
- Execute: LP executes standard withdraw/redeem with approval consumption
Reserved Shares Protection: Approved shares are tracked in totalReservedShares and excluded from getAvailableForBorrowing(), preventing borrowers from drawing funds that LPs have requested to withdraw.
06. Factory Deployment Flow
File: 06-factory-deployment-flow.mmd
Complete pool deployment sequence:
- Deploy StructuredPool as BeaconProxy (includes integrated credit line)
- Deploy Tranche as BeaconProxy
- Deploy immutable Reserve in Tranche constructor
- Register pool in Registry
- Register tranche with pool
Key Feature: All pool components use BeaconProxy pattern for mass upgradeability with timelock protection.
Viewing the Diagrams
Online Viewer
Use Mermaid Live Editor:
- Copy the
.mmdfile contents - Paste into the editor
- View rendered diagram
VS Code
Install the Mermaid Preview extension:
code --install-extension bierner.markdown-mermaidThen open any .mmd file and use Cmd+Shift+V (Mac) or Ctrl+Shift+V (Windows/Linux).
Command Line
Install Mermaid CLI:
bash
npm install -g @mermaid-js/mermaid-cliRender to PNG/SVG:
bash
# PNG output
mmdc -i 01-architecture-overview.mmd -o architecture.png
# SVG output
mmdc -i 01-architecture-overview.mmd -o architecture.svg -b transparent
# PDF output
mmdc -i 01-architecture-overview.mmd -o architecture.pdfMarkdown Documentation
These diagrams can be embedded in Markdown files:
markdown
```mermaid
{{contents of .mmd file}}
```Diagram Conventions
Color Coding
- Light Blue (
#e1f5ff): Infrastructure components - Light Yellow (
#fff4e1): Pool system components - Light Red (
#ffcccc): Custody layer (Reserve) - Light Gray (
#f0f0f0): External actors
Sequence Diagram Sections
Colored rectangles indicate logical phases:
- Pink (
rgb(255, 240, 240)): Validation/authorization checks - Blue (
rgb(240, 248, 255)): Calculations/state reads - Green (
rgb(240, 255, 240)): State updates/transfers - Yellow (
rgb(255, 248, 240)): Interest/fee processing
Annotations
✅indicates successful completion⏳indicates waiting/pending state↑/↓indicate increases/decreases- Notes provide context about checks, calculations, or state changes
Related Documentation
- Auditor Introduction:
../auditor-intro.md- Comprehensive protocol documentation - Developer Guide:
../developer-guide.md- Developer integration guide - Protocol Overview:
../overview.md- Non-technical introduction
Updating Diagrams
When updating the protocol:
- Update the corresponding
.mmdfile(s) - Regenerate any embedded PNG/SVG images
- Update the main auditor intro document if architectural changes occurred
- Verify diagrams render correctly in preview tools
Diagram Generation Script
A script is available to batch-generate all diagrams:
bash
cd packages/protocol
npm run generate:diagramsThis will:
- Validate all
.mmdfiles for syntax errors - Generate PNG and SVG versions
- Output to
docs/v2.1/flows/generated/
Last Updated: 2025-01-14 Protocol Version: v2.1 (Single Tranche)