From b7da440dafa62322bb90db27f66b577297d18fda Mon Sep 17 00:00:00 2001 From: NathanOyewole Date: Wed, 28 Oct 2026 12:38:14 +0000 Subject: [PATCH 1/4] fix(spot): log warning and display token when metadata is missing Instead of silently skipping tokens with missing metadata, log a warning and display the token with available on-chain information (mint address, raw balance). This prevents incomplete portfolio displays without user awareness. Fixes #24 --- src/commands/SpotCommand.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index ab28856..34c0e65 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -400,6 +400,20 @@ export class SpotCommand { } const info = tokenMap.get(mint); if (!info) { + console.warn(`Warning: Token metadata not found for mint ${mint}. Displaying with limited info.`); + outputTokens.push({ + id: mint, + symbol: mint.slice(0, 8) + '...', + decimals: 0, + amount: Number(ata.amount), + rawAmount: ata.amount, + value: 0, + price: 0, + priceChange: 0, + isVerified: false, + scaledUiMultiplier: 1, + reclaimableLamports: ata.reclaimableLamports, + }); continue; } const multiplier = Swap.getScaledUiMultiplier(info); From 3cd28f6e05f067e830b10615c2472338519355f0 Mon Sep 17 00:00:00 2001 From: NathanOyewole Date: Wed, 28 Oct 2026 12:40:52 +0000 Subject: [PATCH 2/4] fix(keys): use Promise.allSettled to handle corrupted keypair files Replace Promise.all() with Promise.allSettled() so that a single corrupted or unreadable keypair file no longer crashes the entire keys list command. Valid keys are still displayed, and a warning is logged for any that failed to load. Fixes #23 --- src/commands/KeysCommand.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/commands/KeysCommand.ts b/src/commands/KeysCommand.ts index 3ba5522..d330726 100644 --- a/src/commands/KeysCommand.ts +++ b/src/commands/KeysCommand.ts @@ -126,7 +126,7 @@ export class KeysCommand { ); const keychainFiles = files.filter((f) => f.endsWith(".keychain.json")); - const keypairData = await Promise.all( + const keypairResults = await Promise.allSettled( keypairFiles.map(async (file) => { const name = file.replace(".json", ""); const signer = await Signer.load(name); @@ -139,6 +139,17 @@ export class KeysCommand { }) ); + const keypairData = keypairResults + .map((result, index) => { + if (result.status === "fulfilled") { + return result.value; + } + const name = keypairFiles[index]?.replace(".json", "") ?? "unknown"; + console.warn(`Warning: Failed to load keypair "${name}": ${result.reason}`); + return null; + }) + .filter((item): item is NonNullable => item !== null); + const keychainData = keychainFiles.map((file) => { const name = file.replace(".keychain.json", ""); const config = KeychainConfig.load(name); From 433847d7780f57cab9009842dc031e9d3925801f Mon Sep 17 00:00:00 2001 From: NathanOyewole Date: Wed, 28 Oct 2026 12:41:20 +0000 Subject: [PATCH 3/4] fix(perps): validate leverage is within reasonable bounds (1-100) Add client-side validation for the --leverage flag in perps open. Previously, any non-zero leverage value was accepted, leading to cryptic API errors. Now throws a clear error if leverage is not between 1 and 100. Fixes #26 --- src/commands/PerpsCommand.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/commands/PerpsCommand.ts b/src/commands/PerpsCommand.ts index 313872c..6c2df64 100644 --- a/src/commands/PerpsCommand.ts +++ b/src/commands/PerpsCommand.ts @@ -311,6 +311,12 @@ export class PerpsCommand { if (opts.leverage && opts.size) { throw new Error("Only one of --leverage or --size can be provided."); } + if (opts.leverage) { + const lev = Number(opts.leverage); + if (isNaN(lev) || lev < 1 || lev > 100) { + throw new Error("Leverage must be a number between 1 and 100."); + } + } if (opts.limit && (opts.tp || opts.sl)) { throw new Error( "--limit cannot be combined with --tp or --sl. Use 'perps set' after the limit order fills." From 1446cae15938dd12ad0dd10381e7c79f9a078322 Mon Sep 17 00:00:00 2001 From: NathanOyewole Date: Wed, 28 Oct 2026 12:42:15 +0000 Subject: [PATCH 4/4] refactor: extract shared DateConverter for parseTimestamp Both SpotCommand and PerpsCommand had duplicate parseTimestamp() implementations with inconsistent return formats (ISO vs Unix seconds). Extract into a shared DateConverter utility in src/lib/. Fixes #25 --- src/commands/PerpsCommand.ts | 10 ++-------- src/commands/SpotCommand.ts | 10 ++-------- src/lib/DateConverter.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 src/lib/DateConverter.ts diff --git a/src/commands/PerpsCommand.ts b/src/commands/PerpsCommand.ts index 6c2df64..011523f 100644 --- a/src/commands/PerpsCommand.ts +++ b/src/commands/PerpsCommand.ts @@ -8,6 +8,7 @@ import { Config } from "../lib/Config.ts"; import { NumberConverter } from "../lib/NumberConverter.ts"; import { Output } from "../lib/Output.ts"; import { Signer } from "../lib/Signer.ts"; +import { DateConverter } from "../lib/DateConverter.ts"; export class PerpsCommand { public static register(program: Command): void { @@ -910,14 +911,7 @@ export class PerpsCommand { } private static parseTimestamp(value: string): string { - if (/^\d+$/.test(value)) { - return value; - } - const ms = new Date(value).getTime(); - if (isNaN(ms)) { - throw new Error(`Invalid date: ${value}`); - } - return String(Math.floor(ms / 1000)); + return DateConverter.toUnixSeconds(value); } private static async history(opts: { diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index 34c0e65..ad883ca 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -18,6 +18,7 @@ import { Config } from "../lib/Config.ts"; import { NumberConverter } from "../lib/NumberConverter.ts"; import { Output } from "../lib/Output.ts"; import { Signer } from "../lib/Signer.ts"; +import { DateConverter } from "../lib/DateConverter.ts"; import { Swap } from "../lib/Swap.ts"; export class SpotCommand { @@ -942,13 +943,6 @@ export class SpotCommand { } private static parseTimestamp(value: string): string { - if (/^\d+$/.test(value)) { - return new Date(Number(value) * 1000).toISOString(); - } - const ms = new Date(value).getTime(); - if (isNaN(ms)) { - throw new Error(`Invalid date: ${value}`); - } - return new Date(ms).toISOString(); + return DateConverter.toISO(value); } } diff --git a/src/lib/DateConverter.ts b/src/lib/DateConverter.ts new file mode 100644 index 0000000..5bd1822 --- /dev/null +++ b/src/lib/DateConverter.ts @@ -0,0 +1,31 @@ +export class DateConverter { + /** + * Parse a timestamp value and return an ISO string. + * Accepts Unix seconds (numeric string) or an ISO date string. + */ + static toISO(value: string): string { + if (/^\d+$/.test(value)) { + return new Date(Number(value) * 1000).toISOString(); + } + const ms = new Date(value).getTime(); + if (isNaN(ms)) { + throw new Error(`Invalid date: ${value}`); + } + return new Date(ms).toISOString(); + } + + /** + * Parse a timestamp value and return Unix seconds as a string. + * Accepts Unix seconds (numeric string) or an ISO date string. + */ + static toUnixSeconds(value: string): string { + if (/^\d+$/.test(value)) { + return value; + } + const ms = new Date(value).getTime(); + if (isNaN(ms)) { + throw new Error(`Invalid date: ${value}`); + } + return String(Math.floor(ms / 1000)); + } +}