Commit Graph

1894 Commits

Author SHA1 Message Date
hailin 20a90fce4c feat(mining-app): add professional kline chart with technical indicators
- Add KlineChartWidget with pinch-to-zoom, fullscreen mode
- Implement MA, EMA, BOLL indicators for main chart
- Implement MACD, KDJ, RSI indicators for sub chart
- Add volume display with crossline info
- Add C2C trading feature with market/publish/detail pages
- Add P2P transfer functionality (send/receive shares)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:51:00 -08:00
hailin 3ce8bb0044 fix(mining-admin): parse burn records response correctly
The trading-service wraps all responses with { success, data, timestamp }.
Need to extract data.data for burn records endpoint.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:41:16 -08:00
hailin 7852b9d673 feat(mining): publish CDC events for mining-admin-service sync
Add event publishing to enable mining-admin-service to sync data via
Debezium CDC instead of direct API calls:

- MiningConfigUpdated: Published every minute with distribution status
- DailyMiningStatCreated: Published when daily stats are generated
- MiningAccountUpdated: Method added for future per-account sync

These events will be captured by Debezium monitoring the outbox_events
table and forwarded to mining-admin-service via Kafka.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:33:02 -08:00
hailin 9d65eef1b1 fix(mining-admin): fetch dashboard data from remote services
Dashboard now fetches totalDistributed and totalBurned directly from
mining-service and trading-service APIs instead of relying solely on
CDC sync which may not have data.

- Add fetchRemoteServiceData() to get real-time data
- Use mining-service /admin/status for totalDistributed
- Use trading-service /asset/market for totalBurned and circulationPool
- Add 30-second cache to reduce API calls

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:25:07 -08:00
hailin 3096297198 feat(mining-app): 资产页面优化及个人资料编辑功能
- 删除资产页面的"提现"按钮,将"划转"改为"C2C"
- 删除积分值卡片上的"可提现"标签
- 简化资产页面和兑换页面的标题栏,移除左右图标
- 统一资产页面背景色与兑换页面一致
- 新增个人资料编辑页面,支持头像颜色选择和昵称修改
- 头像和昵称支持本地存储

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 07:58:16 -08:00
hailin 854bb7a0ac fix(mining-admin): correct ContributionSyncStatus property names
Property names should match what's used in the UI component:
- miningNetworkTotal (was miningTotal)
- networkTotalContribution (was contributionTotal)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 07:41:59 -08:00
hailin 2534068f70 fix(mining): remove duplicate burn mechanism from mining-service
Mining-service incorrectly implemented its own burn mechanism (10-year
cycle) which was not in the requirements. Per requirements, only
trading-service should handle per-minute burn (4756.47/minute).

Removed:
- BlackHoleRepository and all burn-related methods
- executeBurn() from mining distribution service
- Burn stats from admin API and queries
- Burn progress UI from mining admin web

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 07:31:13 -08:00
hailin f22c3efb11 fix: use correct property name 'type' for unallocated contribution
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 05:40:40 -08:00
hailin 0241930011 feat(contribution/mining): sync unallocated contributions to mining-service
- Add UnallocatedContributionSyncedEvent in contribution-service
- Add event handler in mining-service's contribution-event.handler.ts
- Add handleUnallocatedContributionSynced in network-sync.service.ts
- Add admin endpoint to publish all unallocated contributions
- Sync pending/unallocated contributions to PendingContributionMining table

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 05:29:28 -08:00
hailin 130bf57842 fix(contribution): 处理认种时发布系统账户同步事件
- 在保存系统账户算力后,发布 SystemAccountSyncedEvent
- 使 mining-service 能够同步运营/省/市公司的算力

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 05:24:04 -08:00
hailin 962e7874c8 fix(contribution): 修复全网理论算力未同步问题
- 在 calculateForAdoption 中调用 updateNetworkProgress 更新 NetworkAdoptionProgress 表
- 之前 publishNetworkProgressEvent 读取的 totalTreeCount 始终为 0,因为表未被更新

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 04:55:30 -08:00
hailin bb75ff19a4 feat(contribution): 认种处理后自动发布全网进度事件
- 每次认种分配完成后发布 NetworkProgressUpdatedEvent
- mining-service 通过 Kafka 实时接收全网理论算力更新
- 定时同步改为每5分钟一次,作为兜底方案

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 04:46:12 -08:00
hailin 23bb8baa9c feat(mining): 自动同步全网理论算力
- 启动时自动从 contribution-service 同步全网数据
- 每分钟定时同步全网理论算力和系统账户算力
- 使用分布式锁防止并发同步

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 04:44:27 -08:00
hailin 7909bcc3d1 fix(mining-admin): 修复同步状态判断逻辑
- 同步判断改为只检查全网理论算力是否同步
- 全网理论算力是挖矿分母,是判断同步完成的核心指标
- 使用相对误差(0.1%)而非绝对误差来判断同步

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 04:07:18 -08:00
hailin 9e15fa4fd8 fix(admin-web): 修复全网算力同步状态显示
- 将显示内容从用户有效算力改为全网理论算力
- 显示 mining-service 和 contribution-service 的全网理论算力对比

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 04:02:29 -08:00
hailin de5416aee6 feat(mining): 实现系统账户和待解锁算力参与挖矿
重大变更:
- 挖矿分母从用户有效算力改为全网理论算力(networkTotalContribution)
- 系统账户(运营12%/省1%/市2%)参与挖矿,有独立的挖矿记录
- 待解锁算力参与挖矿,收益归总部账户,记录包含完整来源信息

新增功能:
- mining-service: 系统挖矿账户表、待解锁算力表及相关挖矿记录表
- mining-service: NetworkSyncService 同步全网数据
- mining-service: /admin/sync-network 和 /admin/system-accounts 端点
- contribution-service: /admin/system-accounts 和发布系统账户事件端点
- mining-admin-service: 状态检查返回全网理论算力信息

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 03:39:56 -08:00
hailin b5fca7bb04 fix(mining-admin): 修复算力同步状态检查的 API 路径
- contribution-service: 给 /contribution/stats 接口添加 @Public() 装饰器
- mining-admin-service: 修正 API 路径从 api/v1 改为 api/v2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 03:09:05 -08:00
hailin 7c00c900a0 feat(mining-admin): 算力同步完成前禁用激活挖矿按钮
- 后端:getMiningStatus 接口并行获取 contribution-service 总算力,对比两边是否一致
- 前端:未同步时显示"全网算力同步中..."提示,禁用激活按钮
- 前端:同步中每 3 秒刷新状态,同步完成后恢复 30 秒刷新

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 03:00:40 -08:00
hailin 72b3b44d37 feat(trading): 实现K线图真实数据展示与Y轴自适应
后端 (trading-service):
- 新增 GET /api/v2/price/klines API 端点
- 支持多周期K线聚合 (1m/5m/15m/30m/1h/4h/1d)
- 将 PriceSnapshot 数据聚合为 OHLC 格式

前端 (mining-app):
- 添加 klinesProvider 获取K线数据
- 重写 _CandlestickPainter 使用真实数据
- 实现 Y轴自适应显示,放大价格变化
- 周期选择器联动数据刷新

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 23:57:12 -08:00
hailin 8ab11c8f50 feat(wallet): sync burn events from trading-service to deduct SHARE_POOL_A
Add Kafka consumer to listen for burn events (minute burn and sell burn)
from trading-service and deduct from SHARE_POOL_A (100B pool), updating
BLACK_HOLE_POOL balance accordingly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 23:24:43 -08:00
hailin 88368d1705 fix(wallet): 统一使用 accountSequence 查询钱包,修复转账余额不足问题
背景:幽灵钱包 D26010800000 (user_id=133, 余额=0) 导致真实用户
D26010900000 (user_id=0, 余额=200465) 转账失败

原因:
- D26010800000 是 2026-01-08 16:23 通过未知方式创建的脏数据
- 真实用户 D26010900000 在 18:40 注册时,user_id=133 已被占用
- getMyWallet 用 accountSequence 查询显示余额正确
- requestWithdrawal 用 userId 查询找到错误的空钱包

修复:
- Controller: 传 user.accountSequence 而非 user.userId
- Service: 移除 findByUserId fallback,仅用 findByAccountSequence
- 从钱包记录获取 userId 用于订单、流水、事件关联

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 23:00:40 -08:00
hailin 974d660544 feat(mining): sync pool balance via Kafka when mining distributes
- mining-service: publish MINING_MINUTE_DISTRIBUTED event to Kafka after
  each minute's mining distribution is completed
- mining-wallet-service: add MiningDistributionConsumer to consume the
  event and deduct from SHARE_POOL_B
- Add deductFromSharePoolB method in PoolAccountService
- This ensures the share pool balance displayed in mining-app reflects
  the actual remaining balance after mining distributions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 21:30:35 -08:00
hailin 7b3c222b24 fix(admin-web): use dedicated trading client with correct base URL
Trading API was incorrectly routed through mining-admin baseURL in production,
causing 404 errors. Created independent tradingClient with /api/trading baseURL
to properly route requests through Next.js rewrites to Kong -> trading-service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 21:12:33 -08:00
hailin 52a5ae64c0 Revert "fix(admin-web): add API_GATEWAY_URL env var for Docker build"
This reverts commit 1d7f05b12d.
2026-01-15 21:03:57 -08:00
hailin 1d7f05b12d fix(admin-web): add API_GATEWAY_URL env var for Docker build
The Next.js rewrites in next.config.js require API_GATEWAY_URL to be set
at build time. Added this environment variable to both Dockerfile and
docker-compose.yml to ensure proper routing to Kong gateway in production.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 21:01:27 -08:00
hailin 967e6c1f44 fix(admin-web): fix API response data extraction for trading endpoints
- Add proper extraction of nested data from { success, data, timestamp } response format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 20:54:26 -08:00
hailin 2da02e0823 fix(admin-web): fix trading-service proxy routing for Kong gateway
- Add production/development environment detection
- Production: route through Kong gateway at /api/v2/trading/*
- Development: direct connection to trading-service at localhost:3022

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 20:48:31 -08:00
hailin 8018fa5110 feat(admin): add trading system management UI and API
- Add trading system activate/deactivate endpoints to trading-service
- Add trading management page to mining-admin-web with:
  - Trading system status display and control
  - Market overview (price, green points, circulation pool)
  - Burn progress visualization
  - Burn records list with filtering
- Add trading-service proxy configuration to next.config.js
- Add trading menu item to sidebar navigation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 20:37:52 -08:00
hailin 1e2d8d1df7 feat(asset): aggregate mining and trading account balances in asset display
- Modify AssetService to fetch mining account balance from mining-service
- Sum mining balance + trading balance for total share display
- Add miningShareBalance and tradingShareBalance fields to AssetDisplay
- Update frontend entity and model to support new fields

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 19:53:31 -08:00
hailin ed715111ae fix(trading): auto-initialize SharePool and CirculationPool on startup
- Add SharePool and CirculationPool initialization in BurnService.initialize()
- Initialize SharePool with 5760 green points (fixes price showing as 0)
- Remove misleading "= 5,760 积分值" display from trading page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 19:32:46 -08:00
hailin e611894b55 fix(trading-service): use payload.sub as accountSequence in JWT guard
auth-service puts accountSequence in payload.sub, not payload.accountSequence.
This mismatch caused 401 errors when accessing trading endpoints.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 17:54:28 -08:00
hailin 83b05ac146 fix(docker): add JWT_SECRET to mining-service and trading-service
Both services were missing JWT_SECRET environment variable, causing
401 Unauthorized errors when validating JWT tokens from auth-service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 17:25:55 -08:00
hailin 01bd638dbb fix(contribution-service): add parent .env path for shared config
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 07:00:02 -08:00
hailin 7a469be7cd fix(mining-*): add parent .env path for shared config
All mining services need to read shared environment variables
(JWT_SECRET, DATABASE_URL, etc.) from backend/services/.env

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:58:56 -08:00
hailin 0420b0acab fix(trading,auth): add parent .env path for shared JWT_SECRET
Both services need to read JWT_SECRET from the shared .env file
in the parent directory (backend/services/.env).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:57:57 -08:00
hailin 4440f40fba fix(mining-wallet-service): use upsert in seed for 100% overwrite
Remove existence check, directly upsert pool accounts to ensure
consistent state on every seed run.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:42:34 -08:00
hailin fdff3a3119 feat(mining-wallet-service): add migration for SHARE_POOL_A and SHARE_POOL_B
Split the share pool into two accounts:
- SHARE_POOL_A: 100亿 for burning
- SHARE_POOL_B: 200万 for mining distribution
Total: 100.02亿

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:40:56 -08:00
hailin 4b1855f57a fix(mining-app): use public API for asset page to avoid JWT mismatch
Changed from myAssetProvider (requires JWT) to accountAssetProvider
(public API) to avoid 401 errors when trading-service JWT_SECRET
doesn't match auth-service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:34:19 -08:00
hailin 4cef31b1d1 fix(api-gateway): correct mining-admin-service upstream URL to /api/v2
The service uses 'api/v2' as global prefix, not 'api/v1'.
Request flow: /api/v2/mining-admin/auth/login -> strip path -> /auth/login -> upstream /api/v2/auth/login

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:29:10 -08:00
hailin 109986ba49 fix(mining-wallet-service): move share-pool-balance route before :type param route
NestJS routes are matched in order, so the parameterized :type route
was capturing 'share-pool-balance' before it could reach the public
endpoint, causing 401 errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:22:30 -08:00
hailin b5899497ea fix(mining-wallet-service): use SHARE_POOL_A instead of SHARE_POOL for mining rewards 2026-01-15 06:05:17 -08:00
hailin 40869ef00f feat: split share pool into A (100亿) and B (200万) accounts
Backend changes:
- mining-wallet-service: Split SHARE_POOL into SHARE_POOL_A (100亿, for burning)
  and SHARE_POOL_B (200万, for mining distribution)
- Add /pool-accounts/share-pool-balance API endpoint to get total balance
- Update pool initialization logic and seed data
- Fix Kong routing for mining-wallet-service (strip_path: true)
- Fix Kong routing for trading-service (strip_path: true)

Constant updates (100.02亿 = 10,002,000,000):
- mining-service: TOTAL_SHARES
- trading-service: TOTAL_SHARES, trading config defaults
- trading-service seed: initial green points = 5760

Frontend changes:
- Add sharePoolBalanceProvider to fetch pool balance from mining-wallet-service
- Update contribution page to display real-time share pool balance (A + B)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 05:55:52 -08:00
hailin a1508b208e fix(api-gateway): correct Kong routing for trading-service
- Change strip_path to true to strip /api/v2/trading prefix
- Add /api/v2 to upstream URL so requests route correctly
- Revert accidental main.ts change

Request flow: /api/v2/trading/asset/market -> strip /api/v2/trading -> /asset/market -> upstream /api/v2/asset/market

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 05:27:46 -08:00
hailin c60d3b2f26 fix(trading-service): correct global prefix to match Kong routing
Change prefix from 'api/v2' to 'api/v2/trading' to match Kong gateway
configuration with strip_path: false.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 05:26:11 -08:00
hailin bb4143d75b fix(trading-service): exclude prisma from tsconfig to fix build output path 2026-01-15 04:46:01 -08:00
hailin d12bbb17be feat(mining-app): add share pool balance display on contribution page
Display real-time share pool balance (积分股池实时余量) in the total
contribution card on the contribution page.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 04:27:48 -08:00
hailin 19428a8cb7 feat(trading-service): sync trading account creation with wallet service
- Add CDC consumer to listen for UserWalletCreated events from mining-wallet-service
- Create trading accounts when user contribution wallets are created (lazy creation)
- Add WalletSystemAccountCreated handler for province/city system accounts
- Add seed script for core system accounts (HQ, operation, cost, pool)
- Keep auth.user.registered listener for V2 new user registration

This ensures trading accounts are created in sync with wallet accounts,
supporting both V2 new users and V1 migrated users.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 04:27:14 -08:00
hailin 183b2bef59 style(mining-app): hide accountSequence and rename phone to ID on profile page
- Remove accountSequence (ID: xxxx) display from profile page
- Rename "手机:" label to "ID:" for phone number display

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 03:39:18 -08:00
hailin 1bdb9bb336 style(mining-admin-web): display all numbers with 8 decimal places
Update all formatDecimal, formatNumber, formatPercent, formatCompactNumber
and formatShareAmount calls to use 8 decimal precision for consistent display
across all pages (dashboard, users, reports, system-accounts).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 02:55:23 -08:00
hailin d7bbb19571 fix(mining-admin-service): correct effective contribution calculation
Effective contribution should equal theoretical total (totalTrees * 22617)
since it includes all parts: personal 70% + operation 12% + province 1% +
city 2% + level 7.5% + bonus 7.5% = 100%.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 02:20:45 -08:00