Commit Graph

1396 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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
hailin cfbf1b21f3 feat(dashboard): add detailed contribution breakdown by category
Backend (contribution-service):
- Add getDetailedContributionStats() to repository
- Add getUnallocatedByLevelTier/BonusTier() to repository
- Extend stats API with level/bonus breakdown by tier
- Add getTotalTrees() to synced-data repository

Backend (mining-admin-service):
- Add detailed contribution stats calculation
- Calculate theoretical vs actual values per category
- Return level/bonus breakdown with unlocked/pending amounts

Frontend (mining-admin-web):
- Add ContributionBreakdown component showing:
  - Personal (70%), Operation (12%), Province (1%), City (2%)
  - Level contribution (7.5%) by tier: 1-5, 6-10, 11-15
  - Bonus contribution (7.5%) by tier: T1, T2, T3
- Update DashboardStats type definition
- Integrate breakdown component into dashboard page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 01:43:37 -08:00
hailin 1f15daa6c5 fix(planting-records): filter only MINING_ENABLED records and fix UI overflow
- Backend: Add status filter to getPlantingLedger and getPlantingSummary
- Frontend: Change Row to Wrap for info items to prevent width overflow

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 00:12:07 -08:00
hailin 12f8fa67fc feat(mining-admin): add totalTrees, separate level/bonus pending display
- Add totalTrees field from syncedAdoption aggregate
- Rename fields: networkLevelPending, networkBonusPending
- Stats card: show level pending and bonus pending separately
- Add new stats card for total trees count
- Price overview: 2-row layout showing all contribution metrics

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 23:59:32 -08:00
hailin b310fde426 feat(mining-admin): show pending contribution in dashboard
- Add networkPendingContribution and networkBonusPendingContribution to API
- Display combined pending contribution (teamLevel + teamBonus) in stats card
- Replace 'total contribution' with 'pending contribution' in price overview

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 23:46:05 -08:00
hailin 81a58edaca fix(contribution-service): calculate totalContribution correctly in CDC event
Previously, totalContribution was incorrectly set to effectiveContribution.
Now correctly calculated as: personal + teamLevel + teamBonus

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 23:40:50 -08:00
hailin dee9c511e5 feat(mining-admin): add total contribution to dashboard stats
- Add networkTotalContribution field to dashboard API response
- Display total hashrate alongside effective hashrate in stats cards
- Update price overview to show both effective and total contribution
- Change grid from 3 to 4 columns in price overview

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 23:32:29 -08:00
hailin 141db46356 fix(contribution-service): use real contributionPerTree from rate service
Previously, adoptions were synced with hardcoded contributionPerTree=1,
resulting in contribution values like 0.7 instead of the expected 15831.9.

Now the handler fetches the actual contribution rate from ContributionRateService
based on the adoption date, storing values like:
- Personal (70%): 22617 × 70% = 15831.9
- Team Level (0.5%): 22617 × 0.5% = 113.085
- Team Bonus (2.5%): 22617 × 2.5% = 565.425

Note: Historical data may need migration to apply the correct multiplier.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 18:01:30 -08:00
hailin c852f24a72 fix(auth-service): add 'auth/' prefix to controller routes for Kong compatibility
Kong routes /api/v2/auth/* to auth-service without stripping the path,
so controllers need 'auth/' prefix to match frontend requests:
- SmsController: 'sms' -> 'auth/sms'
- PasswordController: 'password' -> 'auth/password'
- UserController: 'user' -> 'auth/user'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:53:48 -08:00
hailin f2692a50ed fix(contribution-service): fix toRecordDto using wrong property name
- Changed `record.finalContribution` to `record.amount` for getting final contribution value
- Added optional chaining to prevent undefined errors
- Added default values for safety

The ContributionRecordAggregate uses `amount` property, not `finalContribution`.
This was causing "Cannot read properties of undefined (reading 'value')" errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:43:14 -08:00
hailin 106a287260 fix(mining-service): make health endpoints public 2026-01-14 07:35:42 -08:00
hailin 30dc2f6665 fix(trading-service): make health endpoints public 2026-01-14 07:28:24 -08:00
hailin e1fb70e2ee feat(trading-service): add burn system, Kafka events, and idempotency
- Add trading burn system with black hole, share pool, and price calculation
- Implement per-minute auto burn and sell burn with multiplier
- Add Kafka event publishing via outbox pattern (order, trade, burn events)
- Add user.registered consumer to auto-create trading accounts
- Implement Redis + DB dual idempotency for event processing
- Add price, burn, and asset API controllers
- Add migrations for burn tables and processed events

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 07:15:41 -08:00
hailin f3d4799efc feat(mining-wallet): add UserWalletCreated/Updated events for CDC sync
- Publish UserWalletCreated when a new wallet is created
- Publish UserWalletUpdated when wallet balance changes
- Events sent to cdc.mining-wallet.outbox topic for mining-admin-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 06:13:34 -08:00
hailin 839feab97d fix(mining-admin): handle CONTRIBUTION_CREDITED event for wallet sync
Add handler for CONTRIBUTION_CREDITED events from mining-wallet-service
to sync user wallet data to synced_user_wallets table.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 06:11:49 -08:00