Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eac2a4d
chore: update oxlint config to ts
ChiefWoods Aug 30, 2026
0c8d81c
chore: replace prettier with oxfmt
ChiefWoods Aug 30, 2026
9626459
feat: add jupiter-api-ts
ChiefWoods Aug 30, 2026
3354c41
feat: add rpcUrl field in config
ChiefWoods Aug 30, 2026
1a13d9f
feat: add SolanaRpc lib
ChiefWoods Aug 30, 2026
1d3eb40
feat: add dry-run flag
ChiefWoods Aug 30, 2026
e38c138
feat: add JupiterApi lib
ChiefWoods Aug 30, 2026
995c432
refactor: replace asset helpers using JupiterDatapi
ChiefWoods Aug 30, 2026
66594a2
feat: add @solana-program/token-2022
ChiefWoods Aug 30, 2026
2393822
feat: add getScaledUiMultiplier method to SolanaRpc
ChiefWoods Aug 30, 2026
b8f7b1a
feat: add getTokenProgram method to SolanaRpc
ChiefWoods Aug 30, 2026
d89bc77
refactor: use Datapi client and SolanaRpc
ChiefWoods Aug 30, 2026
a1215a8
docs: update readme
ChiefWoods Aug 30, 2026
21f7899
refactor: replace handrolled clients with API-backed clients
ChiefWoods Aug 30, 2026
622fd7c
chore: use unambiguous fallback methods
ChiefWoods Aug 31, 2026
afc8dc4
feat: add SolanaTransactions lib
ChiefWoods Aug 31, 2026
15f2c89
chore: update signTransaction method to accept Base64EncodedWireTrans…
ChiefWoods Aug 31, 2026
178b55b
feat: add getTokenPrograms and getTokenAccountsByOwner methods
ChiefWoods Aug 31, 2026
008e494
docs: update readme on dry-run
ChiefWoods Aug 31, 2026
9a2ca84
refactor: replace UltraClient and use primitives for transfer and rec…
ChiefWoods Aug 31, 2026
89b3f84
chore: remove old clients
ChiefWoods Aug 31, 2026
f3522cd
refactor: use RPC primitive and remove request builder
ChiefWoods Aug 31, 2026
30339e4
feat: lift portfolio, transfer and reclaim to top level, update spot …
ChiefWoods Aug 31, 2026
833d2dc
refactor: replace Datapi searchAssets with getTokensV2Search
ChiefWoods Aug 31, 2026
ddaa585
refactor: replace parallel API calls with single call
ChiefWoods Aug 31, 2026
37473aa
feat: add support for negative chain amount
ChiefWoods Aug 31, 2026
c8d648e
chore: fallback to config active key if address is not passed for len…
ChiefWoods Aug 31, 2026
be7312d
feat: add lend borrow commands
ChiefWoods Aug 31, 2026
60fc9df
feat: add dca commands
ChiefWoods Aug 31, 2026
44b63aa
feat: add signTransactionWith method
ChiefWoods Aug 31, 2026
28b659b
feat: add invite commands
ChiefWoods Aug 31, 2026
70f0d02
feat: add jlp commands
ChiefWoods Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add rpcUrl field in config
  • Loading branch information
ChiefWoods committed Aug 30, 2026
commit 3354c41d92b7f9597f5a1d2813d43a89235aa45b
12 changes: 12 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ jup config set --api-key <key>
# Delete or unset the API key
jup config set --api-key
```

### Set an RPC URL

Signable commands use this RPC URL to simulate or submit transactions. It
defaults to `https://api.mainnet.solana.com` when no custom endpoint is set.

```bash
jup config set --rpc-url https://your-rpc.example.com

# Return to the mainnet default
jup config set --rpc-url
```
93 changes: 93 additions & 0 deletions src/commands/ConfigCommand.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { Command } from "commander";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

import { Config } from "../lib/Config.ts";
import { Output } from "../lib/Output.ts";
import { ConfigCommand } from "./ConfigCommand.ts";

const TEST_DIR = join(tmpdir(), `jup-config-command-test-${Date.now()}`);
const origSettingsFile = Config.SETTINGS_FILE;
const originalLog = console.log;

beforeEach(() => {
mkdirSync(TEST_DIR, { recursive: true });
// @ts-expect-error test override
Config.SETTINGS_FILE = join(TEST_DIR, "settings.json");
Output.outputOverride = "json";
});

afterEach(() => {
rmSync(TEST_DIR, { recursive: true, force: true });
// @ts-expect-error restore
Config.SETTINGS_FILE = origSettingsFile;
Output.outputOverride = undefined;
console.log = originalLog;
});

test("config set stores an HTTPS RPC URL and lists it", async () => {
const output: string[] = [];
console.log = (message?: unknown) => output.push(String(message));
const program = new Command();
program.exitOverride();
ConfigCommand.register(program);

await program.parseAsync([
"node",
"jup",
"config",
"set",
"--rpc-url",
"https://rpc.example.com",
]);

expect(Config.load().rpcUrl).toBe("https://rpc.example.com");
expect(JSON.parse(output.at(-1)!)).toMatchObject({
rpcUrl: "https://rpc.example.com",
});
});

test("config set clears an RPC URL when --rpc-url has no value", async () => {
Config.set({ rpcUrl: "https://rpc.example.com" });
console.log = () => {};
const program = new Command();
program.exitOverride();
ConfigCommand.register(program);

await program.parseAsync(["node", "jup", "config", "set", "--rpc-url"]);

expect(Config.load().rpcUrl).toBeUndefined();
expect(Config.getRpcUrl()).toBe("https://api.mainnet.solana.com");
});

test("config list displays the effective default RPC URL", async () => {
const output: string[] = [];
console.log = (message?: unknown) => output.push(String(message));
const program = new Command();
program.exitOverride();
ConfigCommand.register(program);

await program.parseAsync(["node", "jup", "config", "list"]);

expect(JSON.parse(output.at(-1)!)).toMatchObject({
rpcUrl: "https://api.mainnet.solana.com",
});
});

test("config list redacts the API key while displaying the RPC URL", async () => {
Config.set({ apiKey: "secret", rpcUrl: "https://rpc.example.com" });
const output: string[] = [];
console.log = (message?: unknown) => output.push(String(message));
const program = new Command();
program.exitOverride();
ConfigCommand.register(program);

await program.parseAsync(["node", "jup", "config", "list"]);

expect(JSON.parse(output.at(-1)!)).toMatchObject({
apiKey: "<set>",
rpcUrl: "https://rpc.example.com",
});
});
28 changes: 20 additions & 8 deletions src/commands/ConfigCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ export class ConfigCommand {
"--api-key [key]",
"Use an API key from https://portal.jup.ag/ for higher rate limits"
)
.option(
"--rpc-url [url]",
"Set the Solana RPC URL (omit to use public mainnet default)"
)
.action((opts) => this.set(opts));
}

private static list(): void {
const settings = Config.load();
const display = {
...this.redactForDisplay(settings),
rpcUrl: Config.getRpcUrl(),
};
if (Output.isJson()) {
Output.json(this.redactForDisplay(settings));
Output.json(display);
return;
}

const display = this.redactForDisplay(settings);
const data = Object.entries(display).map(([key, value]) => ({
setting: key,
value: value != null && value !== "" ? String(value) : "",
Expand All @@ -56,16 +63,21 @@ export class ConfigCommand {
activeKey?: string;
output?: "table" | "json";
apiKey?: string | true;
rpcUrl?: string | true;
}): void {
if (opts.output && opts.output !== "table" && opts.output !== "json") {
throw new Error("Invalid --output format. Must be 'table' or 'json'.");
}
// --api-key without a value (Commander passes `true`) clears the key
const { apiKey, ...rest } = opts;
Config.set({
...rest,
apiKey: typeof apiKey === "string" ? apiKey : undefined,
});
// An option without a value is `true` in Commander and clears that setting.
const { apiKey, rpcUrl, ...rest } = opts;
const settings: Parameters<typeof Config.set>[0] = { ...rest };
if (apiKey !== undefined) {
settings.apiKey = typeof apiKey === "string" ? apiKey : undefined;
}
if (rpcUrl !== undefined) {
settings.rpcUrl = typeof rpcUrl === "string" ? rpcUrl : undefined;
}
Config.set(settings);
this.list();
}
}
25 changes: 25 additions & 0 deletions src/lib/Config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe("Config.load", () => {
expect(s.apiKey).toBeUndefined();
});

test("uses the mainnet RPC fallback when rpcUrl is unset", () => {
expect(Config.getRpcUrl()).toBe("https://api.mainnet.solana.com");
});

test("throws a clear error when settings.json is not valid json", () => {
writeFileSync(
join(TEST_DIR, "settings.json"),
Expand Down Expand Up @@ -57,6 +61,27 @@ describe("Config.load", () => {
});
});

test("persists a configured HTTPS RPC URL", () => {
Config.set({ rpcUrl: "https://rpc.example.com" });

expect(Config.load().rpcUrl).toBe("https://rpc.example.com");
expect(Config.getRpcUrl()).toBe("https://rpc.example.com");
});

test("clears an RPC URL back to the mainnet fallback", () => {
Config.set({ rpcUrl: "https://rpc.example.com" });
Config.set({ rpcUrl: undefined });

expect(Config.load().rpcUrl).toBeUndefined();
expect(Config.getRpcUrl()).toBe("https://api.mainnet.solana.com");
});

test("rejects non-HTTPS RPC URLs", () => {
expect(() => Config.set({ rpcUrl: "http://localhost:8899" })).toThrow(
"Invalid RPC URL. It must be an HTTPS URL."
);
});

test("treats non-object root as empty object for fields", () => {
writeFileSync(join(TEST_DIR, "settings.json"), "[]");
const s = Config.load();
Expand Down
28 changes: 26 additions & 2 deletions src/lib/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ type Settings = {
activeKey: "default" | string;
output: "table" | "json";
apiKey?: string | undefined;
rpcUrl?: string | undefined;
};

const DEFAULT_RPC_URL = "https://api.mainnet.solana.com";

const DEFAULT_SETTINGS: Settings = {
activeKey: "default",
output: "table",
Expand Down Expand Up @@ -56,13 +59,30 @@ export class Config {
? o.output
: DEFAULT_SETTINGS.output,
apiKey: typeof o?.apiKey === "string" ? o.apiKey : undefined,
rpcUrl: typeof o?.rpcUrl === "string" ? o.rpcUrl : undefined,
};
}

public static getRpcUrl(): string {
return this.load().rpcUrl ?? DEFAULT_RPC_URL;
}

public static set(settings: Partial<Settings>): void {
if (Object.keys(settings).length === 0) {
throw new Error("No settings provided to update.");
}
if (settings.rpcUrl !== undefined) {
let url: URL;
try {
url = new URL(settings.rpcUrl);
} catch {
throw new Error("Invalid RPC URL. It must be an HTTPS URL.");
}
if (url.protocol !== "https:") {
throw new Error("Invalid RPC URL. It must be an HTTPS URL.");
}
}

const currentSettings = this.load();
this.save({
...currentSettings,
Expand All @@ -72,8 +92,12 @@ export class Config {

public static save(settings: Settings): void {
// Strip undefined optional fields so settings.json stays clean
const { apiKey, ...rest } = settings;
const out = apiKey ? { ...rest, apiKey } : rest;
const { apiKey, rpcUrl, ...rest } = settings;
const out = {
...rest,
...(apiKey ? { apiKey } : {}),
...(rpcUrl ? { rpcUrl } : {}),
};
writeFileSync(this.SETTINGS_FILE, JSON.stringify(out, null, 2) + "\n");
}
}