Repository navigation
Expand file tree
/
Copy pathozc_cli.py
More file actions
596 lines (493 loc) · 23.8 KB
/
Copy pathozc_cli.py
File metadata and controls
596 lines (493 loc) · 23.8 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#!/usr/bin/env python3
"""
ozc CLI — エージェントがOZC Data Marketを操作するコマンドラインインターフェース。
Phase 0: oz_economy.db(SQLite)でシミュレート
Phase 1: Base Testnet の実コントラクトを叩く
使用例:
python3 ozc_cli.py deploy --data data.json --stake 100
python3 ozc_cli.py stake --id <data_id> --amount 50
python3 ozc_cli.py unstake --id <data_id> --shares 10
python3 ozc_cli.py list --sort market_cap
python3 ozc_cli.py price --id <data_id>
python3 ozc_cli.py capacity status
python3 ozc_cli.py capacity sell --units 100 --price 0.5
python3 ozc_cli.py capacity buy --listing <id> --units 50
"""
import argparse
import json
import hashlib
import sqlite3
import time
import sys
import os
from pathlib import Path
DB_PATH = Path.home() / ".openclaw/workspace/oz_economy.db"
# ─── Bonding Curve ─────────────────────────────────────────────
BASE_PRICE = 1.0 # OZC / share
SLOPE = 0.000001 # per staked OZC
HOLDING_COST_RATE = 1e-9 # per block (simulated as per second)
MIN_INITIAL_STAKE = 10.0 # OZC
TOTAL_CAPACITY = 10_000 # CU (Phase 0 固定)
BASE_CU_PRICE = 0.1 # OZC / CU
def curve_price(total_staked: float) -> float:
return BASE_PRICE + SLOPE * total_staked
def shares_for_ozc(current_staked: float, ozc_amount: float) -> float:
"""OZC量 → シェア数(midpoint approximation)"""
price = curve_price(current_staked)
return ozc_amount / price
def ozc_for_shares(total_staked: float, total_shares: float, shares: float) -> float:
"""シェア数 → OZC量(proportional)"""
if total_shares == 0:
return 0.0
return total_staked * (shares / total_shares)
# ─── インセンティブ設計 ─────────────────────────────────────────
#
# 新規ユーザー → OZ発展のフライホイール:
#
# 1. Welcome Bonus: 最初の100人は100 OZC。以降は逓減(1/sqrt(n))
# → 早期参加者ほど多く受け取る = 口コミの動機
# 2. Stake-Locked Bonus: ボーナスOZCはstakeにのみ使用可(transferは不可)
# → 新規ユーザーの行動が必ずマーケットの流動性に変わる
# 3. Referral Reward: 紹介者は被紹介者のwelcome bonusの20%を受け取る
# → ユーザー獲得行動に直接的な報酬
# 4. First Stake Bonus: 初回stakeは+10%ボーナスshares
# → 「触ってみる」ハードルを下げる
# 5. Discovery Reward: 誰もstakeしていないデータに最初にstakeすると+20%
# → 価値発見行動にインセンティブ
#
# フライホイール:
# 新規ユーザー → ボーナスOZCをstake → マーケットcap上昇
# → 既存データの価値上昇 → 既存ユーザーの利益 → 口コミ → 新規ユーザー
import math
WELCOME_BASE = 100.0 # 最初の1人が受け取るOZC
REFERRAL_RATE = 0.20 # 紹介報酬 = ボーナスの20%
FIRST_STAKE_BONUS = 0.10 # 初回stake +10%
DISCOVERY_BONUS = 0.20 # 未stakeデータへの最初のstake +20%
def calc_welcome_bonus(seq_number: int) -> float:
"""参加順に応じたwelcome bonus。早期参加者ほど多い。"""
if seq_number <= 0:
seq_number = 1
return WELCOME_BASE / math.sqrt(seq_number)
def register_user(conn, agent: str, referred_by: str = None) -> dict:
"""新規ユーザー登録 + welcome bonus + referral reward"""
existing = conn.execute("SELECT agent FROM user_registry WHERE agent=?", (agent,)).fetchone()
if existing:
return {"status": "already_registered", "agent": agent}
# 順番を取得
count_row = conn.execute("SELECT COUNT(*) as cnt FROM user_registry").fetchone()
seq = (count_row["cnt"] or 0) + 1
now = time.time()
bonus = calc_welcome_bonus(seq)
# ユーザー登録
conn.execute("""
INSERT INTO user_registry (agent, joined_at, referred_by, welcome_bonus, seq_number)
VALUES (?,?,?,?,?)
""", (agent, now, referred_by, bonus, seq))
# balancesにエントリがなければ作成、あればボーナス加算
bal = conn.execute("SELECT balance FROM balances WHERE agent=?", (agent,)).fetchone()
if bal:
conn.execute("UPDATE balances SET balance=balance+? WHERE agent=?", (bonus, agent))
else:
conn.execute("INSERT INTO balances (agent, balance) VALUES (?,?)", (agent, bonus))
# treasury から引く
conn.execute("UPDATE balances SET balance=balance-? WHERE agent='treasury'", (bonus,))
result = {"status": "registered", "agent": agent, "seq": seq,
"welcome_bonus": round(bonus, 4), "referred_by": referred_by}
# 紹介報酬
if referred_by:
referral_reward = bonus * REFERRAL_RATE
conn.execute("UPDATE balances SET balance=balance+? WHERE agent=?", (referral_reward, referred_by))
conn.execute("UPDATE balances SET balance=balance-? WHERE agent='treasury'", (referral_reward,))
conn.execute("""
INSERT INTO referral_rewards (referrer, referred, reward_ozc, reason, created_at)
VALUES (?,?,?,?,?)
""", (referred_by, agent, referral_reward, "welcome_referral", now))
result["referral_reward"] = round(referral_reward, 4)
result["referrer"] = referred_by
conn.commit()
return result
# ─── DB セットアップ ─────────────────────────────────────────────
def get_conn():
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
_ensure_tables(conn)
return conn
def _ensure_tables(conn):
conn.executescript("""
CREATE TABLE IF NOT EXISTS data_listings (
id TEXT PRIMARY KEY,
hash TEXT NOT NULL,
deployer TEXT NOT NULL,
title TEXT NOT NULL,
summary TEXT NOT NULL,
content_url TEXT,
total_staked REAL DEFAULT 0,
total_shares REAL DEFAULT 0,
capacity_units INTEGER DEFAULT 1,
last_cost_ts REAL,
deployed_at REAL,
active INTEGER DEFAULT 1
);
CREATE TABLE IF NOT EXISTS data_stakes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
data_id TEXT NOT NULL,
staker TEXT NOT NULL,
shares REAL NOT NULL,
staked_at REAL,
FOREIGN KEY(data_id) REFERENCES data_listings(id)
);
CREATE TABLE IF NOT EXISTS capacity_listings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
seller TEXT NOT NULL,
units INTEGER NOT NULL,
price_per_unit REAL NOT NULL,
active INTEGER DEFAULT 1,
listed_at REAL
);
CREATE TABLE IF NOT EXISTS user_registry (
agent TEXT PRIMARY KEY,
joined_at REAL NOT NULL,
referred_by TEXT,
welcome_bonus REAL DEFAULT 0,
total_staked REAL DEFAULT 0,
total_profit REAL DEFAULT 0,
seq_number INTEGER
);
CREATE TABLE IF NOT EXISTS referral_rewards (
id INTEGER PRIMARY KEY AUTOINCREMENT,
referrer TEXT NOT NULL,
referred TEXT NOT NULL,
reward_ozc REAL NOT NULL,
reason TEXT,
created_at REAL
);
""")
conn.commit()
# ─── コマンド実装 ────────────────────────────────────────────────
def cmd_deploy(args):
"""データをデプロイする"""
conn = get_conn()
# データ読み込み
if args.data:
with open(args.data) as f:
data = json.load(f)
else:
data = {"title": args.title or "untitled", "summary": args.summary or "", "content_url": ""}
title = data.get("title", "untitled")
summary = data.get("summary", "")
content_url = data.get("content_url", "")
stake = float(args.stake)
if stake < MIN_INITIAL_STAKE:
print(f"ERROR: 最低ステーク量は {MIN_INITIAL_STAKE} OZC です")
sys.exit(1)
# ハッシュ計算
raw = json.dumps(data, sort_keys=True, ensure_ascii=False).encode()
hash_val = hashlib.sha256(raw).hexdigest()
data_id = hashlib.sha256(f"{hash_val}{args.agent}{time.time()}".encode()).hexdigest()[:16]
# 残高チェック
cur = conn.execute("SELECT balance FROM balances WHERE agent=?", (args.agent,))
row = cur.fetchone()
if not row or row["balance"] < stake:
print(f"ERROR: OZC残高不足 (必要: {stake}, 現在: {row['balance'] if row else 0})")
sys.exit(1)
# 容量チェック
cur2 = conn.execute("SELECT SUM(capacity_units) as used FROM data_listings WHERE active=1")
used = cur2.fetchone()["used"] or 0
cu_needed = max(1, len(raw) // 1024)
if used + cu_needed > TOTAL_CAPACITY:
print(f"ERROR: ネットワーク容量不足 (使用中: {used}/{TOTAL_CAPACITY} CU)")
sys.exit(1)
# 初期シェア計算
shares = shares_for_ozc(0, stake)
now = time.time()
# DB更新
conn.execute("UPDATE balances SET balance=balance-? WHERE agent=?", (stake, args.agent))
conn.execute("""
INSERT INTO data_listings (id, hash, deployer, title, summary, content_url,
total_staked, total_shares, capacity_units, last_cost_ts, deployed_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?)
""", (data_id, hash_val, args.agent, title, summary, content_url,
stake, shares, cu_needed, now, now))
conn.execute("""
INSERT INTO data_stakes (data_id, staker, shares, staked_at) VALUES (?,?,?,?)
""", (data_id, args.agent, shares, now))
conn.commit()
print(f"✅ デプロイ完了")
print(f" data_id: {data_id}")
print(f" hash: {hash_val[:16]}...")
print(f" stake: {stake} OZC")
print(f" shares: {shares:.6f}")
print(f" capacity: {cu_needed} CU")
print(f" price: {curve_price(0):.4f} OZC/share")
def cmd_stake(args):
"""データにステークする"""
conn = get_conn()
data_id = args.id
ozc_amount = float(args.amount)
row = conn.execute("SELECT * FROM data_listings WHERE id=? AND active=1", (data_id,)).fetchone()
if not row:
print(f"ERROR: data_id '{data_id}' が見つかりません")
sys.exit(1)
bal = conn.execute("SELECT balance FROM balances WHERE agent=?", (args.agent,)).fetchone()
if not bal or bal["balance"] < ozc_amount:
print("ERROR: OZC残高不足")
sys.exit(1)
_collect_holding_cost(conn, data_id)
row = conn.execute("SELECT * FROM data_listings WHERE id=?", (data_id,)).fetchone()
shares = shares_for_ozc(row["total_staked"], ozc_amount)
now = time.time()
bonus_label = ""
# First Stake Bonus: このユーザーの初めてのstakeか?
any_prev = conn.execute("SELECT id FROM data_stakes WHERE staker=? LIMIT 1", (args.agent,)).fetchone()
if not any_prev:
bonus_shares = shares * FIRST_STAKE_BONUS
shares += bonus_shares
bonus_label += f" [+{FIRST_STAKE_BONUS*100:.0f}% first stake bonus]"
# Discovery Bonus: このデータに誰もstakeしていなければ+20%
stakers = conn.execute("SELECT id FROM data_stakes WHERE data_id=? LIMIT 1", (data_id,)).fetchone()
if not stakers:
bonus_shares = shares * DISCOVERY_BONUS
shares += bonus_shares
bonus_label += f" [+{DISCOVERY_BONUS*100:.0f}% discovery bonus]"
conn.execute("UPDATE balances SET balance=balance-? WHERE agent=?", (ozc_amount, args.agent))
conn.execute("UPDATE data_listings SET total_staked=total_staked+?, total_shares=total_shares+? WHERE id=?",
(ozc_amount, shares, data_id))
# 既存stakeレコードを更新 or 新規挿入
existing = conn.execute("SELECT id,shares FROM data_stakes WHERE data_id=? AND staker=?",
(data_id, args.agent)).fetchone()
if existing:
conn.execute("UPDATE data_stakes SET shares=shares+? WHERE id=?", (shares, existing["id"]))
else:
conn.execute("INSERT INTO data_stakes (data_id, staker, shares, staked_at) VALUES (?,?,?,?)",
(data_id, args.agent, shares, now))
# user_registryのtotal_stakedを更新
conn.execute("UPDATE user_registry SET total_staked=total_staked+? WHERE agent=?", (ozc_amount, args.agent))
conn.commit()
new_price = curve_price(row["total_staked"] + ozc_amount)
new_mcap = new_price * (row["total_shares"] + shares)
print(f"✅ ステーク完了{bonus_label}")
print(f" data_id: {data_id}")
print(f" OZC投入: {ozc_amount}")
print(f" 取得shares: {shares:.6f}")
print(f" 新価格: {new_price:.6f} OZC/share")
print(f" 時価総額: {new_mcap:.2f} OZC")
def cmd_unstake(args):
"""ステークを解除して利確 or ロスカット"""
conn = get_conn()
data_id = args.id
shares = float(args.shares)
row = conn.execute("SELECT * FROM data_listings WHERE id=? AND active=1", (data_id,)).fetchone()
if not row:
print(f"ERROR: data_id '{data_id}' が見つかりません")
sys.exit(1)
stake_row = conn.execute("SELECT * FROM data_stakes WHERE data_id=? AND staker=?",
(data_id, args.agent)).fetchone()
if not stake_row or stake_row["shares"] < shares:
print(f"ERROR: shares不足 (保有: {stake_row['shares'] if stake_row else 0})")
sys.exit(1)
_collect_holding_cost(conn, data_id)
row = conn.execute("SELECT * FROM data_listings WHERE id=?", (data_id,)).fetchone()
ozc_received = ozc_for_shares(row["total_staked"], row["total_shares"], shares)
conn.execute("UPDATE balances SET balance=balance+? WHERE agent=?", (ozc_received, args.agent))
conn.execute("UPDATE data_listings SET total_staked=total_staked-?, total_shares=total_shares-? WHERE id=?",
(ozc_received, shares, data_id))
conn.execute("UPDATE data_stakes SET shares=shares-? WHERE id=? AND data_id=?",
(shares, stake_row["id"], data_id))
# 全シェアが0なら非活性化
updated = conn.execute("SELECT total_shares FROM data_listings WHERE id=?", (data_id,)).fetchone()
if updated["total_shares"] <= 0:
conn.execute("UPDATE data_listings SET active=0 WHERE id=?", (data_id,))
conn.commit()
print(f"✅ アンステーク完了")
print(f" data_id: {data_id}")
print(f" 返却shares: {shares:.6f}")
print(f" 受取OZC: {ozc_received:.4f}")
def cmd_list(args):
"""データ一覧を表示"""
conn = get_conn()
sort = args.sort if args.sort in ("market_cap", "deployed_at", "total_staked") else "market_cap"
limit = int(args.limit) if args.limit else 20
rows = conn.execute("""
SELECT id, deployer, title, summary, total_staked, total_shares, deployed_at, capacity_units
FROM data_listings WHERE active=1
ORDER BY total_staked DESC
LIMIT ?
""", (limit,)).fetchall()
print(f"\n{'ID':16} {'TITLE':24} {'MCAP(OZC)':12} {'STAKED':10} {'DEPLOYER':16}")
print("─" * 90)
for r in rows:
price = curve_price(r["total_staked"])
mcap = price * r["total_shares"]
print(f"{r['id']:16} {r['title'][:24]:24} {mcap:12.2f} {r['total_staked']:10.2f} {r['deployer']:16}")
def cmd_price(args):
"""データの現在価格を表示"""
conn = get_conn()
row = conn.execute("SELECT * FROM data_listings WHERE id=?", (args.id,)).fetchone()
if not row:
print(f"ERROR: data_id '{args.id}' が見つかりません")
sys.exit(1)
price = curve_price(row["total_staked"])
mcap = price * row["total_shares"]
print(f"\n📊 {row['title']}")
print(f" data_id: {row['id']}")
print(f" 現在価格: {price:.6f} OZC/share")
print(f" 時価総額: {mcap:.4f} OZC")
print(f" 総ステーク: {row['total_staked']:.4f} OZC")
print(f" 発行shares: {row['total_shares']:.6f}")
print(f" 容量使用: {row['capacity_units']} CU")
def cmd_capacity(args):
"""容量市場の操作"""
conn = get_conn()
if args.subcmd == "status":
used_row = conn.execute("SELECT SUM(capacity_units) as used FROM data_listings WHERE active=1").fetchone()
used = used_row["used"] or 0
avail = TOTAL_CAPACITY - used
ratio = used / TOTAL_CAPACITY
spot = BASE_CU_PRICE * (ratio ** 2) + BASE_CU_PRICE
print(f"\n⚡ Capacity Market")
print(f" 総容量: {TOTAL_CAPACITY} CU")
print(f" 使用中: {used} CU ({ratio*100:.1f}%)")
print(f" 空き: {avail} CU")
print(f" スポット: {spot:.4f} OZC/CU")
elif args.subcmd == "sell":
units = int(args.units)
price = float(args.price)
# 保有CU確認(Phase 0は簡略化: デプロイヤーはCUを持っていることにする)
now = time.time()
conn.execute("INSERT INTO capacity_listings (seller, units, price_per_unit, listed_at) VALUES (?,?,?,?)",
(args.agent, units, price, now))
conn.commit()
lid = conn.execute("SELECT last_insert_rowid() as id").fetchone()["id"]
print(f"✅ 容量を売りに出しました")
print(f" listing_id: {lid}")
print(f" units: {units} CU @ {price} OZC/CU")
elif args.subcmd == "buy":
lid = int(args.listing)
units = int(args.units)
listing = conn.execute("SELECT * FROM capacity_listings WHERE id=? AND active=1", (lid,)).fetchone()
if not listing:
print(f"ERROR: listing {lid} が見つかりません")
sys.exit(1)
total_cost = listing["price_per_unit"] * units
bal = conn.execute("SELECT balance FROM balances WHERE agent=?", (args.agent,)).fetchone()
if not bal or bal["balance"] < total_cost:
print("ERROR: OZC残高不足")
sys.exit(1)
conn.execute("UPDATE balances SET balance=balance-? WHERE agent=?", (total_cost, args.agent))
conn.execute("UPDATE balances SET balance=balance+? WHERE agent=?", (total_cost, listing["seller"]))
if listing["units"] <= units:
conn.execute("UPDATE capacity_listings SET active=0 WHERE id=?", (lid,))
else:
conn.execute("UPDATE capacity_listings SET units=units-? WHERE id=?", (units, lid))
conn.commit()
print(f"✅ {units} CU を {total_cost:.4f} OZC で購入しました")
def cmd_join(args):
"""OZCネットワークに新規参加"""
conn = get_conn()
result = register_user(conn, args.agent, referred_by=args.ref)
if result["status"] == "already_registered":
print(f"ℹ️ {args.agent} は既に登録済みです")
bal = conn.execute("SELECT balance FROM balances WHERE agent=?", (args.agent,)).fetchone()
print(f" 残高: {bal['balance']:.4f} OZC" if bal else " 残高: 0")
return
print(f"🎉 Welcome to OZC Data Market!")
print(f" agent: {result['agent']}")
print(f" 参加番号: #{result['seq']}")
print(f" welcome bonus: {result['welcome_bonus']} OZC")
if result.get("referrer"):
print(f" 紹介者: {result['referrer']} (+{result['referral_reward']} OZC 報酬)")
print(f"\n ボーナスOZCでデータにstakeして、市場に参加しよう。")
def cmd_stats(args):
"""ネットワーク統計"""
conn = get_conn()
users = conn.execute("SELECT COUNT(*) as cnt FROM user_registry").fetchone()["cnt"] or 0
listings = conn.execute("SELECT COUNT(*) as cnt FROM data_listings WHERE active=1").fetchone()["cnt"] or 0
total_staked = conn.execute("SELECT SUM(total_staked) as s FROM data_listings WHERE active=1").fetchone()["s"] or 0
total_bonus = conn.execute("SELECT SUM(welcome_bonus) as s FROM user_registry").fetchone()["s"] or 0
referrals = conn.execute("SELECT COUNT(*) as cnt FROM referral_rewards").fetchone()["cnt"] or 0
print(f"\n📊 OZC Data Market Stats")
print(f" registered users: {users}")
print(f" active listings: {listings}")
print(f" total staked: {total_staked:.2f} OZC")
print(f" bonuses issued: {total_bonus:.2f} OZC")
print(f" referrals: {referrals}")
if users > 0:
top = conn.execute("""
SELECT agent, welcome_bonus, total_staked, seq_number
FROM user_registry ORDER BY seq_number ASC LIMIT 5
""").fetchall()
print(f"\n Early Adopters:")
for u in top:
print(f" #{u['seq_number']} {u['agent']} — bonus:{u['welcome_bonus']:.1f} staked:{u['total_staked']:.1f}")
def _collect_holding_cost(conn, data_id):
"""Holding cost を計算して simulated burn(treasury に送る)"""
row = conn.execute("SELECT * FROM data_listings WHERE id=? AND active=1", (data_id,)).fetchone()
if not row:
return
elapsed = time.time() - (row["last_cost_ts"] or time.time())
cost = row["total_staked"] * HOLDING_COST_RATE * elapsed
if cost <= 0:
return
cost = min(cost, row["total_staked"])
conn.execute("UPDATE data_listings SET total_staked=total_staked-?, last_cost_ts=? WHERE id=?",
(cost, time.time(), data_id))
# OZC を treasury に送る(burn シミュレーション)
conn.execute("UPDATE balances SET balance=balance+? WHERE agent='treasury'", (cost,))
# ─── エントリポイント ─────────────────────────────────────────────
def main():
parser = argparse.ArgumentParser(description="OZC Data Market CLI")
parser.add_argument("--agent", default="hitomi", help="操作するエージェント名")
sub = parser.add_subparsers(dest="cmd")
# deploy
p = sub.add_parser("deploy", help="データをデプロイする")
p.add_argument("--data", help="データJSONファイルパス")
p.add_argument("--title", help="タイトル(--dataなし時)")
p.add_argument("--summary", help="概要(--dataなし時)")
p.add_argument("--stake", required=True, help="初期ステーク量(OZC)")
# stake
p = sub.add_parser("stake", help="データにステークする")
p.add_argument("--id", required=True)
p.add_argument("--amount", required=True)
# unstake
p = sub.add_parser("unstake", help="ステーク解除")
p.add_argument("--id", required=True)
p.add_argument("--shares", required=True)
# list
p = sub.add_parser("list", help="データ一覧")
p.add_argument("--sort", default="market_cap")
p.add_argument("--limit", default="20")
# price
p = sub.add_parser("price", help="価格確認")
p.add_argument("--id", required=True)
# capacity
p = sub.add_parser("capacity", help="容量市場")
cap_sub = p.add_subparsers(dest="subcmd")
cap_sub.add_parser("status")
ps = cap_sub.add_parser("sell")
ps.add_argument("--units", required=True)
ps.add_argument("--price", required=True)
pb = cap_sub.add_parser("buy")
pb.add_argument("--listing", required=True)
pb.add_argument("--units", required=True)
# join (新規ユーザー登録)
p = sub.add_parser("join", help="OZCネットワークに参加")
p.add_argument("--ref", help="紹介者のagent名")
# stats (ユーザー統計)
sub.add_parser("stats", help="ネットワーク統計")
args = parser.parse_args()
dispatch = {
"deploy": cmd_deploy,
"stake": cmd_stake,
"unstake": cmd_unstake,
"list": cmd_list,
"price": cmd_price,
"capacity": cmd_capacity,
"join": cmd_join,
"stats": cmd_stats,
}
if args.cmd not in dispatch:
parser.print_help()
sys.exit(1)
dispatch[args.cmd](args)
if __name__ == "__main__":
main()