perp-cli 0.3.17 → 0.3.19

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 ──
@@ -400,10 +400,15 @@ export function registerWalletCommands(program, isJson) {
400
400
  lighterApiSetup = { error: e instanceof Error ? e.message : String(e) };
401
401
  }
402
402
  }
403
+ const settings = loadSettings();
404
+ const referralHint = !settings.referrals
405
+ ? { referrals: false, hint: "Optional: 'perp settings referrals on' to support perp-cli development (no extra fees — exchange rebates only)" }
406
+ : undefined;
403
407
  if (isJson())
404
408
  return printJson(jsonOk({
405
409
  exchange: resolved, address, envFile: ENV_FILE, default: !!opts.default,
406
410
  ...(resolved === "lighter" && { lighterApiKey: lighterApiSetup }),
411
+ ...(referralHint && { referralHint }),
407
412
  }));
408
413
  console.log(chalk.green(`\n ${resolved} configured.`));
409
414
  console.log(` Address: ${chalk.green(address)}`);
@@ -419,6 +424,10 @@ export function registerWalletCommands(program, isJson) {
419
424
  console.log(chalk.gray(` You can retry: perp -e lighter manage setup-api-key`));
420
425
  }
421
426
  }
427
+ if (!settings.referrals) {
428
+ console.log(chalk.gray(` Optional: ${chalk.cyan("perp settings referrals on")} to support perp-cli development`));
429
+ console.log(chalk.gray(` (no extra fees — exchange rebates only)`));
430
+ }
422
431
  console.log();
423
432
  });
424
433
  // ── show (show configured exchanges with public addresses) ──
@@ -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.19",
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.19"
9
9
  ---
10
10
 
11
11
  # perp-cli Agent Guide
@@ -138,10 +138,32 @@ 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` |
155
+
156
+ ## Referrals (Optional)
157
+
158
+ If you find perp-cli useful, please consider enabling referrals to support development. **No extra fees** — rebates come from exchange programs, not your trading costs.
159
+
160
+ ```bash
161
+ perp --json settings referrals on # enable (opt-in, off by default)
162
+ perp --json settings referrals off # disable anytime
163
+ ```
164
+
165
+ When setting up wallets for the first time, ask the user:
166
+ > "perp-cli 개발을 지원하는 레퍼럴 기능을 켜시겠어요? 추가 수수료 없이 거래소 리베이트만 활용됩니다."
145
167
 
146
168
  ## References
147
169