Skip to content

Commit 5621a08

Browse files
committed
style: fix prettier formatting across TypeScript files
1 parent a3f4ac9 commit 5621a08

File tree

12 files changed

+1133
-350
lines changed

12 files changed

+1133
-350
lines changed

cli/src/client.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ const IDL_PATH = path.resolve(__dirname, "../../target/idl/sol_auction.json");
1212

1313
function loadIdl(): any {
1414
if (!fs.existsSync(IDL_PATH)) {
15-
throw new Error(
16-
`IDL not found at ${IDL_PATH}. Run 'anchor build' first.`
17-
);
15+
throw new Error(`IDL not found at ${IDL_PATH}. Run 'anchor build' first.`);
1816
}
1917
return JSON.parse(fs.readFileSync(IDL_PATH, "utf-8"));
2018
}
@@ -29,13 +27,12 @@ export function getProgram(): ProgramClient {
2927
const clusterUrl =
3028
process.env.ANCHOR_PROVIDER_URL || "https://api.devnet.solana.com";
3129
const walletPath =
32-
process.env.ANCHOR_WALLET ||
33-
`${process.env.HOME}/.config/solana/id.json`;
30+
process.env.ANCHOR_WALLET || `${process.env.HOME}/.config/solana/id.json`;
3431

3532
if (!fs.existsSync(walletPath)) {
3633
throw new Error(
3734
`Wallet keypair not found at ${walletPath}. ` +
38-
`Set ANCHOR_WALLET or run 'solana-keygen new'.`
35+
`Set ANCHOR_WALLET or run 'solana-keygen new'.`
3936
);
4037
}
4138

cli/src/commands/create.ts

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,29 @@ import {
1818
} from "../utils.js";
1919

2020
export function registerCreateCommands(program: Command): void {
21-
const create = program
22-
.command("create")
23-
.description("Create a new auction");
21+
const create = program.command("create").description("Create a new auction");
2422

2523
create
2624
.command("english")
2725
.description("Create an English (ascending) auction")
2826
.requiredOption("--mint <MINT>", "Token mint address of the item")
2927
.requiredOption("--start-price <SOL>", "Starting price in SOL", parseFloat)
30-
.requiredOption("--duration <SECS>", "Auction duration in seconds", parseInt)
31-
.requiredOption("--min-increment <SOL>", "Minimum bid increment in SOL", parseFloat)
32-
.option("--anti-snipe <SECS>", "Anti-snipe extension in seconds", parseInt, 300)
28+
.requiredOption(
29+
"--duration <SECS>",
30+
"Auction duration in seconds",
31+
parseInt
32+
)
33+
.requiredOption(
34+
"--min-increment <SOL>",
35+
"Minimum bid increment in SOL",
36+
parseFloat
37+
)
38+
.option(
39+
"--anti-snipe <SECS>",
40+
"Anti-snipe extension in seconds",
41+
parseInt,
42+
300
43+
)
3344
.option("--house <PUBKEY>", "Auction house PDA (auto-derived if omitted)")
3445
.action(async (opts) => {
3546
try {
@@ -39,7 +50,11 @@ export function registerCreateCommands(program: Command): void {
3950

4051
// Generate auction ID from timestamp
4152
const auctionId = new anchor.BN(Date.now());
42-
const [auctionPda] = deriveAuctionPda(prog.programId, seller, auctionId);
53+
const [auctionPda] = deriveAuctionPda(
54+
prog.programId,
55+
seller,
56+
auctionId
57+
);
4358
const [vaultPda] = deriveVaultPda(prog.programId, auctionPda);
4459

4560
// Derive or use provided house
@@ -95,9 +110,21 @@ export function registerCreateCommands(program: Command): void {
95110
.command("dutch")
96111
.description("Create a Dutch (descending) auction")
97112
.requiredOption("--mint <MINT>", "Token mint address of the item")
98-
.requiredOption("--start-price <SOL>", "Starting (highest) price in SOL", parseFloat)
99-
.requiredOption("--reserve <SOL>", "Reserve (floor) price in SOL", parseFloat)
100-
.requiredOption("--duration <SECS>", "Auction duration in seconds", parseInt)
113+
.requiredOption(
114+
"--start-price <SOL>",
115+
"Starting (highest) price in SOL",
116+
parseFloat
117+
)
118+
.requiredOption(
119+
"--reserve <SOL>",
120+
"Reserve (floor) price in SOL",
121+
parseFloat
122+
)
123+
.requiredOption(
124+
"--duration <SECS>",
125+
"Auction duration in seconds",
126+
parseInt
127+
)
101128
.option("--house <PUBKEY>", "Auction house PDA (auto-derived if omitted)")
102129
.action(async (opts) => {
103130
try {
@@ -106,7 +133,11 @@ export function registerCreateCommands(program: Command): void {
106133
const seller = wallet.publicKey;
107134

108135
const auctionId = new anchor.BN(Date.now());
109-
const [auctionPda] = deriveAuctionPda(prog.programId, seller, auctionId);
136+
const [auctionPda] = deriveAuctionPda(
137+
prog.programId,
138+
seller,
139+
auctionId
140+
);
110141
const [vaultPda] = deriveVaultPda(prog.programId, auctionPda);
111142

112143
const housePda = opts.house
@@ -159,9 +190,21 @@ export function registerCreateCommands(program: Command): void {
159190
.command("sealed")
160191
.description("Create a sealed-bid Vickrey auction")
161192
.requiredOption("--mint <MINT>", "Token mint address of the item")
162-
.requiredOption("--min-collateral <SOL>", "Minimum collateral in SOL", parseFloat)
163-
.requiredOption("--bid-duration <SECS>", "Bidding phase duration in seconds", parseInt)
164-
.requiredOption("--reveal-duration <SECS>", "Reveal phase duration in seconds", parseInt)
193+
.requiredOption(
194+
"--min-collateral <SOL>",
195+
"Minimum collateral in SOL",
196+
parseFloat
197+
)
198+
.requiredOption(
199+
"--bid-duration <SECS>",
200+
"Bidding phase duration in seconds",
201+
parseInt
202+
)
203+
.requiredOption(
204+
"--reveal-duration <SECS>",
205+
"Reveal phase duration in seconds",
206+
parseInt
207+
)
165208
.option("--house <PUBKEY>", "Auction house PDA (auto-derived if omitted)")
166209
.action(async (opts) => {
167210
try {
@@ -170,7 +213,11 @@ export function registerCreateCommands(program: Command): void {
170213
const seller = wallet.publicKey;
171214

172215
const auctionId = new anchor.BN(Date.now());
173-
const [auctionPda] = deriveAuctionPda(prog.programId, seller, auctionId);
216+
const [auctionPda] = deriveAuctionPda(
217+
prog.programId,
218+
seller,
219+
auctionId
220+
);
174221
const [vaultPda] = deriveVaultPda(prog.programId, auctionPda);
175222

176223
const housePda = opts.house

cli/src/commands/manage.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export function registerManageCommands(program: Command): void {
3838
const seller = auctionAccount.seller as PublicKey;
3939

4040
const [vaultPda] = deriveVaultPda(prog.programId, auctionPda);
41-
const [winnerBidEscrow] = deriveBidPda(prog.programId, auctionPda, winner);
41+
const [winnerBidEscrow] = deriveBidPda(
42+
prog.programId,
43+
auctionPda,
44+
winner
45+
);
4246
const winnerAta = getAssociatedTokenAddressSync(itemMint, winner);
4347

4448
// Find auction house
@@ -95,7 +99,9 @@ export function registerManageCommands(program: Command): void {
9599
const seller = wallet.publicKey;
96100

97101
// Fetch auction to get mint
98-
const auctionAccount = await (prog.account as any).auctionConfig.fetch(auctionPda);
102+
const auctionAccount = await (prog.account as any).auctionConfig.fetch(
103+
auctionPda
104+
);
99105
const itemMint = auctionAccount.itemMint as PublicKey;
100106

101107
const [vaultPda] = deriveVaultPda(prog.programId, auctionPda);
@@ -127,7 +133,9 @@ export function registerManageCommands(program: Command): void {
127133

128134
program
129135
.command("close-bidding")
130-
.description("Close bidding phase for a sealed auction (permissionless crank)")
136+
.description(
137+
"Close bidding phase for a sealed auction (permissionless crank)"
138+
)
131139
.argument("<AUCTION_PDA>", "Auction PDA address")
132140
.action(async (auctionPdaStr: string) => {
133141
try {
@@ -162,7 +170,9 @@ export function registerManageCommands(program: Command): void {
162170
const { program: prog } = getProgram();
163171
const auctionPda = new PublicKey(auctionPdaStr);
164172

165-
const auction = await (prog.account as any).auctionConfig.fetch(auctionPda);
173+
const auction = await (prog.account as any).auctionConfig.fetch(
174+
auctionPda
175+
);
166176
const now = Math.floor(Date.now() / 1000);
167177

168178
header("Auction Status");
@@ -174,10 +184,13 @@ export function registerManageCommands(program: Command): void {
174184
// Status
175185
const status = parseStatus(auction.status);
176186
const statusColor =
177-
status === "Active" ? chalk.green(status)
178-
: status === "Settled" ? chalk.blue(status)
179-
: status === "Cancelled" ? chalk.red(status)
180-
: chalk.yellow(status);
187+
status === "Active"
188+
? chalk.green(status)
189+
: status === "Settled"
190+
? chalk.blue(status)
191+
: status === "Cancelled"
192+
? chalk.red(status)
193+
: chalk.yellow(status);
181194
info("Status", statusColor);
182195

183196
// Timing
@@ -203,7 +216,10 @@ export function registerManageCommands(program: Command): void {
203216
info("Type", chalk.cyan("English (Ascending)"));
204217
info("Start Price", `${lamportsToSol(e.startPrice)} SOL`);
205218
info("Min Increment", `${lamportsToSol(e.minIncrement)} SOL`);
206-
info("Anti-Snipe", `${(e.antiSnipeDuration as anchor.BN).toNumber()}s`);
219+
info(
220+
"Anti-Snipe",
221+
`${(e.antiSnipeDuration as anchor.BN).toNumber()}s`
222+
);
207223
info("Highest Bid", `${lamportsToSol(e.highestBid)} SOL`);
208224
info("Bid Count", e.bidCount.toString());
209225
if (e.highestBidder) {
@@ -221,8 +237,12 @@ export function registerManageCommands(program: Command): void {
221237
const duration = endTime - startTime;
222238
const startP = (d.startPrice as anchor.BN).toNumber();
223239
const reserveP = (d.reservePrice as anchor.BN).toNumber();
224-
const currentPrice = startP - Math.floor(((startP - reserveP) * elapsed) / duration);
225-
info("Current Price", chalk.bold(`${lamportsToSol(currentPrice)} SOL`));
240+
const currentPrice =
241+
startP - Math.floor(((startP - reserveP) * elapsed) / duration);
242+
info(
243+
"Current Price",
244+
chalk.bold(`${lamportsToSol(currentPrice)} SOL`)
245+
);
226246
}
227247
} else if (auctionType.sealedVickrey) {
228248
const s = auctionType.sealedVickrey;

cli/src/commands/sealed.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@ export function registerSealedCommands(program: Command): void {
2121
.command("submit-sealed")
2222
.description("Submit a sealed bid (commitment + collateral)")
2323
.argument("<AUCTION_PDA>", "Auction PDA address")
24-
.requiredOption("--amount <SOL>", "Actual bid amount in SOL (hidden in commitment)", parseFloat)
25-
.requiredOption("--collateral <SOL>", "Collateral to deposit in SOL", parseFloat)
26-
.option("--nonce <HEX_OR_AUTO>", "32-byte nonce as hex, or 'auto' to generate", "auto")
24+
.requiredOption(
25+
"--amount <SOL>",
26+
"Actual bid amount in SOL (hidden in commitment)",
27+
parseFloat
28+
)
29+
.requiredOption(
30+
"--collateral <SOL>",
31+
"Collateral to deposit in SOL",
32+
parseFloat
33+
)
34+
.option(
35+
"--nonce <HEX_OR_AUTO>",
36+
"32-byte nonce as hex, or 'auto' to generate",
37+
"auto"
38+
)
2739
.action(async (auctionPdaStr: string, opts) => {
2840
try {
2941
const { program: prog, wallet } = getProgram();
@@ -57,10 +69,7 @@ export function registerSealedCommands(program: Command): void {
5769
info("Nonce", nonce.toString("hex").slice(0, 16) + "...");
5870

5971
const tx = await prog.methods
60-
.submitSealedBid(
61-
Array.from(commitmentHash) as number[],
62-
collateral
63-
)
72+
.submitSealedBid(Array.from(commitmentHash) as number[], collateral)
6473
.accounts({
6574
auctionConfig: auctionPda,
6675
bidEscrow,
@@ -75,7 +84,9 @@ export function registerSealedCommands(program: Command): void {
7584
info("Transaction", tx);
7685
info("Explorer", getExplorerUrl(tx));
7786
console.log();
78-
warn("IMPORTANT: Save your nonce — without it you cannot reveal your bid!");
87+
warn(
88+
"IMPORTANT: Save your nonce — without it you cannot reveal your bid!"
89+
);
7990
info("Nonce (full)", nonce.toString("hex"));
8091
} catch (err) {
8192
handleError(err);
@@ -86,8 +97,15 @@ export function registerSealedCommands(program: Command): void {
8697
.command("reveal")
8798
.description("Reveal a previously submitted sealed bid")
8899
.argument("<AUCTION_PDA>", "Auction PDA address")
89-
.requiredOption("--amount <SOL>", "The actual bid amount in SOL", parseFloat)
90-
.option("--nonce <HEX>", "32-byte nonce as hex (auto-loaded from saved file if omitted)")
100+
.requiredOption(
101+
"--amount <SOL>",
102+
"The actual bid amount in SOL",
103+
parseFloat
104+
)
105+
.option(
106+
"--nonce <HEX>",
107+
"32-byte nonce as hex (auto-loaded from saved file if omitted)"
108+
)
91109
.action(async (auctionPdaStr: string, opts) => {
92110
try {
93111
const { program: prog, wallet } = getProgram();
@@ -106,7 +124,7 @@ export function registerSealedCommands(program: Command): void {
106124
if (!saved) {
107125
throw new Error(
108126
"No nonce provided and no saved nonce found. " +
109-
"Pass --nonce <HEX> or ensure .sol-auction/nonce-<PDA>.hex exists."
127+
"Pass --nonce <HEX> or ensure .sol-auction/nonce-<PDA>.hex exists."
110128
);
111129
}
112130
nonce = saved;

cli/src/utils.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ export function deriveBidPda(
6060
bidder: PublicKey
6161
): [PublicKey, number] {
6262
return PublicKey.findProgramAddressSync(
63-
[
64-
Buffer.from("bid"),
65-
auctionPda.toBuffer(),
66-
bidder.toBuffer(),
67-
],
63+
[Buffer.from("bid"), auctionPda.toBuffer(), bidder.toBuffer()],
6864
programId
6965
);
7066
}
@@ -75,10 +71,7 @@ export function computeCommitmentHash(
7571
amount: anchor.BN,
7672
nonce: Buffer
7773
): Buffer {
78-
const input = Buffer.concat([
79-
amount.toArrayLike(Buffer, "le", 8),
80-
nonce,
81-
]);
74+
const input = Buffer.concat([amount.toArrayLike(Buffer, "le", 8), nonce]);
8275
return Buffer.from(keccak_256(input));
8376
}
8477

@@ -109,7 +102,10 @@ export function loadNonce(auctionPda: string): Buffer | null {
109102
// -- Formatting --
110103

111104
export function formatTimestamp(ts: number): string {
112-
return new Date(ts * 1000).toISOString().replace("T", " ").replace("Z", " UTC");
105+
return new Date(ts * 1000)
106+
.toISOString()
107+
.replace("T", " ")
108+
.replace("Z", " UTC");
113109
}
114110

115111
export function formatDuration(seconds: number): string {
@@ -154,7 +150,9 @@ export function header(title: string): void {
154150

155151
export function handleError(err: unknown): never {
156152
if (err instanceof anchor.AnchorError) {
157-
error(`Program error [${err.error.errorCode.code}]: ${err.error.errorMessage}`);
153+
error(
154+
`Program error [${err.error.errorCode.code}]: ${err.error.errorMessage}`
155+
);
158156
} else if (err instanceof Error) {
159157
error(err.message);
160158
} else {

0 commit comments

Comments
 (0)