Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ test-ledger
test-programs/*
.goki/
yarn-error.log
.idea
.idea
clients/
1 change: 1 addition & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000"
generate-clients = "yarn node ./scripts/generate-clients.js"
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Gum, at its core, is a decentralized social media protocol on Solana. It unbundles traditional social media into Social Legos similar to how Defi unbundled traditional finance into Money Legos.

![Gum Social Legos](https://2840179994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhE7mGtqPpj3sUoePsT2p%2Fuploads%2FdPZGJ7tF8CQotSD0LIUK%2Flegos.e93068d9.svg?alt=media&token=7537963b-33a6-4e08-901f-d4c67f40586c)
Expand All @@ -25,6 +24,16 @@ Our thesis is that this is the key ingredient missing from most consumer applica

Documentation: https://docs.gum.fun/

## Generating the SDK

To generate the TypeScript SDK for the session keys program, run:

```bash
anchor run generate-clients
```

This will generate the client code in the `clients/gpl_session/src/generated/` directory with the standard structure including accounts, errors, instructions, programs, and shared folders.
Comment on lines +27 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add prerequisite steps to the SDK generation documentation.

The documentation doesn't mention that users must first run anchor build to generate the IDL file, and should run yarn install to install dependencies. Without these prerequisites, the script will fail.

📝 Proposed documentation enhancement
 ## Generating the SDK
 
-To generate the TypeScript SDK for the session keys program, run:
+To generate the TypeScript SDK for the session keys program:
+
+1. Install dependencies:
+```bash
+yarn install
+```
+
+2. Build the Anchor programs to generate the IDL:
+```bash
+anchor build
+```
+
+3. Generate the client code:
 
 ```bash
 anchor run generate-clients
 ```
 
 This will generate the client code in the `clients/gpl_session/src/generated/` directory with the standard structure including accounts, errors, instructions, programs, and shared folders.
🤖 Prompt for AI Agents
In @README.md around lines 27 - 35, The README's "Generating the SDK" steps miss
prerequisites; update the section around the "anchor run generate-clients"
instructions to first tell users to install dependencies (run "yarn install")
and then build the Anchor programs to produce the IDL (run "anchor build")
before running "anchor run generate-clients", so the generated client in
clients/gpl_session/src/generated/ succeeds.


_NOTE_:

All the code and artificats in this repo are unaudited and is shared publicly in the true spirit of opensource. So there could potentially be bugs, if you do spot them. Please raise an issue or send a PR in the same spirit.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
"@project-serum/anchor": "^0.26.0"
},
"devDependencies": {
"@codama/nodes-from-anchor": "^1.3.8",
"@codama/renderers-js": "^1.5.5",
"@faker-js/faker": "^7.6.0",
"@solana/kit": "^5.3.0",
"@solana/spl-account-compression": "^0.1.5",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"@types/randombytes": "^2.0.0",
"chai": "^4.3.4",
"codama": "^1.5.0",
"js-sha3": "^0.8.0",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
Expand Down
21 changes: 21 additions & 0 deletions scripts/generate-clients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createFromRoot } from "codama";
import { rootNodeFromAnchor } from "@codama/nodes-from-anchor";
import { renderVisitor as renderJavaScriptVisitor } from "@codama/renderers-js";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const anchorIdl = JSON.parse(
fs.readFileSync(
new URL("../target/idl/gpl_session.json", import.meta.url),
"utf8"
)
);
Comment on lines +11 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add error handling for missing or invalid IDL file.

The script will crash with an unhelpful error if the IDL file doesn't exist or isn't valid JSON. This typically happens when anchor build hasn't been run yet.

🛡️ Proposed fix with error handling
+try {
   const anchorIdl = JSON.parse(
     fs.readFileSync(
       new URL("../target/idl/gpl_session.json", import.meta.url),
       "utf8"
     )
   );
+} catch (error) {
+  console.error("Error: Could not read IDL file. Have you run 'anchor build' first?");
+  console.error(error.message);
+  process.exit(1);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const anchorIdl = JSON.parse(
fs.readFileSync(
new URL("../target/idl/gpl_session.json", import.meta.url),
"utf8"
)
);
try {
const anchorIdl = JSON.parse(
fs.readFileSync(
new URL("../target/idl/gpl_session.json", import.meta.url),
"utf8"
)
);
} catch (error) {
console.error("Error: Could not read IDL file. Have you run 'anchor build' first?");
console.error(error.message);
process.exit(1);
}
🤖 Prompt for AI Agents
In @scripts/generate-clients.js around lines 11 - 16, The code currently calls
JSON.parse(fs.readFileSync(new URL("../target/idl/gpl_session.json",
import.meta.url), "utf8")) without guarding against a missing file or invalid
JSON; wrap the read-and-parse in a try/catch (or check fs.existsSync first)
around the anchorIdl creation to catch ENOENT and JSON parsing errors, log a
clear error via console.error (including the file path/new URL value and the
caught error.message), and exit with process.exit(1) when the IDL is missing or
invalid so the script fails fast with a helpful message.


const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));

const jsClient = path.join(__dirname, "..", "clients", "gpl_session");
codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated")));
Comment on lines +18 to +21
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider adding error handling and user feedback.

The Codama generation may fail if the output directory doesn't exist or if there are issues with the IDL structure. Adding try-catch and console feedback would improve the developer experience.

♻️ Proposed enhancement with error handling and logging
+console.log("Generating Solana Kit client from IDL...");
+
+try {
   const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));
 
   const jsClient = path.join(__dirname, "..", "clients", "gpl_session");
+  console.log(`Output directory: ${path.join(jsClient, "src", "generated")}`);
+  
   codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated")));
+  
+  console.log("✓ Client generation completed successfully!");
+} catch (error) {
+  console.error("Error: Client generation failed");
+  console.error(error.message);
+  process.exit(1);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));
const jsClient = path.join(__dirname, "..", "clients", "gpl_session");
codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated")));
console.log("Generating Solana Kit client from IDL...");
try {
const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));
const jsClient = path.join(__dirname, "..", "clients", "gpl_session");
console.log(`Output directory: ${path.join(jsClient, "src", "generated")}`);
codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated")));
console.log("✓ Client generation completed successfully!");
} catch (error) {
console.error("Error: Client generation failed");
console.error(error.message);
process.exit(1);
}
🤖 Prompt for AI Agents
In @scripts/generate-clients.js around lines 18 - 21, Wrap the Codama generation
steps (rootNodeFromAnchor(anchorIdl), createFromRoot(...), and
codama.accept(renderJavaScriptVisitor(...))) in a try-catch; before calling
codama.accept ensure the target directory computed by path.join(jsClient, "src",
"generated") exists (create it with fs.mkdirSync(..., { recursive: true }) if
missing), and on error log a clear message including the caught error via
console.error and exit with non-zero status (e.g., process.exit(1)) so failures
surface to the user.

Loading