#!/usr/bin/env python3
"""配置我们的 8 个跟单钱包到 copybot.paper.json 和 config.live.json。

跟作者的方法论一致：
- Kruto2027 floor_pin=80（钉死，跟作者一样）
- 其它钱包 floor 由 sync_floors.py 每天自动算 p80
- backtest.json 保持作者的 15 个钱包（8 个 live + 7 个 bench 观察区）
"""
import json
import os

HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)

# 我们的 8 个跟单钱包（基于 watch_sharps.json 排名 + 作者方法论）
OUR_WALLETS = [
    # floor_pin=80 跟作者一样，防止 p80 漂移到 125
    {"wallet": "0xe8ca3f758c93f44f3ec210542ab78afb7c0bcccb",
     "name": "Kruto2027", "class": "volume", "floor": 80.0, "floor_pin": 80.0},
    # 其它钱包不钉 pin，让 sync_floors.py 每天算 p80
    {"wallet": "0xbadaf319415c17f28824a43ae0cd912b9d84d874",
     "name": "0xbadaf319", "class": "volume", "floor": 42.0},
    {"wallet": "0xa1d57d329227c75b12b09f927fb3d6d6ef8f1343",
     "name": "1kto1m", "class": "volume", "floor": 332.0},
    {"wallet": "0x2d462b29127b919ae4c085e03be44ae7077e3e2d",
     "name": "Vahan88", "class": "volume", "floor": 245.0},
    {"wallet": "0x41558102a796ba971c7567cad41c307e59f8fa41",
     "name": "LSB1", "class": "volume", "floor": 315.0},
    # 新加的 3 个，floor 先设 25，sync_floors.py 会自动更新
    {"wallet": "0x0c3e55cf50a00a7e74fabd8584c6fdde21603c4c",
     "name": "EdwardIN", "class": "volume", "floor": 25.0},
    {"wallet": "0x82d2e4dbb0a849ff8e2f5380719769145648beea",
     "name": "lma0o0o0o", "class": "volume", "floor": 25.0},
    {"wallet": "0x69b9bd4fa27813091fcfe726541f2fd7baa3a5d5",
     "name": "Coteykens", "class": "volume", "floor": 25.0},
]

# 更新 copybot.paper.json
paper_path = os.path.join(HERE, "copybot.paper.json")
paper = json.load(open(paper_path))
paper["wallets"] = OUR_WALLETS
json.dump(paper, open(paper_path, "w"), indent=2)
print(f"copybot.paper.json: {len(OUR_WALLETS)} wallets")
for w in OUR_WALLETS:
    pin = f" (PINNED {w['floor_pin']})" if "floor_pin" in w else ""
    print(f"  {w['name']:20s} floor=${w['floor']}{pin}")

# 更新 config.live.json（如果存在）
live_path = os.path.join(ROOT, "config.live.json")
if os.path.exists(live_path):
    live = json.load(open(live_path))
    live["wallets"] = OUR_WALLETS
    json.dump(live, open(live_path, "w"), indent=2)
    print(f"\nconfig.live.json: {len(OUR_WALLETS)} wallets (synced)")
else:
    print(f"\nconfig.live.json: not found (create from config.live.example.json first)")

# 确认 backtest.json 有 bench 观察区
bt_path = os.path.join(HERE, "backtest.json")
bt = json.load(open(bt_path))
bt_names = [w.get("name", w["wallet"][:10]) for w in bt["wallets"]]
our_names = [w["name"] for w in OUR_WALLETS]
bench = [n for n in bt_names if n not in our_names]
print(f"\nbacktest.json: {len(bt_names)} wallets total")
print(f"  live (跟单): {len(our_names)} - {', '.join(our_names)}")
print(f"  bench (观察): {len(bench)} - {', '.join(bench)}")
print(f"\nbench 区的钱包每天被 portfolio.py 回测，周五 review 时看前瞻盈亏决定晋升/降级")
