Investment Lifecycle Architecture¶
Обзор¶
UPDATED: 2025-11-03 - Mobile-First MVP
Документация жизненного цикла инвестиций в Saga DeFi Platform - mobile-first MVP с auto-approve flow и multi-network test support.
Investment Flow Overview¶
High-Level Architecture (Integration-Only MVP)¶
stateDiagram-v2
[*] --> Deposit: User deposits via Crypto2B
Deposit --> CREATE: Auto-Invest enabled
CREATE --> ACTIVE: Auto-Approve (immediate)
ACTIVE --> COMPLETED: Yield accrued
ACTIVE --> WITHDRAWN: User withdraws
COMPLETED --> WITHDRAWN: User withdraws
note right of CREATE
- NO PENDING STATE
- NO BLOCKCHAIN INTERACTION
- AUTO-INVEST on deposit
end note
note right of WITHDRAWN
- Withdrawal via Fordefi
- From general balance
end note
Key Principles:
- NO PENDING STATE: Investments immediately "active"
- NO BLOCKCHAIN INTERACTION: Crypto2B + Fordefi handle all crypto operations
- AUTO-INVEST: Automatic investment creation on deposit
- WITHDRAWAL: From general balance (not specific investment)
MVP Implementation¶
Key Files¶
Backend:
backend/shared/routing/user_api_router.go- Auto-invest deposit handler (lines ~550-580)backend/shared/services/canonical/investment_service.go- Auto-approve logic (status="active")backend/shared/services/multi_network_test_provider.go- Multi-network TEST address generation
Frontend:
frontend/user-app/src/components/dashboard/MobileDashboard.tsx- Main mobile-first containerfrontend/user-app/src/components/dashboard/DepositSection.tsx- Multi-network deposits + auto-invest togglefrontend/user-app/src/components/dashboard/WithdrawalSection.tsx- Withdrawal from general balancefrontend/user-app/src/components/dashboard/PortfolioSection.tsx- Portfolio overview with strategy chartfrontend/user-app/src/components/modals/TransactionDetailsModal.tsx- Investment details modal
MVP Flow¶
- Deposit → User deposits via multi-network TEST address (Tron/EVM/Solana)
- Auto-Invest → Automatic investment creation on deposit (10% APY)
- Investment Status → Immediately "active" (no pending, no blockchain interaction)
- Yield Config → APY configured in
config/limits.yaml(10% MVP) - Withdrawal → From general balance (not specific investment)
Database Changes¶
Users Table (Auto-Invest Fields):
Investments Table (Status Flow):
- CREATE →
status='active'(immediate, no pending) - User withdrawal →
status='completed'
Multi-Network Support:
wallets.network_idINTEGER (1=Tron, 2=EVM, 3=Solana)- TEST address formats documented in
docs/developers/testing/multi-network-test-addresses.md