primecli 0.1.2__tar.gz → 0.2.0__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.
- primecli-0.2.0/PKG-INFO +264 -0
- primecli-0.2.0/README.md +232 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli/degenprime.py +287 -61
- {primecli-0.1.2 → primecli-0.2.0}/primecli/deltaprime.py +509 -124
- primecli-0.2.0/primecli.egg-info/PKG-INFO +264 -0
- {primecli-0.1.2 → primecli-0.2.0}/pyproject.toml +3 -3
- primecli-0.1.2/PKG-INFO +0 -231
- primecli-0.1.2/README.md +0 -199
- primecli-0.1.2/primecli.egg-info/PKG-INFO +0 -231
- {primecli-0.1.2 → primecli-0.2.0}/LICENSE +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli/__init__.py +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli.egg-info/SOURCES.txt +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli.egg-info/dependency_links.txt +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli.egg-info/entry_points.txt +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli.egg-info/requires.txt +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/primecli.egg-info/top_level.txt +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/setup.cfg +0 -0
- {primecli-0.1.2 → primecli-0.2.0}/tests/test_redstone_encoding.py +0 -0
primecli-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: primecli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Agent-friendly CLI tools for the DeltaPrime (Avalanche) and DegenPrime (Base) lending and leverage protocols. Preview-by-default; no Etherscan key required.
|
|
5
|
+
Author: Mnemosyne-quest contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Mnemosyne-quest/primecli
|
|
8
|
+
Project-URL: Issues, https://github.com/Mnemosyne-quest/primecli/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/Mnemosyne-quest/primecli/tree/main/docs
|
|
10
|
+
Keywords: defi,deltaprime,degenprime,avalanche,base,lending,leverage,ethereum,web3,agent,cli
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Operating System :: MacOS
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: web3<8,>=7.0
|
|
27
|
+
Requires-Dist: eth-account>=0.13
|
|
28
|
+
Requires-Dist: eth-keys>=0.5
|
|
29
|
+
Requires-Dist: eth-abi>=5.0
|
|
30
|
+
Requires-Dist: requests>=2.31
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# primecli
|
|
34
|
+
|
|
35
|
+
> Command-line tools for the **DeltaPrime** (Avalanche C-chain) and **DegenPrime** (Base) lending and leverage protocols.
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/primecli/)
|
|
38
|
+
[](https://pypi.org/project/primecli/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
`primecli` installs two console commands, `deltaprime` and `degenprime`, that drive the lending and leverage protocols built by the DeltaPrimeLabs team on Avalanche C-chain and Base respectively. Both share a per-user smart-account architecture (EIP-2535 diamond) and are operated through the same CLI shape: savings pools, per-user Prime / Degen Accounts, borrow / repay / fund, swaps, debt refinancing, delayed collateral withdrawals. The Avalanche side additionally exposes GMX V2 LP (GM and GM+), TraderJoe V2 LB, sJOE staking, PRIME leverage tiers, and a leveraged-long zap macro. The Base side ships a read-only Aerodrome position inventory; write paths are deferred to v2.
|
|
42
|
+
|
|
43
|
+
Built for agent use:
|
|
44
|
+
|
|
45
|
+
- Preview by default. Every state-changing command prints the plan and stops unless you pass `--execute`.
|
|
46
|
+
- Predictable stdout. Read-only commands emit fixed-format tables or JSON.
|
|
47
|
+
- No Etherscan, Snowtrace, or Basescan API key required. Hand-curated ABIs, proxy reads via the EIP-1967 storage slot.
|
|
48
|
+
- RedStone-signed solvency math handled internally, with a regression test pinning the half-boundary `toFixed(8)` encoding.
|
|
49
|
+
- ParaSwap calldata validated client-side against the on-chain executor allowlist before broadcast.
|
|
50
|
+
|
|
51
|
+
**Current version:** 0.1.2. The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
|
|
52
|
+
|
|
53
|
+
## Security and trust
|
|
54
|
+
|
|
55
|
+
**This tool moves real on-chain funds.** Read before using.
|
|
56
|
+
|
|
57
|
+
- You manage your own private key. The tool reads it from `DELTAPRIME_PRIVATE_KEY` or `DEGENPRIME_PRIVATE_KEY` (or a file path you point at via `*_KEY_FILE`, or a one-shot `--key` flag). It never writes the key anywhere.
|
|
58
|
+
- Every state-changing command **previews by default**. You must pass `--execute` to broadcast. Don't pass `--execute` until you have read the preview and understand what it is about to do.
|
|
59
|
+
- The RedStone payload, ParaSwap executor allowlist, and facet ABIs are pinned to specific on-chain state at the dates noted in the source. If DeltaPrime or DegenPrime upgrade their diamonds, the tool may need updating. Open an issue.
|
|
60
|
+
- The DeltaPrimeLabs team is not affiliated with this project. This is community-maintained tooling.
|
|
61
|
+
|
|
62
|
+
Full threat model and trust assumptions: [docs/security.md](docs/security.md).
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
Requires Python 3.10+.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install primecli
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
From the latest `main` (ahead of the most recent release):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install git+https://github.com/Mnemosyne-quest/primecli.git
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
From a local clone (development):
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/Mnemosyne-quest/primecli.git
|
|
82
|
+
cd primecli
|
|
83
|
+
pip install -e .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Quickstart
|
|
87
|
+
|
|
88
|
+
Read-only commands work with no key configured. Set the key when you want to broadcast.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Read live pool state, no key needed.
|
|
92
|
+
deltaprime pool-info usdc
|
|
93
|
+
|
|
94
|
+
# Configure the key (or pass --key on each command for one-off use).
|
|
95
|
+
export DELTAPRIME_PRIVATE_KEY=0xabc...
|
|
96
|
+
|
|
97
|
+
# Preview a deposit. Prints the plan, broadcasts nothing.
|
|
98
|
+
deltaprime deposit --pool usdc --amount 100
|
|
99
|
+
|
|
100
|
+
# Broadcast.
|
|
101
|
+
deltaprime deposit --pool usdc --amount 100 --execute
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Same shape on Base. The same EVM key works on both chains, and `DEGENPRIME_PRIVATE_KEY` falls back to `DELTAPRIME_PRIVATE_KEY` if unset.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export DEGENPRIME_PRIVATE_KEY=0xabc... # optional; falls back to DELTAPRIME_PRIVATE_KEY
|
|
108
|
+
|
|
109
|
+
degenprime pool-info usdc
|
|
110
|
+
degenprime my-positions
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Commands
|
|
114
|
+
|
|
115
|
+
State-changing commands preview by default. Add `--execute` to broadcast.
|
|
116
|
+
|
|
117
|
+
### `deltaprime` (Avalanche C-chain)
|
|
118
|
+
|
|
119
|
+
| Group | Commands |
|
|
120
|
+
|-------|----------|
|
|
121
|
+
| Lending core | `pool-info [--json]`, `my-positions`, `deposit`, `withdraw`, `borrow`, `repay`, `fund` |
|
|
122
|
+
| Prime Account | `create-prime-account` (alias `create-account`), `prime-summary`, `defi --json`, `withdraw-collateral`, `withdrawal-intents`, `execute-withdrawal` |
|
|
123
|
+
| Swaps | `swap --from S --to S --amount N [--via yak\|paraswap] [--slippage P]`, `swap-debt --from S --to S --amount N [--slippage P]` |
|
|
124
|
+
| GMX V2 LP (async, keeper-executed) | `gmx-positions`, `gmx-deposit --market M --amount N [--side long\|short]`, `gmx-withdraw --market M --amount N` |
|
|
125
|
+
| TraderJoe V2 LB | `lb-positions`, `lb-add --pair P --amount-x N --amount-y N [--shape spot\|curve\|bidask] [--range R]`, `lb-remove --pair P` |
|
|
126
|
+
| sJOE staking | `sjoe-position`, `sjoe-stake --amount N`, `sjoe-unstake --amount N`, `sjoe-claim` |
|
|
127
|
+
| PRIME leverage tiers | `prime-tier`, `prime-needed --borrow X [--tier premium\|basic]`, `prime-deposit --amount N`, `prime-activate [--amount N]`, `prime-deactivate [--withdraw]`, `prime-unstake --amount N`, `prime-repay --amount N` |
|
|
128
|
+
| Zaps (multi-tx macro) | `zap --market M --collateral P --collateral-amount N --borrow-amount N --deposit-amount N [--side long\|short] [--swap]` |
|
|
129
|
+
|
|
130
|
+
Pools: `usdc`, `wavax`, `weth`, `btc`, `usdt`. GM markets: `avax-usdc`, `btc-usdc`, `eth-usdc` (two-sided GM); `avax+`, `btc+`, `eth+` (single-sided GM+). LB pairs: `avax-usdc`, `avax-usdc-20`, `btc-usdc`, `eth-avax`, `btc-avax`, `avax-btc`, `eurc-usdc`, `usdt-usdc`, `joe-avax`.
|
|
131
|
+
|
|
132
|
+
`defi --json` emits a full positions snapshot in a DeBank-like shape — `null`, empty-list, and empty-dict fields are stripped, and the decorative `url` key is dropped (numeric `0` and boolean `false` are preserved, since they carry real information). `pool-info --json` emits a single JSON object for a named pool, or a `{name: {...}}` dict for `all`. `zap` composes `fund` → `borrow` → optional `swap` → `gmx-deposit` into one preview-and-execute flow, stopping on the first failure.
|
|
133
|
+
|
|
134
|
+
Full per-command reference: [docs/deltaprime-reference.md](docs/deltaprime-reference.md). Per-capability build spec: [docs/deltaprime-capabilities.md](docs/deltaprime-capabilities.md).
|
|
135
|
+
|
|
136
|
+
### `degenprime` (Base)
|
|
137
|
+
|
|
138
|
+
| Group | Commands |
|
|
139
|
+
|-------|----------|
|
|
140
|
+
| Lending core | `pool-info [--json]`, `my-positions`, `deposit`, `withdraw`, `borrow`, `repay`, `fund` |
|
|
141
|
+
| Degen Account | `create-account`, `summary`, `withdraw-collateral`, `withdrawal-intents`, `execute-withdrawal`, `cancel-withdrawal` |
|
|
142
|
+
| Swaps | `swap --from S --to S --amount N [--slippage P]` (ParaSwap v6), `swap-debt --from S --to S --amount N` |
|
|
143
|
+
| Aerodrome (read-only in v1) | `aerodrome-positions` |
|
|
144
|
+
|
|
145
|
+
Pools (v1): `usdc`, `weth`, `cbbtc`, `aero`, `brett`, `kaito`, `cbdoge`, `cbxrp`. Beyond the lendable pools, the on-chain TokenManager exposes 32 collateral symbols (memecoins, LSTs, blue-chips) usable for `swap` / `swap-debt`.
|
|
146
|
+
|
|
147
|
+
`aerodrome-positions` lists owned and staked Aerodrome NFT tokenIds. Composition decoding and write paths (claim, decrease, add, stake) are deferred to v2.
|
|
148
|
+
|
|
149
|
+
Full per-command reference: [docs/degenprime-reference.md](docs/degenprime-reference.md). Per-capability build spec: [docs/degenprime-capabilities.md](docs/degenprime-capabilities.md).
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
| Env var | Default | Purpose |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `DELTAPRIME_PRIVATE_KEY` | — | Your Avalanche signing key. Raw `0x...` hex. |
|
|
156
|
+
| `DELTAPRIME_KEY_FILE` | — | Path to a file containing the key. Use this if you don't want the key in process env. |
|
|
157
|
+
| `DELTAPRIME_RPC` | `https://api.avax.network/ext/bc/C/rpc` | Avalanche C-chain RPC. Override with a paid Alchemy / QuickNode / Infura endpoint for high-throughput use. |
|
|
158
|
+
| `DEGENPRIME_PRIVATE_KEY` | falls back to `DELTAPRIME_PRIVATE_KEY` | Your Base signing key. Same EVM key works on both chains. |
|
|
159
|
+
| `DEGENPRIME_KEY_FILE` | falls back to `DELTAPRIME_KEY_FILE` | Path to key file for Base. |
|
|
160
|
+
| `DEGENPRIME_RPC` | `https://base.publicnode.com` | Base RPC. |
|
|
161
|
+
|
|
162
|
+
The CLI also accepts a per-command `--key <0xhex>` override that takes precedence over all env vars. Handy for one-off operations from a shell where you don't want to persist the key.
|
|
163
|
+
|
|
164
|
+
A copy-paste template is at [examples/env.example](examples/env.example).
|
|
165
|
+
|
|
166
|
+
## What's covered
|
|
167
|
+
|
|
168
|
+
### `deltaprime` (Avalanche C-chain)
|
|
169
|
+
|
|
170
|
+
| Area | Status |
|
|
171
|
+
|------|--------|
|
|
172
|
+
| Savings pools (USDC, WAVAX, WETH, BTC, USDT) | full read + write |
|
|
173
|
+
| Prime Account creation and funding | full |
|
|
174
|
+
| Borrow / repay / fund / withdraw-collateral | full |
|
|
175
|
+
| Solvency views (health ratio, total value, debt, solvent flag) | full (RedStone-gated reads) |
|
|
176
|
+
| Swap (YieldYak + ParaSwap) | full |
|
|
177
|
+
| Swap-debt (debt refinancing) | full |
|
|
178
|
+
| GMX V2 LP (GM + GM+, 6 markets) | full (async, account freezes until keeper callback) |
|
|
179
|
+
| TraderJoe V2 LB (9 whitelisted pairs) | full (max 80 bins per account) |
|
|
180
|
+
| sJOE staking | full |
|
|
181
|
+
| PRIME leverage tiers (BASIC / PREMIUM) | full |
|
|
182
|
+
| Leveraged-long zap macro | full (GM-terminal) |
|
|
183
|
+
| Wombat / GLP / Pangolin LP | not yet (specced in docs) |
|
|
184
|
+
|
|
185
|
+
### `degenprime` (Base)
|
|
186
|
+
|
|
187
|
+
| Area | Status |
|
|
188
|
+
|------|--------|
|
|
189
|
+
| Savings pools (8 v1 pools) | full read + write |
|
|
190
|
+
| Degen Account creation and funding | full |
|
|
191
|
+
| Borrow / repay / fund | full |
|
|
192
|
+
| Universal 24h delayed collateral withdrawal | full (3-step create / list / execute, plus cancel) |
|
|
193
|
+
| Solvency views | full (RedStone-gated reads, with BaseOracle TWAP fallback for non-RedStone symbols) |
|
|
194
|
+
| Swap (ParaSwap v6) | full |
|
|
195
|
+
| Swap-debt | full (both legs must have RedStone feeds) |
|
|
196
|
+
| Aerodrome positions | read-only (tokenId inventory) |
|
|
197
|
+
| Aerodrome write paths (claim, decrease, add, stake) | deferred to v2 |
|
|
198
|
+
| `$DgP` staking | not deployed on-chain yet |
|
|
199
|
+
|
|
200
|
+
## Documentation
|
|
201
|
+
|
|
202
|
+
- [DeltaPrime reference](docs/deltaprime-reference.md): protocol model, addresses, facet map, RedStone integration, full command table, GMX / LB / PRIME flows.
|
|
203
|
+
- [DeltaPrime capabilities](docs/deltaprime-capabilities.md): per-command build spec with function signatures, parameter encoding, approve targets, slippage / oracle / exec-fee requirements.
|
|
204
|
+
- [DegenPrime reference](docs/degenprime-reference.md): Base-side equivalent.
|
|
205
|
+
- [DegenPrime capabilities](docs/degenprime-capabilities.md): Base-side per-command build spec.
|
|
206
|
+
- [Security model](docs/security.md): key handling, preview-by-default, ParaSwap executor allowlist, RedStone trust model, threat model.
|
|
207
|
+
|
|
208
|
+
## Using from an AI agent
|
|
209
|
+
|
|
210
|
+
`primecli` is built for autonomous and semi-autonomous use. Three properties matter:
|
|
211
|
+
|
|
212
|
+
1. **Preview by default.** Every state-changing command prints a structured preview and stops unless `--execute` is passed. An agent can call any command speculatively, parse the preview, decide whether to broadcast, then re-run with `--execute`.
|
|
213
|
+
2. **Predictable, parseable stdout.** Read-only commands (`pool-info` (also `--json`), `my-positions`, `prime-summary`, `summary`, `withdrawal-intents`, `lb-positions`, `gmx-positions`, `aerodrome-positions`, `sjoe-position`, `prime-tier`, `defi --json`) emit fixed-format tables or JSON. `defi --json` is a one-shot full positions snapshot.
|
|
214
|
+
3. **Clean failure modes.** Configuration errors do not print stack traces. A missing key prints `deltaprime: No signing key found. Set DELTAPRIME_PRIVATE_KEY ...` to stderr and exits 1.
|
|
215
|
+
|
|
216
|
+
Full agent integration guide (Claude Code skill template, MCP notes, recommended guardrails): [docs/agent-integration.md](docs/agent-integration.md).
|
|
217
|
+
|
|
218
|
+
### Drop-in patterns
|
|
219
|
+
|
|
220
|
+
**Shell-tooled agents** (Claude Code, Cursor agent mode, Aider, OpenAI Codex CLI, custom bash-using agents). Install with `pip install primecli`, set the env var, and the agent calls `deltaprime` / `degenprime` as normal CLI commands. No further wiring.
|
|
221
|
+
|
|
222
|
+
**Claude Code skills.** Drop a `SKILL.md` into `.claude/skills/deltaprime/` (or `degenprime/`) describing when to invoke the tool and which commands are read-only vs state-changing. Starter template in [docs/agent-integration.md](docs/agent-integration.md).
|
|
223
|
+
|
|
224
|
+
**MCP server.** Not shipped in v0.1. If you have a use case, file an issue. The wrapper is a few hundred lines of FastMCP.
|
|
225
|
+
|
|
226
|
+
### Recommended guardrails
|
|
227
|
+
|
|
228
|
+
- Never store `--execute` in a model-controlled string. Treat it as a separate authorisation step the operator (or a deliberate policy layer) attaches after seeing the preview.
|
|
229
|
+
- Cap daily spend with an external budget check. The tool has no built-in caps; that is the operator's responsibility.
|
|
230
|
+
- Log the preview before broadcasting. If the agent decided to swap 100 USDC and the preview says 100,000 USDC, the operator needs to see that.
|
|
231
|
+
|
|
232
|
+
## Troubleshooting
|
|
233
|
+
|
|
234
|
+
Common failure modes and their fixes:
|
|
235
|
+
|
|
236
|
+
- **`No signing key found`.** Set `DELTAPRIME_PRIVATE_KEY` (or `DEGENPRIME_PRIVATE_KEY`), or point `*_KEY_FILE` at a file holding the key, or pass `--key 0x...` for a one-off command.
|
|
237
|
+
- **RPC rate-limited (429 or stalls).** The default public RPCs are fine for occasional reads. For sustained or write-heavy use, point `DELTAPRIME_RPC` / `DEGENPRIME_RPC` at a paid endpoint (Alchemy, QuickNode, Infura, your own node).
|
|
238
|
+
- **`RedStone gateway unreachable` on a read.** `prime-summary` / `summary` fall back to balances-only when the RedStone gateway is down. On `--execute` of a solvency-gated write, the call cannot proceed without a payload; wait and retry, or try the alternate gateway via the env override.
|
|
239
|
+
- **Swap fails on-chain with `InvalidExecutor`.** ParaSwap rotated an executor that is not in the tool's mirror of the on-chain allowlist. The tool patches to a known-good fallback automatically; if reverts persist, the on-chain allowlist itself has likely rotated. Open an issue.
|
|
240
|
+
- **GMX deposit reverts `InsufficientNumberOfUniqueSigners(0,3)`.** A required RedStone feed was missing from the appended payload. This was the load-bearing fix on the GMX path (24-05-2026). If you hit it on a current build, capture the tx hash and open an issue.
|
|
241
|
+
- **GMX deposit accepted but no GM minted.** The execution fee was below the keeper's threshold and the request expired (refund without mint). Re-run; the tool floors gas at 25 gwei in the fee estimator to clear the keeper's bar.
|
|
242
|
+
- **`createLoan` succeeded but `getLoansForOwner` returns empty.** The factory's owner→loans map lags a beat behind the receipt. The tool polls for up to 12s; rerun `my-positions` shortly after if it timed out.
|
|
243
|
+
|
|
244
|
+
If your failure is not on this list and the on-chain revert reason is opaque, capture the tx hash, the exact CLI invocation, and the preview output, and file an issue.
|
|
245
|
+
|
|
246
|
+
## Versions and releases
|
|
247
|
+
|
|
248
|
+
`primecli` is on a 0.x line. **Breaking changes are possible** between minor versions until 1.0. Once the on-chain surface stabilises and the v2 work (DegenPrime Aerodrome writes, Wombat / GLP on DeltaPrime) is in, the project will commit to semver.
|
|
249
|
+
|
|
250
|
+
- Latest version on PyPI: <https://pypi.org/project/primecli/>.
|
|
251
|
+
- Per-version release notes: <https://github.com/Mnemosyne-quest/primecli/releases>.
|
|
252
|
+
- The `main` branch may be ahead of the latest tagged release; install from git if you need the bleeding edge.
|
|
253
|
+
|
|
254
|
+
## Contributing
|
|
255
|
+
|
|
256
|
+
PRs welcome. Open an issue first if you are planning anything non-trivial (new facet support, new chain, write paths for Aerodrome). Pinning ABIs and verifying on-chain shapes takes a real probe pass, and it is worth aligning before doing the work.
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT. See [LICENSE](LICENSE).
|
|
261
|
+
|
|
262
|
+
## Acknowledgements
|
|
263
|
+
|
|
264
|
+
Built on the work of the [DeltaPrimeLabs team](https://www.deltaprime.io/) (DeltaPrime + DegenPrime) and the broader DeFi tooling ecosystem: web3.py, eth-account, RedStone, ParaSwap (Velora), YieldYak, TraderJoe (LFJ), GMX, Aerodrome.
|
primecli-0.2.0/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# primecli
|
|
2
|
+
|
|
3
|
+
> Command-line tools for the **DeltaPrime** (Avalanche C-chain) and **DegenPrime** (Base) lending and leverage protocols.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/primecli/)
|
|
6
|
+
[](https://pypi.org/project/primecli/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
`primecli` installs two console commands, `deltaprime` and `degenprime`, that drive the lending and leverage protocols built by the DeltaPrimeLabs team on Avalanche C-chain and Base respectively. Both share a per-user smart-account architecture (EIP-2535 diamond) and are operated through the same CLI shape: savings pools, per-user Prime / Degen Accounts, borrow / repay / fund, swaps, debt refinancing, delayed collateral withdrawals. The Avalanche side additionally exposes GMX V2 LP (GM and GM+), TraderJoe V2 LB, sJOE staking, PRIME leverage tiers, and a leveraged-long zap macro. The Base side ships a read-only Aerodrome position inventory; write paths are deferred to v2.
|
|
10
|
+
|
|
11
|
+
Built for agent use:
|
|
12
|
+
|
|
13
|
+
- Preview by default. Every state-changing command prints the plan and stops unless you pass `--execute`.
|
|
14
|
+
- Predictable stdout. Read-only commands emit fixed-format tables or JSON.
|
|
15
|
+
- No Etherscan, Snowtrace, or Basescan API key required. Hand-curated ABIs, proxy reads via the EIP-1967 storage slot.
|
|
16
|
+
- RedStone-signed solvency math handled internally, with a regression test pinning the half-boundary `toFixed(8)` encoding.
|
|
17
|
+
- ParaSwap calldata validated client-side against the on-chain executor allowlist before broadcast.
|
|
18
|
+
|
|
19
|
+
**Current version:** 0.1.2. The 0.x line is pre-1.0, so breaking changes are possible. See [Releases](https://github.com/Mnemosyne-quest/primecli/releases).
|
|
20
|
+
|
|
21
|
+
## Security and trust
|
|
22
|
+
|
|
23
|
+
**This tool moves real on-chain funds.** Read before using.
|
|
24
|
+
|
|
25
|
+
- You manage your own private key. The tool reads it from `DELTAPRIME_PRIVATE_KEY` or `DEGENPRIME_PRIVATE_KEY` (or a file path you point at via `*_KEY_FILE`, or a one-shot `--key` flag). It never writes the key anywhere.
|
|
26
|
+
- Every state-changing command **previews by default**. You must pass `--execute` to broadcast. Don't pass `--execute` until you have read the preview and understand what it is about to do.
|
|
27
|
+
- The RedStone payload, ParaSwap executor allowlist, and facet ABIs are pinned to specific on-chain state at the dates noted in the source. If DeltaPrime or DegenPrime upgrade their diamonds, the tool may need updating. Open an issue.
|
|
28
|
+
- The DeltaPrimeLabs team is not affiliated with this project. This is community-maintained tooling.
|
|
29
|
+
|
|
30
|
+
Full threat model and trust assumptions: [docs/security.md](docs/security.md).
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Requires Python 3.10+.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install primecli
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
From the latest `main` (ahead of the most recent release):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install git+https://github.com/Mnemosyne-quest/primecli.git
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
From a local clone (development):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/Mnemosyne-quest/primecli.git
|
|
50
|
+
cd primecli
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quickstart
|
|
55
|
+
|
|
56
|
+
Read-only commands work with no key configured. Set the key when you want to broadcast.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Read live pool state, no key needed.
|
|
60
|
+
deltaprime pool-info usdc
|
|
61
|
+
|
|
62
|
+
# Configure the key (or pass --key on each command for one-off use).
|
|
63
|
+
export DELTAPRIME_PRIVATE_KEY=0xabc...
|
|
64
|
+
|
|
65
|
+
# Preview a deposit. Prints the plan, broadcasts nothing.
|
|
66
|
+
deltaprime deposit --pool usdc --amount 100
|
|
67
|
+
|
|
68
|
+
# Broadcast.
|
|
69
|
+
deltaprime deposit --pool usdc --amount 100 --execute
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Same shape on Base. The same EVM key works on both chains, and `DEGENPRIME_PRIVATE_KEY` falls back to `DELTAPRIME_PRIVATE_KEY` if unset.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
export DEGENPRIME_PRIVATE_KEY=0xabc... # optional; falls back to DELTAPRIME_PRIVATE_KEY
|
|
76
|
+
|
|
77
|
+
degenprime pool-info usdc
|
|
78
|
+
degenprime my-positions
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Commands
|
|
82
|
+
|
|
83
|
+
State-changing commands preview by default. Add `--execute` to broadcast.
|
|
84
|
+
|
|
85
|
+
### `deltaprime` (Avalanche C-chain)
|
|
86
|
+
|
|
87
|
+
| Group | Commands |
|
|
88
|
+
|-------|----------|
|
|
89
|
+
| Lending core | `pool-info [--json]`, `my-positions`, `deposit`, `withdraw`, `borrow`, `repay`, `fund` |
|
|
90
|
+
| Prime Account | `create-prime-account` (alias `create-account`), `prime-summary`, `defi --json`, `withdraw-collateral`, `withdrawal-intents`, `execute-withdrawal` |
|
|
91
|
+
| Swaps | `swap --from S --to S --amount N [--via yak\|paraswap] [--slippage P]`, `swap-debt --from S --to S --amount N [--slippage P]` |
|
|
92
|
+
| GMX V2 LP (async, keeper-executed) | `gmx-positions`, `gmx-deposit --market M --amount N [--side long\|short]`, `gmx-withdraw --market M --amount N` |
|
|
93
|
+
| TraderJoe V2 LB | `lb-positions`, `lb-add --pair P --amount-x N --amount-y N [--shape spot\|curve\|bidask] [--range R]`, `lb-remove --pair P` |
|
|
94
|
+
| sJOE staking | `sjoe-position`, `sjoe-stake --amount N`, `sjoe-unstake --amount N`, `sjoe-claim` |
|
|
95
|
+
| PRIME leverage tiers | `prime-tier`, `prime-needed --borrow X [--tier premium\|basic]`, `prime-deposit --amount N`, `prime-activate [--amount N]`, `prime-deactivate [--withdraw]`, `prime-unstake --amount N`, `prime-repay --amount N` |
|
|
96
|
+
| Zaps (multi-tx macro) | `zap --market M --collateral P --collateral-amount N --borrow-amount N --deposit-amount N [--side long\|short] [--swap]` |
|
|
97
|
+
|
|
98
|
+
Pools: `usdc`, `wavax`, `weth`, `btc`, `usdt`. GM markets: `avax-usdc`, `btc-usdc`, `eth-usdc` (two-sided GM); `avax+`, `btc+`, `eth+` (single-sided GM+). LB pairs: `avax-usdc`, `avax-usdc-20`, `btc-usdc`, `eth-avax`, `btc-avax`, `avax-btc`, `eurc-usdc`, `usdt-usdc`, `joe-avax`.
|
|
99
|
+
|
|
100
|
+
`defi --json` emits a full positions snapshot in a DeBank-like shape — `null`, empty-list, and empty-dict fields are stripped, and the decorative `url` key is dropped (numeric `0` and boolean `false` are preserved, since they carry real information). `pool-info --json` emits a single JSON object for a named pool, or a `{name: {...}}` dict for `all`. `zap` composes `fund` → `borrow` → optional `swap` → `gmx-deposit` into one preview-and-execute flow, stopping on the first failure.
|
|
101
|
+
|
|
102
|
+
Full per-command reference: [docs/deltaprime-reference.md](docs/deltaprime-reference.md). Per-capability build spec: [docs/deltaprime-capabilities.md](docs/deltaprime-capabilities.md).
|
|
103
|
+
|
|
104
|
+
### `degenprime` (Base)
|
|
105
|
+
|
|
106
|
+
| Group | Commands |
|
|
107
|
+
|-------|----------|
|
|
108
|
+
| Lending core | `pool-info [--json]`, `my-positions`, `deposit`, `withdraw`, `borrow`, `repay`, `fund` |
|
|
109
|
+
| Degen Account | `create-account`, `summary`, `withdraw-collateral`, `withdrawal-intents`, `execute-withdrawal`, `cancel-withdrawal` |
|
|
110
|
+
| Swaps | `swap --from S --to S --amount N [--slippage P]` (ParaSwap v6), `swap-debt --from S --to S --amount N` |
|
|
111
|
+
| Aerodrome (read-only in v1) | `aerodrome-positions` |
|
|
112
|
+
|
|
113
|
+
Pools (v1): `usdc`, `weth`, `cbbtc`, `aero`, `brett`, `kaito`, `cbdoge`, `cbxrp`. Beyond the lendable pools, the on-chain TokenManager exposes 32 collateral symbols (memecoins, LSTs, blue-chips) usable for `swap` / `swap-debt`.
|
|
114
|
+
|
|
115
|
+
`aerodrome-positions` lists owned and staked Aerodrome NFT tokenIds. Composition decoding and write paths (claim, decrease, add, stake) are deferred to v2.
|
|
116
|
+
|
|
117
|
+
Full per-command reference: [docs/degenprime-reference.md](docs/degenprime-reference.md). Per-capability build spec: [docs/degenprime-capabilities.md](docs/degenprime-capabilities.md).
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
| Env var | Default | Purpose |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `DELTAPRIME_PRIVATE_KEY` | — | Your Avalanche signing key. Raw `0x...` hex. |
|
|
124
|
+
| `DELTAPRIME_KEY_FILE` | — | Path to a file containing the key. Use this if you don't want the key in process env. |
|
|
125
|
+
| `DELTAPRIME_RPC` | `https://api.avax.network/ext/bc/C/rpc` | Avalanche C-chain RPC. Override with a paid Alchemy / QuickNode / Infura endpoint for high-throughput use. |
|
|
126
|
+
| `DEGENPRIME_PRIVATE_KEY` | falls back to `DELTAPRIME_PRIVATE_KEY` | Your Base signing key. Same EVM key works on both chains. |
|
|
127
|
+
| `DEGENPRIME_KEY_FILE` | falls back to `DELTAPRIME_KEY_FILE` | Path to key file for Base. |
|
|
128
|
+
| `DEGENPRIME_RPC` | `https://base.publicnode.com` | Base RPC. |
|
|
129
|
+
|
|
130
|
+
The CLI also accepts a per-command `--key <0xhex>` override that takes precedence over all env vars. Handy for one-off operations from a shell where you don't want to persist the key.
|
|
131
|
+
|
|
132
|
+
A copy-paste template is at [examples/env.example](examples/env.example).
|
|
133
|
+
|
|
134
|
+
## What's covered
|
|
135
|
+
|
|
136
|
+
### `deltaprime` (Avalanche C-chain)
|
|
137
|
+
|
|
138
|
+
| Area | Status |
|
|
139
|
+
|------|--------|
|
|
140
|
+
| Savings pools (USDC, WAVAX, WETH, BTC, USDT) | full read + write |
|
|
141
|
+
| Prime Account creation and funding | full |
|
|
142
|
+
| Borrow / repay / fund / withdraw-collateral | full |
|
|
143
|
+
| Solvency views (health ratio, total value, debt, solvent flag) | full (RedStone-gated reads) |
|
|
144
|
+
| Swap (YieldYak + ParaSwap) | full |
|
|
145
|
+
| Swap-debt (debt refinancing) | full |
|
|
146
|
+
| GMX V2 LP (GM + GM+, 6 markets) | full (async, account freezes until keeper callback) |
|
|
147
|
+
| TraderJoe V2 LB (9 whitelisted pairs) | full (max 80 bins per account) |
|
|
148
|
+
| sJOE staking | full |
|
|
149
|
+
| PRIME leverage tiers (BASIC / PREMIUM) | full |
|
|
150
|
+
| Leveraged-long zap macro | full (GM-terminal) |
|
|
151
|
+
| Wombat / GLP / Pangolin LP | not yet (specced in docs) |
|
|
152
|
+
|
|
153
|
+
### `degenprime` (Base)
|
|
154
|
+
|
|
155
|
+
| Area | Status |
|
|
156
|
+
|------|--------|
|
|
157
|
+
| Savings pools (8 v1 pools) | full read + write |
|
|
158
|
+
| Degen Account creation and funding | full |
|
|
159
|
+
| Borrow / repay / fund | full |
|
|
160
|
+
| Universal 24h delayed collateral withdrawal | full (3-step create / list / execute, plus cancel) |
|
|
161
|
+
| Solvency views | full (RedStone-gated reads, with BaseOracle TWAP fallback for non-RedStone symbols) |
|
|
162
|
+
| Swap (ParaSwap v6) | full |
|
|
163
|
+
| Swap-debt | full (both legs must have RedStone feeds) |
|
|
164
|
+
| Aerodrome positions | read-only (tokenId inventory) |
|
|
165
|
+
| Aerodrome write paths (claim, decrease, add, stake) | deferred to v2 |
|
|
166
|
+
| `$DgP` staking | not deployed on-chain yet |
|
|
167
|
+
|
|
168
|
+
## Documentation
|
|
169
|
+
|
|
170
|
+
- [DeltaPrime reference](docs/deltaprime-reference.md): protocol model, addresses, facet map, RedStone integration, full command table, GMX / LB / PRIME flows.
|
|
171
|
+
- [DeltaPrime capabilities](docs/deltaprime-capabilities.md): per-command build spec with function signatures, parameter encoding, approve targets, slippage / oracle / exec-fee requirements.
|
|
172
|
+
- [DegenPrime reference](docs/degenprime-reference.md): Base-side equivalent.
|
|
173
|
+
- [DegenPrime capabilities](docs/degenprime-capabilities.md): Base-side per-command build spec.
|
|
174
|
+
- [Security model](docs/security.md): key handling, preview-by-default, ParaSwap executor allowlist, RedStone trust model, threat model.
|
|
175
|
+
|
|
176
|
+
## Using from an AI agent
|
|
177
|
+
|
|
178
|
+
`primecli` is built for autonomous and semi-autonomous use. Three properties matter:
|
|
179
|
+
|
|
180
|
+
1. **Preview by default.** Every state-changing command prints a structured preview and stops unless `--execute` is passed. An agent can call any command speculatively, parse the preview, decide whether to broadcast, then re-run with `--execute`.
|
|
181
|
+
2. **Predictable, parseable stdout.** Read-only commands (`pool-info` (also `--json`), `my-positions`, `prime-summary`, `summary`, `withdrawal-intents`, `lb-positions`, `gmx-positions`, `aerodrome-positions`, `sjoe-position`, `prime-tier`, `defi --json`) emit fixed-format tables or JSON. `defi --json` is a one-shot full positions snapshot.
|
|
182
|
+
3. **Clean failure modes.** Configuration errors do not print stack traces. A missing key prints `deltaprime: No signing key found. Set DELTAPRIME_PRIVATE_KEY ...` to stderr and exits 1.
|
|
183
|
+
|
|
184
|
+
Full agent integration guide (Claude Code skill template, MCP notes, recommended guardrails): [docs/agent-integration.md](docs/agent-integration.md).
|
|
185
|
+
|
|
186
|
+
### Drop-in patterns
|
|
187
|
+
|
|
188
|
+
**Shell-tooled agents** (Claude Code, Cursor agent mode, Aider, OpenAI Codex CLI, custom bash-using agents). Install with `pip install primecli`, set the env var, and the agent calls `deltaprime` / `degenprime` as normal CLI commands. No further wiring.
|
|
189
|
+
|
|
190
|
+
**Claude Code skills.** Drop a `SKILL.md` into `.claude/skills/deltaprime/` (or `degenprime/`) describing when to invoke the tool and which commands are read-only vs state-changing. Starter template in [docs/agent-integration.md](docs/agent-integration.md).
|
|
191
|
+
|
|
192
|
+
**MCP server.** Not shipped in v0.1. If you have a use case, file an issue. The wrapper is a few hundred lines of FastMCP.
|
|
193
|
+
|
|
194
|
+
### Recommended guardrails
|
|
195
|
+
|
|
196
|
+
- Never store `--execute` in a model-controlled string. Treat it as a separate authorisation step the operator (or a deliberate policy layer) attaches after seeing the preview.
|
|
197
|
+
- Cap daily spend with an external budget check. The tool has no built-in caps; that is the operator's responsibility.
|
|
198
|
+
- Log the preview before broadcasting. If the agent decided to swap 100 USDC and the preview says 100,000 USDC, the operator needs to see that.
|
|
199
|
+
|
|
200
|
+
## Troubleshooting
|
|
201
|
+
|
|
202
|
+
Common failure modes and their fixes:
|
|
203
|
+
|
|
204
|
+
- **`No signing key found`.** Set `DELTAPRIME_PRIVATE_KEY` (or `DEGENPRIME_PRIVATE_KEY`), or point `*_KEY_FILE` at a file holding the key, or pass `--key 0x...` for a one-off command.
|
|
205
|
+
- **RPC rate-limited (429 or stalls).** The default public RPCs are fine for occasional reads. For sustained or write-heavy use, point `DELTAPRIME_RPC` / `DEGENPRIME_RPC` at a paid endpoint (Alchemy, QuickNode, Infura, your own node).
|
|
206
|
+
- **`RedStone gateway unreachable` on a read.** `prime-summary` / `summary` fall back to balances-only when the RedStone gateway is down. On `--execute` of a solvency-gated write, the call cannot proceed without a payload; wait and retry, or try the alternate gateway via the env override.
|
|
207
|
+
- **Swap fails on-chain with `InvalidExecutor`.** ParaSwap rotated an executor that is not in the tool's mirror of the on-chain allowlist. The tool patches to a known-good fallback automatically; if reverts persist, the on-chain allowlist itself has likely rotated. Open an issue.
|
|
208
|
+
- **GMX deposit reverts `InsufficientNumberOfUniqueSigners(0,3)`.** A required RedStone feed was missing from the appended payload. This was the load-bearing fix on the GMX path (24-05-2026). If you hit it on a current build, capture the tx hash and open an issue.
|
|
209
|
+
- **GMX deposit accepted but no GM minted.** The execution fee was below the keeper's threshold and the request expired (refund without mint). Re-run; the tool floors gas at 25 gwei in the fee estimator to clear the keeper's bar.
|
|
210
|
+
- **`createLoan` succeeded but `getLoansForOwner` returns empty.** The factory's owner→loans map lags a beat behind the receipt. The tool polls for up to 12s; rerun `my-positions` shortly after if it timed out.
|
|
211
|
+
|
|
212
|
+
If your failure is not on this list and the on-chain revert reason is opaque, capture the tx hash, the exact CLI invocation, and the preview output, and file an issue.
|
|
213
|
+
|
|
214
|
+
## Versions and releases
|
|
215
|
+
|
|
216
|
+
`primecli` is on a 0.x line. **Breaking changes are possible** between minor versions until 1.0. Once the on-chain surface stabilises and the v2 work (DegenPrime Aerodrome writes, Wombat / GLP on DeltaPrime) is in, the project will commit to semver.
|
|
217
|
+
|
|
218
|
+
- Latest version on PyPI: <https://pypi.org/project/primecli/>.
|
|
219
|
+
- Per-version release notes: <https://github.com/Mnemosyne-quest/primecli/releases>.
|
|
220
|
+
- The `main` branch may be ahead of the latest tagged release; install from git if you need the bleeding edge.
|
|
221
|
+
|
|
222
|
+
## Contributing
|
|
223
|
+
|
|
224
|
+
PRs welcome. Open an issue first if you are planning anything non-trivial (new facet support, new chain, write paths for Aerodrome). Pinning ABIs and verifying on-chain shapes takes a real probe pass, and it is worth aligning before doing the work.
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT. See [LICENSE](LICENSE).
|
|
229
|
+
|
|
230
|
+
## Acknowledgements
|
|
231
|
+
|
|
232
|
+
Built on the work of the [DeltaPrimeLabs team](https://www.deltaprime.io/) (DeltaPrime + DegenPrime) and the broader DeFi tooling ecosystem: web3.py, eth-account, RedStone, ParaSwap (Velora), YieldYak, TraderJoe (LFJ), GMX, Aerodrome.
|