feat: AI cost tracking, pre-launch balance check, low balance alerts

- store/ai_charge.go: local AI cost tracking per call (SQLite)
- wallet/usdc.go: shared USDC balance query (Base chain RPC)
- Pre-launch: estimate daily cost + runway days
- Low balance: warn <$1, error at $0 (every 10 cycles)
- API: GET /api/ai-costs for cost history
- Frontend: model cards show price per call
- Frontend: wallet create + QR deposit + balance display
This commit is contained in:
shinchan-zhai
2026-03-21 12:31:20 +08:00
parent 79a513470b
commit fd77f2df3e
12 changed files with 629 additions and 98 deletions

View File

@@ -28,6 +28,7 @@ type Store struct {
equity *EquityStore
order *OrderStore
grid *GridStore
aiCharge *AIChargeStore
telegramConfig TelegramConfigStore
mu sync.RWMutex
@@ -160,6 +161,9 @@ func (s *Store) initTables() error {
if err := s.TelegramConfig().(*telegramConfigStore).initTables(); err != nil {
return fmt.Errorf("failed to initialize telegram config tables: %w", err)
}
if err := s.AICharge().initTables(); err != nil {
return fmt.Errorf("failed to initialize AI charge tables: %w", err)
}
return nil
}
@@ -283,6 +287,16 @@ func (s *Store) Grid() *GridStore {
return s.grid
}
// AICharge gets AI charge storage
func (s *Store) AICharge() *AIChargeStore {
s.mu.Lock()
defer s.mu.Unlock()
if s.aiCharge == nil {
s.aiCharge = NewAIChargeStore(s.gdb)
}
return s.aiCharge
}
// TelegramConfig gets Telegram bot configuration storage
func (s *Store) TelegramConfig() TelegramConfigStore {
s.mu.Lock()