perp-cli 0.3.17 → 0.3.18

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.
@@ -225,8 +225,8 @@ describe("computeAutoSize", () => {
225
225
  bids: [["99", "10000"]], // $990K depth
226
226
  });
227
227
  const size = await computeAutoSize(longAdapter, shortAdapter, "BTC", 5.0);
228
- // Default maxPositionUsd is 5000
229
- expect(size).toBeLessThanOrEqual(5000);
228
+ // Default maxPositionUsd is 100000
229
+ expect(size).toBeLessThanOrEqual(100000);
230
230
  });
231
231
  });
232
232
  // ── Rebalance computation ──
@@ -97,15 +97,29 @@ export class LighterAdapter {
97
97
  }
98
98
  // Initialize signer for trading if we have an API key (reuse singleton WASM client)
99
99
  if (this._apiKey && !signerReady) {
100
- const client = await LighterAdapter.getWasmClient();
101
- await client.createClient({
102
- url: this._baseUrl,
103
- privateKey: this._apiKey,
104
- chainId: this._chainId,
105
- apiKeyIndex: this._apiKeyIndex,
106
- accountIndex: this._accountIndex,
107
- });
108
- this._signer = client;
100
+ // Clean & validate API key before passing to WASM (Go hex decoder gives cryptic errors on non-hex)
101
+ let cleanKey = this._apiKey.trim().replace(/['"` \t\n\r.]/g, "");
102
+ if (cleanKey.startsWith("0x"))
103
+ cleanKey = cleanKey.slice(2);
104
+ if (cleanKey.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanKey)) {
105
+ console.error(`[lighter] API key contains invalid chars (expected hex). Check LIGHTER_API_KEY in ~/.perp/.env or run 'perp -e lighter manage setup-api-key' to regenerate.`);
106
+ this._apiKey = "";
107
+ }
108
+ else if (cleanKey.length === 0) {
109
+ this._apiKey = "";
110
+ }
111
+ else {
112
+ this._apiKey = cleanKey;
113
+ const client = await LighterAdapter.getWasmClient();
114
+ await client.createClient({
115
+ url: this._baseUrl,
116
+ privateKey: this._apiKey,
117
+ chainId: this._chainId,
118
+ apiKeyIndex: this._apiKeyIndex,
119
+ accountIndex: this._accountIndex,
120
+ });
121
+ this._signer = client;
122
+ }
109
123
  }
110
124
  if (this._apiKey) {
111
125
  this._readOnly = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perp-cli",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "Multi-DEX Perpetual Futures CLI - Pacifica, Hyperliquid, Lighter",
5
5
  "bin": {
6
6
  "perp": "dist/index.js",
@@ -5,7 +5,7 @@ allowed-tools: "Bash(perp:*), Bash(npx perp-cli:*), Bash(npx -y perp-cli:*)"
5
5
  license: MIT
6
6
  metadata:
7
7
  author: hypurrquant
8
- version: "0.3.17"
8
+ version: "0.3.18"
9
9
  ---
10
10
 
11
11
  # perp-cli Agent Guide
@@ -138,10 +138,20 @@ Close both: perp --json -e <EX1> trade close <SYM> & perp --json -e <EX2> trade
138
138
 
139
139
  Responses: `{ "ok": true, "data": {...} }` or `{ "ok": false, "error": { "code": "...", "retryable": true/false } }`
140
140
 
141
- - **Retryable** (wait 5s, max 3 retries): `RATE_LIMITED`, `EXCHANGE_UNREACHABLE`, `TIMEOUT`
142
- - **Non-retryable**: `INSUFFICIENT_BALANCE`, `SYMBOL_NOT_FOUND`, `RISK_VIOLATION` — fix the cause, don't retry
143
- - **Lighter `invalid signature`**: `perp --json -e lighter manage setup-api-key`
144
- - If `error.retryable` is `false`, do NOT retry. Report to user.
141
+ If `error.retryable` is `false`, do NOT retry — fix the cause first.
142
+
143
+ | Error | Action |
144
+ |-------|--------|
145
+ | `RATE_LIMITED` | wait 5s, retry (max 3) |
146
+ | `EXCHANGE_UNREACHABLE` | wait 10s, retry. 3x fail → skip that exchange |
147
+ | `TIMEOUT` | wait 5s, retry (max 3) |
148
+ | `INSUFFICIENT_BALANCE` | reduce size or bridge funds to that exchange |
149
+ | `SYMBOL_NOT_FOUND` | `perp --json -e <EX> market list` to verify symbol |
150
+ | `RISK_VIOLATION` | check `risk limits`, ask user to adjust if needed |
151
+ | `SIZE_TOO_SMALL` | `perp --json -e <EX> market info <SYM>` for min order size |
152
+ | `MARGIN_INSUFFICIENT` | reduce leverage or close existing positions |
153
+ | `DUPLICATE_ORDER` | already submitted — check positions, don't retry |
154
+ | Lighter `invalid signature` | check ~/.perp/.env or `perp --json -e lighter manage setup-api-key` |
145
155
 
146
156
  ## References
147
157