primecli 0.5.1__tar.gz → 0.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: primecli
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Agent-friendly CLI tools for the DeltaPrime (Avalanche + Arbitrum) and DegenPrime (Base) lending and leverage protocols. Preview-by-default; no Etherscan key required.
5
5
  Author: Mnemosyne-quest contributors
6
6
  License: MIT
@@ -48,7 +48,7 @@ Built for agent use:
48
48
  - RedStone-signed solvency math handled internally, with a regression test pinning the half-boundary `toFixed(8)` encoding.
49
49
  - ParaSwap calldata validated client-side against the on-chain executor allowlist before broadcast.
50
50
 
51
- **Current version:** 0.5.1 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
51
+ **Current version:** 0.5.2 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
52
52
 
53
53
  > **Breaking change in 0.5.0:** there is no longer a default signing key. Earlier versions silently fell back to a baked-in agent when no key was configured; that fallback has been removed. With no key configured, every command now fails closed with `No signing key found...`. Set a key explicitly (see [Configuration](#configuration)).
54
54
 
@@ -16,7 +16,7 @@ Built for agent use:
16
16
  - RedStone-signed solvency math handled internally, with a regression test pinning the half-boundary `toFixed(8)` encoding.
17
17
  - ParaSwap calldata validated client-side against the on-chain executor allowlist before broadcast.
18
18
 
19
- **Current version:** 0.5.1 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
19
+ **Current version:** 0.5.2 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
20
20
 
21
21
  > **Breaking change in 0.5.0:** there is no longer a default signing key. Earlier versions silently fell back to a baked-in agent when no key was configured; that fallback has been removed. With no key configured, every command now fails closed with `No signing key found...`. Set a key explicitly (see [Configuration](#configuration)).
22
22
 
@@ -15,6 +15,7 @@ Usage:
15
15
  degenprime create-account [--execute]
16
16
  degenprime create-account --fund-pool usdc --fund-amount 100 [--execute]
17
17
  degenprime summary
18
+ degenprime defi --json (aggregate ALL positions as DeBank-style JSON; read-only)
18
19
  degenprime fund --pool usdc --amount 100 [--execute]
19
20
  degenprime borrow --pool usdc --amount 100 [--execute]
20
21
  degenprime repay --pool usdc --amount 100 [--execute]
@@ -1293,34 +1294,10 @@ def _prices_usd(w3, account, symbols: list, payload: bytes) -> dict:
1293
1294
  except Exception:
1294
1295
  return {}
1295
1296
 
1296
- def cmd_summary(as_json: bool = False):
1297
- """Read-only Degen Account view: in-account collateral, debts, and live
1298
- RedStone-gated solvency (getTotalValue/getDebt/getHealthRatio/isSolvent). Falls
1299
- back to balances-only if the RedStone gateway is unreachable or a view reverts.
1300
- Note: per-asset USD is best-effort - only symbols with a RedStone primary-prod
1301
- feed are priced here. Symbols sourced on-chain from BaseOracle TWAP show as
1302
- balance-only (the SolvencyFacet still values them for the total/debt figures).
1303
-
1304
- With --json: emits a single JSON object covering wallet, account, native
1305
- balance, per-asset supplied/borrowed with optional USD, poolDeposits (the EOA's
1306
- 'Diamond Hands' lending-pool balances, emitted even with no Degen Account),
1307
- total/debt/health-ratio/solvent flags. Null fields, empty lists, and empty dicts are dropped (same
1308
- trim contract as `deltaprime defi --json`). Numeric 0 and boolean false are
1309
- preserved.
1310
-
1311
- Multicall: stage A batches getAllOwnedAssets + getDebts (2 -> 1 RPC). Stage B
1312
- batches one getBalance per owned asset (N -> 1 RPC). Stage C batches the four
1313
- RedStone-gated solvency views + getPrices (4-5 -> 1 RPC), each leg carrying the
1314
- same RedStone payload appended."""
1315
- w3 = get_w3()
1316
- acct = get_account()
1317
- pa = get_prime_account(w3, acct.address)
1318
- if not as_json:
1319
- print(f"Wallet: {acct.address}")
1320
-
1321
- # Pool deposits ("Diamond Hands") are EOA balances independent of the Degen Account,
1322
- # so read them up front via one Multicall3 — they must surface even for a wallet with
1323
- # no Degen Account (e.g. a deposit made before creating one).
1297
+ def _gather_pool_deposits(w3, owner: str) -> list:
1298
+ """The EOA's 'Diamond Hands' lending-pool balances, read independently of the Degen
1299
+ Account via one Multicall3 (one balanceOf per pool). Surfaces even for a wallet with
1300
+ no Degen Account. Returns [{symbol, raw, decimals}, ...] for non-zero balances."""
1324
1301
  pool_deposits = []
1325
1302
  dep_legs, dep_meta = [], []
1326
1303
  for _pname, _pcfg in POOLS.items():
@@ -1329,7 +1306,7 @@ def cmd_summary(as_json: bool = False):
1329
1306
  except Exception:
1330
1307
  continue
1331
1308
  _proxy_cs = Web3.to_checksum_address(_pcfg["proxy"])
1332
- dep_legs.append((_proxy_cs, bytes.fromhex(_pc.encode_abi("balanceOf", args=[acct.address])[2:])))
1309
+ dep_legs.append((_proxy_cs, bytes.fromhex(_pc.encode_abi("balanceOf", args=[owner])[2:])))
1333
1310
  dep_meta.append(_pcfg)
1334
1311
  if dep_legs:
1335
1312
  try:
@@ -1340,32 +1317,21 @@ def cmd_summary(as_json: bool = False):
1340
1317
  _bal = w3.codec.decode(["uint256"], _rd)[0] if _ok and _rd else 0
1341
1318
  if _bal > 0:
1342
1319
  pool_deposits.append({"symbol": _pcfg["symbol"], "raw": _bal, "decimals": _pcfg["decimals"]})
1320
+ return pool_deposits
1343
1321
 
1344
- if not pa:
1345
- # No Degen Account: still surface Diamond Hands deposits (balance-only — the
1346
- # RedStone getPrices view lives on the Degen Account, absent here).
1347
- if as_json:
1348
- out = {"wallet": acct.address, "account": None}
1349
- if pool_deposits:
1350
- out["poolDeposits"] = [{"symbol": r["symbol"], "amount": r["raw"] / 10**r["decimals"]}
1351
- for r in pool_deposits]
1352
- print(json.dumps(out, indent=2))
1353
- else:
1354
- print("No Degen Account yet. Create one with: degenprime create-account --execute")
1355
- if pool_deposits:
1356
- print(" Pool Deposits (Diamond Hands):")
1357
- for r in pool_deposits:
1358
- print(f" {r['symbol']:<8} {r['raw'] / 10**r['decimals']:,.6f}")
1359
- return
1360
1322
 
1361
- pa_eth = w3.eth.get_balance(pa) / 1e18
1362
- if not as_json:
1363
- print(f"Degen Account: {pa}")
1364
- if pa_eth >= 1e-9:
1365
- print(f" Native ETH (gas): {pa_eth:.6f}")
1323
+ def _gather_account_state(w3, account, pool_deposits: list):
1324
+ """Read-only collateral / debt / RedStone-gated solvency for an existing Degen Account.
1325
+ Shared by `summary` and `defi`. Returns (pa_eth, supplied, borrowed, solvency) where
1326
+ supplied/borrowed are [{symbol, raw, decimals}, ...] and solvency carries
1327
+ total/debt/ratio/solvent/error/prices. pool_deposits is taken so their feeds get folded
1328
+ into the RedStone payload (else getPrices reverts on a deposit-only symbol).
1366
1329
 
1367
- account = w3.eth.contract(address=Web3.to_checksum_address(pa), abi=PRIME_ACCOUNT_ABI)
1330
+ Multicall: stage A batches getAllOwnedAssets + getDebts (2 -> 1 RPC). Stage B batches
1331
+ one getBalance per owned asset (N -> 1 RPC). Stage C batches the four RedStone-gated
1332
+ solvency views + getPrices (4-5 -> 1 RPC), each leg carrying the same payload appended."""
1368
1333
  pa_cs = account.address
1334
+ pa_eth = w3.eth.get_balance(pa_cs) / 1e18
1369
1335
  stage_a_legs = [
1370
1336
  ("getAllOwnedAssets", ["bytes32[]"], account.encode_abi("getAllOwnedAssets", args=[])),
1371
1337
  ("getDebts", ["(bytes32,uint256)[]"], account.encode_abi("getDebts", args=[])),
@@ -1449,6 +1415,160 @@ def cmd_summary(as_json: bool = False):
1449
1415
  solvency["prices"] = prices
1450
1416
  except Exception as e:
1451
1417
  solvency["error"] = type(e).__name__
1418
+ return pa_eth, supplied, borrowed, solvency
1419
+
1420
+
1421
+ def gather_defi() -> dict:
1422
+ """Aggregate ALL DegenPrime positions for the selected wallet into one DeBank-style dict,
1423
+ matching the cross-tool shape `deltaprime defi --json` emits. Read-only: reuses the same
1424
+ gather helpers as `summary` (lending/solvency via the RedStone-gated views, plus the EOA's
1425
+ own pool deposits surfaced as a Savings group). Empty groups are omitted. total_usd /
1426
+ health_ratio / solvent come from the RedStone-gated solvency views; per-asset USD is
1427
+ best-effort (omitted where a RedStone feed is missing). Never broadcasts."""
1428
+ w3 = get_w3()
1429
+ acct = get_account()
1430
+ pa = get_prime_account(w3, acct.address)
1431
+ result = {
1432
+ "protocol": "DegenPrime", "url": "https://degenprime.io", "chain": "base",
1433
+ "wallet": acct.address, "prime_account": pa,
1434
+ "total_usd": None, "health_ratio": None, "solvent": None,
1435
+ "groups": [], "status": "ok",
1436
+ }
1437
+
1438
+ pool_deposits = _gather_pool_deposits(w3, acct.address)
1439
+ # _gather_account_state folds pool-deposit symbols into getPrices, so this map covers
1440
+ # both in-account assets and Diamond-Hands deposits. Empty with no Degen Account.
1441
+ prices = {}
1442
+
1443
+ if pa:
1444
+ account = w3.eth.contract(address=Web3.to_checksum_address(pa), abi=PRIME_ACCOUNT_ABI)
1445
+ _pa_eth, supplied, borrowed, solvency = _gather_account_state(w3, account, pool_deposits)
1446
+ prices = solvency["prices"]
1447
+ result["total_usd"] = solvency["total"]
1448
+ result["health_ratio"] = solvency["ratio"]
1449
+ result["solvent"] = solvency["solvent"]
1450
+ if solvency["error"]:
1451
+ result["solvency_error"] = solvency["error"]
1452
+
1453
+ def _row(r):
1454
+ amt = r["raw"] / 10**r["decimals"]
1455
+ row = {"symbol": r["symbol"], "balance": f"{amt:.6f}"}
1456
+ usd = prices.get(r["symbol"])
1457
+ if usd is not None:
1458
+ row["usd"] = round(amt * usd, 2)
1459
+ return row
1460
+
1461
+ if supplied or borrowed:
1462
+ result["groups"].append({
1463
+ "type": "Lending / Leverage", "health_ratio": solvency["ratio"],
1464
+ "supplied": [_row(r) for r in supplied],
1465
+ "borrowed": [_row(r) for r in borrowed],
1466
+ })
1467
+
1468
+ # Savings: the EOA's own pool deposits ("Diamond Hands"), independent of the Degen
1469
+ # Account (so NOT in getTotalValue) — surfaced as their own group and added on top.
1470
+ # Priced from the same RedStone read used for the account (no extra RPC).
1471
+ if pool_deposits:
1472
+ sav_rows, sav_usd_total = [], 0.0
1473
+ for r in pool_deposits:
1474
+ amt = r["raw"] / 10**r["decimals"]
1475
+ row = {"symbol": r["symbol"], "balance": f"{amt:.6f}"}
1476
+ usd = prices.get(r["symbol"])
1477
+ if usd is not None:
1478
+ row["usd"] = round(amt * usd, 2)
1479
+ sav_usd_total += amt * usd
1480
+ sav_rows.append(row)
1481
+ result["groups"].append({"type": "Savings", "label": "Savings", "supplied": sav_rows})
1482
+ if sav_usd_total:
1483
+ result["total_usd"] = (result["total_usd"] or 0) + sav_usd_total
1484
+
1485
+ return result
1486
+
1487
+
1488
+ _DEFI_DECORATIVE_KEYS = {"url"}
1489
+
1490
+
1491
+ def _trim_defi_json(value):
1492
+ """Recursively strip noise from `defi --json` output so an LLM consumer doesn't pay
1493
+ context for fields that carry no information: drops dict keys whose value is exactly
1494
+ None, drops keys whose value is an empty list or empty dict, drops the decorative
1495
+ top-level `url` key, but PRESERVES numeric 0 and boolean False (zero balance,
1496
+ explicitly-not-solvent, etc.) and keeps the top-level structure so a consumer can tell
1497
+ what's missing from what shape the response took. Same contract as `deltaprime`'s."""
1498
+ if isinstance(value, dict):
1499
+ out = {}
1500
+ for k, v in value.items():
1501
+ if k in _DEFI_DECORATIVE_KEYS:
1502
+ continue
1503
+ trimmed = _trim_defi_json(v)
1504
+ if trimmed is None:
1505
+ continue
1506
+ if isinstance(trimmed, (list, dict)) and len(trimmed) == 0:
1507
+ continue
1508
+ out[k] = trimmed
1509
+ return out
1510
+ if isinstance(value, list):
1511
+ return [_trim_defi_json(v) for v in value]
1512
+ return value
1513
+
1514
+
1515
+ def cmd_defi(as_json: bool = True):
1516
+ """Aggregate all DegenPrime positions for the wallet. Default output is the DeBank-style
1517
+ JSON (the cross-tool shape the health monitor consumes). On error, emits
1518
+ {"status":"error", ...} rather than raising, so the caller always gets parseable JSON."""
1519
+ try:
1520
+ data = gather_defi()
1521
+ except Exception as e:
1522
+ data = {"protocol": "DegenPrime", "chain": "base",
1523
+ "status": "error", "error": f"{type(e).__name__}: {e}"}
1524
+ print(json.dumps(_trim_defi_json(data), indent=2))
1525
+
1526
+
1527
+ def cmd_summary(as_json: bool = False):
1528
+ """Read-only Degen Account view: in-account collateral, debts, and live
1529
+ RedStone-gated solvency (getTotalValue/getDebt/getHealthRatio/isSolvent). Falls
1530
+ back to balances-only if the RedStone gateway is unreachable or a view reverts.
1531
+ Note: per-asset USD is best-effort - only symbols with a RedStone primary-prod
1532
+ feed are priced here. Symbols sourced on-chain from BaseOracle TWAP show as
1533
+ balance-only (the SolvencyFacet still values them for the total/debt figures).
1534
+
1535
+ With --json: emits a single JSON object covering wallet, account, native
1536
+ balance, per-asset supplied/borrowed with optional USD, poolDeposits (the EOA's
1537
+ 'Diamond Hands' lending-pool balances, emitted even with no Degen Account),
1538
+ total/debt/health-ratio/solvent flags. Null fields, empty lists, and empty dicts are dropped (same
1539
+ trim contract as `deltaprime defi --json`). Numeric 0 and boolean false are
1540
+ preserved."""
1541
+ w3 = get_w3()
1542
+ acct = get_account()
1543
+ pa = get_prime_account(w3, acct.address)
1544
+ if not as_json:
1545
+ print(f"Wallet: {acct.address}")
1546
+
1547
+ pool_deposits = _gather_pool_deposits(w3, acct.address)
1548
+
1549
+ if not pa:
1550
+ # No Degen Account: still surface Diamond Hands deposits (balance-only — the
1551
+ # RedStone getPrices view lives on the Degen Account, absent here).
1552
+ if as_json:
1553
+ out = {"wallet": acct.address, "account": None}
1554
+ if pool_deposits:
1555
+ out["poolDeposits"] = [{"symbol": r["symbol"], "amount": r["raw"] / 10**r["decimals"]}
1556
+ for r in pool_deposits]
1557
+ print(json.dumps(out, indent=2))
1558
+ else:
1559
+ print("No Degen Account yet. Create one with: degenprime create-account --execute")
1560
+ if pool_deposits:
1561
+ print(" Pool Deposits (Diamond Hands):")
1562
+ for r in pool_deposits:
1563
+ print(f" {r['symbol']:<8} {r['raw'] / 10**r['decimals']:,.6f}")
1564
+ return
1565
+
1566
+ account = w3.eth.contract(address=Web3.to_checksum_address(pa), abi=PRIME_ACCOUNT_ABI)
1567
+ pa_eth, supplied, borrowed, solvency = _gather_account_state(w3, account, pool_deposits)
1568
+ if not as_json:
1569
+ print(f"Degen Account: {pa}")
1570
+ if pa_eth >= 1e-9:
1571
+ print(f" Native ETH (gas): {pa_eth:.6f}")
1452
1572
 
1453
1573
  if as_json:
1454
1574
  def _asset_row(r):
@@ -2315,6 +2435,8 @@ def _dispatch():
2315
2435
  cmd_create_account("--execute" in args, fund_pool, fund_amount)
2316
2436
  elif cmd == "summary":
2317
2437
  cmd_summary(as_json="--json" in args)
2438
+ elif cmd == "defi":
2439
+ cmd_defi("--json" in args)
2318
2440
  elif cmd == "fund":
2319
2441
  pool, amount = None, None
2320
2442
  execute = "--execute" in args
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: primecli
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Agent-friendly CLI tools for the DeltaPrime (Avalanche + Arbitrum) and DegenPrime (Base) lending and leverage protocols. Preview-by-default; no Etherscan key required.
5
5
  Author: Mnemosyne-quest contributors
6
6
  License: MIT
@@ -48,7 +48,7 @@ Built for agent use:
48
48
  - RedStone-signed solvency math handled internally, with a regression test pinning the half-boundary `toFixed(8)` encoding.
49
49
  - ParaSwap calldata validated client-side against the on-chain executor allowlist before broadcast.
50
50
 
51
- **Current version:** 0.5.1 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
51
+ **Current version:** 0.5.2 The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
52
52
 
53
53
  > **Breaking change in 0.5.0:** there is no longer a default signing key. Earlier versions silently fell back to a baked-in agent when no key was configured; that fallback has been removed. With no key configured, every command now fails closed with `No signing key found...`. Set a key explicitly (see [Configuration](#configuration)).
54
54
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "primecli"
7
- version = "0.5.1"
7
+ version = "0.5.2"
8
8
  description = "Agent-friendly CLI tools for the DeltaPrime (Avalanche + Arbitrum) and DegenPrime (Base) lending and leverage protocols. Preview-by-default; no Etherscan key required."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes
File without changes
File without changes
File without changes