-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstake_manager.py
More file actions
193 lines (152 loc) · 6.22 KB
/
Copy pathstake_manager.py
File metadata and controls
193 lines (152 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python3
"""
stake_manager.py — Manage staking across all bots.
Check tiers, stake, register as staker, or view lock status.
Usage:
python stake_manager.py status
python stake_manager.py stake --tier 1
python stake_manager.py stake --tier 1 --bot Bot_2
python stake_manager.py register
python stake_manager.py register --bot Bot_1
"""
import json
import sys
import argparse
from pathlib import Path
try:
from litcoin import Agent
except ImportError:
print("ERROR: litcoin package not installed. Run: pip install litcoin")
sys.exit(1)
def load_config(path="config.json"):
p = Path(path)
if not p.exists():
print(f"ERROR: Config file not found: {path}")
print("Copy config.example.json to config.json and fill in your values.")
sys.exit(1)
with open(p) as f:
return json.load(f)
TIER_INFO = {
0: {"name": "None", "stake": 0, "lock": "—", "boost": "1.00x"},
1: {"name": "Spark", "stake": 1_000_000, "lock": "7d", "boost": "1.10x"},
2: {"name": "Circuit", "stake": 5_000_000, "lock": "30d", "boost": "1.25x"},
3: {"name": "Core", "stake": 50_000_000, "lock": "90d", "boost": "1.50x"},
4: {"name": "Architect", "stake": 500_000_000, "lock": "180d", "boost": "2.00x"},
}
def cmd_status(bots, config_path):
"""Show staking status for all bots."""
config = load_config(config_path)
all_bots = [b for b in config.get("bots", []) if b.get("enabled", True)]
print(f"\n{'='*60}")
print(f" Staking Status")
print(f"{'='*60}")
for bot_cfg in all_bots:
name = bot_cfg["name"]
try:
agent = Agent(bot_cfg["api_key"])
stk = agent.stake_info()
tier = stk.get("tier", 0)
amount = stk.get("amount", 0)
ti = TIER_INFO.get(tier, {})
try:
lock_secs = agent.time_until_unlock()
if lock_secs > 0:
days = lock_secs // 86400
hours = (lock_secs % 86400) // 3600
lock_str = f"{days}d {hours}h remaining"
else:
lock_str = "Unlocked"
except Exception:
lock_str = "Unknown"
try:
sy = agent.staking_yield()
daily_yield = sy.get("dailyYield", 0)
apy = sy.get("apy", 0)
except Exception:
daily_yield = 0
apy = 0
print(f"\n {name}")
print(f" Tier: {tier} ({ti.get('name', '?')})")
print(f" Staked: {amount:>12,.0f} LIT")
print(f" Lock: {lock_str}")
print(f" Boost: {ti.get('boost', '?')}")
print(f" Yield: {daily_yield:,.0f} LIT/day ({apy:.1f}% APY)")
except Exception as e:
print(f"\n {name}: ERROR — {e}")
print(f"\n{'='*60}\n")
print(" Tier reference:")
for t, info in TIER_INFO.items():
if t == 0:
continue
print(f" Tier {t} ({info['name']}): {info['stake']:>12,} LIT, {info['lock']} lock, {info['boost']} boost")
print()
def cmd_stake(bots, config_path, tier, bot_filter):
"""Stake a specific tier on selected bots."""
config = load_config(config_path)
all_bots = [b for b in config.get("bots", []) if b.get("enabled", True)]
if bot_filter:
all_bots = [b for b in all_bots if b["name"] == bot_filter]
if not all_bots:
print(f"ERROR: Bot '{bot_filter}' not found in config.")
sys.exit(1)
if tier not in TIER_INFO or tier == 0:
print(f"ERROR: Invalid tier {tier}. Choose 1-4.")
sys.exit(1)
ti = TIER_INFO[tier]
print(f"\nStaking tier {tier} ({ti['name']}) — {ti['stake']:,} LIT, {ti['lock']} lock\n")
for bot_cfg in all_bots:
name = bot_cfg["name"]
try:
agent = Agent(bot_cfg["api_key"])
result = agent.stake(tier)
print(f" {name}: Staked successfully — {result}")
# Auto-register after staking (critical for mining eligibility)
try:
agent.register_staker()
print(f" {name}: Registered as staker")
except Exception as e:
print(f" {name}: Register warning — {e}")
except Exception as e:
print(f" {name}: FAILED — {e}")
print()
def cmd_register(bots, config_path, bot_filter):
"""Register as staker on selected bots. Required after staking for mining."""
config = load_config(config_path)
all_bots = [b for b in config.get("bots", []) if b.get("enabled", True)]
if bot_filter:
all_bots = [b for b in all_bots if b["name"] == bot_filter]
if not all_bots:
print(f"ERROR: Bot '{bot_filter}' not found in config.")
sys.exit(1)
print(f"\nRegistering stakers...\n")
for bot_cfg in all_bots:
name = bot_cfg["name"]
try:
agent = Agent(bot_cfg["api_key"])
agent.register_staker()
print(f" {name}: Registered")
except Exception as e:
print(f" {name}: {e}")
print()
def main():
parser = argparse.ArgumentParser(description="LITCOIN staking manager")
parser.add_argument("--config", default="config.json", help="Path to config file")
sub = parser.add_subparsers(dest="command")
sub.add_parser("status", help="Show staking status for all bots")
stake_p = sub.add_parser("stake", help="Stake a tier on bots")
stake_p.add_argument("--tier", type=int, required=True, help="Tier to stake (1-4)")
stake_p.add_argument("--bot", default=None, help="Target a specific bot by name")
reg_p = sub.add_parser("register", help="Register as staker (required after staking)")
reg_p.add_argument("--bot", default=None, help="Target a specific bot by name")
args = parser.parse_args()
if not args.command:
parser.print_help()
sys.exit(1)
if args.command == "status":
cmd_status(None, args.config)
elif args.command == "stake":
cmd_stake(None, args.config, args.tier, args.bot)
elif args.command == "register":
cmd_register(None, args.config, args.bot)
if __name__ == "__main__":
main()