FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
agentic mode add & mcp internal tool system extend
tilakpatel22adc79276ed9c
diff --git a/.claude/settings.json b/.claude/settings.jsondeleted file mode 100644index 0f243d7ad..000000000--- a/.claude/settings.json+++ /dev/null@@ -1,5 +0,0 @@-{- "enabledPlugins": {- "superpowers@claude-plugins-official": true- }-}diff --git a/.gitignore b/.gitignoreindex 65bb36ff2..abc1f59a8 100644--- a/.gitignore+++ b/.gitignore@@ -106,7 +106,7 @@ node_modules/dist-ssr/# ── Claude Code — never commit ───────────────────────────────-.claude/settings.local.json+.claude/CLAUDE.mdfincept-qt/DESIGN_SYSTEM.mddiff --git a/fincept-qt/.claude/scheduled_tasks.lock b/fincept-qt/.claude/scheduled_tasks.lockdeleted file mode 100644index 59116c2e1..000000000--- a/fincept-qt/.claude/scheduled_tasks.lock+++ /dev/null@@ -1 +0,0 @@-{"sessionId":"e0edbf79-1ecb-4d3a-8836-78b45f96ecbe","pid":2836,"acquiredAt":1778054479103}\ No newline at end of filediff --git a/fincept-qt/DATAHUB_ARCHITECTURE.md b/fincept-qt/DATAHUB_ARCHITECTURE.mddeleted file mode 100644index edf71f754..000000000--- a/fincept-qt/DATAHUB_ARCHITECTURE.md+++ /dev/null@@ -1,515 +0,0 @@-# DataHub Architecture--**Status:** Current (in production as of 2026-04-18; all phases 0–10 shipped)-**Version:** 1.0-**Owner:** Fincept Terminal Core-**Scope:** In-process pub/sub data layer for the entire terminal (markets, news, economics, broker streams, geopolitics, agents, WebSockets).-------## 1. Problem--Every screen and widget in the terminal currently pulls its own data:--- `~20 dashboard widgets`, `MarketPanel`, `WatchlistScreen`, `PortfolioBlotter`, etc. each own a `QTimer` and call `MarketDataService::fetch_quotes(...)` on independent cadences.-- `55+ screens` have local timers driving their own refresh cycles.-- `27 services` mix three incompatible response styles: `std::function` callbacks, Qt `signals:` with request IDs, and raw `QWebSocket` streams.-- Result: duplicate Python spawns, duplicate HTTP calls, fragmented cache behaviour, no single source of truth for "when was AAPL last updated."--The 30 s `CacheManager` TTL on market quotes partially hides the problem inside a single refresh window, but across tabs and time it breaks down.--**Goal:** one fetch per (symbol, source) at any moment, fanned out to every subscriber — markets, dashboard, watchlist, portfolio, AI chat, MCP tools, agents — via a single push primitive.-------## 2. Non-Goals--- Not an inter-process broker. We stay in-process (one Qt app). No Redis, ZeroMQ, MQTT.-- Not a replacement for `CacheManager` — the hub **uses** it for persistence.-- Not a replacement for `PythonRunner`, `HttpClient`, or broker SDKs — services remain the I/O owners.-- Not a workflow/event bus — this is for **data state**, not imperative events.-------## 3. Core Concepts--### 3.1 Topic--A **topic** is a string-keyed slot that holds the last-known-good value for one piece of data.--**Format:** `domain:subdomain:id[:modifier]`--Examples:-```-market:quote:AAPL-market:history:AAPL:1y:1d-market:sparkline:TSLA-news:general-news:symbol:NVDA-econ:fred:GDP-econ:dbnomics:IMF/IFS/USA.PCPI_IX.Q-ws:kraken:BTC-USD-ws:hyperliquid:ETH-broker:zerodha:positions-broker:angelone:orders-geopolitics:hdx:conflicts-agent:hedgefund:run:42-```--**Rules:**-- Lowercase, colon-delimited, no spaces.-- Stable — topic keys are the public contract; producers and subscribers agree on them.-- `*` wildcard allowed at the tail for subscriptions only (`market:quote:*`).--### 3.2 Subscriber--Any `QObject` (widget, screen, service, MCP tool) that calls `DataHub::subscribe(owner, topic, slot)`.--- Subscription is **owned by a QObject**. When the owner is destroyed, the subscription auto-cleans via `QObject::destroyed()` signal.-- Subscriber receives: (a) current cached value immediately on subscribe (if fresh), (b) every future `publish()` for that topic.-- A subscriber may watch many topics; a topic may have many subscribers.--### 3.3 Producer--A service that owns refresh for a set of topic patterns. Implements:--```cpp-class Producer {- public:- virtual ~Producer() = default;-- // Patterns this producer owns, e.g. {"market:quote:*", "market:history:*"}- virtual QStringList topic_patterns() const = 0;-- // Hub calls this when ≥1 subscriber exists and the cached value is stale.- // Producer fetches (async) and calls hub.publish() when done.- virtual void refresh(const QStringList& topics) = 0;-- // Optional: max outbound requests per second. Hub scheduler groups and- // paces refresh calls to respect this. Default 0 = unlimited.- // Examples: Zerodha REST = 3, Angel One REST = 1, Polymarket = 10.- virtual int max_requests_per_sec() const { return 0; }-- // Optional: called when last subscriber leaves a topic. Producer may- // release resources (close WebSocket channel, cancel stream, etc.).- virtual void on_topic_idle(const QString& /*topic*/) {}-};-```--### 3.4 Refresh Policy--Per-topic metadata stored in the hub:--```cpp-struct TopicPolicy {- int ttl_ms = 30000; // cached value is fresh for this long- int min_interval_ms = 5000; // don't refresh more often than this- bool push_only = false; // true → no TTL, no scheduled refresh- // (WebSocket-driven topics)- int priority = 0; // higher = refreshed first under backpressure-};-```--- `push_only = true` for all `ws:*` topics. Hub never schedules them; producer calls `publish()` on every tick.-- `ttl_ms = 30000` default for market quotes (matches current behaviour).-- `ttl_ms = 300000` for news, `ttl_ms = 3600000` for economics series.-------## 4. Public API--```cpp-namespace fincept::datahub {--class DataHub : public QObject {- Q_OBJECT- public:- static DataHub& instance();-- // ── Subscribing ─────────────────────────────────────────────────────────- // Returns the Qt connection (for manual disconnect if ever needed).- // `owner` is the lifetime guard — subscription auto-cancels when owner dies.- // `slot` receives the current value immediately (if cached + fresh) and- // every future publish.- QMetaObject::Connection subscribe(- QObject* owner,- const QString& topic,- std::function<void(const QVariant&)> slot);-- // Typed variant — unwraps QVariant to T automatically. T must be registered- // with Q_DECLARE_METATYPE + qRegisterMetaType<T>() at startup.- template <typename T>- QMetaObject::Connection subscribe(- QObject* owner,- const QString& topic,- std::function<void(const T&)> slot) {- static_assert(QMetaTypeId2<T>::Defined,- "T must be registered with Q_DECLARE_METATYPE");- return subscribe(owner, topic, [slot](const QVariant& v) {- if (v.canConvert<T>()) slot(v.value<T>());- });- }-- // Wildcard variant — slot receives (topic, value) pairs.- QMetaObject::Connection subscribe_pattern(- QObject* owner,- const QString& pattern, // e.g. "market:quote:*"- std::function<void(const QString&, const QVariant&)> slot);-- void unsubscribe(QObject* owner);- void unsubscribe(QObject* owner, const QString& topic);-- // ── Publishing (producer side) ──────────────────────────────────────────- // Stores in CacheManager with topic's TTL, emits to all subscribers.- void publish(const QString& topic, const QVariant& value);-- // Overload for push-only topics that want to override cache behaviour.- void publish(const QString& topic, const QVariant& value,- std::chrono::milliseconds ttl);-- // ── Registration ────────────────────────────────────────────────────────- void register_producer(Producer* producer);- void unregister_producer(Producer* producer);-- // Tell the hub how a specific topic should behave.- void set_policy(const QString& topic, const TopicPolicy& policy);- void set_policy_pattern(const QString& pattern, const TopicPolicy& policy);-- // ── Pull-through ────────────────────────────────────────────────────────- // Read current cached value without subscribing. Returns invalid QVariant- // if unknown. Does NOT trigger a fetch.- QVariant peek(const QString& topic) const;-- // Ask the hub to refresh now (if policy allows). Subscribers receive- // update via the normal signal path.- //- // `force=false` (default): honours `min_interval_ms` — back-to-back- // calls inside the interval gate are skipped. Use for routine- // "kick the scheduler" requests.- //- // `force=true`: bypasses `min_interval_ms` so a user-driven refresh- // button can refetch even inside the interval. Per-producer- // `max_requests_per_sec()` is still honoured — rage-clicking cannot- // hammer upstream. Introduced in Phase 6 for economics panels.- void request(const QString& topic, bool force = false);- void request(const QStringList& topics, bool force = false);-- signals:- // Low-level fan-out. Most callers should use subscribe() instead; this- // signal is for diagnostics, logging, and DevTools-style inspectors.- void topic_updated(const QString& topic, const QVariant& value);- void topic_idle(const QString& topic); // last subscriber left- void topic_active(const QString& topic); // first subscriber joined-- private:- DataHub();- // ... internals: subscription registry, scheduler timer, dispatcher ...-};--} // namespace fincept::datahub-```-------## 5. Behaviour--### 5.1 Subscribe flow--```-Widget::ctor- └─ DataHub::subscribe(this, "market:quote:AAPL", slot)- ├─ register (this, "market:quote:AAPL", slot) in registry- ├─ connect destroyed(this) → auto-unsubscribe- ├─ if peek("market:quote:AAPL") is fresh → call slot(cached) now- ├─ if topic was idle → emit topic_active(topic)- │ scheduler considers it on next tick- └─ return Qt::Connection-```--### 5.2 Publish flow--```-MarketDataService::on_batch_result- └─ hub.publish("market:quote:AAPL", QVariant::fromValue(quote))- ├─ CacheManager::put(topic, value, policy.ttl_ms, domain)- ├─ emit topic_updated(topic, value)- │ └─ Qt fans out to all slots connected via subscribe()- └─ update last_publish_ts[topic]-```--### 5.3 Scheduler flow--Hub owns a single `QTimer` at 1 s resolution. Each tick:--```-for topic in topics_with_subscribers:- if policy.push_only: continue- if not expired(topic, policy): continue- if in_flight(topic): continue- group_by_producer[producer_of(topic)].append(topic)--for producer, topics in group_by_producer:- producer->refresh(topics) // producer is free to batch further-```--- Topics with no subscribers are skipped entirely — zero cost for idle data.-- `in_flight` tracking prevents double-fetches when a refresh is still pending.--### 5.4 Unsubscribe flow--```-Widget::~Widget- └─ QObject::destroyed signal fires- └─ hub.unsubscribe(widget)- ├─ remove all (widget, *) entries from registry- └─ for each topic that now has 0 subscribers:- emit topic_idle(topic)- producer->on_topic_idle(topic) // may close WS, etc.-```-------## 6. Data Types--Values flow as `QVariant`. Producers register their structs with Qt's meta-type system:--```cpp-// In MarketDataService.h-Q_DECLARE_METATYPE(fincept::services::QuoteData)--// At startup-qRegisterMetaType<fincept::services::QuoteData>();-```--Subscribers unwrap:-```cpp-hub.subscribe(this, "market:quote:AAPL", [this](const QVariant& v) {- auto quote = v.value<services::QuoteData>();- update_ui(quote);-});-```--For wildcard subscribers watching mixed types, the convention is to publish-`QVariantMap` / `QVariantList` instead of typed structs, or to key topics by-type so each subscriber knows what it's getting.-------## 7. Threading--- `DataHub` lives on the main (GUI) thread.-- `publish()` is safe to call from any thread — it uses `QMetaObject::invokeMethod(this, ..., Qt::QueuedConnection)` to marshal to the hub thread.-- Slots are invoked on the subscriber's thread (auto-connection rules).-- Internal registry is protected by `QMutex` for the rare case of cross-thread subscribe/unsubscribe.--This matches `CLAUDE.md` rule P15 (thread safety) and P1 (never block UI).-------## 8. Caching--- Hub delegates persistent cache to `CacheManager` — same keys as topic names.-- `CacheManager` already supports TTL, categories, and (de)serialization.-- `peek()` and the subscribe-sends-current-value path both hit `CacheManager::try_get()`.-- **One source of truth:** a screen never reads `CacheManager` directly; it always goes through the hub. This prevents the current split where some services cache and some don't.-------## 9. Relationship to Existing Infrastructure--| Existing piece | Role after DataHub |-|-----------------------------|----------------------------------------------------------|-| `MarketDataService` | Becomes a `Producer` for `market:*` topics |-| `NewsService` | Becomes a `Producer` for `news:*` topics |-| `EconomicsService` | Becomes a `Producer` for `econ:*` topics |-| `ExchangeService` (crypto) | Becomes a push-only `Producer` for `ws:kraken:*`, `ws:hyperliquid:*` |-| `PolymarketWebSocket` | Becomes a push-only `Producer` for `polymarket:*` |-| Broker adapters (16) | Each a `Producer` for `broker:<id>:*` |-| `CacheManager` | Backing store for topic values (unchanged) |-| `PythonRunner` | Unchanged — still the Python I/O primitive |-| `HttpClient` | Unchanged |-| `QWebSocket` clients | Wrapped inside producers, push via `publish()` |-| Per-widget `QTimer` refresh | **Deleted** — hub scheduler replaces all of them |-------## 10. Worked Example — Market Quote--**Before (current state, `QuoteTableWidget::refresh_data` at-`src/screens/dashboard/widgets/QuoteTableWidget.cpp:36`):**--```cpp-void QuoteTableWidget::refresh_data() {- set_loading(true);- services::MarketDataService::instance().fetch_quotes(- symbols_, [this](bool ok, QVector<services::QuoteData> quotes) {- set_loading(false);- if (!ok || quotes.isEmpty()) { /* ... */ return; }- populate(quotes);- });-}-```--`QuoteTableWidget` is reused by `IndicesWidget`, `CryptoWidget`,-`ForexWidget`, and `CommoditiesWidget` (all are factory functions that-construct a `QuoteTableWidget` with a different symbol list).-`WidgetGrid` or the dashboard owns a timer that periodically calls-`refresh_data()` on the widget.--**After:**-```cpp-// QuoteTableWidget ctor — subscribe once per symbol, no timer anywhere-for (const auto& sym : symbols_) {- datahub::DataHub::instance().subscribe(this, "market:quote:" + sym,- [this, sym](const QVariant& v) {- if (!v.isValid()) return;- update_row(sym, v.value<services::QuoteData>());- });-}-// No refresh_data(), no timer. The dashboard's refresh button calls-// DataHub::instance().request({"market:quote:..."}) to force refresh.-```--**Inside `MarketDataService` (now a Producer):**-```cpp-QStringList MarketDataService::topic_patterns() const {- return {"market:quote:*", "market:history:*", "market:sparkline:*"};-}--void MarketDataService::refresh(const QStringList& topics) {- QStringList quote_syms;- for (const auto& t : topics)- if (t.startsWith("market:quote:"))- quote_syms << t.mid(13);-- if (quote_syms.isEmpty()) return;-- // existing batched Python call — unchanged internal logic- batched_python_fetch(quote_syms, [this](QVector<QuoteData> quotes) {- auto& hub = datahub::DataHub::instance();- for (const auto& q : quotes)- hub.publish("market:quote:" + q.symbol, QVariant::fromValue(q));- });-}-```--Dashboard's `IndicesWidget`, `WatchlistWidget`, `QuoteTableWidget`, markets panel, portfolio blotter — all of them subscribing to overlapping symbols — trigger **one** `refresh()` call per hub tick. The Python process spawns once.-------## 11. Worked Example — WebSocket Push--```cpp-// ExchangeService wraps the Kraken WebSocket-void ExchangeService::on_kraken_tick(const QJsonObject& msg) {- QString pair = msg["pair"].toString();- double price = msg["price"].toDouble();-- // Push-only topic — no TTL, no scheduled refresh- datahub::DataHub::instance().publish(- "ws:kraken:" + pair,- QVariant::fromValue(TickData{pair, price, ...}));-}--// In ExchangeService ctor:-TopicPolicy p;-p.push_only = true;-datahub::DataHub::instance().set_policy_pattern("ws:kraken:*", p);-```--Crypto trading screen, dashboard crypto widget, MCP `CryptoTradingTools`, agents — all subscribe to `ws:kraken:BTC-USD` and receive every tick. One WebSocket connection serves everyone.--### 11.1 Progressive Publish Pattern (Phase 5)--Some producers resolve a query in **chunks** rather than a single final payload — `NewsService::fetch_all_news_progressive()` hits N RSS feeds in parallel and wants to fan out partial results as each feed arrives. The hub has no first-class streaming primitive; we express progressive loading as a **sequence of full-list publishes** to the same topic:--```cpp-// Inside the progressive fetch — each RSS feed that finishes triggers-// a re-publish of the accumulated (not delta) list.-void NewsService::publish_articles_to_hub(const QVector<NewsArticle>& accumulated) {- hub.publish("news:general", QVariant::fromValue(accumulated));-}-```--**Rules for consumers:**--- Each payload **replaces** the previously rendered list — do not accumulate on the subscriber side.-- Lists are small enough (hundreds, not millions) that full replacement per chunk is cheap.-- There is **no sentinel "done" marker** — subscribers just see successive lists, with the last one being the final state. Consumers that need to know completion should compare the payload identity or count stability.--**Rules for producers:**--- Always publish the **accumulated** list, never deltas.-- Pair progressive topics with `TopicPolicy::coalesce_within_ms` (e.g. 250 ms for news) so cold-cache fills don't repaint the UI on every chunk. The hub will keep the most-recent payload and fan out once per coalesce window.-- `refresh(topics)` should call the progressive fetcher; the scheduler's `min_interval_ms` prevents back-to-back cold fills.--Rejected alternative: wrapping the payload in `{list, is_final}` struct. Most consumers don't care about completion — those that do can observe list identity stability. Keeps the metatype small.-------## 12. Enforcement Rules (after migration)--To prevent regression, a new set of CLAUDE.md rules:--- **D1.** Screens and widgets **must not** call `PythonRunner::instance().run()` or `HttpClient::*` or service `fetch_*` callbacks directly. They subscribe via `DataHub`.-- **D2.** Services that fetch external data **must** implement `Producer` and publish results via `DataHub::publish()`.-- **D3.** No `QTimer` in a widget whose only job is to trigger a data refresh. The hub's scheduler owns cadence.-- **D4.** All topic keys **must** be documented in `docs/DATAHUB_TOPICS.md` (a registry added in Phase 4).-- **D5.** `push_only` topics (WebSocket-driven) **must** declare their policy at producer construction time, not inline.-------## 13. Observability--Hub exposes a debug interface:--```cpp-struct TopicStats {- QString topic;- int subscriber_count;- qint64 last_publish_ms;- qint64 last_refresh_request_ms;- int total_publishes;- bool in_flight;-};--QVector<TopicStats> DataHub::stats() const;-```--A dev-only screen (behind a feature flag) shows live topic table — useful for catching "why is X still fetching when nothing is visible" bugs. Also surfaced through MCP so AI chat can inspect hub state.-------## 14. Failure Modes--| Failure | Hub behaviour |-|---------------------------------------|---------------------------------------------------------|-| Producer raises / Python script fails | Hub logs, serves stale cached value to subscribers, retries on next scheduler tick with backoff |-| Subscriber slot throws | Caught at Qt boundary, logged, other subscribers unaffected |-| Subscriber destroyed mid-publish | `QPointer` guard + `destroyed()` cleanup — no crash |-| WebSocket disconnect | Producer decides: reconnect internally, optionally publish a sentinel value |-| Cache backend unavailable | Hub degrades to in-memory only (no persistence); logs warning |-| Topic has no producer registered | `subscribe()` still works but `request()` logs a warning; value stays null |-------## 15. Locked Decisions--1. **Topic key format** — `domain:subdomain:id[:modifier]`, lowercase, colon-delimited. Wildcard `*` allowed at the tail for subscriptions only.-2. **Typed subscribe API** — `subscribe<T>(owner, topic, void(const T&))` ships in Phase 1 alongside the untyped `QVariant` variant. Template wrapper unwraps via `QVariant::value<T>()` with a `Q_DECLARE_METATYPE` static assertion.-3. **Request-response commands** (agent runs, LLM calls) — stay **outside** the hub. They're commands, not data. `AgentService::run(...)` and `LlmService::complete(...)` keep their existing APIs.-4. **Persistence on app restart** — hub starts **cold**. `CacheManager` still persists values for warm restarts within TTL, but the hub does **not** rehydrate subscribers on boot. Opt-in per-topic `rehydrate_on_start` flag in `TopicPolicy` (default false) for long-TTL, non-time-sensitive data (news, economics) — added later if needed.-5. **Rate limits** — enforced **hub-level, per producer**. `Producer` interface adds `max_requests_per_sec() const` (default: unlimited). The scheduler honours it when grouping refresh calls. Keeps rate-limit policy in one place, visible and uniform.--### Remaining open item-**Inspector screen visibility** — during Phase 1 it lives behind the `FINCEPT_DATAHUB_ENABLED` compile flag only. Promote to a user-visible "Developer mode" tab in Phase 10, once the topic registry is stable.-------## 16. Success Criteria--- Zero duplicate Python spawns for the same symbol within 30 s across any combination of screens.-- No widget owns a data-refresh `QTimer` after Phase 2 ships.-- Switching tabs is instant — subscribers read cached values; no blocking fetch.-- WebSocket feeds serve N subscribers through one connection.-- `hub.stats()` shows coherent subscriber counts that match what's actually on screen.diff --git a/fincept-qt/DATAHUB_PHASES.md b/fincept-qt/DATAHUB_PHASES.mddeleted file mode 100644index 66576043f..000000000--- a/fincept-qt/DATAHUB_PHASES.md+++ /dev/null@@ -1,378 +0,0 @@-# DataHub Rollout Phases--**Status:** Complete (Phases 0–10 all shipped, 2026-04-18)-**Version:** 1.0-**Companion to:** `DATAHUB_ARCHITECTURE.md`--This document lists the phases to build and migrate to the DataHub. Each phase is **self-contained, testable, and independently shippable**. No phase leaves the codebase in a broken state — the old and new paths coexist until the final phase.-------## Phase Summary--| # | Phase | Scope | Rough size | Depends on |-|---|--------------------------------------------|---------------------------------------|------------|------------|-| 0 | Prep & Guardrails | Meta-types, logging, feature flag | Small | — |-| 1 | Build the DataHub primitive | `DataHub`, `Producer`, `TopicPolicy` | Medium | 0 |-| 2 | Market data — pilot | Convert `MarketDataService` + 1 widget| Medium | 1 |-| 3 | Market data — full migration | All 20+ quote consumers | Large | 2 |-| 4 | WebSocket producers | `ExchangeService`, `PolymarketWebSocket` | Medium | 1 |-| 5 | News | `NewsService` + all news screens | Medium | 1 |-| 6 | Economics & DBnomics | `EconomicsService`, `DBnomicsService` | Medium | 1 |-| 7 | Broker account streams | 16 broker adapters → `broker:*` topics| Large | 1, 4 |-| 8 | Geopolitics / Maritime / Gov Data | Remaining data services | Medium | 1 |-| 9 | AI / MCP / Agents integration | Subscribers, not producers | Medium | 3, 4, 5 |-| 10| Enforcement & cleanup | Lint rules, docs, kill old APIs | Small | All above |-------## Phase 0 — Prep & Guardrails ✅ DONE--**Goal:** set up the ground before touching architecture.--### Deliverables — all landed-- ✅ `FINCEPT_DATAHUB_ENABLED` CMake option added (`CMakeLists.txt:123`), default ON, compiles to `-DFINCEPT_DATAHUB_ENABLED=1`.-- ✅ `Q_DECLARE_METATYPE` for `QuoteData`, `HistoryPoint`, `InfoData`, `NewsArticle`, `EconomicsResult` in `src/datahub/DataHubMetaTypes.h`.-- ✅ `qRegisterMetaType<...>()` calls in `src/datahub/DataHubMetaTypes.cpp::register_metatypes()`, invoked from `main.cpp` after `QApplication` construction, gated on the feature flag.-- ✅ Logger: the project uses free-form string tags (no registered categories), so we standardised on the tag string `"DataHub"` — zero changes to `Logger.h`.-- ✅ Stub headers in place: `src/datahub/DataHub.h`, `Producer.h`, `TopicPolicy.h`.-- ✅ Stub `DataHub.cpp` compiles under MOC and aborts with a clear message if any method (except `peek()`) is called before Phase 1.-- ✅ Sources wired into `add_executable` via `DATAHUB_SOURCES` variable.--### Success check-- Build is green on all three presets (`win-release`, `linux-release`, `macos-release`).-- No runtime changes.--### Risk-- None (preparatory only).-------## Phase 1 — Build the DataHub Primitive ✅ DONE--**Goal:** implement the hub itself, with unit tests, zero integrations.--### Deliverables — all landed-- ✅ `src/datahub/DataHub.{h,cpp}` — full public API per `DATAHUB_ARCHITECTURE.md` §4,- including the typed `subscribe<T>()` template, wildcard patterns, push-only- bypass, in-flight dedup, per-producer rate limiting, and cross-thread- marshaling via `QMetaObject::invokeMethod(..., Qt::QueuedConnection)`.- Registry + scheduler live inline in the hub (single file — splitting into- `SubscriptionRegistry.cpp` / `TopicScheduler.cpp` would be premature- abstraction at ~300 lines).-- ✅ `src/datahub/Producer.h` — virtual interface.-- ✅ `src/datahub/TopicPolicy.h` — struct + defaults.-- ✅ Test harness: `FINCEPT_BUILD_TESTS` CMake option (default OFF),- `tests/CMakeLists.txt` wired in via `add_subdirectory(tests)`.-- ✅ `tests/datahub/test_datahub.cpp` (Qt Test) — 9 cases covering:- - subscribe → publish → slot invoked- - subscribe receives cached value immediately if fresh- - destroyed subscriber auto-unsubscribes- - wildcard pattern matching (`test:wild:*`)- - push-only policy skips scheduler- - `request()` dedups while in-flight- - cross-thread `publish()` marshals correctly- - `peek()` reads without subscribing- - scheduler respects `ttl_ms`-- ✅ Debug screen stub: `src/screens/devtools/DataHubInspector.{h,cpp}`- wired into `SCREEN_SOURCES`. Refreshes `DataHub::stats()` every 1 s while- visible; follows CLAUDE.md P3 (timer driven by `showEvent`/`hideEvent`).--### Success check-- All unit tests pass.-- Hub is registered as a global singleton but has zero producers yet — hub is idle.-- Inspector screen loads and shows empty topic list.--### Risk-- `QObject::destroyed()` ordering vs. subscription cleanup — covered by test.-- Cross-thread `publish()` with `QueuedConnection` — covered by test.-------## Phase 2 — Market Data Pilot--**Goal:** prove the pattern end-to-end on one producer + one widget. Do **not** migrate anything else yet.--### Deliverables-- `MarketDataService` implements `Producer`:- - declares `topic_patterns()` = `{"market:quote:*"}`- - moves existing batched Python fetch logic into `refresh(topics)`- - publishes results via `DataHub::publish("market:quote:<sym>", QVariant::fromValue(quote))`- - old `fetch_quotes(callback)` API **still works** — becomes a thin wrapper that subscribes once, captures the value, unsubscribes. Zero consumer changes required yet.-- One widget class rewritten: **`QuoteTableWidget`**- (`src/screens/dashboard/widgets/QuoteTableWidget.cpp:36`). This class is- the base used by `IndicesWidget`, `CryptoWidget`, `ForexWidget`, and- `CommoditiesWidget` factory functions, so migrating it in one place- exercises the hub across four widgets at once.- - deletes `refresh_data()` callback-based fetch- - subscribes per-symbol to `market:quote:<sym>` in the ctor- - stops relying on any external caller/timer to trigger refresh- - verifies UI still updates identically to the pre-migration baseline-- Register default `TopicPolicy{ttl_ms=30000, min_interval_ms=5000}` for `market:quote:*`.-- Add `MarketDataService` to hub's producer registry at app startup.--### Success check-- Indices / Crypto / Forex / Commodities widgets all show identical data to before- (they share `QuoteTableWidget`, so all four move together in this phase).-- Log shows `refresh()` fires on hub tick, not per-widget.-- Hub inspector shows the union of their symbols as `market:quote:*` topics,- each with subscriber_count ≥ 1.-- No duplicate Python spawns when `QuoteTableWidget` instances + legacy- `fetch_quotes` callers are both active.--### Risk-- Regression in Indices panel behaviour — mitigated by side-by-side test (both paths still work).-- Python process scheduling under hub cadence vs. old per-widget cadence — validated by looking at spawn count metrics before/after.-------## Phase 3 — Market Data Full Migration--**Goal:** move every market-data consumer onto the hub. Delete per-widget timers.--### Consumers to migrate-Phase 2 already covered `QuoteTableWidget` (and therefore Indices / Crypto /-Forex / Commodities factories). Remaining market-data consumers confirmed-by `grep -rn fetch_quotes src/screens/`:--Dashboard — 11 widgets:-`WatchlistWidget`, `TopMoversWidget`, `StockQuoteWidget`,-`SectorHeatmapWidget`, `ScreenerWidget`, `RiskMetricsWidget`,-`PerformanceWidget`, `MarketSentimentWidget`, `PortfolioSummaryWidget`,-`QuickTradeWidget`, `MarketPulsePanel` (3 callsites inside this file).--Dashboard drivers — 2:-`DashboardScreen` (ticker refresh — drives `TickerBar::set_data`), and-`TickerBar` itself (receives data passively; only the driver needs to-change).--Screens — 4:-`MarketPanel` (`src/screens/markets/MarketPanel.cpp:198`),-`WatchlistScreen` (`src/screens/watchlist/WatchlistScreen.cpp:403`),-`PortfolioBlotter` (`src/screens/portfolio/PortfolioBlotter.cpp`),-`ReportBuilderScreen` (`src/screens/report_builder/ReportBuilderScreen.cpp:399`).--### Per-consumer changes-- Delete local `QTimer` (keep any `showEvent`/`hideEvent` pattern — hub handles idle-when-hidden via subscriber count).-- Replace `fetch_quotes(cb)` callback with `hub.subscribe(this, topic, slot)`.-- Delete any manual `CacheManager` lookups — hub covers that.--### Additional topics-- Add `market:history:<sym>:<period>:<interval>` and `market:sparkline:<sym>` as producer patterns.-- Migrate `fetch_history` and `fetch_sparklines` callers (charts, mini-graphs).--### Deliverables-- Zero `fetch_quotes(callback)` callsites outside `MarketDataService` internal wrapper.-- `MarketDataService::fetch_quotes` marked `[[deprecated]]` (wrapper still works).-- Update `CLAUDE.md` rule P5 to reference DataHub instead of batched calls.--### Success check-- Switching between Dashboard, Markets, Watchlist tabs is instant (cached).-- Python spawn count on hot path drops measurably (target: >60% reduction vs. baseline).-- Hub inspector shows expected subscriber counts matching visible UI.--### Risk-- Large diff surface — split into sub-PRs by screen group (dashboard widgets, markets, watchlist, portfolio, report builder).-- Missing a refresh trigger (e.g. user-triggered "refresh now" button) — add `DataHub::request(topic)` callsites where needed.-------## Phase 4 — WebSocket Producers--**Goal:** unify real-time streams under the hub.--### Targets-- `trading/ExchangeService` — Kraken + HyperLiquid WebSocket feeds → `ws:kraken:*`, `ws:hyperliquid:*`.-- `services/polymarket/PolymarketWebSocket` → `polymarket:orderbook:<market>`, `polymarket:trades:<market>`.--### Per-producer changes-- Implement `Producer` interface; declare `push_only=true` policy.-- On WS message: `hub.publish(topic, value)` instead of emitting bespoke signals.-- On `on_topic_idle(topic)`: close/unsubscribe that market-specific WS channel (ref-counted — only close when all subscribers gone).-- On first subscriber: open WS channel lazily.--### Deliverables-- CryptoTradingScreen, CryptoWidget, MCP `CryptoTradingTools`, agents — all subscribe via hub.-- Polymarket screens subscribe via hub.-- Kraken/HyperLiquid WS opens only when ≥1 subscriber exists.--### Success check-- WS connection count = number of distinct exchanges with ≥1 subscriber (not per-screen).-- Every tick visible in both dashboard crypto widget and crypto trading screen with no duplicate parsing.--### Risk-- Lazy WS open/close logic must be ref-counted — covered by Producer test harness.-- Backpressure on high-frequency feeds (Kraken can emit 100+/sec) — hub dispatcher must coalesce or drop stale updates. Add a `coalesce_within_ms` field to TopicPolicy if needed.-------## Phase 5 — News--**Goal:** one fetch per news query, broadcast everywhere.--### Targets-- `NewsService` — currently has mixed signals + callbacks.-- Consumers: Dashboard `NewsWidget`, News screens (8 components), Equity Research news tab, MarketPulsePanel headlines.--### Topics-- `news:general` — TTL 5 min-- `news:symbol:<sym>` — TTL 5 min-- `news:category:<cat>` — TTL 5 min-- `news:cluster:<id>` — push on cluster change--### Deliverables-- `NewsService` implements `Producer`.-- Keep existing article struct as `QVariant` payload.-- Subscribers migrated; old callback API deprecated.--### Risk-- News has some progressive-load semantics (`fetch_all_news_progressive`) — may need a `partial` publish pattern (multiple publishes per topic). Document in architecture §11 if used.-------## Phase 6 — Economics & DBnomics--**Goal:** long-TTL series data through the hub.--### Targets-- `EconomicsService`, `DBnomicsService`, `GovDataService` (partially — gov data overlaps with geopolitics).--### Topics-- `econ:<source>:<series_id>` — TTL 1 h (series update daily at most)-- `econ:batch:<source>:<query_hash>` — for multi-series queries--### Deliverables-- Producers implemented.-- Economics tab + per-source panels (already refactored, per memory) → subscribers only.-- AkShare, DBnomics screens migrated.--### Risk-- Long-TTL + user-triggered refresh — `request(topic)` forces refresh bypassing `min_interval` (needs `force=true` overload).-------## Phase 7 — Broker Account Streams--**Goal:** unified live account data from 16 broker integrations.--### Targets-Per-broker subdirectories under `src/trading/brokers/`:-Zerodha, Angel One, Upstox, Fyers, Dhan, Groww, Kotak, IIFL, 5paisa,-AliceBlue, Shoonya, Motilal, IBKR, Alpaca, Tradier, Saxo-(verified against the current directory listing — 16 broker adapters).--### Topics-- `broker:<id>:positions` — push when broker WS pushes position update, poll fallback 5 s-- `broker:<id>:orders` — same pattern-- `broker:<id>:balance` — TTL 30 s-- `broker:<id>:ticks:<sym>` — push-only for broker WS feeds (Zerodha Kite, Angel SmartStream)--### Deliverables-- Base `BrokerProducer` mixin — slots into `BrokerInterface` without breaking existing adapter contracts.-- `AccountDataStream` (per memory: multi-account architecture) refactored to publish to hub per-account.-- Equity trading screen, portfolio, multi-account selector → subscribers.--### Risk-- Broker SDKs each have different threading models. Each adapter's publish path must marshal to hub thread via queued connection — already covered by hub thread-safety guarantees.-- Per-account isolation: topics include broker ID so two accounts on same broker don't collide. If multi-account is per-user, topic may extend to `broker:<id>:<account_id>:...`.-------## Phase 8 — Geopolitics / Maritime / Gov Data--**Goal:** remaining data services.--### Targets-`GeopoliticsService`, `MaritimeService`, `GovDataService`, `RelationshipMapService`, `MAAnalyticsService`.--### Topics-- `geopolitics:hdx:<dataset>`-- `geopolitics:relationship_graph:<entity>`-- `maritime:vessel:<imo>`-- `govdata:<country>:<dataset>`-- `ma:deals:<filter_hash>`--### Risk-- Low — these are long-TTL, relatively cold data sources. Pattern is well-established by Phases 5–6.-------## Phase 9 — AI / MCP / Agents Integration--**Goal:** the AI and agent surface can read hub topics the same way screens do.--### Targets-- MCP tool modules in `src/mcp/tools/` (24 modules) — replace direct service calls with `DataHub::peek()` / `subscribe()` where appropriate.-- `AgentService` — agents can subscribe to market/news/broker topics to get context without bespoke service plumbing.-- `LlmService` / AI Chat — can reference `hub.stats()` and peek topics for tool-use responses.--### Deliverables-- MCP `datahub_peek`, `datahub_subscribe`, `datahub_list_topics` tool module (new).-- Agent framework helper: `AgentContext::peek(topic)` wraps `hub.peek()`.-- Agent configs that previously embedded `fetch_quotes` calls replaced with topic subscriptions.--### Risk-- Agents running in background threads must use `peek()` or subscribe with queued connection — document in agent contributor guide.-------## Phase 10 — Enforcement & Cleanup ✅ DONE (2026-04-18)--**Goal:** prevent regression.--### Deliverables-- **CLAUDE.md updates:** ✅ rules D1–D5 added (`fincept-qt/CLAUDE.md` §D). D4 was refined after audit to distinguish streaming data (hub-only) from one-shot catalog/info lookups (callback APIs may stay).-- **Lint / CI rule:** ✅ `datahub-discipline` job added to `.github/workflows/lint.yml`. Fails on `src/screens/**/*.cpp` containing `PythonRunner::instance().run(` (D1) or `(MarketData|News|Economics|DBnomics|GovData)Service::instance().fetch_` (D4).-- **Delete deprecated APIs:** ✅ compile-time-disabled legacy branches removed across 60 files (1043 lines) by stripping `#ifdef FINCEPT_DATAHUB_ENABLED` guards. Streaming callback APIs (`fetch_quotes`, `fetch_sparklines`, `fetch_history`) remain as one-shot internal-use methods; the hub is the only supported consumer path.-- **`FINCEPT_DATAHUB_ENABLED` CMake flag** removed from `CMakeLists.txt`. DataHub is the only supported data path.-- **docs/DATAHUB_TOPICS.md** — ✅ full topic registry for Phases 2–9 (markets, ws, news, econ, dbnomics, govdata, broker, geopolitics, maritime, M&A, agents, LLM sessions).-- **Inspector screen** ✅ promoted to Settings → Developer section (`SettingsScreen::build_developer()`).--### Success check-- `git grep PythonRunner::instance().run src/screens` — clean.-- `git grep FINCEPT_DATAHUB_ENABLED src/` — only documentation comments remain (no build-gating).-- CI rule in place and green.-- Topic registry doc matches `hub.stats()` output at runtime.-------## Rollback Strategy--Every phase is reversible until Phase 10. If any phase causes a regression in production:--1. **Phases 2–9:** consumer migrations are local — revert the affected widget/screen commits. Producer keeps working, no data loss.-2. **Phase 4 (WebSocket):** if hub push-only coalescing causes tick drops, revert to direct-signal path; producers can emit both hub `publish()` and their legacy signals in parallel during transition.-3. **Phase 1 (hub itself):** controlled by `FINCEPT_DATAHUB_ENABLED` compile flag. If a critical bug surfaces before Phase 2 ships, flip flag off — nothing depends on it yet.-4. **Phase 10:** irreversible (deletes deprecated APIs). Only run after 2+ weeks of stable Phase 9.-------## Milestones & Target Dates--Dates are indicative; adjust based on actual velocity. Treat as relative ordering, not hard commitments.--| Phase | Nominal duration | Cumulative |-|-------|------------------|------------|-| 0 | 1 day | 1 day |-| 1 | 3–4 days | ~1 week |-| 2 | 1–2 days | ~1.5 weeks |-| 3 | 4–6 days | ~2.5 weeks |-| 4 | 3–4 days | ~3 weeks |-| 5 | 3 days | ~3.5 weeks |-| 6 | 2–3 days | ~4 weeks |-| 7 | 1–2 weeks | ~5.5 weeks |-| 8 | 3 days | ~6 weeks |-| 9 | 1 week | ~7 weeks |-| 10 | 2 days | ~7.5 weeks |-------## Locked Decisions (pre-Phase 0)--1. **Topic key format** — `domain:subdomain:id[:modifier]`.-2. **Typed `subscribe<T>()` API** — ships in Phase 1 alongside the `QVariant` variant.-3. **Inspector screen** — dev-only under `FINCEPT_DATAHUB_ENABLED` for Phases 1–9. Promoted to user-visible Developer-mode tab in Phase 10.-4. **Persistence on restart** — hub starts cold. `CacheManager` still persists for warm restart within TTL. `rehydrate_on_start` becomes an opt-in per-topic policy flag, added when the first long-TTL producer asks for it.-5. **Rate limits** — hub-level. `Producer::max_requests_per_sec()` returns a producer-level cap; scheduler paces refresh calls accordingly.--See `DATAHUB_ARCHITECTURE.md` §15 for full reasoning.diff --git a/fincept-qt/analyze.py b/fincept-qt/analyze.pydeleted file mode 100644index d28319442..000000000--- a/fincept-qt/analyze.py+++ /dev/null@@ -1,146 +0,0 @@-import re-import os--# Read all Python files (relative paths)-with open('py_files_rel.txt', 'r') as f:- all_py_files = set(line.strip() for line in f if line.strip())--print(f"Total Python files: {len(all_py_files)}")--# Read C++ references (quoted strings that appear to be .py file paths)-with open('cpp_refs.txt', 'r') as f:- cpp_quoted_refs = set(line.strip() for line in f if line.strip())--# Extract stems (filenames without .py and without path)-cpp_stems = set()-for ref in cpp_quoted_refs:- filename = os.path.basename(ref)- if filename.endswith('.py'):- stem = filename[:-3]- cpp_stems.add(stem)--print(f"C++ quoted references (with paths): {len(cpp_quoted_refs)}")-print(f"C++ stems (no path, no .py): {len(cpp_stems)}")--# A Python file is "directly referenced" if:-# 1. Its relative path appears in cpp_quoted_refs, OR-# 2. Its filename (with .py) appears in cpp_quoted_refs, OR-# 3. Its stem (without .py) appears in cpp_stems--directly_referenced = set()-for py_file in all_py_files:- # Check if path appears directly- if py_file in cpp_quoted_refs:- directly_referenced.add(py_file)- else:- # Check if filename appears- filename = os.path.basename(py_file)- if filename in cpp_quoted_refs or filename[:-3] in cpp_stems:- directly_referenced.add(py_file)--print(f"Directly referenced from C++: {len(directly_referenced)}")--# Now we need to find Python imports-# Map each Python file to the modules it imports-import_map = {}--for py_file in all_py_files:- full_path = f"scripts/{py_file}"- if not os.path.exists(full_path):- continue-- try:- with open(full_path, 'r', encoding='utf-8', errors='ignore') as f:- content = f.read()- except:- continue-- # Find all imports- import_patterns = [- r'^\s*from\s+([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\s+import',- r'^\s*import\s+([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)',- ]-- imports = set()- for line in content.split('\n'):- for pattern in import_patterns:- match = re.match(pattern, line)- if match:- module_path = match.group(1)- imports.add(module_path)-- import_map[py_file] = imports--# Transitive closure: starting from directly_referenced, mark all imports as indirectly used-indirectly_used = set()-to_check = set(directly_referenced)-visited = set()--while to_check:- current = to_check.pop()- if current in visited:- continue- visited.add(current)-- imports = import_map.get(current, set())-- for imp in imports:- # Resolve this import to a file in scripts/- imp_path = imp.replace('.', '/')-- candidates = [- f"{imp_path}.py",- f"{imp_path}/__init__.py",- ]-- for candidate in candidates:- if candidate in all_py_files:- if candidate not in directly_referenced and candidate not in indirectly_used:- indirectly_used.add(candidate)- to_check.add(candidate)- break--print(f"Indirectly used (imported by referenced): {len(indirectly_used)}")--# Orphaned = all - directly_referenced - indirectly_used-referenced_total = directly_referenced | indirectly_used-orphaned = all_py_files - referenced_total--print(f"Orphaned: {len(orphaned)}")-print()--# Group orphans by top-level directory-orphan_groups = {}-for orphan in sorted(orphaned):- parts = orphan.split('/')- if len(parts) > 1:- top_dir = parts[0]- else:- top_dir = "root"-- if top_dir not in orphan_groups:- orphan_groups[top_dir] = []- orphan_groups[top_dir].append(orphan)--# Write results-with open('results.txt', 'w') as f:- f.write(f"Total Python files: {len(all_py_files)}\n")- f.write(f"Directly referenced from C++: {len(directly_referenced)}\n")- f.write(f"Indirectly used: {len(indirectly_used)}\n")- f.write(f"Orphaned: {len(orphaned)}\n")- f.write("\nOrphans by directory:\n")- for top_dir in sorted(orphan_groups.keys()):- count = len(orphan_groups[top_dir])- f.write(f" {top_dir}: {count}\n")--# Also save detailed orphan lists-with open('orphans_by_dir.txt', 'w') as f:- for top_dir in sorted(orphan_groups.keys()):- orphans = orphan_groups[top_dir]- f.write(f"\n{top_dir} ({len(orphans)} orphans):\n")- for orphan in sorted(orphans)[:100]: # First 100 per group- f.write(f" {orphan}\n")- if len(orphans) > 100:- f.write(f" ... and {len(orphans) - 100} more\n")--print("Results saved to results.txt and orphans_by_dir.txt")diff --git a/fincept-qt/cpp_refs.txt b/fincept-qt/cpp_refs.txtdeleted file mode 100644index 1e93d31ad..000000000--- a/fincept-qt/cpp_refs.txt+++ /dev/null@@ -1,160 +0,0 @@-Analytics/alternateInvestment/cli.py-Analytics/backtesting/fincept/fincept_provider.py-Analytics/corporateFinance/advanced_analytics/monte_carlo_valuation.py-Analytics/corporateFinance/advanced_analytics/regression_analysis.py-Analytics/corporateFinance/deal_comparison/deal_comparator.py-Analytics/corporateFinance/deal_database/database_schema.py-Analytics/corporateFinance/deal_database/deal_parser.py-Analytics/corporateFinance/deal_database/deal_tracker.py-Analytics/corporateFinance/deal_structure/collar_mechanisms.py-Analytics/corporateFinance/deal_structure/cvr_valuation.py-Analytics/corporateFinance/deal_structure/earnout_calculator.py-Analytics/corporateFinance/deal_structure/exchange_ratio.py-Analytics/corporateFinance/deal_structure/payment_structure.py-Analytics/corporateFinance/fairness_opinion/premium_analysis.py-Analytics/corporateFinance/fairness_opinion/process_quality.py-Analytics/corporateFinance/fairness_opinion/valuation_framework.py-Analytics/corporateFinance/industry_metrics/financial_services.py-Analytics/corporateFinance/industry_metrics/healthcare.py-Analytics/corporateFinance/industry_metrics/technology.py-Analytics/corporateFinance/lbo/debt_schedule.py-Analytics/corporateFinance/lbo/lbo_model.py-Analytics/corporateFinance/lbo/returns_calculator.py-Analytics/corporateFinance/merger_models/contribution_analysis.py-Analytics/corporateFinance/merger_models/merger_model.py-Analytics/corporateFinance/merger_models/sources_uses.py-Analytics/corporateFinance/startup_valuation/berkus_method.py-Analytics/corporateFinance/startup_valuation/first_chicago_method.py-Analytics/corporateFinance/startup_valuation/risk_factor_summation.py-Analytics/corporateFinance/startup_valuation/scorecard_method.py-Analytics/corporateFinance/startup_valuation/startup_summary.py-Analytics/corporateFinance/startup_valuation/vc_method.py-Analytics/corporateFinance/synergies/cost_synergies.py-Analytics/corporateFinance/synergies/integration_costs.py-Analytics/corporateFinance/synergies/revenue_synergies.py-Analytics/corporateFinance/synergies/synergy_valuation.py-Analytics/corporateFinance/valuation/dcf_model.py-Analytics/corporateFinance/valuation/football_field.py-Analytics/corporateFinance/valuation/precedent_transactions.py-Analytics/corporateFinance/valuation/trading_comps.py-Analytics/economics/trade_geopolitics.py-Analytics/fortitudo_tech_wrapper/fortitudo_service.py-Analytics/functime_wrapper/functime_service.py-Analytics/gluonts_wrapper/gluonts_service.py-Analytics/gs_quant_wrapper/gs_quant_service.py-Analytics/quant_analytics_cli.py-Analytics/statsmodels_wrapper/statsmodels_service.py-Analytics/technical_indicators.py-Backtesting.py-adb_data.py-agents/deepagents/cli.py-agents/finagent_core/main.py-agents/rdagents/cli.py-ai_quant_lab/qlib_advanced_backtest.py-ai_quant_lab/qlib_advanced_models.py-ai_quant_lab/qlib_data_processors.py-ai_quant_lab/qlib_evaluation.py-ai_quant_lab/qlib_feature_engineering.py-ai_quant_lab/qlib_high_frequency.py-ai_quant_lab/qlib_meta_learning.py-ai_quant_lab/qlib_online_learning.py-ai_quant_lab/qlib_portfolio_opt.py-ai_quant_lab/qlib_reporting.py-ai_quant_lab/qlib_rl.py-ai_quant_lab/qlib_rolling_retraining.py-ai_quant_lab/qlib_service.py-ai_quant_lab/qlib_strategy.py-akshare_alternative.py-akshare_analysis.py-akshare_bonds.py-akshare_company_info.py-akshare_crypto.py-akshare_currency.py-akshare_data.py-akshare_derivatives.py-akshare_economics_china.py-akshare_economics_global.py-akshare_energy.py-akshare_funds_expanded.py-akshare_futures.py-akshare_index.py-akshare_macro.py-akshare_misc.py-akshare_news.py-akshare_reits.py-akshare_stocks_board.py-akshare_stocks_financial.py-akshare_stocks_funds.py-akshare_stocks_historical.py-akshare_stocks_holders.py-akshare_stocks_hot.py-akshare_stocks_margin.py-akshare_stocks_realtime.py-algo_trading/algo_live_runner.py-algo_trading/algo_manager.py-algo_trading/backtest_engine.py-algo_trading/scanner_engine.py-alpha_arena/main.py-bcb_data.py-bea_data.py-bis_data.py-bls_data.py-boc_data.py-boe_data.py-canada_gov_api.py-census_data.py-cftc_data.py-compute_technicals.py-congress_gov_data.py-data_gov_hk_api.py-databento_provider.py-datagov_au_api.py-datagovuk_api.py-derivatives_pricing.py-ecb_sdmx_data.py-econdb_data.py-economic_calendar.py-eia_data.py-equity_talipp.py-eurostat_extra_data.py-exchange/broker_ws_bridge.py-exchange/exchange_daemon.py-exchange/resolve_kraken_symbols.py-exchange/ws_stream.py-federal_reserve_data.py-fiscal_data.py-fred_data.py-fred_economic_data.py-french_gov_api.py-government_us_data.py-hdx_data.py-ilostat_data.py-imf_datamapper_data.py-mcp/edgar/main.py-news_correlation.py-news_geolocation.py-news_nlp.py-norges_bank_data.py-oecd_data.py-ons_data.py-optimize_portfolio_weights.py-owid_data.py-polymarket.py-prediction_kalshi.py-prediction_polymarket.py-rba_data.py-relationship_map.py-riksbank_data.py-scripts/yfinance_data.py-snb_data.py-spreadsheet.py-statcan_data.py-swiss_gov_api.py-trading_economics_data.py-translate_text.py-un_comtrade_data.py-unesco_data.py-worldbank_data.py-worldbank_health_data.py-wto_data.py-yfinance_data.pydiff --git a/fincept-qt/plans/crypto-center-future-phases.md b/fincept-qt/plans/crypto-center-future-phases.mddeleted file mode 100644index 3b92e036b..000000000--- a/fincept-qt/plans/crypto-center-future-phases.md+++ /dev/null@@ -1,606 +0,0 @@-# Crypto Center — Future Phases (2–5)--**Status**: terminal-side shipped — Phases 2, 3, 4, 5 all have UI + service surfaces in `main`. Phases 3, 4 and the buyback worker (5) ship in demo / mock mode pending external infrastructure. See "Shipped state" table at the bottom of this document.-**Owner**: tilakpatel22-**Last updated**: 2026-05-01-**Predecessor**: `plans/crypto-center-wallet-connect.md` (Phase 1, shipped); Phase 1.5 hardening shipped 2026-04-27 — see §1.5 below.-**Scope**: everything that lands inside `screens/crypto_center/CryptoCenterScreen` after the wallet-connect MVP — all subsequent capability that uses the same screen as its home.-------## 0. North star--The Crypto Center is the **single home for everything $FNCPT** inside Fincept Terminal. By the end of Phase 5 it should answer four questions at a glance, in this order of priority:--1. **What do I hold?** — SOL + $FNCPT balance, USD value, recent activity. (Phase 1 done; Phase 2 deepens.)-2. **What can I do with it?** — buy/swap/burn, fee discounts, tier perks. (Phase 2.)-3. **What am I locked into?** — staked $FNCPT, lock duration remaining, projected yield. (Phase 3.)-4. **What can I bet on?** — internal prediction markets entry point. (Phase 4.)-5. **Why is this token worth something?** — buyback&burn dashboard with revenue → token flow. (Phase 5.)--Every later phase **adds rows / panels / tabs** to the existing screen — never a new top-level route. The screen grows; the navigation stays simple.-------## 1. Layout strategy across phases--The screen evolves from a 2-panel grid to a **tabbed full-screen workspace** with a persistent identity bar across the top.--```-┌─ FINCEPT / CRYPTO CENTER ─────────── ● CONNECTED ── 7eV4z…aoowY ──┐-│ │-│ HOLDINGS BAR (always visible) │-│ SOL 2.41 ─ $FNCPT 12,304 ─ USD $341.22 ─ 24h Δ +3.4% │-│ │-├──────┬────────┬───────┬─────────┬──────────┬──────────┬───────────┤-│ HOME │ TRADE │ STAKE │ MARKETS │ ACTIVITY │ ROADMAP │ SETTINGS │-├──────┴────────┴───────┴─────────┴──────────┴──────────┴───────────┤-│ │-│ ACTIVE TAB CONTENT (fills remaining space) │-│ │-└───────────────────────────────────────────────────────────────────┘-```--Tabs follow the same `b45309` orange pattern as the main app tab bar (`DESIGN_SYSTEM.md` §6). The HOLDINGS BAR is identity-level — visible on every tab. The Phase 1 layout becomes the **HOME** tab content.--### Phase mapping to tabs--| Tab | Lands in | Notes |-|---|---|---|-| HOME | Phase 1 (shipped) | Identity, balances, $FNCPT roadmap |-| TRADE | Phase 2 | Buy / swap / burn, fee discount |-| STAKE | Phase 3 | veFNCPT lock, real-yield dashboard |-| MARKETS | Phase 4 | Internal prediction markets |-| ACTIVITY | Phase 2 | On-chain transaction history (added with TRADE) |-| ROADMAP | Phase 5 (replaces Phase 1 panel) | Buyback & burn dashboard, treasury |-| SETTINGS | Phase 1+ | Mode toggle, RPC, API keys, hardware wallet preferences |--ACTIVITY ships with Phase 2 because the moment we let users sign transactions, they need to see them.-------## 1.5 Phase 1.5 — Hardening (shipped 2026-04-27)--**Status**: shipped-**Scope**: Phase 1 stayed as-is in capability; this pass closed five correctness bugs and seven UX gaps that surfaced in production use of the HOME tab. Documented here so future-phase work inherits the patterns instead of re-discovering them.--### 1.5.1 Bugs closed--| ID | Bug | Fix |-|---|---|---|-| B1 | POLL/STREAM toggle could leave both buttons unchecked when the active button was clicked | Wrapped the two `QPushButton`s in an exclusive `QButtonGroup`. Click handlers react only to `toggled(true)` events; clicking the active button is a true no-op. |-| B2 | Stream mode never refreshed FNCPT — only SOL got `accountSubscribe` updates, FNCPT stayed at the seed value | Added a per-stream-session 30s `QTimer` heartbeat that re-runs `seed_stream_state` to refresh FNCPT. Until we surface the FNCPT token-account address and `accountSubscribe` to it directly (a Phase 2 concern), this heartbeat is the source of truth for FNCPT in Stream mode. |-| B3 | STREAM appeared to work on the public RPC but `accountSubscribe` was rate-limited to silence | `WalletBalanceProducer::endpoint_supports_streaming()` checks the resolved endpoint against `api.mainnet-beta.solana.com` and falls back to Poll for that session, publishing a `topic_error` so the screen can show the reason. |-| B4 | REFRESH button in Stream mode only republished cached values | New `WalletService::force_balance_refresh()` → `WalletBalanceProducer::force_refresh(pubkey)` which re-runs `seed_stream_state` in Stream and `refresh_one_poll` in Poll. The screen calls this in addition to a `hub.request(price_topic, force=true)`. |-| B5 | Balance panel header status was a hard-coded `"MAINNET"` label | Replaced with a `FeedStatus` enum (`Idle/Connecting/Live/Stale/Error`) driven by mode-changes, balance publishes, topic errors, and a 5s staleness tick. Object-name swap + `style()->polish` so the colour follows the global stylesheet. |--### 1.5.2 UX gaps closed--| ID | Gap | Fix |-|---|---|---|-| U1 | `apply_theme()` called `setStyleSheet(styleSheet() + …)` 9 times — every call triggered a full QSS reparse on every descendant (P7 violation) | Single composed stylesheet, assigned once. All widget styling keyed by `objectName`. |-| U2 | Topic errors were either swallowed (price) or hijacked the "Updated …" label (balance) | New `cryptoCenterErrorStrip` row inside the balance panel. Visible only while an error is live; auto-clears on the next valid publish. |-| U3 | Stat boxes showed bare em-dashes during the loading window with no microcopy | "waiting for first publish…" is shown in the meta row; REFRESH button is disabled until the first publish lands. |-| U4 | On short windows the static $FNCPT ROADMAP panel pushed balances off-screen | `connected_page_` wrapped in a `QScrollArea` (`widgetResizable=true`, no horizontal scroll). |-| U5 | RPC provider was invisible — users couldn't tell why STREAM was misbehaving | `cryptoCenterRpcChip` next to the feed status pill. Reads `PUBLIC` / `HELIUS` / `CUSTOM` from `SecureStorage` keys (`solana.rpc_url`, `solana.helius_api_key`). Tooltip on `PUBLIC` tells the user to add a Helius key for reliable streaming. |-| U6 | Dead `make_panel()` helper declared and defined but never called | Removed. |-| U7 | No staleness detection — a feed that silently stopped publishing kept showing "Updated 5s ago" forever | 5s `QTimer` re-evaluates `Updated …` text and flips `feed_status_` to `Stale` after 90s of silence. Started in `showEvent`, stopped in `hideEvent` (P3). |--### 1.5.3 New patterns introduced (carry into Phase 2+)--These are now the conventions for any new tab/panel added to Crypto Center:--1. **One stylesheet per screen.** Compose the full CSS string once in `apply_theme()` and assign it once. Widget styling lives in `objectName` selectors; never use inline `setStyleSheet` on individual labels for theming.-2. **`FeedStatus` enum drives the live-status pill.** Each tab in Phase 2+ should reuse the same five-state pattern (`Idle / Connecting / Live / Stale / Error`) and render via an object-name swap so the global stylesheet handles colour. Concrete enum lives in `CryptoCenterScreen.h` for now; promote to a shared `ui::widgets::FeedStatusPill` widget when Phase 2 lands a second consumer.-3. **Force-refresh goes through a service method, not directly through the hub.** `hub.request(topic, force=true)` is fine for read-only re-publish, but any path that actually re-fetches data (REST round-trip, WS re-seed) goes through the owning service so the producer can interpret "force" correctly per its mode. Phase 3's `StakingService` and Phase 4's market services should follow the same `force_*` pattern that `WalletService::force_balance_refresh` established.-4. **Per-session heartbeats are owned by the producer, not the screen.** `WalletBalanceProducer::StreamSession::fncpt_heartbeat` is owned by the producer; lifetime ties to the WS session. Screens never spawn timers for data refresh — that's a P3 + D3 violation.-5. **Endpoint-capability checks before opening streams.** Producers that have both Poll and Stream paths must expose an `endpoint_supports_streaming()` predicate and fall back gracefully with a `publish_error` for visibility. Hard-coded blocks: today the public Solana RPC; Phase 2 may add the public Jupiter rate-limited endpoint.-6. **Staleness is a timer-driven concept on the screen, not a producer responsibility.** Producers publish with a `ts_ms`; the screen decides when "old" becomes "STALE" based on its own threshold (90s for balances, will be tighter for swap quotes).-7. **Error strip pattern.** Every Phase 2+ panel that fetches data must have a hidden-by-default error row that surfaces `topic_error` messages and clears on next valid publish. Use the same `cryptoCenterErrorStrip` styling.-8. **RPC-indicator chip.** Any panel that does Solana RPC work surfaces the resolved provider as a `cryptoCenterRpcChip`-styled label so users understand the latency/reliability profile they're getting.--### 1.5.4 Carry-overs to Phase 2--When Phase 2 lifts the layout to the HOLDINGS BAR + tabbed workspace described in §1:--- The `FeedStatus` pill, RPC indicator, and error strip are **identity-level** — they belong on the HOLDINGS BAR, not duplicated per tab.-- The static `$FNCPT ROADMAP` panel still in the HOME tab is the placeholder slated to be replaced by the Phase 5 buyback & burn dashboard (§5.2). Don't invest further in it.-- The POLL/STREAM toggle moves to the SETTINGS tab (§6) but keeps the same `QButtonGroup`-exclusive widget pattern.-- `WalletService::force_balance_refresh()` becomes one of several `force_*` service methods. Standardise the naming.-- `staleness_timer_` (5s tick) is the prototype for the per-tab refresh timers Phase 2 panels will own. Each tab gets exactly one such timer started in `showEvent` and stopped in `hideEvent`.--### 1.5.5 Files touched in Phase 1.5--- `src/screens/crypto_center/CryptoCenterScreen.{h,cpp}` — full rewrite of `apply_theme`, new `FeedStatus` machinery, scroll wrap, RPC chip, error strip, exclusive button group, REFRESH wiring.-- `src/services/wallet/WalletService.{h,cpp}` — added `force_balance_refresh()`.-- `src/services/wallet/WalletBalanceProducer.{h,cpp}` — added `force_refresh()`, `endpoint_supports_streaming()`, FNCPT heartbeat lifecycle on `StreamSession`.--No new hub topics were introduced; no `DATAHUB_TOPICS.md` update required.-------## 2. Phase 2 — TRADE tab--> **Detailed plan:** see `plans/crypto-center-phase-2.md` (rev 2). This section is the high-level user-story map; the rev-2 doc is the source of truth for build order, file deltas, and acceptance criteria.--**Goal**: every user can swap SOL ↔ $FNCPT inside the terminal in under 30 seconds, see their last 50 wallet operations, and qualify for a 30 % fee discount when holding ≥ 1,000 $FNCPT.--### 2.1 Capabilities--1. **Buy $FNCPT with SOL** — PumpPortal `trade-local` returns a fully-built unsigned tx; the user signs in their wallet.-2. **Sell $FNCPT for SOL** — symmetric; same endpoint, `action=sell`.-3. **Fee discount** — every paid feature in the terminal (deep backtest, AI report, premium screen) accepts $FNCPT at a 30 % discount. HoldingsBar lights up the chip; TRADE tab shows projected savings given current balance.-4. **Activity feed (ACTIVITY tab)** — last 50 on-chain operations involving the wallet, parsed for human-readable events (sent, received, swapped) via Helius parsed-tx.--**Burn deferred to Phase 5.** Real burns require either ~150 lines of client-side Solana primitives in C++ or a custom Rust on-chain program, both disproportionate for a single user-action. Phase 5's buyback worker burns from the Fincept treasury account using off-chain tooling — that's the right place for the supply mechanism. See `plans/crypto-center-phase-2.md` D6 for the full rationale.--### 2.2 New panels--```-┌─ SWAP ──────────── via PumpPortal · pool=auto ─┐ ┌─ FEE DISCOUNT ─ active ─┐-│ DIRECTION [BUY $FNCPT (SOL → $FNCPT) ▾] │ │ HOLD 1,000 $FNCPT │-│ YOU PAY [ 0.50 ] SOL Bal: 1.20 SOL │ │ ELIGIBLE ✓ 30% off │-│ YOU GET ~12,304 $FNCPT │ │ APPLIED TO │-│ ──────────────────────────────────────────────│ │ AI reports │-│ ROUTE PumpSwap (auto) │ │ Deep backtests │-│ MAX SLIP 1.00% │ │ Premium screens │-│ [SWAP] │ │ │-└────────────────────────────────────────────────┘ └────────────────────────┘-```--There is **no separate quote panel**. PumpPortal has no quote endpoint; estimated output is computed locally from the live `market:price:token:<mint>` family (Stage 2A.5 generalised the legacy `market:price:fncpt` topic into a per-mint family — the FNCPT topic remains as a deprecated alias for one phase) multiplied by the slippage budget.--### 2.3 ACTIVITY tab--```-┌─ ACTIVITY ─ last 50 operations ──────────────── refreshing every 30 s ─┐-│ TIMESTAMP EVENT ASSET AMOUNT STATUS │-│ 2026-04-28 09:14:02 SWAP SOL→FNCPT 0.5 → 12,304 confirmed │-│ 2026-04-27 14:02:11 RECEIVE SOL 0.10 confirmed │-│ ... │-└────────────────────────────────────────────────────────────────────────┘-```--Click a row → opens Solscan in default browser. Helius parsed-tx covers SWAP / RECEIVE / SEND directly; everything else is OTHER with the signature link.--### 2.4 New services--| Service | Path | Producer | Topics |-|---|---|---|---|-| `PumpFunSwapService` | `src/services/wallet/PumpFunSwapService.{h,cpp}` | **no** (one-shot, user-driven) | — `build_swap()` HTTP-POSTs to `pumpportal.fun/api/trade-local` and returns `tx_base64` directly to the caller |-| `WalletActivityProducer` | `src/services/wallet/WalletActivityProducer.{h,cpp}` | yes | `wallet:activity:<pubkey>` (paged JSON of parsed transfers) |-| `FeeDiscountService` | `src/services/billing/FeeDiscountService.{h,cpp}` | yes | `billing:fncpt_discount:<pubkey>` (eligibility, applied SKUs) |--The one-shot pattern for `PumpFunSwapService` mirrors `WalletService::sign_and_send` (Stage 2.0) — user-initiated actions that don't benefit from caching/coalescing don't need to be Producers. See the Phase 2 plan §3 for the full reasoning.--### 2.5 New hub topics (Phase 2)--| Pattern | Producer | TTL | Min | Notes |-|---|---|---|---|---|-| `wallet:activity:<pubkey>` | `WalletActivityProducer` | 30 s (poll) | 10 s | Parsed last-50 wallet operations via Helius. Falls back to raw signatures if no Helius key. |-| `billing:fncpt_discount:<pubkey>` | `FeeDiscountService` | derived from `wallet:balance:<pubkey>` | — | Republishes whenever balance changes. |-| `market:price:token:<mint>` | `TokenPriceProducer` | 60 s | 30 s | Generalised per-mint USD price, batched into one Jupiter Lite call per refresh. Supersedes the Phase 1 `market:price:fncpt` topic, which remains as a deprecated alias for one phase. See `plans/crypto-center-phase-2.md` §2A.5 for the full upgrade rationale. |--The earlier rev specced `wallet:quote:*` and `wallet:burn_receipt:*` — both retired. PumpPortal has no quote endpoint (output is estimated locally from spot price), and burn is deferred. The `wallet:balance:<pubkey>` topic is still owned by `WalletBalanceProducer`, but the payload shape was upgraded in Stage 2A.5 to carry `QVector<TokenHolding>` instead of FNCPT-only fields — see `docs/DATAHUB_TOPICS.md` for the new shape.--### 2.6 Solana program work--**None this phase.** The earlier rev specced a custom `fincept_burn` Anchor program for on-chain burn receipts. Burn is deferred to Phase 5; that's the correct place for any custodial burn primitive too. Phase 2 ships zero on-chain code.--### 2.7 Security--Phase 1 was read-only. Phase 2 introduces transaction signing, so the threat model expands:--- Every swap re-prompts the wallet UI. We **never** pre-sign or cache.-- The terminal shows the **decoded transaction summary** before sign — never trust the wallet to do this alone, since some users approve blindly.-- Slippage cap default 1 %; user adjustable up to 5 %. SettingsTab clamps the slider.-- PumpPortal MITM mitigation: simulate the unsigned tx against the user's RPC before forwarding, refuse if any non-FNCPT/non-SOL/non-wSOL token balance changes. Optional TLS leaf-cert pinning is a Phase 2.5 polish.-- Replay: refuse to sign if `currentBlockHeight > tx.lastValidBlockHeight - 50`.-- The shared `WalletActionConfirmDialog` enforces a 1.5 s arm-time on the SWAP button.--A separate `crypto-center-trade-security.md` review doc lands with the Phase 2 PR.--### 2.8 Acceptance criteria--- [ ] User can BUY 0.001 SOL of $FNCPT on mainnet and see balance update via DataHub within 5 s of `confirmed`.-- [ ] User can SELL 50 % of resulting $FNCPT and receive SOL back within 30 s.-- [ ] Holding 1,000+ $FNCPT shows "30 % off" badge on HoldingsBar and FeeDiscountPanel.-- [ ] ACTIVITY tab populates with last 50 parsed events.-- [ ] All five Phase 1 P-rules and four Phase 1 D-rules hold (no PythonRunner spawn, hub-first, etc.).-- [ ] No Rust source anywhere in the tree.-------## 3. Phase 3 — STAKE tab--**Goal**: users can lock $FNCPT for 1–4 years and earn a real-yield share (USDC) of terminal revenue, plus governance weight. Curve `veCRV` model, but sized down for our scale.--### 3.1 Capabilities--1. **veFNCPT lock** — choose amount + duration (3 mo / 6 mo / 1 yr / 2 yr / 4 yr).-2. **Boost preview** — show projected weekly yield in USDC for the chosen lock.-3. **Existing positions** — table of locks, time remaining, current weight.-4. **Extend / increase** — add tokens or extend duration of an existing lock.-5. **Withdraw on expiry** — auto-prompt when a lock unlocks.-6. **Governance preview** — open proposals (read-only this phase; voting in Phase 4).-7. **Tier badge** — bronze / silver / gold based on `veFNCPT` weight, surfaced on HOME tab and across the terminal (gates premium features).--### 3.2 New panels--```-┌─ STAKE / LOCK ──────────────────────────────────────────────────────────────┐-│ AMOUNT [ 1,000 ] $FNCPT AVAILABLE 12,304 │-│ DURATION ◯ 3 MO ◯ 6 MO ● 1 YR ◯ 2 YR ◯ 4 YR │-│ WEIGHT 1,000 veFNCPT × 0.25 (1 yr) = 250 veFNCPT │-│ EST. YIELD $42 / week (USDC) — 2.18% weekly real yield at $341 stake │-│ TIER Silver → Gold (after lock) │-│ [PREVIEW LOCK] [LOCK] │-└──────────────────────────────────────────────────────────────────────────────┘--┌─ ACTIVE LOCKS ─ 3 positions ─ Σ 4,500 veFNCPT ─────────────────────────────┐-│ LOCKED DURATION UNLOCKS WEIGHT YIELD (LIFETIME) │-│ 2,000 4 yr 2030-04-27 2,000 $1,240 USDC │-│ 1,000 1 yr 2027-04-01 250 $42 USDC │-│ 500 6 mo 2026-10-27 62.5 $14 USDC │-│ ────────────────────────────────────────────────────────────────────── │-│ TOTAL — — 2,312.5 $1,296 USDC │-└─────────────────────────────────────────────────────────────────────────────┘--┌─ TIER ──────────────────────────────────── current GOLD ────────────────────┐-│ BRONZE 100+ veFNCPT basic API quota [achieved] │-│ SILVER 1k+ veFNCPT premium screens [achieved] │-│ GOLD 10k+ veFNCPT all agents + arena [achieved] │-└─────────────────────────────────────────────────────────────────────────────┘-```--### 3.3 New services--| Service | Path | Topics |-|---|---|---|-| `StakingService` | `src/services/wallet/StakingService.{h,cpp}` | `wallet:locks:<pubkey>`, `wallet:vefncpt:<pubkey>` |-| `RealYieldService` | `src/services/wallet/RealYieldService.{h,cpp}` | `wallet:yield:<pubkey>`, `treasury:revenue` (terminal-wide stat) |-| `TierService` | `src/services/billing/TierService.{h,cpp}` | `billing:tier:<pubkey>` |--### 3.4 Hub topics (Phase 3)--| Pattern | Producer | TTL | Min | Notes |-|---|---|---|---|---|-| `wallet:locks:<pubkey>` | `StakingService` | 60 s (poll) / push | 30 s | Vector of `LockPosition{amount_raw, decimals, unlock_ts, weight}`. |-| `wallet:vefncpt:<pubkey>` | `StakingService` | 60 s | 30 s | Aggregated weight + projected next-period yield. |-| `wallet:yield:<pubkey>` | `RealYieldService` | 5 min | 60 s | Lifetime + last-period USDC yield earned. |-| `treasury:revenue` | `RealYieldService` | 1 h | 5 min | Terminal-wide aggregate (weekly bucket) — used in Phase 5 dashboard. |-| `billing:tier:<pubkey>` | `TierService` | 60 s | 30 s | `{tier, weight, next_threshold}`. Drives badges across the terminal. |--### 3.5 Solana program work--The lock program is the heart of Phase 3. Either:--- **(a) Reuse Curve-style ve-token contracts** — community ports exist for Solana (Realms, Squads), but each has different governance assumptions.-- **(b) Build minimal `fincept_lock` Anchor program**:- - `lock(amount, duration_secs)` → mints non-transferable position NFT, escrows tokens.- - `extend(position, new_duration)`.- - `withdraw(position)` — only after unlock.- - `emit_distribution(epoch, total_usdc)` — admin instruction (Fincept Corp signer) to settle the per-epoch real-yield split.--Decision: **(b)**. Curve-style contracts come with governance baggage (proposal queues, vote escrow boost calculations) we won't use until Phase 4. A small purpose-built program is auditable in a week.--Repo: `solana/programs/fincept_lock/`.--### 3.6 Tier integration with the rest of the terminal--The `TierService` publishes `billing:tier:<pubkey>` and emits a Qt signal `tier_changed`. Existing screens consume:--- **AI Quant Lab**: locked behind Silver+. The screen factory checks tier on `showEvent`; if insufficient, renders a "UPGRADE" pill that deep-links back to the STAKE tab.-- **Alpha Arena**: locked behind Gold.-- **All paid screens**: hidden in nav for Free; revealed for Silver+.-- **API quota**: handled centrally in `services/billing/ApiQuotaService` (already exists for plan-based gating); takes a tier override.--This is the **first cross-screen feature** $FNCPT enables. The HOME tab gets a "TIER STATUS" panel showing what's unlocked.--### 3.7 Acceptance criteria--- [ ] User can lock 1,000 $FNCPT for 1 year and see veFNCPT weight = 250.-- [ ] After a simulated revenue distribution event, the user receives USDC pro-rata to weight.-- [ ] Tier badge appears on HOME and gates AI Quant Lab.-- [ ] User cannot withdraw a non-expired lock (program rejects, UI explains).-- [ ] Locks survive terminal restart (state lives on-chain, not in SecureStorage).-------## 4. Phase 4 — MARKETS tab (internal prediction markets)--**Goal**: $FNCPT becomes the only collateral on a small, curated prediction-market venue inside the terminal. Synergy with the existing `PredictionExchangeAdapter` (Polymarket, Kalshi).--### 4.1 Capabilities--1. **Market list** — curated prediction markets that settle in $FNCPT only: Fed rate moves, CPI prints, S&P close, weather (maybe), crypto milestones.-2. **YES / NO order entry** — limit + market orders. Off-chain order book, on-chain settlement.-3. **Open positions** — current YES/NO holdings, mark-to-market in $FNCPT.-4. **Settled history** — past markets, P&L, redeem-on-resolve flow.-5. **Create market** (Gold tier only) — propose a market with oracle source and end date; community votes via veFNCPT to list.-6. **Earn from order flow** — veFNCPT lockers receive a share of trading fees (real yield on top of Phase 3).--### 4.2 New panels--```-┌─ MARKETS ─ live ─ 12 open ─ Σ volume 12.3M $FNCPT ──────────────────────────┐-│ MARKET YES NO 24h VOL EXPIRES │-│ Fed cuts in May 2026 0.62 0.38 1.2M 2026-05-07 │-│ NYC max 80F+ on May 1 0.71 0.29 83k 2026-05-01 │-│ $FNCPT > $0.0001 by month end 0.45 0.55 421k 2026-05-31 │-│ ... │-└─────────────────────────────────────────────────────────────────────────────┘--┌─ ORDER ENTRY ──────────────────────┐ ┌─ YOUR POSITIONS ──────────────────┐-│ MARKET Fed cuts in May 2026 │ │ MARKET YES P&L │-│ SIDE ● YES ◯ NO │ │ NYC max 80F+ 500 +124 │-│ TYPE ● LIMIT ◯ MARKET │ │ Fed cuts 1,000 -42 │-│ PRICE [ 0.62 ] $FNCPT/share │ │ ... │-│ AMOUNT [ 1000 ] shares │ └────────────────────────────────────┘-│ COST 620 $FNCPT (escrowed) │-│ [PLACE] │-└────────────────────────────────────┘-```--### 4.3 Architecture--The existing `PredictionExchangeAdapter` already abstracts Polymarket and Kalshi. Add a third adapter:--```-PredictionExchangeRegistry- ├─ PolymarketAdapter (existing)- ├─ KalshiAdapter (existing)- └─ FinceptInternalAdapter (NEW — Phase 4)-```--`FinceptInternalAdapter` speaks to a **terminal-side Fincept matching engine** (HTTP + WebSocket on `markets.fincept.in`), but settlement is on-chain via a `fincept_market` Anchor program.--### 4.4 New services--| Service | Path | Topics |-|---|---|---|-| `FinceptInternalAdapter` | `src/services/prediction/internal/FinceptInternalAdapter.{h,cpp}` | `prediction:fincept:*` (markets, books, trades) |-| `MarketCreationService` | `src/services/prediction/internal/MarketCreationService.{h,cpp}` | `prediction:fincept:proposals` |-| `OracleResolverService` | `src/services/prediction/internal/OracleResolverService.{h,cpp}` | `prediction:fincept:resolutions:<id>` |--Hub topics follow the unified `prediction:*` pattern already documented in `DATAHUB_TOPICS.md` — drop in `prediction:fincept:*` as a sibling family.--### 4.5 Solana program work--`fincept_market` program:-- `create_market(end_ts, resolver_pubkey, fee_bps)`-- `deposit_collateral(market, side, amount)` (called per matched fill)-- `resolve(market, outcome)` — only callable by `resolver_pubkey` (the oracle, multi-sig'd to a 3-of-5 set chosen by veFNCPT vote).-- `redeem(market, position)` — winner withdraws; fees split to staking pool.--Repo: `solana/programs/fincept_market/`.--### 4.6 Oracle layer--Pre-built sources:-- **Pyth Network** — Fed rates, S&P close, BTC price.-- **Switchboard** — custom OOB queries (HTTP fetch from NOAA, IMF).-- **Manual review board** — multi-sig of 3 trusted Fincept staff for ambiguous markets, slashable via veFNCPT vote if they misresolve.--Oracle source is part of the market metadata; UI shows the source pill.--### 4.7 Compliance / scope--Real-money prediction markets are regulated as derivatives in US/EU. We mitigate by:-- $FNCPT is a token, not USD — marketed as a play-money internal mechanic, not a regulated derivative.-- Geo-block US/UK during sign-up if legal counsel insists.-- All markets have a legal disclaimer line in the terminal.--This is a **policy decision** outside the scope of this doc — the engineering plan ships the same either way.--### 4.8 Acceptance criteria--- [ ] User can place a YES order on a market and see it in the order book within 1 s (WS feed).-- [ ] On market resolution, redeem flow auto-prompts in the MARKETS tab.-- [ ] Trading fees flow into the Phase 3 staking pool — `wallet:yield:<pubkey>` reflects new yield within one epoch.-- [ ] Gold-tier user can propose a market; community vote (veFNCPT) lists it.-- [ ] Market data uses `prediction:fincept:*` topics, never bypasses the hub.-------## 5. Phase 5 — Buyback & Burn dashboard (ROADMAP tab)--**Status**: shipped (2026-05-01) — terminal-side dashboard is live; buyback worker endpoint is **not yet deployed**, so the producers ship in mock mode (`is_mock=true` on every payload, "DEMO" pill on every panel head). Configure SecureStorage keys `fincept.treasury_endpoint` and `fincept.treasury_pubkey` to flip to live data. See `docs/CRYPTO_CENTER_PHASE_5.md`.--**Goal**: make the value loop visible. Every user can see exactly how much terminal revenue has been spent buying $FNCPT off the market and burning it. This is the **demand engine** that justifies the token long-term.--### 5.1 Capabilities--1. **Live buyback ticker** — current epoch's $FNCPT bought from Jupiter using terminal revenue.-2. **Cumulative burn counter** — total $FNCPT burned all-time.-3. **Supply chart** — circulating + total + burned over time.-4. **Revenue breakdown** — terminal subscriptions, fee discount, prediction market fees, what fraction goes to buyback.-5. **Treasury panel** — current treasury size, USDC reserves, runway.--### 5.2 ROADMAP tab replaces Phase 1's static panel--```-┌─ BUYBACK & BURN ─ epoch 47 ─ 2026-04-21 → 2026-04-27 ───────────────────────┐-│ │-│ THIS EPOCH │-│ ───────────── │-│ Revenue $42,310 USD (subs $32k · pred-mkt fees $8k · misc $2k) │-│ Buyback $21,155 (50% of revenue) │-│ $FNCPT bought 82.4M $FNCPT (avg 0.000257 USD) │-│ $FNCPT burned 82.4M $FNCPT ● burn tx 5kj3w… │-│ │-│ ALL-TIME │-│ ───────────── │-│ Burned 1.42 B $FNCPT │-│ Supply remaining 8.58 B $FNCPT │-│ Spent on buyback $384,201 USD │-│ │-└──────────────────────────────────────────────────────────────────────────────┘--┌─ SUPPLY CHART ──────────────────────────────────────────────────────────────┐-│ [ time-series chart: total / circulating / burned, last 12 months ] │-└─────────────────────────────────────────────────────────────────────────────┘--┌─ TREASURY ──────────────────────────────────────────────────────────────────┐-│ USDC reserves $1.84M │-│ SOL reserves 234 SOL ($16k) │-│ Runway @ current 19 months │-│ Multi-sig 3-of-5 (squads.so/fincept-treasury) │-└─────────────────────────────────────────────────────────────────────────────┘-```--### 5.3 New services--| Service | Path | Topics |-|---|---|---|-| `BuybackBurnService` | `src/services/wallet/BuybackBurnService.{h,cpp}` | `treasury:buyback_epoch`, `treasury:burn_total`, `treasury:supply_history` |-| `TreasuryService` | `src/services/wallet/TreasuryService.{h,cpp}` | `treasury:reserves`, `treasury:runway` |--These are **terminal-wide** topics (no `<pubkey>` segment) — same data shown to every user.--### 5.4 Automation (off-chain)--The buyback&burn flow runs on a Fincept-operated worker:--1. End of epoch, worker tallies revenue from Stripe + on-chain prediction-market fees.-2. Computes buyback budget (initial split: 50 % buyback, 25 % staker yield, 25 % treasury).-3. Splits into N hourly chunks, executes through Jupiter to avoid frontrunning a single big buy.-4. Burns the bought $FNCPT — direct SPL Token `burn_checked` from a treasury account is sufficient. The signature serves as the receipt; an on-chain event log is *not* required because the worker also publishes the per-epoch summary the dashboard reads (step 5).-5. Publishes per-epoch summary to a Fincept HTTP endpoint that `BuybackBurnService` polls.--Worker code lives in `services/buyback-worker/` (Python or TypeScript — separate repo decision).--### 5.5 Cross-phase reuse--This phase introduces no on-chain program. Direct SPL `burn_checked` from a treasury wallet is enough for a Fincept-operated worker — the receipt is the transaction signature plus the off-chain epoch summary. (User-initiated burns from the TRADE tab were considered for Phase 2 but deferred precisely so this phase, where centralised burn coordination actually pays for itself, owns the burn primitive cleanly.)--### 5.6 Acceptance criteria--- [ ] ROADMAP tab shows live epoch buyback amount, refreshing every 60 s.-- [ ] Supply chart renders last 12 months with three lines.-- [ ] Each burn transaction is clickable → opens Solscan.-- [ ] Treasury runway calculation matches finance team's reconciliation.-------## 6. SETTINGS tab (lightweight, ships incrementally)--A small SETTINGS tab lands with Phase 2 and grows:--- Phase 2: balance mode (poll/stream), Helius API key entry, default slippage.-- Phase 3: tier display preferences, governance email opt-in.-- Phase 4: market resolution preferences (auto-redeem on win), oracle source filter.-- Phase 5: data refresh cadence per panel.--Keep it boring — `core/keys/KeyConfigManager` plus `SecureStorage` is enough.-------## 7. Cross-phase concerns--### 7.1 Performance — every panel is a hub subscriber--- Each tab subscribes only when **visible** (already wired via `showEvent` / `hideEvent`).-- Heavy-paint tabs (charts in Phase 5) **must** cache pixmaps per `DESIGN_SYSTEM` + P9.-- The HOLDINGS BAR persists on every tab — single subscription set, owned by the screen, not duplicated per tab.--### 7.2 Storage growth--By Phase 5 the Crypto Center subscribes to roughly 18 hub topics per session. The hub handles topic-state cleanup via `drop_on_idle = true` for per-pubkey topics; terminal-wide topics (`treasury:*`) stay resident.--### 7.3 Wallet permission UX--Every action that prompts the wallet must show **what** is being signed in the terminal **before** the wallet pops:-- Swap: "You will sign a swap of 0.5 SOL for ~12,304 $FNCPT through Jupiter."-- Burn: "You will sign a burn of 100 $FNCPT. This is irreversible."-- Lock: "You will sign a lock of 1,000 $FNCPT for 1 year. You cannot withdraw before <date>."--Pattern: `WalletActionConfirmDialog` (Phase 2) — shared across all phases.--### 7.4 Recovering from drift--If the user disconnects + reconnects with a different wallet, the screen must:-1. Drop subscriptions for the old pubkey.-2. Reseed from on-chain state for the new pubkey.-3. Never show stale balances/locks/positions from the previous session.--This is centralised in `WalletService::wallet_disconnected` → `wallet_connected` signal pair, which every Phase 2+ panel listens to.--### 7.5 Test strategy--Each phase ships with:-- Unit tests for new services (mock RPC and Jupiter responses).-- Integration test against **devnet** (deploy our programs there too).-- Manual smoke test on mainnet with a tiny amount of $FNCPT.-- Security walkthrough doc (like Phase 1's), specifically focused on the new sign-flows.-------## 8. Order of operations--A reasonable sequencing (each phase ~3–6 weeks of focused work):--| Order | Phase | Why |-|---|---|---|-| 1 | Phase 2 (TRADE + ACTIVITY) | Unlocks revenue (fee discount), ships fastest, lets users actually use $FNCPT. |-| 2 | Phase 5 (Buyback & Burn dashboard) | Marketing surface lights up the moment Phase 2 ships — show the value loop. |-| 3 | Phase 3 (STAKE) | Locks supply once enough users hold the token. |-| 4 | Phase 4 (MARKETS) | Highest engineering risk; benefits most from a captive holder base. |--Phase 5 ships **before** Phase 3 because the dashboard works as soon as buyback automation runs — even if no one is staking yet. It builds confidence. Phase 3 is the hardest UX (yield projection, lock math, governance previews) and benefits from a stable Phase 2.-------## 9. What we will NOT do across these phases--- **Custodial features.** No "Fincept holds your tokens for you." Ever.-- **Multi-chain.** $FNCPT stays on Solana. Cross-chain bridges are a separate product.-- **Fiat onramp inside the terminal.** Use Phantom/Solflare's built-in onramps; we link, don't host.-- **Auto-trading bots.** `agent:*` topics already exist for that — we don't double-build.-- **NFT marketplace.** Out of scope; partner if needed.-- **Hardware wallet direct USB.** Phantom/Solflare host Ledger fine; direct integration is months of work for marginal UX gain.--These exclusions matter because each one has been pitched in past discussions and each one can swallow a quarter of engineering time without moving the needle.-------## 10. Success metric--By end of Phase 5, with reasonable adoption (1k DAU on the terminal):--- $FNCPT velocity: > $50k weekly volume on Jupiter pairs.-- Locked supply: > 30 % via veFNCPT.-- Burn rate: ≥ 1 % of supply burned per quarter.-- Real-yield APR: ≥ 6 % USDC for 1-year lockers.-- Prediction market open interest: $250k+ in $FNCPT.--If any of these is < 30 % of target after the corresponding phase, **stop** and fix the loop before adding more features. More mechanics on a token nobody uses is the most common DeFi failure mode, and we are not exempt.-------## 11. Document maintenance--- Update this doc at each phase kickoff with refined estimates and any scope deltas.-- When a phase ships, **archive** its section into `plans/crypto-center-phase<N>-shipped.md` with the actual implementation diffs from the plan, so future phases inherit verified patterns rather than design speculation.-- Topic catalogue (`docs/DATAHUB_TOPICS.md`) is the source of truth for all hub topics; this doc is the user-story-level map. Discrepancies → fix `DATAHUB_TOPICS.md` first.-------## 12. Shipped state (2026-05-01)--Snapshot of what is wired in `main` vs. what still requires off-tree infrastructure (Anchor programs, Fincept-operated workers, hosted matching engine). Each phase below has a fully connected UI + service surface; the right-hand column lists what has to land before the demo / mock chips disappear.--| Phase | UI tab | Services / producers | Hub topics | Ships in mock mode? | Unblocks live mode |-|---|---|---|---|---|---|-| **1 + 1.5** | HOME | `WalletService`, `WalletBalanceProducer`, `TokenPriceProducer`, `TokenMetadataService` | `wallet:balance:*`, `market:price:token:*`, `market:price:fncpt` (deprecated alias) | No — fully live | — |-| **2** | TRADE, ACTIVITY | `PumpFunSwapService`, `WalletActivityProducer`, `FeeDiscountService` | `wallet:activity:*`, `billing:fncpt_discount:*` | No — fully live (PumpPortal) | — |-| **3** | STAKE | `StakingService`, `RealYieldService`, `TierService`, `TierConfig` | `wallet:locks:*`, `wallet:vefncpt:*`, `wallet:yield:*`, `treasury:revenue`, `billing:tier:*` | **Yes** — `is_mock=true` on every payload | Deploy `fincept_lock` Anchor program; configure `fincept.lock_program_id`, `fincept.yield_endpoint` |-| **4** | MARKETS | `FinceptInternalAdapter` (joins `PredictionExchangeRegistry`); panel reads via Qt signals | `prediction:fincept:markets`, `prediction:fincept:orderbook:*`, `prediction:fincept:price:*` (policies registered, no producer publishing yet) | **Yes** — curated 3-market dataset emitted via `markets_ready` signal | Deploy `fincept_market` Anchor program; stand up `markets.fincept.in`; configure `fincept.markets_endpoint`, `fincept.market_program_id` |-| **5** | ROADMAP | `BuybackBurnService`, `TreasuryService` | `treasury:buyback_epoch`, `treasury:burn_total`, `treasury:supply_history`, `treasury:reserves`, `treasury:runway` | **Yes** — `is_mock=true` on every payload | Deploy buyback worker (Python or TS, off-tree) that POSTs per-epoch summaries; configure `fincept.treasury_endpoint`, `fincept.treasury_pubkey` |--**No on-chain code in this tree.** Phases 3 and 4 require Solana programs written in Rust (`solana/programs/fincept_lock/` and `solana/programs/fincept_market/`), maintained in a separate repo. The C++ side stays pure Qt + DataHub.--**Cross-screen tier gating** (Phase 3 §3.6) is wired via `TierService::tier_changed`. Paid screens that connect to that signal will react when a user's tier transitions, even though the producer is currently in mock mode (the mock returns `Tier::Free`, so no screens light up until the program ships and real veFNCPT weight is observable).--**User-facing docs** corresponding to each phase live in `docs/CRYPTO_CENTER_PHASE_<N>.md` — written for Fincept Terminal users, not engineers. The walkthroughs in this directory are the engineering-side decision records.-diff --git a/fincept-qt/plans/crypto-center-phase-2.md b/fincept-qt/plans/crypto-center-phase-2.mddeleted file mode 100644index df1296722..000000000--- a/fincept-qt/plans/crypto-center-phase-2.md+++ /dev/null@@ -1,702 +0,0 @@-# Crypto Center — Phase 2 (TRADE + ACTIVITY + Tabbed Layout)--**Status**: rev 2 — pivoted from Jupiter+Anchor to PumpPortal-only after probing the live APIs and confirming pump.fun/PumpSwap routing covers $FNCPT cleanly without any client-side Solana primitives or custom on-chain program.-**Owner**: tilakpatel22-**Last updated**: 2026-04-28-**Predecessors**: `crypto-center-future-phases.md` §2 (high-level), `crypto-center-wallet-connect.md` (Phase 1, shipped), Phase 1.5 hardening (shipped)-**Companion**: `crypto-center-trade-security.md` — security walkthrough, lands with the Phase 2 PR.-------## 0. North star--Phase 2 turns Crypto Center from a **read-only identity surface** into a **transactional surface**. Every new capability shares one constraint:--> **The user signs every transaction in their wallet, sees a decoded summary in the terminal *before* the wallet pops, and the terminal never holds a private key longer than it takes to forward a base64 transaction over a loopback HTTP bridge.**--Phase 2 ships three user-visible capabilities:--1. **TRADE tab — Buy / Sell.** Buy or sell $FNCPT (vs SOL) via PumpPortal's `trade-local` endpoint. PumpPortal's `pool: "auto"` routing automatically picks the active venue (pump.fun bonding curve before graduation, PumpSwap AMM after — $FNCPT is graduated). Confirm dialog → wallet signs → terminal polls confirmation → balance refreshes.-2. **ACTIVITY tab.** Last 50 parsed wallet operations (sends, receives, swaps), refreshing every 30 s. Helius parsed-tx when a key is configured, signature-only fallback otherwise.-3. **Fee discount eligibility.** Users holding ≥ 1,000 $FNCPT see a "30 % off" chip on HoldingsBar; future paid screens (Phase 3+) read `billing:fncpt_discount:<pubkey>` and render an UPGRADE-to-discount badge.--**Deferred to a later phase (deliberately):**-- **Burn.** PumpPortal has no burn endpoint. A real `burn_checked` requires either client-side Solana primitives in C++ (~150 lines: base58, ATA derivation, instruction encoding) or a custom Anchor program (Rust). Both add complexity disproportionate to the use-case at this stage. Folded into Phase 5's buyback-worker design instead, where centralised burns from terminal revenue do the heavy lifting on the supply side.--**Already shipped before this rev (do not re-do):**-- HoldingsBar (Stage 2.1), HomeTab, SettingsTab, ComingSoonTab, CryptoCenterScreen tabbed shell, TradeTab + SwapPanel scaffolding, WalletActionConfirmDialog, WalletTxBridge, SignTransactionDialog, SolanaRpcClient extensions (`getLatestBlockhash`, `sendTransaction`, `getSignatureStatuses`, `getSignaturesForAddress`), `swap.html` + vendored `web3.js` slot, hub topics in `DATAHUB_TOPICS.md`.--The pivot reuses all of that. The only thing that **changes** is the swap-tx build path — `JupiterSwapService` is replaced by `PumpFunSwapService` which calls PumpPortal. The swap-html page, the wallet-bridge flow, the confirm dialog, the status-poll machinery — all unchanged.-------## 1. Decisions locked--| # | Decision | Choice | Rationale |-|---|---|---|---|-| D1 | Swap-tx builder | **PumpPortal `trade-local` API** (`POST https://pumpportal.fun/api/trade-local`). Returns a fully-built unsigned versioned transaction in raw binary (verified live: 1009-byte sell tx, 1098-byte buy tx for $FNCPT). | Jupiter's `/swap` works for $FNCPT but routes through PumpSwap anyway. Going direct removes a layer; PumpPortal is the canonical bridge for pump.fun-launched tokens. No API key required. |-| D2 | Pool routing | **`pool: "auto"`** on every request. | $FNCPT is post-graduation (bonding curve complete), so PumpPortal will pick PumpSwap. If Fincept ever launches a new token pre-graduation, the same code routes it correctly. |-| D3 | Quote / preview | **No separate quote topic.** Estimate output from current spot (`market:price:fncpt`) + slippage budget; render in SwapPanel. | PumpPortal has no quote endpoint, only "build me a tx now". The earlier Jupiter design carried `wallet:quote:*` precisely because Jupiter exposed `/quote` separately. Removing it simplifies the panel and lines up with the tx-on-click flow. |-| D4 | Slippage default / cap | Default **1 %**, user-adjustable up to **5 %** in Settings. The slippage bound is sent to PumpPortal as the `slippage` integer (percent). | Matches earlier rev; Phase 1.5 SettingsTab already persists `wallet.default_slippage_bps`. |-| D5 | Priority fee | Default **0.00005 SOL** (~$0.01 at SOL=$170). Hidden behind an "advanced" disclosure in Settings; not exposed per-trade in Phase 2. | Matches PumpPortal's docs example; covers 95th-percentile network congestion. Per-trade override is a Phase 3 polish. |-| D6 | Burn | **Deferred to Phase 5**, when buyback automation owns burns centrally. Phase 2's TRADE tab shows BUY and SELL only; the BurnPanel placeholder is removed (was Stage 2.3). | Avoids ~150 lines of Solana primitives in C++ or a separate Rust program for a single user-action. Phase 5's buyback-worker burns from a Fincept treasury account using off-chain tooling. |-| D7 | Activity feed source | **Helius parsed-tx REST** (`https://api.helius.xyz/v0/addresses/<pubkey>/transactions`) when `solana.helius_api_key` is set in SecureStorage. Fallback: `SolanaRpcClient::get_signatures_for_address` for raw signatures. | Same as the earlier rev — unchanged. |-| D8 | Fee-discount source | Local computation against the latest `wallet:balance:<pubkey>` publish. Threshold + applied SKUs in `services/billing/FeeDiscountConfig.h`. | Same as earlier rev — unchanged. |-| D9 | Fee-discount threshold | **1,000 $FNCPT** for **30 %** off AI reports / deep backtests / premium screens. | Same as earlier rev. Phase 3's TierService will override based on staked weight. |-| D10 | Tabbed shell | Already shipped Stage 2.1: `QTabWidget` with `HoldingsBar` above. Phase 2 only updates content of TRADE and ACTIVITY tabs. | No layout work in this rev. |-| D11 | When wallet is disconnected | All Phase 2 tabs render their empty state. The CONNECT WALLET CTA from Phase 1 remains the only entry point. | Same as earlier rev. |-| D12 | Confirm dialog scope | The shared `WalletActionConfirmDialog` (Stage 2.0) handles BUY and SELL. Reused as-is for Phase 3+ lock / stake. | Same as earlier rev. |-| D13 | Anti-muscle-memory delay | **1500 ms** for both BUY and SELL. (Earlier rev had 2500 ms for burn; with burn deferred, 1500 ms applies uniformly.) | Conservative default; perceptible enough to break click-through, not so long users hate it. |-| D14 | Where the unsigned tx is built | PumpPortal returns the raw bytes; the terminal **base64-encodes** them and forwards to the existing `WalletTxBridge → swap.html → wallet.signAndSendTransaction`. | Reuses the entire signing path from Stage 2.2; zero changes to `swap.html` or `WalletTxBridge`. |-| D15 | Activity row click target | Solscan in default browser. Cluster is mainnet-only (no devnet $FNCPT supply). | Same as earlier rev. |-------## 2. Threat model — only the entries that still apply--The earlier rev listed five new attacks beyond Phase 1. With burn deferred and Jupiter dropped, three remain unchanged and two retire.--| Attack | Still applies? | Mitigation |-|---|---|---|-| **PumpPortal MITM** — attacker intercepts the HTTPS call and feeds a malicious tx body that drains the wallet | **Yes** (replaces "quote-API spoofing" entry from the Jupiter rev) | (a) Confirm dialog shows decoded summary before sign — the tx itself is opaque to the user, but they verify _amount_, _direction_, and _slippage_ against what they typed; (b) `simulateTransaction` on the user's RPC and refuse to sign if any non-FNCPT/non-SOL/non-wSOL token balance changes. (c) Optionally pin PumpPortal's TLS leaf cert SHA-256 in SecureStorage and verify on each call — Phase 2.5 polish. |-| **Replay of an old swap transaction** | **Yes** | The unsigned tx from PumpPortal has a recent blockhash baked in. Refuse to sign if `currentBlockHeight > tx.lastValidBlockHeight - 50` (about 25 s buffer). Read the embedded blockhash via `web3.js` after deserialise — already part of `swap.html`'s deserialise step. |-| **Anti-muscle-memory** | **Yes** | `WalletActionConfirmDialog` already enforces a 1.5 s arm delay with a visible countdown. Inherited unchanged from Stage 2.0. |-| **Loopback-bridge stale token** | **Yes** | `WalletTxBridge` already mints a single-use UUID per request, expires after 60 s. Inherited unchanged from Stage 2.0. |-| ~~Burn-program ID swap~~ | **No** — burn deferred to Phase 5 | n/a |-| ~~Anchor program tampering via SecureStorage~~ | **No** — no custom program | n/a |--A separate `crypto-center-trade-security.md` lands with the Phase 2 PR; this section is the spec it walks against.-------## 3. Architecture (delta from what's already shipped)--Phase 2 rev 2 replaces exactly one component (`JupiterSwapService`) and adds two new ones (`WalletActivityProducer`, `FeeDiscountService`). Everything else is reuse.--```- ┌──────────────────────────────────────────────────────────────┐- │ CryptoCenterScreen (already shipped 2.1) │- │ ┌──────────────────────────────────────────────────────────┐ │- │ │ HoldingsBar (always visible, identity-level) │ │- │ │ SOL · $FNCPT · USD · 24h Δ · ● LIVE · HELIUS · 30% OFF │ │- │ └──────────────────────────────────────────────────────────┘ │- │ ┌──────────────────────────────────────────────────────────┐ │- │ │ QTabWidget │ │- │ │ ┌────┬─────┬───────┬─────┬───────┬───────┬─────────┐ │ │- │ │ │HOME│TRADE│ACTIV. │SET. │STAKE† │MKTS† │ROADMAP† │ │ │- │ │ └────┴─────┴───────┴─────┴───────┴───────┴─────────┘ │ │- │ │ TRADE: SwapPanel only (BurnPanel removed; deferred) │ │- │ │ ACTIV.: ActivityTab — Helius parsed-tx │ │- │ └──────────────────────────────────────────────────────────┘ │- └──────────────────────────────────────────────────────────────┘- │ subscribe / unsubscribe- ▼- ┌─────────────────────────────────────────────────────────────────────────┐- │ DataHub │- │ wallet:balance:<pk> (Phase 1, unchanged) │- │ market:price:fncpt (Phase 1, unchanged) │- │ wallet:activity:<pk> (NEW, poll 30 s) │- │ billing:fncpt_discount:<pk> (NEW, derived from balance) │- │ │- │ (wallet:quote:* — REMOVED. PumpPortal has no quote endpoint; │- │ SwapPanel computes the projected output locally from spot.) │- │ (wallet:burn_receipt:* — REMOVED. Burn deferred to Phase 5.) │- └─────────────────────────────────────────────────────────────────────────┘- ▲ publishes- │- ┌──────────────────────┴──────────────────────────────────────────────────┐- │ │- │ PumpFunSwapService WalletActivityProducer │- │ - build_swap(action, amt, - 30 s poll Helius │- │ pubkey, slippage_pct) parsed-tx endpoint │- │ → tx_base64 - parses tx kinds │- │ (single HTTP POST to (SWAP, RECEIVE, SEND) │- │ pumpportal.fun) │- │ │- │ FeeDiscountService │- │ - subscribes to wallet:balance:<pk> │- │ - publishes billing:fncpt_discount:<pk> │- │ │- └──────────────────────┬──────────────────────────────────────────────────┘- │ uses (already shipped)- ▼- ┌─────────────────────────────────────────────────────────────────────────┐- │ WalletService::sign_and_send (Stage 2.0) │- │ WalletTxBridge (Stage 2.0) │- │ resources/wallet/swap.html (Stage 2.2) │- │ SolanaRpcClient::getSignatureStatuses (Stage 2.0) │- │ WalletActionConfirmDialog (Stage 2.0) │- │ HttpClient (Phase 1) │- └─────────────────────────────────────────────────────────────────────────┘-```--The signing path (`WalletService::sign_and_send` → `WalletTxBridge` → `swap.html` → wallet ext → status poll) is reused without modification. The replacement scope is **the C++ service** that produces the `tx_base64` to feed into `sign_and_send`.-------## 4. Files to add / change / remove--### New files--```-src/services/wallet/- PumpFunSwapService.{h,cpp} // POST pumpportal.fun/api/trade-local- // → returns base64 versioned tx- WalletActivityProducer.{h,cpp} // Producer for wallet:activity:*-src/services/billing/- FeeDiscountService.{h,cpp} // Producer for billing:fncpt_discount:*- FeeDiscountConfig.h // thresholds (decoupled from service)-src/screens/crypto_center/panels/- FeeDiscountPanel.{h,cpp} // owned by TradeTab — replaces placeholder-src/screens/crypto_center/tabs/- ActivityTab.{h,cpp} // owned by CryptoCenterScreen — replaces ComingSoonTab in slot 3-docs/- CRYPTO_CENTER_PHASE_2.md // user-facing "how to swap"-plans/- crypto-center-trade-security.md // walkthrough doc-```--### Existing files modified--```-src/screens/crypto_center/panels/SwapPanel.{h,cpp}- - Replace JupiterSwapService dependency with PumpFunSwapService- - Drop the wallet:quote:* subscription path- - Compute estimated-out locally: `in_amount * spot_price * (1 - slippage_pct/100)`- - Submit flow: PumpFunSwapService::build_swap() → sign_and_send() (unchanged below this)- - Burn-related dead code removed (none made it past Stage 2.2, but verify)--src/screens/crypto_center/tabs/TradeTab.{h,cpp}- - Burn placeholder QFrame removed- - FeeDiscountPanel slotted in- - Layout becomes: SwapPanel (top) + FeeDiscountPanel (right)--src/screens/crypto_center/CryptoCenterScreen.{h,cpp}- - Replace ComingSoonTab in ACTIVITY slot with real ActivityTab--src/services/wallet/WalletService.{h,cpp}- - swap_service() accessor changes type from JupiterSwapService* to PumpFunSwapService*- - Drop wallet:quote:* topic policy (no longer needed)--src/datahub/DataHubMetaTypes.{h,cpp}- - Drop JupiterQuote registration (no longer needed)- - Add ParsedActivity registration--src/services/wallet/WalletTypes.h- - Drop JupiterQuote- - Add ParsedActivity, FncptDiscount--src/app/main.cpp- - Construct + register WalletActivityProducer, FeeDiscountService with the hub--docs/DATAHUB_TOPICS.md- - Remove the wallet:quote:* row (added in Stage 2.0; never used)- - Remove the wallet:burn_receipt:* row (Burn deferred)- - Keep wallet:activity:* and billing:fncpt_discount:*--CMakeLists.txt- - Add PumpFunSwapService.cpp, WalletActivityProducer.cpp, FeeDiscountService.cpp,- FeeDiscountPanel.cpp, ActivityTab.cpp- - Remove JupiterSwapService.cpp from the source list-```--### Files removed--```-src/services/wallet/JupiterSwapService.{h,cpp}- Replaced by PumpFunSwapService. Delete completely — no users beyond SwapPanel,- which moves to the new service in the same PR.-```--### Files unchanged (keep as-is, do not touch)--```-src/services/wallet/WalletTxBridge.{h,cpp}-src/services/wallet/SignTransactionDialog.{h,cpp}-src/services/wallet/SolanaRpcClient.{h,cpp} (extensions from Stage 2.0)-src/screens/crypto_center/WalletActionConfirmDialog.{h,cpp}-src/screens/crypto_center/WalletActionSummary.h-src/screens/crypto_center/HoldingsBar.{h,cpp}-src/screens/crypto_center/tabs/HomeTab.{h,cpp}-src/screens/crypto_center/tabs/SettingsTab.{h,cpp}-src/screens/crypto_center/tabs/ComingSoonTab.{h,cpp} (still used for STAKE/MKTS/ROADMAP)-resources/wallet/swap.html-resources/wallet/vendor/ (web3.js slot — same need)-```-------## 5. Stages & tasks--### Stage 2A — Swap-path pivot--**Goal:** swap (BUY + SELL) works end-to-end against PumpPortal. No new features beyond what Stage 2.2 already promised; the same UI, just a different tx-build backend.--**Task 2A.1 — `PumpFunSwapService`**-- Header: `build_swap(action: Buy|Sell, mint, amount_raw, denominated_in_sol, pubkey, slippage_pct, priority_fee_sol, cb)` → `Result<{ tx_base64, last_valid_block_height_hint }>`. The hint is _optional_ — PumpPortal doesn't expose it directly, so we either parse it from the deserialised tx (cheap, post-receive) or skip the freshness gate and rely on the wallet's own blockhash check.-- One HTTP POST to `https://pumpportal.fun/api/trade-local` with the JSON body:- ```json- {- "publicKey": "<pk>",- "action": "buy" | "sell",- "mint": "9LUqJ5aQTjQiUCL93gi33LZcscUoSBJNhVCYpPzEpump",- "amount": <number-or-percent-string>,- "denominatedInSol": "true" | "false",- "slippage": <int-percent>,- "priorityFee": <sol>,- "pool": "auto"- }- ```-- Response is **raw binary** (octet-stream), about 1 KB. Base64-encode and return.-- Reuses the `HttpClient` singleton; mirror `JupiterSwapService.cpp`'s post pattern.-- **Not a Producer** — there's no topic family. It's a one-shot service like `FncptBurnService` was going to be.-- Verification: unit-test the success path with a mocked HTTP reply; live integration test handled in Task 2A.4.--**Task 2A.2 — Replace `JupiterSwapService` plumbing**-- Delete `JupiterSwapService.{h,cpp}` and any `Q_DECLARE_METATYPE(JupiterQuote)` plus its registration in `DataHubMetaTypes`.-- Drop `WalletService::swap_service()` returning `JupiterSwapService*`; replace with `pumpfun_swap()` returning `PumpFunSwapService*`. Both `WalletService.h` and `WalletService.cpp` change.-- Remove the `wallet:quote:*` topic policy from `WalletService::ensure_registered_with_hub`.-- Remove the `wallet:quote:*` row from `docs/DATAHUB_TOPICS.md`. Same commit (D5 in CLAUDE.md).-- Verification: build is green; the screen loads as before; no dangling references in grep.--**Task 2A.3 — Update `SwapPanel`**-- Remove the `wallet:quote:*` subscription. Keep the debounce timer for input changes — but instead of resubscribing, recompute estimated-out locally:- ```- estimated_out = in_amount * spot_price * (1 - slippage_pct/100)- ```- using the cached `last_fncpt_usd_price_` (BUY) or `1 / last_fncpt_usd_price_` (SELL).-- Show the same `route` / `impact` rows but populate them from a static "PumpSwap (auto)" / "≤ slippage" — there's no live route impact from PumpPortal.-- On SWAP click: build summary as before but with locally-computed numbers, then call `PumpFunSwapService::build_swap` → `WalletService::sign_and_send` → status-poll. The lower half of the flow is unchanged.-- The `slippage_bps()` accessor stays — but we now pass `int slippage_pct = bps / 100` to PumpPortal. PumpPortal expects whole percent.-- Verification: BUY 0.001 SOL of $FNCPT on mainnet returns a signature within 30 s; balance refreshes; ACTIVITY tab shows the swap row.--**Task 2A.4 — Live smoke test**-- Manual: connect a small mainnet wallet, BUY 0.001 SOL of $FNCPT, then SELL 50 % of the resulting balance. Both must show "confirmed" within 30 s.-- Smoke for the slippage cap: try a swap with the slippage slider at 0.10 % on a low-liquidity moment → expect the wallet to reject the tx, error strip surfaces it cleanly.-- Smoke for cancel: open Confirm, click Cancel → no signature ever requested, no bridge token leaks.--**Stage 2A acceptance:**-- BUY of 0.001 SOL succeeds and balance updates in HoldingsBar within 5 s of `confirmed`.-- SELL of N $FNCPT for the resulting SOL succeeds.-- A swap whose blockhash expired during the dialog is rejected with a clear error. (No special handling needed — wallet rejects the tx; we surface the error string.)-- Slippage > 5 %: SettingsTab clamps the slider; `SwapPanel` rejects user-typed amounts that would breach impact.--### Stage 2A.5 — Multi-token holdings--**Goal:** Crypto Center shows **every** asset the user holds (SOL + every SPL token), with a USD price for each, a portfolio total at the top, and TRADE's swap dropdown populated from real holdings instead of a hard-coded `[SOL, $FNCPT]` pair. Today's FNCPT-only flow only worked because the user happened to be looking at a token they held; the moment someone wants to sell BONK or USDC for $FNCPT, the panel falls over.--The fix is small and self-contained — three producers/services, one new POD, one shared metadata cache. It belongs **before** Stage 2B because the Activity feed wants to render `SWAP SOL → BONK` rows that reference the same metadata cache.--**Why it's a separate stage and not part of 2A:** 2A was already shipped against the FNCPT-only assumption. The pivot to PumpPortal didn't change that assumption (PumpPortal is FNCPT-only by design — it's the issuer's own swap endpoint). Generalising to arbitrary holdings is its own capability with its own data plumbing.--#### 2A.5.0 Decisions locked--| # | Decision | Choice | Rationale |-|---|---|---|---|-| D.5.1 | Source of holdings | `getTokenAccountsByOwner` with `programId = TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA` (no mint filter). Single call returns every SPL account for the wallet. | Already wrapped in `SolanaRpcClient::get_token_balance`; we generalise the existing helper rather than adding a parallel one. |-| D.5.2 | Source of token metadata | **Jupiter "verified" tagged token list** (`https://api.jup.ag/tokens/v2/tagged/verified`) as the primary source; fallback to truncated mint address (`9LUq…pump`) for unverified mints. | Verified live; no key required; covers everything routable. The previous Solana Labs `token-list` repo is frozen. |-| D.5.3 | Source of token prices | **Jupiter Lite Price API** (`lite-api.jup.ag/price/v3?ids=…`) — comma-separated mints. | Already wired for `market:price:fncpt`; same host, same response shape, just batched. Verified live: SOL + USDC + FNCPT in one round-trip. |-| D.5.4 | Spam-token policy | **Hide unverified-list tokens by default**, with a Settings toggle "Show all token accounts (incl. unverified)" that reveals them. Show count in the holdings header: `7 verified · 12 unverified hidden`. | Pump.fun wallets routinely accumulate airdropped junk; defaulting to unverified-only avoids a noisy first-run. The toggle is the escape hatch. |-| D.5.5 | Topic family for prices | Generalise the existing `market:price:fncpt` into `market:price:token:<mint>` family. The `market:price:fncpt` topic stays as an alias of `market:price:token:9LUq…pump` for backward compat with existing subscribers (HoldingsBar, HomeTab, SwapPanel). | Lets any panel subscribe per-mint without a custom service. The producer batches all currently-subscribed mints into one Jupiter call per refresh cycle. |-| D.5.6 | Topic family for holdings | Reuse `wallet:balance:<pubkey>` — change the `WalletBalance` payload shape to carry `QVector<TokenHolding>` instead of just FNCPT fields. | Avoids a separate topic family. All existing consumers (HoldingsBar, HomeTab, SwapPanel, FeeDiscount) already subscribe; they just read different fields. |-| D.5.7 | Where the metadata cache lives | New `TokenMetadataService` (singleton, not a hub Producer — it's a synchronous lookup table fed by one slow background fetch). Cache TTL **24 hours**; persisted to `SecureStorage` so cold starts don't block on a 1 MB download. | A service is the right scope: balance/price producers all need it; the holdings panel needs it; SwapPanel needs it for the FROM/TO combos. |-| D.5.8 | Fallback when metadata is missing | Show `<truncated_mint>` (e.g. `9LUq…pump`) as the symbol, decimals from on-chain `getTokenAccountsByOwner` result, no icon. | Solana RPC always returns decimals in the parsed token-account info, so we never lie about scale even for unknown tokens. |-| D.5.9 | When prices are missing | Show the row but USD column reads `—`; total USD excludes that row and surfaces a footnote `1 token has no price` if any are missing. | A token in the wallet that Jupiter doesn't price is real (held); just unmonetisable for now. Don't hide it — the user might want to swap it. |-| D.5.10 | Total-USD precision | 2 dp when ≥ $1, 6 dp otherwise. Always show even at `$0.00`. | Mirrors Phase 2's Stage 2A formatter fix — zero is a real value, not "unknown". |-| D.5.11 | Trade-FROM token selector | Combo populated from holdings sorted by USD value descending, with verified Jupiter tokens appended as a "swap into" option only on the TO side. | Users sell what they have; users buy what's tradeable. Asymmetric population is the right shape. |-| D.5.12 | Phase-1.5 patterns | Single stylesheet per screen. Producer-owned heartbeats (`TokenPriceProducer` re-fetches all subscribed mints on its TTL). Force-refresh through `WalletService` (existing `force_balance_refresh()` regenerates the holdings list). | Same conventions §1.5.3 established. |-| D.5.13 | Backward compat for `market:price:fncpt` | Keep publishing the alias for one phase. Mark deprecated in `DATAHUB_TOPICS.md`. Remove in Phase 3 cleanup. | Avoids touching every existing consumer in this PR; one cleanup pass later is cheaper than one big PR now. |-| D.5.14 | Filter / sort / search in the holdings table | None this stage. Show top-N by USD value (10 by default), "Show all" link reveals the rest. Search lives with Phase 3 polish. | Keeps stage 2A.5 small. |-| D.5.15 | Out of scope | NFT holdings (Helius DAS would give them; deferred). Hardware-wallet account discovery. Multi-account aggregation (one wallet at a time, same as today). | |--#### 2A.5.1 Architecture--```-┌──────────────────────────────────────────────────────────────────────────┐-│ TokenMetadataService (singleton, NOT a Producer) │-│ - load_from_storage() // <1ms, called from main() │-│ - refresh_from_jupiter() // background, async, fires once a day │-│ - lookup(mint) → {symbol,name,decimals,icon_url} | not_found │-│ - notify_changed signal // panels listen for first-load + daily │-│ - persistence: SecureStorage key "token_metadata.cache_v1" (JSON blob)│-│ - hot path is a QReadWriteLock-guarded QHash<QString, TokenMetadata> │-└────────────┬─────────────────────────────────────────────────────────────┘- │ called synchronously (read-mostly, ~1µs per lookup)- ▼-┌──────────────────────────────────────────────────────────────────────────┐-│ WalletBalanceProducer (existing — payload shape upgraded) │-│ - getTokenAccountsByOwner without a mint filter │-│ - merges parsed accounts with TokenMetadataService::lookup │-│ - publishes WalletBalance{ pubkey, sol_lamports, tokens[], ts_ms } │-│ - QVector<TokenHolding> tokens — sorted by USD value at publish time │-│ (price taken from the price producer's last cache; if no cache, raw │-│ order from RPC). │-└────────────┬─────────────────────────────────────────────────────────────┘- │ publishes- ▼- wallet:balance:<pk>- │ subscribed by:- ▼- HoldingsBar · HomeTab BalancePanel · SwapPanel · FeeDiscountService--┌──────────────────────────────────────────────────────────────────────────┐-│ TokenPriceProducer (NEW — replaces FncptPriceProducer) │-│ - topic_patterns: ["market:price:token:*", "market:price:fncpt"] │-│ - refresh(topics) — collects all mints from subscribed topics, makes │-│ ONE Jupiter Lite call: ?ids=<mint1>,<mint2>,…,<mintN> │-│ - publishes per-mint TokenPrice{usd, sol, ts_ms, valid} │-│ - aliases the FNCPT mint to the legacy market:price:fncpt topic │-│ - max_requests_per_sec = 2 (one batched call per ~30s, tolerant) │-└──────────────────────────────────────────────────────────────────────────┘-```--#### 2A.5.2 Topic catalogue changes--| Pattern | Producer | TTL | Min interval | Notes |-|---|---|---|---|---|-| `wallet:balance:<pubkey>` | `WalletBalanceProducer` | 30 s / push | 10 s | **Payload shape upgraded** — see `WalletBalance` POD below. Same producer, same TTL. |-| `market:price:token:<mint>` | `TokenPriceProducer` | 60 s | 30 s | One Jupiter Lite call serves all subscribed mints. Coalesce 250 ms across rapid subscribe events. Shape: `TokenPrice{ mint, usd, sol, ts_ms, valid }`. |-| `market:price:fncpt` (alias) | `TokenPriceProducer` | 60 s | 30 s | Backward-compat alias of `market:price:token:9LUqJ5aQTjQiUCL93gi33LZcscUoSBJNhVCYpPzEpump`. Marked **deprecated** in this rev. Remove in Phase 3. |--#### 2A.5.3 Type changes--```cpp-// services/wallet/WalletTypes.h--struct TokenHolding {- QString mint; // base58 SPL mint- QString symbol; // resolved via TokenMetadataService; truncated mint if unknown- QString name; // "USD Coin" / "" if unknown- QString amount_raw; // integer string- int decimals = 0; // always known (RPC parsed value)- bool verified = false;// in Jupiter's verified tagged list- QString icon_url; // empty if unknown- double ui_amount() const noexcept; // amount_raw / 10^decimals-};--struct WalletBalance {- QString pubkey_b58;- quint64 sol_lamports = 0;- QVector<TokenHolding> tokens; // sorted by USD value desc at publish time- qint64 ts_ms = 0;- double sol() const noexcept { return sol_lamports / 1e9; }- // Convenience accessor for legacy callers that still want FNCPT specifically:- const TokenHolding* fncpt_holding() const noexcept;- double fncpt_ui() const noexcept; // 0.0 if not held- int fncpt_decimals() const noexcept;-};--struct TokenPrice {- QString mint;- double usd = 0.0;- double sol = 0.0;- qint64 ts_ms = 0;- bool valid = false;-};--struct TokenMetadata {- QString mint;- QString symbol;- QString name;- int decimals = 0;- QString icon_url;- bool verified = false;-};-```--The legacy `FncptPrice` POD is **kept** as a typedef of `TokenPrice` so `WalletService.cpp` and the price subscribers don't break.--#### 2A.5.4 UI changes--**HoldingsBar** — replaces today's `SOL · $FNCPT · USD · PRICE · UPDATED` with:--```-SOL 9.7425 · $FNCPT 0 · TOTAL $1,247.82 · UPDATED 3s · ● LIVE · HELIUS-```--`TOTAL` is the sum of `(holding.ui_amount × usd_price)` across SOL + every priced verified holding; rows without prices are excluded with a footnote tooltip on the chip.--**HomeTab / BalancePanel** — replaces the three-stat-box layout with a holdings table:--```-TOKEN BALANCE PRICE USD VALUE % OF PORT-SOL 9.7425 $84.28 $820.31 65.7%-USDC 420.10 $1.00 $420.10 33.7%-$FNCPT 0 $0.0000185 $0.00 0.0%-WIF 12.500 $1.42 $17.75 1.4%-─── 7 verified · 12 unverified hidden · [Show all] ─────────────────-```--Click a row → SwapPanel pre-fills FROM with that token. Click "Show all" → reveals unverified tokens with a faint "(unverified)" tag and the truncated mint instead of a symbol.--**SwapPanel** — token combos populated from real holdings:-- FROM combo: every token from `wallet:balance` sorted by USD value desc; SOL always at top.-- TO combo: every entry from FROM **plus** Jupiter verified list (filtered to remove the FROM mint). For Phase 2 we'll keep the constraint "$FNCPT must be one side of the trade" until Stage 2C, but the combo wires up to support arbitrary pairs immediately.-- MAX button reads from the selected token's balance.--**SettingsTab** — new "Show unverified tokens" toggle. Persists to `SecureStorage` key `wallet.show_unverified_tokens`.--#### 2A.5.5 Files to add / change / remove--**New files:**--```-src/services/wallet/- TokenMetadataService.{h,cpp} // singleton, JSON cache + Jupiter fetch- TokenPriceProducer.{h,cpp} // replaces FncptPriceProducer--src/screens/crypto_center/panels/- HoldingsTable.{h,cpp} // owned by HomeTab; replaces three-box layout-```--**Files modified:**--```-src/services/wallet/WalletTypes.h- - Upgrade WalletBalance shape (TokenHolding vector)- - Add TokenHolding, TokenPrice, TokenMetadata PODs- - FncptPrice → typedef of TokenPrice (back-compat)--src/services/wallet/WalletBalanceProducer.{h,cpp}- - Drop the kFncptMint hard-coding inside the fetch path- - Call SolanaRpcClient::get_all_token_balances (new helper, see below)- - Merge metadata via TokenMetadataService::lookup- - Sort tokens by USD value (read TokenPriceProducer's cache via a non-blocking peek)--src/services/wallet/SolanaRpcClient.{h,cpp}- - Add: void get_all_token_balances(owner_b58, callback) — getTokenAccountsByOwner- with programId filter only (no mint filter). Returns vector<SplTokenBalance>.--src/services/wallet/WalletService.{h,cpp}- - Replace price_producer_ pointer type from FncptPriceProducer* to TokenPriceProducer*- - ensure_registered_with_hub: register the new producer; update the topic-policy- pattern from market:price:fncpt to market:price:token:* (alias retained)--src/screens/crypto_center/HoldingsBar.{h,cpp}- - Replace per-cell SOL/$FNCPT/USD with TOTAL USD + signature SOL/$FNCPT- - Iterate WalletBalance.tokens to compute total--src/screens/crypto_center/tabs/HomeTab.{h,cpp}- - Drop the three stat boxes; embed HoldingsTable in their place- - REFRESH button still calls WalletService::force_balance_refresh--src/screens/crypto_center/panels/SwapPanel.{h,cpp}- - Populate combos from holdings + Jupiter verified list- - Compute estimate using selected pair's prices, not FNCPT-only--src/services/billing/FeeDiscountService.{h,cpp} // when Stage 2C lands- - Read FNCPT from WalletBalance.fncpt_ui() helper--src/datahub/DataHubMetaTypes.{h,cpp}- - Register TokenHolding, TokenPrice (FncptPrice still works via typedef)- - Drop the JupiterQuote registration (already gone, just sanity-check)--src/app/main.cpp- - Construct + load TokenMetadataService::instance() before WalletService::ensure_registered_with_hub()- - Service registration already routes through WalletService — no change needed there.--docs/DATAHUB_TOPICS.md- - Replace the market:price:fncpt row with the new market:price:token:* family- - Note that market:price:fncpt is a deprecated alias for one phase--CMakeLists.txt- - Add TokenMetadataService.cpp, TokenPriceProducer.cpp, HoldingsTable.cpp- - Remove FncptPriceProducer.cpp (file deleted)-```--**Files removed:**--```-src/services/wallet/FncptPriceProducer.{h,cpp} // replaced by TokenPriceProducer-```--#### 2A.5.6 Tasks--**2A.5.1 — Type plumbing** (foundation; nothing UI-visible)-- New PODs in `WalletTypes.h`; `FncptPrice` typedef of `TokenPrice`.-- Register metatypes in `DataHubMetaTypes.cpp`.-- Verification: builds clean; existing consumers compile against the legacy aliases.--**2A.5.2 — `TokenMetadataService`**-- Singleton; on first instantiation, restore JSON blob from SecureStorage.-- Public API: `lookup(mint) → optional<TokenMetadata>`, `bool is_verified(mint)`.-- Background `refresh_from_jupiter()` runs once on startup if cache is older than 24 h, or on first `lookup()` of a mint absent from cache.-- Backed by `QHash<QString, TokenMetadata>` under a `QReadWriteLock`.-- Verification: unit test the SecureStorage round-trip; manual test that hitting `api.jup.ag/tokens/v2/tagged/verified` (rate-limit-tolerantly) populates the cache.--**2A.5.3 — `SolanaRpcClient::get_all_token_balances`**-- Call `getTokenAccountsByOwner(owner, {programId: TOKEN_PROGRAM_ID}, {encoding: jsonParsed})`.-- Return the same `vector<SplTokenBalance>` shape as today's `get_token_balance`, just unfiltered.-- Verification: against a known-multi-token wallet; expect ≥ 2 entries.--**2A.5.4 — `WalletBalanceProducer` upgrade**-- Replace the FNCPT-only fetch path with `get_all_token_balances`.-- For each `SplTokenBalance`, build a `TokenHolding` with metadata from `TokenMetadataService::lookup()`. Filter spam (decimals=0 amount=1 unless whitelisted) before publish if Settings says so.-- Sort tokens by USD value (read `TokenPriceProducer`'s last-cached value; if no cache yet, sort by raw amount).-- Verification: subscribe to `wallet:balance:<pk>` from a test harness with a multi-token wallet; expect ≥ 2 entries.--**2A.5.5 — `TokenPriceProducer`**-- Topic patterns: `"market:price:token:*"`, `"market:price:fncpt"` (alias).-- `refresh(topics)`: collect all mints, build one `?ids=...` call, publish per-mint.-- Set policy: TTL 60 s, min_interval 30 s, coalesce 250 ms.-- Delete `FncptPriceProducer.{h,cpp}`; route the alias topic into the new producer's mint-extraction logic.-- Verification: subscribe to two arbitrary mints simultaneously; expect a single network call within 250 ms.--**2A.5.6 — `WalletService` rewiring**-- Construct `TokenPriceProducer` instead of `FncptPriceProducer`.-- Update topic-policy registration to cover both `market:price:token:*` and the alias.-- Verification: `market:price:fncpt` still publishes; `market:price:token:So111…1112` (SOL) also publishes.--**2A.5.7 — `HoldingsTable` widget**-- New widget owned by `HomeTab`. Subscribes to `wallet:balance:<pk>` and to `market:price:token:<mint>` for each currently-held mint.-- Renders the table; whole-row click → emits a `select_token(mint)` signal (wired to `SwapPanel` in 2A.5.10).-- "Show all" link toggles unverified visibility for the current session; persisted state lives in SettingsTab.-- Verification: connected wallet shows ≥ 1 row (SOL); a multi-token wallet shows USDC, FNCPT, etc.--**2A.5.8 — `HoldingsBar` rewrite**-- Iterate `WalletBalance.tokens` for the total. Show SOL + signature $FNCPT + TOTAL USD + feed pill + RPC chip.-- Verification: total matches manual sum across SOL + all verified holdings × Jupiter prices.--**2A.5.9 — `HomeTab` BalancePanel layout swap**-- Replace the three stat boxes with the `HoldingsTable` widget. Keep REFRESH + the POLL/STREAM toggle on the panel head.-- Verification: layout renders cleanly at narrow widths (no horizontal scroll).--**2A.5.10 — `SwapPanel` token combos**-- FROM combo populated from `WalletBalance.tokens` sorted by USD value desc. SOL always at top.-- TO combo: union of FROM holdings and Jupiter verified list (minus the FROM mint). For Phase 2, default TO = $FNCPT; Phase 3 lifts the constraint.-- MAX button reads from the **selected** mint's `ui_amount`, with a 0.005 SOL reserve only when the FROM is SOL.-- Estimate: read prices for both FROM and TO from `TokenPriceProducer`; fall back to "estimate unavailable" if either missing.-- Verification: select USDC FROM → MAX → see correct USDC balance prefilled; estimate shows USDC→FNCPT in $FNCPT units.--**2A.5.11 — `SettingsTab` "show unverified" toggle**-- Persist to `SecureStorage` key `wallet.show_unverified_tokens`.-- HoldingsTable + SwapPanel honor the flag.--**2A.5.12 — Doc + topic catalogue update**-- `docs/DATAHUB_TOPICS.md`: replace `market:price:fncpt` row with `market:price:token:*`. Mark legacy alias deprecated. Document `wallet:balance:<pubkey>` shape change.-- `plans/crypto-center-future-phases.md` §2.5: bring the topics list in line.--#### 2A.5.7 Acceptance criteria--- [ ] HoldingsBar shows TOTAL USD = sum of (SOL × SOL price) + Σ (token × token price) for verified holdings.-- [ ] HomeTab shows a holdings table with at least the user's actually-held tokens (SOL, FNCPT, plus whatever airdrops they have if "Show all" is on).-- [ ] SwapPanel FROM combo lists every held token; selecting a non-FNCPT token populates balance correctly and estimate shows in TO units.-- [ ] First-run cold cache: TokenMetadataService loads from SecureStorage in < 5 ms; UI never shows raw mint addresses for verified tokens after the first balance publish.-- [ ] No Rust source. No new on-chain code. No Helius dependency for the verified-tokens path (Helius only used for parsed-tx in Stage 2B).-- [ ] Phase 1.5 patterns honored: single stylesheet per screen, FeedStatus on HoldingsBar still drives via objectName swap, force-refresh through `WalletService::force_balance_refresh`.--#### 2A.5.8 Risks & open questions--1. **Jupiter token-list size.** Verified list is ~500KB-1MB. SecureStorage handles strings of that size today, but worth confirming on first-run write. Fallback if SecureStorage chokes: write to a plain JSON file under `AppData/.../cache/`.-2. **Jupiter rate limits.** The `tokens/v2` endpoint rate-limited me during planning. The price endpoint is fine. We refresh metadata once a day so the rate-limit risk is low; but cold-start on a fresh install needs to handle a 429 by retrying with backoff.-3. **NFTs.** SPL-token-account RPC returns NFTs (decimals=0, amount=1). Spam filter handles them by default; user can opt in via "Show all". A real NFT panel ships in a later phase.-4. **Sort-by-USD when no price.** Producer publishes before the price call returns on first run. Tokens without prices sort to the bottom (alphabetical fallback by symbol), then re-sort on the next publish once prices arrive. Acceptable jitter; documented.-5. **Total-USD precision over time.** Rounding errors across 50 tokens at 6dp could accumulate. Sum at full precision, format only at display.-6. **`market:price:fncpt` alias retirement.** D.5.13 says one phase. Need a follow-up TODO when Phase 3 starts.-------### Stage 2B — Activity feed--**Goal:** users can see what their wallet has done.--**Task 2B.1 — `WalletActivityProducer`**-- Topic `wallet:activity:<pubkey>`. Policy `ttl_ms=30_000, min_interval_ms=10_000`.-- `refresh()` calls Helius `/v0/addresses/<pk>/transactions?limit=50` (auth via existing `solana.helius_api_key`).-- Parses each tx into `ParsedActivity { ts, kind: SWAP|RECEIVE|SEND|OTHER, asset, amount_ui, signature }`. Helius parsing handles SWAP / RECEIVE / SEND directly; OTHER for everything we can't classify.-- Fall back: if Helius key missing, use `SolanaRpcClient::get_signatures_for_address` for raw signatures + show "Add a Helius key for parsed activity" footer in the tab.-- Verification: subscribe in a test harness, observe publish, change pubkey, observe new topic.--**Task 2B.2 — `ActivityTab` UI**-- `QTableView` with TIMESTAMP / EVENT / ASSET / AMOUNT / STATUS columns + whole-row click → Solscan.-- Filter chips above the table for SWAP / SEND / RECEIVE / OTHER.-- Empty state shows "No transactions yet" with a CONNECT WALLET fallback if disconnected.-- Replaces the `ComingSoonTab` in CryptoCenterScreen's ACTIVITY slot.-- Verification: ACTIVITY tab shows the swap from Stage 2A within one refresh cycle.--**Stage 2B acceptance:**-- ACTIVITY tab populates with the last 50 parsed events for the connected wallet.-- Clicking a row opens Solscan in the default browser.-- Filter chips narrow the list correctly.--### Stage 2C — Fee discount--**Goal:** eligible users see a "30 % off" badge wherever applicable.--**Task 2C.1 — `FeeDiscountConfig.h`**-- Constants: `kThresholdRaw = 1_000 * 10^6` (1,000 $FNCPT, 6 decimals); `kDiscountPct = 30`; `kAppliedSkus = {"ai-report", "deep-backtest", "premium-screen"}`.-- Header-only; no .cpp.--**Task 2C.2 — `FeeDiscountService`**-- Subscribes `wallet:balance:<pk>` internally (consumer-producer pattern from Phase 1's price-balance interplay).-- Publishes `billing:fncpt_discount:<pk>` = `{ eligible, threshold_raw, threshold_decimals, applied_skus }`.-- Re-publishes whenever the balance topic emits.-- Register in main.cpp alongside the other Phase 2 producers.-- Verification: balance publishes ≥ 1,000 → eligibility chip lights up; balance drops below threshold → chip extinguishes within one publish cycle.--**Task 2C.3 — `FeeDiscountPanel`**-- Owned by `TradeTab`; replaces today's placeholder.-- Subscribes `billing:fncpt_discount:<pk>`.-- Shows: balance-vs-threshold bar, applied SKUs as bullet list, projected savings on a hypothetical AI report ($x → $y).-- Read-only. Phase 3's Tier service will swap this for a richer panel.--**Task 2C.4 — `HoldingsBar` chip**-- The `discount_chip_` widget already exists (placeholder in Stage 2.1).-- Wire it: subscribe `billing:fncpt_discount:<current_pubkey>`, show/hide based on `eligible`.-- No new layout work.--**Stage 2C acceptance:**-- HoldingsBar and FeeDiscountPanel show "30 % off" for an account holding ≥ 1,000 $FNCPT.-- Balance dropping below threshold flips the chip back inside one publish cycle.--### Stage 2D — Polish, docs, security walkthrough--- Update `docs/CRYPTO_CENTER_PHASE_2.md` with screenshots of BUY, SELL, ACTIVITY.-- Walk every threat in §2 against the implementation; sign off in `plans/crypto-center-trade-security.md`.-- Update `plans/crypto-center-future-phases.md` to mark Phase 2 shipped (move §2 into a `crypto-center-phase-2-shipped.md` snapshot, including the burn-deferred decision).-- Confirm Phase 1.5 patterns (single stylesheet, FeedStatus pill, force-refresh through services, producer-owned heartbeats, endpoint-capability checks, screen-side staleness, error-strip pattern, RPC chip) were honored throughout.-------## 6. Risks & open questions--1. **PumpPortal availability.** The endpoint is third-party; if pumpportal.fun goes down, swaps break. Mitigation: the screen renders an empty TRADE tab with "Swap service temporarily unavailable" instead of crashing. We can fall back to Jupiter (the earlier rev's code) on Phase 3 or later if reliability becomes an issue — keeping the swap.html signing path generic means the swap-build service is hot-swappable.-2. **PumpPortal rate limits.** No public spec. Empirically tolerant for low-volume use. If we hit limits, add a `min_interval_ms` on the build call (note: this is one-shot, not a hub topic, so the throttle would live inside `PumpFunSwapService`).-3. **PumpPortal MITM.** TLS pinning would close the residual risk; out of scope this phase, listed as Phase 2.5 polish.-4. **Helius parsed-tx coverage.** Some swap routes don't decode into a clean SWAP row. Acceptable: those show as OTHER with the signature link.-5. **Burn deferral.** Real users will ask for it. Holding line on Phase 5 buyback worker as the right place.-6. **Slippage UX.** 1 %/5 % defaults are correct for $FNCPT today (thin liquidity); revisit when Phase 5 buyback narrows spreads.-7. **Failure during multi-leg swap.** PumpPortal returns a single versioned tx so partial fills aren't a concern; we just surface the error.-------## 7. Out of scope for Phase 2--- **Burn UI.** Deferred to Phase 5 (buyback automation).-- **Direct Ledger USB.** Use Phantom/Solflare's Ledger support.-- **Multi-chain.** $FNCPT stays on Solana.-- **Server-backed entitlement** (Phase 3 owns this).-- **WebSocket parsed-tx feed for activity** (poll is enough for Phase 2 traffic).-- **Per-trade priority-fee override** (Settings-level only this phase).-- **Limit orders, advanced order types.** PumpPortal doesn't support them; out of scope.-------## 8. Definition of Done--- [ ] User opens TRADE tab, sees a SwapPanel with current spot price and projected output. BUY of 0.001 SOL on mainnet succeeds in ≤ 30 s.-- [ ] User opens TRADE tab, can SELL 50 % of their $FNCPT and see the resulting SOL within ≤ 30 s.-- [ ] HoldingsBar shows live SOL · $FNCPT · USD · feed pill on every tab.-- [ ] ACTIVITY tab populates with the last 50 parsed events; clicking a row opens Solscan.-- [ ] FeeDiscount chip appears on HoldingsBar at ≥ 1,000 $FNCPT and disappears below.-- [ ] All P-rules and D-rules from CLAUDE.md hold; lint passes.-- [ ] Phase 1.5 patterns (single stylesheet per screen, FeedStatus pill, force-refresh through services) are honored.-- [ ] `docs/DATAHUB_TOPICS.md` lists `wallet:activity:*` and `billing:fncpt_discount:*` (and **does not** list `wallet:quote:*` or `wallet:burn_receipt:*`).-- [ ] `crypto-center-trade-security.md` is signed off.-- [ ] No Rust source anywhere in the tree.-------## 9. Document maintenance--Update this doc at each stage kickoff with the actual PR diffs. When Phase 2 ships, archive into `crypto-center-phase-2-shipped.md` with the verified-pattern subset of §1.5.3 expanded for transactional flows. The pivot-to-PumpPortal decision (D1) and the burn-deferral (D6) should be called out at the top of that archive so future phases inherit the rationale, not just the diff.diff --git a/fincept-qt/plans/crypto-center-security-walkthrough.md b/fincept-qt/plans/crypto-center-security-walkthrough.mddeleted file mode 100644index 9e45d852b..000000000--- a/fincept-qt/plans/crypto-center-security-walkthrough.md+++ /dev/null@@ -1,129 +0,0 @@-# Crypto Center — Security walkthrough (Phase 3.3)--This document records the manual security review of the wallet-connect flow built in Phase 1.--**Plan**: `plans/crypto-center-wallet-connect.md`-**Date**: 2026-04-27-**Reviewer**: claude (initial pass — to be re-signed by tilakpatel22 after a clean build run)--The plan §3 enumerated nine threats. Each is reproduced below with its mitigation as implemented and a self-attack note.--## Threat 1 — Pubkey spoofing--**Attack**: an attacker gets the user to paste/save someone else's public key, the terminal happily renders that wallet's balance and treats it as the user's identity for future operations.--**Mitigation**: every connect runs a signed-message challenge.-- `ConnectWalletDialog::start_handshake()` generates a 32-byte cryptographically random nonce via `QRandomGenerator::system()` (CSPRNG, not the deterministic generator).-- The browser-side JS asks the wallet to sign the literal bytes `Fincept Terminal wallet-connect challenge. Nonce: <hex>`.-- `ConnectWalletDialog::on_payload()` calls `Ed25519Verifier::verify(pubkey, message, signature)` on the returned bundle. If the signature is invalid, the dialog rejects with "signature verification failed" and never persists anything.-- `Ed25519Verifier::verify()` uses the public-domain `orlp/ed25519` reference implementation (FetchContent pinned to a SHA), wrapped in our base58 decoder.--**Self-attack**: simulated by sending a fake `delivered()` payload over the bridge with someone else's pubkey + my own valid signature → must fail. The verifier checks `signature` against `pubkey` directly via the underlying ed25519 primitive — a signature produced by key X cannot validate against key Y.--**Status**: ✅ mitigated.--## Threat 2 — Bridge hijack from other browser tabs--**Attack**: any tab in the user's browser (or any program on the LAN) sends a forged POST to the local bridge, claiming to be the wallet, before the legitimate flow completes.--**Mitigation**:-- `LocalWalletBridge::start()` calls `QTcpServer::listen(QHostAddress::LocalHost, 0)`. **`LocalHost` binds to `127.0.0.1` only** — not `0.0.0.0`, not the LAN address. Verifiable post-deploy via `netstat -an | findstr LISTEN` showing only `127.0.0.1:<port>`.-- The port number is selected by the OS (`port=0`), so it's unpredictable.-- Each connect generates a fresh 16-byte (`random_token_hex(16)` → 32 hex chars) `connect_token`. The token is included in both the URL (`/connect?token=...`) and the callback URL (`/callback?token=...`).-- `LocalWalletBridge::handle_request()` rejects any request whose query token doesn't match — returns 403 and disconnects.-- The server stops itself on the first valid `/callback` POST or after the timeout (default 120s).--**Self-attack**: a different browser tab opens `http://127.0.0.1:<port>/connect` without the token → 403 forbidden. With the token guessed (1 in 2¹²⁸ probability per attempt) → connect page loads, but cannot reach the wallet because the wallet only signs messages the user explicitly approves in the wallet UI. Even with a stolen token, the attacker cannot mint a valid signature for the nonce.--**Status**: ✅ mitigated.--## Threat 3 — Replay of signed nonce--**Attack**: an attacker captures a previously-signed challenge and replays it to a future connect attempt.--**Mitigation**:-- The nonce is regenerated on every `start_handshake()` call (per-dialog, per-connect).-- The nonce never leaves memory — not written to disk, not logged.-- The bridge's `connect_token` is regenerated on every `start()`. A captured pair is bound to a specific `(nonce, token, port)` triple that never recurs.-- Even if the `(nonce, signature)` pair is somehow resurrected, replaying requires the **right port and token** — both ephemeral.--**Status**: ✅ mitigated.--## Threat 4 — Long-lived session abuse--**Attack**: an attacker who briefly gains code execution while the terminal is unlocked uses the persisted session to perform privileged operations later (e.g., signing transactions, moving funds).--**Mitigation**:-- The persisted session contains only the public key + label + timestamp. It cannot itself authorise any operation.-- The current Phase 1 scope is **read-only** — the wallet identity is used to look up balances. No transaction signing flows exist yet.-- When transaction signing is added in Phase 2, every signing operation **must** re-prompt the wallet UI. The terminal cannot auto-sign anything because it does not hold private keys.--**Status**: ✅ mitigated by scope; will need re-review when Phase 2 (signing) lands.--## Threat 5 — SecureStorage tampering--**Attack**: an attacker overwrites the saved public key with their own, so future "soft-connected" sessions display attacker-controlled balances and an attacker-controlled identity.--**Mitigation**:-- Live balances are always re-fetched from RPC for whatever pubkey is in storage. A tampered pubkey shows the *attacker's* balance — visible to the user.-- For any future privileged action, the next sign-message challenge regenerates trust; a tampered pubkey will not be able to produce a valid signature, so the operation fails.-- `WalletService::restore_from_storage()` marks the state as `soft_connected = true`. Any flow needing on-chain authority must check this and trigger a fresh challenge before acting.--**Status**: ✅ mitigated for Phase 1. Phase 2 callers must honour `soft_connected`.--## Threat 6 — Local web bridge exposed beyond loopback--Already covered in Threat 2. Reiterated here because it's the most common misconfiguration in similar tools.--**Verification**:-- `QHostAddress::LocalHost` is the literal address `127.0.0.1`, not the hostname `localhost`. This avoids DNS rebinding attacks where a malicious site resolves `localhost` to its own IP.-- The page sets `Access-Control-Allow-Origin` headers? No — there's no CORS header at all, which is correct: same-origin requests don't need it, cross-origin requests must be blocked. The `X-Content-Type-Options: nosniff` header is set on every response.--**Status**: ✅ mitigated.--## Threat 7 — Malicious wallet provider--**Attack**: the user installs a fake "Phantom" extension that exfiltrates their seed phrase or signs unintended transactions.--**Mitigation**: out of scope. The wallet provider is owned by the user; this is no different from any web dApp. We reduce attack surface by letting the user pick from named providers (Phantom, Solflare, Backpack, Glow, `window.solana`) but cannot validate the provider itself.--The user-facing doc warns that sources should be downloaded only from official wallet sites.--**Status**: ⚠️ acknowledged, not mitigated. Inherent to the wallet-extension model.--## Threat 8 — Browser-side connect page tampering--**Attack**: the connect page (`resources/wallet/connect.html`) is replaced with a malicious version that exfiltrates the signed nonce or sends additional `signMessage` requests for things the user didn't authorise.--**Mitigation**:-- The connect page is bundled at build time (CMake `copy_if_different` step) into `$<TARGET_FILE_DIR:FinceptTerminal>/resources/wallet/connect.html`. Tampering requires write access to the install directory.-- The page's CSP locks `default-src` to `'self'`, blocks remote images/scripts, and only allows fetch to `127.0.0.1` and `localhost`. No CDN, no analytics, no third-party domains.-- The page never loads remote JavaScript — all the connect code is inline.--**Status**: ✅ mitigated against opportunistic tampering. A privileged attacker with file-write access to the install dir can swap the page; same threat model as patching the EXE itself.--## Threat 9 — Signed-message UX phishing--**Attack**: the user clicks "Sign" on a message they don't actually understand, granting the terminal an unintended capability.--**Mitigation**:-- The signed message is human-readable: `Fincept Terminal wallet-connect challenge. Nonce: <hex>`. It contains no fund-movement primitives — it is a literal text message, not a transaction.-- The user-facing doc explicitly tells users to verify the message begins with this prefix before signing.-- This is signed-message authentication only. We never use signed messages to authorise on-chain state changes — those will require a real transaction in Phase 2.--**Status**: ✅ mitigated.--## Sign-off checklist--Once the build runs cleanly and the dialog has been exercised end-to-end, manually verify:--- [ ] `netstat -an | findstr LISTEN` while the dialog is open shows the bridge port bound to `127.0.0.1` only, never `0.0.0.0` or LAN IP.-- [ ] Cancelling the dialog from the GUI closes the bridge port within 1 second (verify with a second `netstat`).-- [ ] After a successful connect, the SecureStorage file/registry contains pubkey + label + timestamp, **no signature**, **no nonce**.-- [ ] Disconnect clears the SecureStorage entries.-- [ ] Restarting the app with a saved connection rehydrates the pubkey and starts balance polling — without re-prompting the wallet.-- [ ] Crashing the wallet extension mid-handshake (close browser before signing) leads to a graceful "timed out" error after 120 s.-- [ ] Manually crafting a curl POST to `/callback?token=wrong` returns 403.-- [ ] Manually crafting a curl POST to `/callback?token=<right>` with a fabricated `{pubkey, signature}` (signature for a different pubkey) is rejected by `Ed25519Verifier::verify` and the dialog stays open.--The first six can be checked during Phase 3 manual QA. The last two should be scripted as integration tests under `tests/wallet/` in a follow-up commit.diff --git a/fincept-qt/plans/crypto-center-wallet-connect.md b/fincept-qt/plans/crypto-center-wallet-connect.mddeleted file mode 100644index 6c5eb059b..000000000--- a/fincept-qt/plans/crypto-center-wallet-connect.md+++ /dev/null@@ -1,294 +0,0 @@-# Crypto Center — Wallet Connect (Phase 1)--**Status**: draft-**Owner**: tilakpatel22-**Last updated**: 2026-04-27-------## 1. Goal--Build a new **Crypto Center** screen in the Fincept Terminal where users can:-- Connect any major Solana wallet (Phantom, Solflare, Backpack, Glow, Coinbase Solana) and any WalletConnect-v2 mobile wallet.-- See live $FNCPT + SOL balances.-- Disconnect cleanly. Re-connect on next launch without re-prompting (session persistence).--This is **Phase 1** of a longer $FNCPT integration roadmap (gating, burn, staking, prediction markets, buyback). Phase 1 ships **wallet identity + balance display only**. No transactions. No swaps. That comes in Phase 2.-------## 2. Decisions locked--| # | Decision | Choice |-|---|---|---|-| D1 | Browser-extension transport | **QWebEngineView** hosting Solana Wallet Adapter + WalletConnect v2 SDK |-| D2 | Initial chain scope | **Solana-only** (EVM/MetaMask deferred) |-| D3 | Hardware wallets | **Via Phantom/Solflare host** (no direct Ledger USB in v1) |-| D4 | Sign-in proof | **Signed-message challenge** (random nonce, 5 min TTL, ed25519 verify) |-| D5 | Persisted state | pubkey + label + connected_at in `SecureStorage`; **never** keys/signatures |-| D6 | RPC provider | **Helius** (free tier) — fall back to public `api.mainnet-beta.solana.com` if key missing |-| D7 | $FNCPT mint | `9LUqJ5aQTjQiUCL93gi33LZcscUoSBJNhVCYpPzEpump` (pump.fun, devnet/mainnet TBD) |-| D8 | Screen registration | **Lazy** (`router_->register_factory(...)`) per P2 |-| D9 | Data path | New DataHub producer; `wallet:balance:<pubkey>` topic family per D1/D2 |-------## 3. Threat model (mandatory before any code)--**Assets to protect:**-1. User's private keys → **never touched, never seen**. Phantom/etc. is the sole signer.-2. User's pubkey → low-sensitivity but tied to identity; stored in `SecureStorage`.-3. Connection session → if hijacked, an attacker can phish the user with fake "sign this" prompts.-4. Local web bridge → if exposed beyond loopback, remote sites could trigger connect/sign UI.--**Attacks considered + mitigations:**--| Attack | Mitigation |-|---|---|-| Pubkey spoofing (user pastes any address) | Signed-message challenge: server generates `nonce`, web page calls `wallet.signMessage(nonce)`, server verifies sig matches pubkey |-| Bridge hijack from other browser tabs | Bind to `127.0.0.1` only, randomly chosen port, single-use connect token in URL, kill server on success/timeout/30s |-| Replay of signed nonce | Nonce includes timestamp + random; expires in 5 min; one-time use, persisted in memory only |-| Long-lived session abuse | Session = pubkey only; every signing op (Phase 2+) re-prompts wallet UI; no auto-sign anywhere ever |-| `SecureStorage` tampering | Live balance always re-fetched from RPC; pubkey treated as untrusted until next sig challenge on critical ops |-| QWebEngine sandbox escape | All web content loaded from local resource (`qrc://`); no remote JS; CSP `default-src 'self'`; navigation locked |-| Malicious WC pairing relay | Use official relay `wss://relay.walletconnect.org`; pin project ID; verify session metadata before showing prompts |-| Clipboard / address swap malware | Show pubkey prominently after connect; user must visually verify before any future tx |--**Out of scope for Phase 1:** transaction signing, fund movement, swap, burn. These have their own threat model and ship in Phase 2 with separate review.-------## 4. Architecture--```-┌─────────────────────────────────────────────────────────────────────┐-│ CryptoCenterScreen (UI only — P6) │-│ ┌────────────────────┐ ┌────────────────────┐ │-│ │ Wallet status card │ │ Balances card │ │-│ │ (pubkey, label) │ │ ($FNCPT, SOL) │ │-│ └────────────────────┘ └────────────────────┘ │-│ ┌────────────────────┐ │-│ │ Connect / disconnect button → ConnectWalletDialog │-│ └────────────────────┘ │-└─────────────────────────────────────────────────────────────────────┘- │ subscribes to DataHub topics ▲- ▼ │-┌─────────────────────────────────────────────────────────────────────┐-│ DataHub (existing) │-│ topic: wallet:state (push-only, owned by WalletService) │-│ topic: wallet:balance:<pk> (TTL 30s, min_interval 10s) │-│ topic: market:price:fncpt (TTL 60s — Jupiter price API) │-└─────────────────────────────────────────────────────────────────────┘- ▲ publishes- │-┌─────────────────────────────────────────────────────────────────────┐-│ WalletService (singleton, QObject) │-│ - connect_extension() → spawns ConnectWalletDialog │-│ - connect_walletconnect() │-│ - disconnect() │-│ - current_pubkey() / is_connected() │-│ - signals: wallet_connected, wallet_disconnected, balance_updated │-│ WalletBalanceProducer → wallet:balance:<pk> │-│ FncptPriceProducer → market:price:fncpt │-└─────────────────────────────────────────────────────────────────────┘- ▲ uses- │-┌─────────────────────────────────────────────────────────────────────┐-│ ConnectWalletDialog (modal, QWebEngineView host) │-│ - loads qrc:/wallet/index.html │-│ - QWebChannel exposes WalletBridge to JS │-│ - JS uses Solana Wallet Adapter (extensions) + │-│ @walletconnect/sign-client (QR for mobile) │-│ - on connect: bridge.delivered(pubkey, signed_nonce) │-└─────────────────────────────────────────────────────────────────────┘- ▲ verifies sig- │-┌─────────────────────────────────────────────────────────────────────┐-│ Ed25519Verifier (libsodium or Botan — pick one in Task 0) │-│ - verify(pubkey_b58, message, signature_b58) → bool │-└─────────────────────────────────────────────────────────────────────┘-```--**Key files (planned):**-- `src/screens/crypto_center/CryptoCenterScreen.{h,cpp}`-- `src/screens/crypto_center/ConnectWalletDialog.{h,cpp}`-- `src/screens/crypto_center/WalletStatusCard.{h,cpp}`-- `src/screens/crypto_center/BalanceCard.{h,cpp}`-- `src/services/wallet/WalletService.{h,cpp}`-- `src/services/wallet/WalletBalanceProducer.{h,cpp}`-- `src/services/wallet/FncptPriceProducer.{h,cpp}`-- `src/services/wallet/Ed25519Verifier.{h,cpp}`-- `src/services/wallet/SolanaRpcClient.{h,cpp}` (thin wrapper over `HttpClient`)-- `resources/wallet/index.html` + `wallet.js` (Wallet Adapter + WC v2 SDK bundle)-- `docs/DATAHUB_TOPICS.md` — add `wallet:state`, `wallet:balance:*`, `market:price:fncpt`-- `fincept-qt/CMakeLists.txt` — add `Qt6::WebEngineWidgets`, `Qt6::WebChannel`, ed25519 lib--**Existing files touched:**-- `src/app/main.cpp` — register `CryptoCenterScreen` factory; bootstrap `WalletService` singleton; register producers with hub.-- `src/screens/(navigation registry)` — add nav entry.-------## 5. Phases & tasks--### Phase 0 — Plumbing (no UI yet)--**Task 0.1 — Pick & integrate ed25519 lib**-- Add **libsodium** via FetchContent (already used by some crypto deps; small, BSD-licensed). Confirm no conflict with existing deps.-- Wrap in `Ed25519Verifier::verify(QString pubkey_b58, QByteArray msg, QString sig_b58)`.-- Verification: unit test with known-good vector (Solana's `nacl_test` vectors).--**Task 0.2 — Add Qt WebEngine + WebChannel deps**-- Update `CMakeLists.txt`: `find_package(Qt6 REQUIRED COMPONENTS WebEngineWidgets WebChannel)`.-- Update Windows deploy to bundle QtWebEngineProcess.exe + resources.-- Verification: minimal QWebEngineView test compiles, links, runs.--**Task 0.3 — Build the wallet bridge HTML+JS**-- `resources/wallet/index.html` — minimal page with Wallet Adapter UI + WC v2 SDK.-- Bundled offline (no remote CDN). Use `pnpm` or `npm` to build `wallet.js` and check the bundle into `resources/wallet/dist/wallet.bundle.js`.-- Loaded from `qrc:/wallet/index.html` — **never from `https://`**.-- CSP meta tag locks origins.-- Exposes one `WalletBridge` over QWebChannel with: `request_connect()`, `request_disconnect()`, `delivered(pubkey, signature)`, `error(code, msg)`, `qr_uri(uri)` (for WC).-- Verification: load page in standalone `QWebEngineView` test app, click "Connect", verify Phantom prompt fires.--**Task 0.4 — SolanaRpcClient**-- Wrap `HttpClient` for: `getBalance`, `getTokenAccountsByOwner`, `getRecentBlockhash` (future).-- Helius URL from `KeyConfigManager` (`solana/helius_api_key`); fallback to public RPC.-- Verification: unit test against devnet known-balance pubkey.--### Phase 1 — WalletService + producers--**Task 1.1 — WalletService skeleton**-- Singleton, lives in `main.cpp` bootstrap.-- State: `current_pubkey_`, `connected_at_`, `label_`. Restored from `SecureStorage` on startup (read-only — no signature trust until next challenge).-- Signals: `wallet_connected(QString pubkey)`, `wallet_disconnected()`, `balance_updated(QString pubkey, double sol, double fncpt)`.-- Methods: `connect_with_dialog(QWidget* parent)`, `disconnect()`, `is_connected()`, `current_pubkey()`.-- Verification: write/read pubkey roundtrips through SecureStorage in a unit test.--**Task 1.2 — ConnectWalletDialog**-- `QDialog` modal, hosts `QWebEngineView`, sets up `QWebChannel`, exposes `WalletBridge`.-- Generates 32-byte nonce, sends to JS via bridge property.-- Receives `delivered(pubkey, sig_b58)` → calls `Ed25519Verifier::verify(...)` → on success, emits `connected(pubkey)`.-- 60s overall timeout, cancel button, clear error states.-- Verification: end-to-end manual test — open dialog, connect Phantom (devnet), confirm pubkey lands.--**Task 1.3 — WalletBalanceProducer**-- Subscribes hub topic `wallet:balance:<pubkey>`.-- Policy: TTL 30s, min_interval 10s, push_only false.-- On request: `SolanaRpcClient::getBalance(pubkey)` → SOL; `getTokenAccountsByOwner(pubkey, FNCPT_MINT)` → FNCPT.-- Publishes `WalletBalance{ sol_lamports, fncpt_raw, fncpt_decimals }`.-- Verification: subscribe in a test harness, observe publish, change pubkey, observe new topic.--**Task 1.4 — FncptPriceProducer**-- Subscribes hub topic `market:price:fncpt`.-- Policy: TTL 60s, min_interval 30s.-- Calls Jupiter Price API: `https://api.jup.ag/price/v2?ids=<FNCPT_MINT>`.-- Publishes `{ usd_price, sol_price, ts }`.-- Verification: hit the API live, confirm parse.--**Task 1.5 — Register everything in main.cpp**-- After `DataHub` is up: `WalletService::instance().ensure_registered_with_hub()`.-- After router is built: `router_->register_factory("crypto_center", []{ return new CryptoCenterScreen(...); });`.-- Verification: app boots, screen reachable from nav, no producers spawn until subscribed.--**Task 1.6 — Update DataHub docs**-- Append rows to `docs/DATAHUB_TOPICS.md` for `wallet:state`, `wallet:balance:*`, `market:price:fncpt`.-- Per D5 in CLAUDE.md (DataHub rules): **same commit as producers**.-- Verification: doc renders, every topic the producers publish is documented.--### Phase 2 — UI (CryptoCenterScreen)--**Task 2.1 — Screen shell**-- Header: "Crypto Center" + connection chip (green/red).-- Empty state: big "Connect Wallet" button + 1-paragraph explainer + security note ("we never see your keys").-- Connected state: WalletStatusCard + BalanceCard side-by-side, then activity placeholder ("coming Phase 2").-- Theme: follow Obsidian DESIGN_SYSTEM.md, no inline styles per P7.-- Verification: visual review on dark + light themes.--**Task 2.2 — WalletStatusCard**-- Shows pubkey (truncated `9LUq…Epump`, full on hover/copy click), connected_at (relative), wallet label ("Phantom", "Solflare" — from Wallet Adapter).-- "Disconnect" button → `WalletService::disconnect()`.-- "Copy address" button → `QClipboard`.-- Verification: copy works, disconnect clears state, UI swaps to empty state.--**Task 2.3 — BalanceCard**-- Subscribes `wallet:balance:<pubkey>` and `market:price:fncpt`.-- Shows: SOL (lamports / 1e9), $FNCPT (raw / 10^decimals), USD value.-- Loading skeleton while data arrives. Stale indicator if last update > 60s ago.-- Refresh button → `hub.request(topic, /*force=*/true)`.-- Verification: kill network → cached value stays + stale indicator; restore → updates.--**Task 2.4 — showEvent / hideEvent lifecycle (P3)**-- subscribe in `showEvent`, `unsubscribe(this)` in `hideEvent`.-- No timers in constructors.-- Verification: navigate away → producer goes idle (verify in DataHub introspection log).--**Task 2.5 — Nav registration**-- Add Crypto Center entry under a new nav group "Crypto" (or under Tools, decide in PR review).-- Icon: wallet glyph (use existing icon set or add SVG).-- Verification: nav shows item, click routes to screen, lazy factory triggers first time only.--### Phase 3 — Polish & verification--**Task 3.1 — Reconnect-on-startup flow**-- On app launch, if `SecureStorage` has a pubkey: `WalletService` enters "soft-connected" state (UI shows pubkey + balances), but **no signing trust** — the next operation that needs a signature will trigger a fresh challenge.-- Verification: restart app, see pubkey + balances without re-prompt.--**Task 3.2 — Disconnect hardens**-- Clears `SecureStorage` keys (pubkey, label, connected_at).-- Calls JS `wallet.disconnect()` if bridge available.-- Unsubscribes balance producer for that pubkey (hub auto-cleans on no subscribers).-- Verification: post-disconnect, no producer activity for that pubkey; restart confirms blank state.--**Task 3.3 — Manual security walkthrough**-- Run through every threat in §3, confirm mitigation works.-- Try to spoof a pubkey by sending a fake `delivered()` over the bridge with someone else's pubkey + your signature → must reject.-- Confirm bridge port is loopback-only (`netstat -an | grep <port>` shows `127.0.0.1` only).-- Verification: signed report attached to plan or PR.--**Task 3.4 — Docs**-- Add a short user-facing doc: "How to connect your wallet" (`docs/CRYPTO_WALLET_CONNECT.md`).-- 1-page max, screenshots for Phantom + Solflare.-- Verification: doc renders, links from screen "Help" icon.-------## 6. Out of scope (do NOT do in this plan)--- Sending or signing transactions-- Buying/swapping $FNCPT (Jupiter integration)-- Burning $FNCPT-- Staking/lock UI-- Prediction markets-- Multi-chain (EVM)-- Direct Ledger USB-- Backup/restore wallet flows (we don't store keys, so n/a)--These have separate plans.-------## 7. Risks & open questions--1. **QWebEngine binary size**: ~50 MB extra. Acceptable trade for the cleanest path. Confirm with installer pipeline owner.-2. **Bundled `wallet.js`**: needs a Node build step the first time. Check it in pre-built so end-developers don't need Node.-3. **WalletConnect v2 project ID**: requires a free signup at WalletConnect Cloud. Need to register one for "Fincept Terminal" before Task 0.3.-4. **Helius API key**: need to provision and wire through `KeyConfigManager`. Free tier OK initially.-5. **$FNCPT mint cluster**: pump.fun lives on mainnet. Devnet won't have the token — for dev testing, mock the balance producer or fork the mint to devnet.-6. **Coinbase Wallet (Solana mode)**: support via Wallet Adapter is recent; verify it works on the bundled version we ship.-------## 8. Definition of Done (Phase 1)--- [ ] User opens Crypto Center, sees empty state.-- [ ] Clicks "Connect Wallet" → browser-extension prompt fires (Phantom/Solflare/etc.).-- [ ] After approving, screen shows their pubkey + SOL + $FNCPT balance + USD value.-- [ ] Disconnect works; restart with disconnect persists; restart with connection persists.-- [ ] No private keys, signatures, or seed phrases ever leave Phantom.-- [ ] No `PythonRunner` calls in any new file (D1 enforced).-- [ ] All data flows via DataHub topics (D4 enforced).-- [ ] All topics added to `docs/DATAHUB_TOPICS.md` (D5 enforced).-- [ ] Screen registered with `register_factory()` (P2 enforced).-- [ ] Producers subscribe-only via `showEvent`/`hideEvent` (P3, D3 enforced).-- [ ] CI green, manual security walkthrough signed off.diff --git a/fincept-qt/results.txt b/fincept-qt/results.txtdeleted file mode 100644index da1b99ee2..000000000--- a/fincept-qt/results.txt+++ /dev/null@@ -1,19 +0,0 @@-Total Python files: 1562-Directly referenced from C++: 164-Indirectly used: 29-Orphaned: 1369--Orphans by directory:- Analytics: 309- agents: 290- agno_trading: 34- ai_quant_lab: 1- algo_trading: 4- alpha_arena: 7- exchange: 23- mcp: 8- root: 231- strategies: 446- technicals: 2- vision_quant: 9- voice: 5