Skip to content

Commit 0c81498

Browse files
committed
chore: add prettier formatting scripts and fix formatting
1 parent 08877ea commit 0c81498

9 files changed

Lines changed: 25 additions & 50 deletions

File tree

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
"build": "bun build src/index.ts --outdir dist --target node --format esm --minify",
2626
"build:binary": "bash scripts/build.sh",
2727
"typecheck": "bunx tsc --noEmit",
28+
"fmt": "bunx prettier --write .",
29+
"fmt:check": "bunx prettier --check .",
2830
"lint": "bunx oxlint src",
2931
"test": "bun test",
30-
"ci": "bun run lint && bun run typecheck && bun run test",
32+
"ci": "bun run fmt:check && bun run lint && bun run typecheck && bun run test",
3133
"prepublishOnly": "bun run build"
3234
},
3335
"dependencies": {

src/clients/DatapiClient.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ export class DatapiClient {
155155
return this.#ky.get("_datapi/v1/txs/users", { searchParams }).json();
156156
}
157157

158-
public static async getTokensByMints(
159-
mints: string[]
160-
): Promise<Token[]> {
158+
public static async getTokensByMints(mints: string[]): Promise<Token[]> {
161159
if (mints.length === 0) {
162160
return [];
163161
}

src/commands/KeysCommand.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export class KeysCommand {
4545
"--private-key <key>",
4646
"Import from private key (hex, base58, base64, or JSON byte array)"
4747
)
48-
.option(
49-
"--backend <type>",
50-
`Keychain backend (${this.VALID_BACKENDS})`
51-
)
48+
.option("--backend <type>", `Keychain backend (${this.VALID_BACKENDS})`)
5249
.option("--param <key=value...>", "Backend parameters (repeatable)")
5350
.action((name, opts) => this.add(name, opts));
5451
keys
@@ -186,11 +183,9 @@ export class KeysCommand {
186183
const isKeychain = !!opts.backend;
187184

188185
if (isKeychain) {
189-
const keypairModes = [
190-
opts.file,
191-
opts.seedPhrase,
192-
opts.privateKey,
193-
].filter(Boolean);
186+
const keypairModes = [opts.file, opts.seedPhrase, opts.privateKey].filter(
187+
Boolean
188+
);
194189
if (keypairModes.length > 0) {
195190
throw new Error(
196191
"--backend is mutually exclusive with --file, --seed-phrase, and --private-key."
@@ -262,10 +257,7 @@ export class KeysCommand {
262257

263258
const params = this.parseParams(opts.param ?? []);
264259
const def = KeychainConfig.BACKENDS[backend];
265-
const knownParams = new Set([
266-
...def.requiredParams,
267-
...def.optionalParams,
268-
]);
260+
const knownParams = new Set([...def.requiredParams, ...def.optionalParams]);
269261

270262
for (const required of def.requiredParams) {
271263
if (!params[required]) {
@@ -343,9 +335,7 @@ export class KeysCommand {
343335
}
344336

345337
if (isKeychain && (opts.seedPhrase || opts.privateKey)) {
346-
throw new Error(
347-
"Cannot replace credentials for a keychain-backed key."
348-
);
338+
throw new Error("Cannot replace credentials for a keychain-backed key.");
349339
}
350340

351341
if (opts.seedPhrase || opts.privateKey) {

src/commands/LendCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class LendCommand {
125125

126126
const address =
127127
opts.address ??
128-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
128+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
129129

130130
const allPositions = await LendClient.getPositions(address);
131131
let activePositions = allPositions.filter((p) => p.shares !== "0");

src/commands/PerpsCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class PerpsCommand {
118118

119119
const address =
120120
opts.address ??
121-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
121+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
122122

123123
const [positionsRes, ordersRes] = await Promise.all([
124124
PerpsClient.getPositions(address),
@@ -945,7 +945,7 @@ export class PerpsCommand {
945945

946946
const address =
947947
opts.address ??
948-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
948+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
949949
const mint = opts.asset ? resolveAsset(opts.asset).id : undefined;
950950

951951
const res = await PerpsClient.getTrades({

src/commands/PredictionsCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class PredictionsCommand {
240240
} else {
241241
const address =
242242
opts.address ??
243-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
243+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
244244
const res = await PredictionsClient.getPositions(address);
245245
data = res.data;
246246
}
@@ -393,7 +393,7 @@ export class PredictionsCommand {
393393

394394
const address =
395395
opts.address ??
396-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
396+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
397397

398398
const res = await PredictionsClient.getHistory({
399399
ownerPubkey: address,

src/commands/SpotCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class SpotCommand {
331331

332332
const address =
333333
opts.address ??
334-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
334+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
335335

336336
const SOL_DECIMALS = Asset.SOL.decimals;
337337

@@ -616,7 +616,7 @@ export class SpotCommand {
616616

617617
const address =
618618
opts.address ??
619-
await Signer.loadAddress(opts.key ?? Config.load().activeKey);
619+
(await Signer.loadAddress(opts.key ?? Config.load().activeKey));
620620
const targetAsset = opts.token
621621
? await DatapiClient.resolveToken(opts.token)
622622
: undefined;

src/lib/KeyPair.test.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ describe("fromSeedPhrase", () => {
7171
});
7272

7373
describe("fromSeedPhrase — uses SLIP10 for all-hardened paths", () => {
74-
const toAddress = (kp: KeyPair) =>
75-
getBase58Decoder().decode(kp.publicKey);
74+
const toAddress = (kp: KeyPair) => getBase58Decoder().decode(kp.publicKey);
7675

7776
test("derives correct addresses for m/44'/501'/x'/0'", async () => {
7877
for (const { index, address } of [
@@ -103,42 +102,27 @@ describe("fromSeedPhrase — uses SLIP10 for all-hardened paths", () => {
103102
});
104103

105104
test("different account indices derive different keypairs", async () => {
106-
const a = await KeyPair.fromSeedPhrase(
107-
TEST_MNEMONIC,
108-
"m/44'/501'/0'/0'"
109-
);
110-
const b = await KeyPair.fromSeedPhrase(
111-
TEST_MNEMONIC,
112-
"m/44'/501'/1'/0'"
113-
);
105+
const a = await KeyPair.fromSeedPhrase(TEST_MNEMONIC, "m/44'/501'/0'/0'");
106+
const b = await KeyPair.fromSeedPhrase(TEST_MNEMONIC, "m/44'/501'/1'/0'");
114107
expect(a.publicKey).not.toEqual(b.publicKey);
115108
expect(a.privateKey).not.toEqual(b.privateKey);
116109
});
117110
});
118111

119112
describe("fromSeedPhrase — uses BIP32 for non-hardened paths", () => {
120-
const toAddress = (kp: KeyPair) =>
121-
getBase58Decoder().decode(kp.publicKey);
113+
const toAddress = (kp: KeyPair) => getBase58Decoder().decode(kp.publicKey);
122114

123115
test("derives correct address for m/44'/501'/0'/0/0", async () => {
124116
const kp = await KeyPair.fromSeedPhrase(
125117
"flee artwork post brown april bulk wash limb melody zoo rib law",
126118
"m/44'/501'/0'/0/0"
127119
);
128-
expect(toAddress(kp)).toBe(
129-
"F8oiKU5wmZs8jZQng1zyzbcHPkvECSwHitFJvuc5rQGP"
130-
);
120+
expect(toAddress(kp)).toBe("F8oiKU5wmZs8jZQng1zyzbcHPkvECSwHitFJvuc5rQGP");
131121
});
132122

133123
test("same non-hardened path is deterministic", async () => {
134-
const a = await KeyPair.fromSeedPhrase(
135-
TEST_MNEMONIC,
136-
"m/44'/501'/0'/0"
137-
);
138-
const b = await KeyPair.fromSeedPhrase(
139-
TEST_MNEMONIC,
140-
"m/44'/501'/0'/0"
141-
);
124+
const a = await KeyPair.fromSeedPhrase(TEST_MNEMONIC, "m/44'/501'/0'/0");
125+
const b = await KeyPair.fromSeedPhrase(TEST_MNEMONIC, "m/44'/501'/0'/0");
142126
expect(a.privateKey).toEqual(b.privateKey);
143127
expect(a.publicKey).toEqual(b.publicKey);
144128
});

0 commit comments

Comments
 (0)