forge-solana-sdk 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # FORGE SDK
1
+ # FORGE
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/forge-solana-sdk)
4
4
  ![npm](https://img.shields.io/npm/dm/forge-solana-sdk)
5
5
  ![License](https://img.shields.io/npm/l/forge-solana-sdk)
6
6
 
7
- Intent-driven app assembly on Solana. Infrastructure that survives.
7
+ **Intent-driven Solana program assembly.** Generate production-ready Anchor programs from natural language. Modern CPI helpers included.
8
+
9
+ > ⚡ **FORGE generates code, not excuses.**
8
10
 
9
11
  ## ⚡ Install
10
12
 
@@ -16,7 +18,15 @@ npm install -g forge-solana-sdk
16
18
 
17
19
  ### Initialize a project
18
20
  ```bash
21
+ # Basic project
19
22
  forge init my-project
23
+
24
+ # With intent-driven CPI generation
25
+ forge init my-project --intent "transfer 100 tokens safely"
26
+
27
+ # With specific Anchor version
28
+ forge init my-project --anchor-version 0.31.0
29
+
20
30
  cd my-project
21
31
  ```
22
32
 
@@ -25,27 +35,159 @@ cd my-project
25
35
  forge status
26
36
  ```
27
37
 
38
+ Enhanced status checks include:
39
+ - ✅ Version compatibility warnings
40
+ - ✅ Rust edition 2024 requirements
41
+ - ✅ Anchor CLI vs project version matching
42
+ - ✅ Network configuration
43
+
44
+ ### Generate TypeScript SDK
45
+ ```bash
46
+ forge generate-sdk
47
+
48
+ # Or specify custom output directory
49
+ forge generate-sdk ./my-sdk
50
+ ```
51
+
28
52
  ### Deploy to Solana
29
53
  ```bash
30
54
  forge deploy
31
55
  ```
32
56
 
57
+ ### Update FORGE
58
+ ```bash
59
+ forge update
60
+ ```
61
+
62
+ **Smart Update System:**
63
+ - ✅ Checks current vs latest version
64
+ - ✅ Auto-updates via npm when needed
65
+ - ✅ Shows clear progress feedback
66
+ - ✅ No manual version management required
67
+
33
68
  ## 📋 Prerequisites
34
69
 
35
70
  - **Node.js** 18+
36
- - **Rust** 1.70+
71
+ - **Rust** 1.85.0+ (required for edition 2024 compatibility)
37
72
  - **Solana CLI** (latest)
38
- - **Anchor CLI** 0.29.0
73
+ - **Anchor CLI** 0.29.0+
74
+
75
+ ⚠️ **Important**: Rust 1.85.0+ is required for modern Anchor dependencies. Update with: `rustup update stable`
39
76
 
40
77
  ## 🎯 What FORGE Does
41
78
 
42
- FORGE generates production-ready Anchor programs from intent. It creates the boilerplate so you focus on business logic.
79
+ FORGE transforms natural language intents into production-ready Solana programs. Modern, safe, and future-proof code generation.
80
+
81
+ ### Core Features
82
+ - ✅ **Intent-Driven Generation**: `"transfer 100 tokens safely"` → Modern CPI code
83
+ - ✅ **Complete Anchor Workspace**: Ready-to-build projects with proper structure
84
+ - ✅ **Client SDK Generation**: Auto-generated TypeScript SDK for program interaction
85
+ - ✅ **Modern CPI Helpers**: `transfer_checked`, `mint_to`, PDA signers with `ctx.bumps`
86
+ - ✅ **Version Compatibility**: Auto-aligns Anchor versions (CLI vs project)
87
+ - ✅ **Production Ready**: IDL features, proper dependencies, deployment configs
88
+
89
+ ### Generated Code Quality
90
+ - 🔒 **Safe Operations**: Uses `anchor_spl::token_interface` for Token & Token-2022
91
+ - 🎯 **Modern Patterns**: `InterfaceAccount`, `Interface` types (Anchor 0.31+ compatible)
92
+ - ⚡ **Optimized**: Minimal boilerplate, maximum functionality
93
+ - 🚀 **Future-Proof**: Edition 2024 compatible, latest Anchor best practices
94
+
95
+ ### Supported CPI Intents
96
+ - 💸 **Token Transfers**: `"transfer 100 tokens safely"` → `transfer_checked`
97
+ - 🪙 **Token Minting**: `"mint 500 tokens to user"` → `mint_to` with PDA authority
98
+ - 🎫 **ATA Creation**: `"create associated token account"` → `create_associated_token_account`
99
+ - 📊 **Token Metadata**: `"create metadata for token"` → MPL Token Metadata CPIs
100
+
101
+ **Example Generated Code:**
102
+ ```rust
103
+ // From: forge init --intent "transfer 100 tokens safely"
104
+ token_interface::transfer_checked(
105
+ CpiContext::new(
106
+ ctx.accounts.token_program.to_account_info(),
107
+ TransferChecked {
108
+ from: ctx.accounts.from.to_account_info(),
109
+ to: ctx.accounts.to.to_account_info(),
110
+ authority: ctx.accounts.authority.to_account_info(),
111
+ mint: ctx.accounts.mint.to_account_info(),
112
+ },
113
+ ),
114
+ 100, // amount
115
+ decimals, // automatic decimals lookup
116
+ )?;
117
+ ```
118
+
119
+ **Client SDK Generated:**
120
+ ```typescript
121
+ // Auto-generated TypeScript client
122
+ const client = new TokenTransferClient(connection, wallet);
123
+ await client.transferTokens(amount, from, to, mint, authority);
124
+ ```
125
+
126
+ ## 🚀 SDK Generation
127
+
128
+ FORGE can automatically generate production-ready TypeScript SDKs from your Anchor programs. The generated SDK includes:
129
+
130
+ - **Type-Safe Client**: Full TypeScript client with proper types for all instructions and accounts
131
+ - **PDA Helpers**: Utility functions to find program-derived addresses
132
+ - **Package Template**: Ready-to-publish npm package with proper dependencies
133
+ - **Modern Standards**: Uses latest Anchor patterns and best practices
134
+
135
+ ### SDK Features
136
+
137
+ - ✅ **Zero-config generation** from Anchor IDL
138
+ - ✅ **Type-safe method calls** with full IntelliSense
139
+ - ✅ **PDA finder utilities** for program addresses
140
+ - ✅ **Production-ready package** structure
141
+ - ✅ **Anchor integration** with latest patterns
142
+
143
+ ### Generated SDK Structure
144
+
145
+ ```
146
+ my-program-sdk/
147
+ ├── package.json # Ready-to-publish npm package
148
+ ├── types.ts # Auto-generated TypeScript types
149
+ ├── client.ts # Program interaction client
150
+ ├── pdas.ts # PDA finder utilities
151
+ ├── index.ts # Main exports
152
+ └── tsconfig.json # TypeScript configuration
153
+ ```
154
+
155
+ ### Using Generated SDKs
156
+
157
+ ```typescript
158
+ import { MyProgramClient } from 'my-program-sdk';
159
+ import { Connection, Keypair } from '@solana/web3.js';
160
+
161
+ // Initialize client
162
+ const connection = new Connection('https://api.mainnet-beta.solana.com');
163
+ const client = new MyProgramClient(connection);
164
+
165
+ // Call program methods with full type safety
166
+ const txId = await client.myInstruction({
167
+ accounts: {
168
+ user: userPublicKey,
169
+ // ... other accounts
170
+ },
171
+ args: {
172
+ amount: 1000,
173
+ // ... other args
174
+ }
175
+ });
176
+ ```
177
+
178
+ ## 🛠️ Troubleshooting
43
179
 
44
- - Generates complete Anchor workspace
45
- - Creates Cargo.toml with proper dependencies
46
- - ✅ Sets up lib.rs with Anchor framework
47
- - Configures Anchor.toml for deployment
48
- - Works with real Solana networks
180
+ ### Version Compatibility Issues
181
+ If you encounter build errors:
182
+
183
+ 1. **Update Rust**: `rustup update stable` (requires 1.85.0+)
184
+ 2. **Check versions**: `forge status` (shows mismatches)
185
+ 3. **Specify version**: `forge init --anchor-version 0.32.1`
186
+
187
+ ### Common Errors
188
+ - `edition2024` errors → Update Rust to 1.85.0+
189
+ - Version mismatches → Use `forge status` to check alignment
190
+ - Build failures → Ensure Anchor CLI matches project versions
49
191
 
50
192
  ## 🚫 What FORGE Does NOT Do
51
193
 
@@ -69,41 +211,122 @@ You must have:
69
211
 
70
212
  | Command | Description |
71
213
  |---------|-------------|
72
- | `forge init <name>` | Create new Anchor project |
73
- | `forge status` | Check environment and tools |
74
- | `forge deploy` | Deploy program to Solana |
214
+ | `forge init <name>` | Create new Anchor project with optional intent |
215
+ | `forge init <name> --intent "transfer tokens"` | Generate CPI code from natural language |
216
+ | `forge init <name> --anchor-version 0.31.0` | Specify Anchor version for project |
217
+ | `forge generate-sdk [dir]` | Generate TypeScript SDK from Anchor program |
218
+ | `forge status` | Check environment, versions, and compatibility |
219
+ | `forge update` | Update FORGE to latest version |
220
+ | `forge deploy` | Deploy program to Solana network |
75
221
 
76
222
  ## 📖 Examples
77
223
 
224
+ ### Basic Project Creation
78
225
  ```bash
79
- # Create a token program
80
- forge init my-token
81
-
82
- # Check everything is ready
226
+ # Simple Anchor project
227
+ forge init my-project
228
+ cd my-project
83
229
  forge status
230
+ ```
84
231
 
85
- # Deploy to devnet
86
- forge deploy
232
+ ### Intent-Driven CPI Generation
233
+ ```bash
234
+ # Generate token transfer program
235
+ forge init token-transfer --intent "transfer 100 tokens safely"
236
+ cd token-transfer
237
+
238
+ # Modern CPI code is automatically generated:
239
+ # - transfer_checked with decimals validation
240
+ # - InterfaceAccount<TokenAccount> types
241
+ # - Proper error handling
242
+
243
+ anchor build # ✅ Works immediately
244
+ anchor test # ✅ Ready for testing
87
245
  ```
88
246
 
89
- ## 🏗️ Architecture
247
+ ### Client SDK Generation
248
+ ```bash
249
+ # Generate program with auto-generated TypeScript SDK
250
+ forge init token-transfer --intent "transfer tokens safely"
251
+
252
+ # Project structure includes:
253
+ # ├── programs/token-transfer/src/lib.rs # Anchor program
254
+ # └── client/ # Auto-generated SDK
255
+ # ├── index.ts # Client class
256
+ # ├── idl.ts # Program IDL
257
+ # ├── package.json # SDK package
258
+ # └── tsconfig.json # TypeScript config
259
+
260
+ # Build and use the SDK
261
+ cd client && npm install && npm run build
262
+
263
+ # Use in your frontend/dApp:
264
+ import { TokenTransferClient } from './client';
265
+ const client = new TokenTransferClient(connection, wallet);
266
+ await client.transferTokens(amount, from, to, mint, authority);
267
+ ```
268
+
269
+ ### SDK Generation
270
+ ```bash
271
+ # Generate SDK after building your program
272
+ cd my-project
273
+ anchor build
274
+ forge generate-sdk
275
+
276
+ # SDK appears in ./sdk/ directory
277
+ cd sdk
278
+ npm install
279
+ npm run build
280
+
281
+ # Publish your SDK
282
+ npm publish
283
+ ```
284
+
285
+ ### Advanced Usage
286
+ ```bash
287
+ # Mint tokens with PDA authority
288
+ forge init token-minter --intent "mint 500 tokens to user"
90
289
 
290
+ # Custom Anchor version
291
+ forge init legacy-project --anchor-version 0.30.1
292
+
293
+ # Stay updated
294
+ forge update
91
295
  ```
92
- FORGE CLI (npm)
93
- ├── forge-sdk-solana - Node.js CLI tool
94
- └── forge-runtime - Rust runtime (crates.io)
95
296
 
96
- Both work together for complete Solana development
297
+ ## 🏗️ Architecture
298
+
299
+ ```
300
+ FORGE Ecosystem
301
+ ├── forge-solana-sdk (npm) - Node.js CLI tool
302
+ │ ├── Intent parsing & code generation
303
+ │ ├── Version compatibility management
304
+ │ ├── Project scaffolding
305
+ │ └── Deployment orchestration
306
+
307
+ └── forge-runtime (crates.io) - Rust runtime library
308
+ └── Future: Enhanced runtime capabilities
97
309
  ```
98
310
 
311
+ **Current Focus**: CLI-first approach with intent-driven generation. Runtime library for future enhancements.
312
+
99
313
  ## 🐛 Support
100
314
 
101
- This is infrastructure. If it breaks:
102
- 1. File an issue on GitHub
103
- 2. Include your `forge status` output
104
- 3. Describe what you expected vs what happened
315
+ **FORGE is infrastructure, not a tutorial.** If you need help:
316
+
317
+ ### Getting Help
318
+ 1. **Run diagnostics first**: `forge status` (includes version compatibility checks)
319
+ 2. **Check prerequisites**: Ensure Rust 1.85.0+, Node 18+, Anchor CLI installed
320
+ 3. **File an issue**: Include `forge status` output and error details
321
+ 4. **Describe expected vs actual**: What did you expect? What happened instead?
322
+
323
+ ### Before Asking
324
+ - ✅ Have you run `forge status`?
325
+ - ✅ Is your Rust version 1.85.0+?
326
+ - ✅ Are you in an Anchor project directory?
327
+ - ✅ Have you tried `forge update`?
105
328
 
106
- If you don't understand Solana, learn Solana first.
329
+ **If you don't understand Solana concepts, learn Solana first.** FORGE assumes basic blockchain knowledge.
107
330
 
108
331
  ## 📄 License
109
332
 
@@ -117,4 +340,4 @@ MIT - [https://github.com/forge-protocol/forge/blob/main/LICENSE](https://github
117
340
 
118
341
  ---
119
342
 
120
- **FORGE: Infrastructure, not cosplay.** ⚡
343
+ **FORGE: Intent → Code. No magic, just infrastructure.** ⚡
package/dist/cli.js CHANGED
@@ -6,11 +6,12 @@ const ascii_js_1 = require("./ascii.js");
6
6
  const init_js_1 = require("./commands/init.js");
7
7
  const deploy_js_1 = require("./commands/deploy.js");
8
8
  const status_js_1 = require("./commands/status.js");
9
+ const generate_sdk_js_1 = require("./commands/generate-sdk.js");
9
10
  const program = new commander_1.Command();
10
11
  program
11
12
  .name('forge')
12
13
  .description('FORGE - Intent-driven app assembly on Solana')
13
- .version('2.1.3');
14
+ .version('2.2.0');
14
15
  program
15
16
  .command('init [projectName]')
16
17
  .description('Initialize a new FORGE project')
@@ -25,15 +26,33 @@ program
25
26
  .action(async () => {
26
27
  await (0, deploy_js_1.deployCommand)();
27
28
  });
29
+ program
30
+ .command('generate-sdk [outputDir]')
31
+ .description('Generate TypeScript SDK from Anchor program')
32
+ .action(async (outputDir) => {
33
+ await (0, generate_sdk_js_1.generateSdkCommand)(outputDir);
34
+ });
28
35
  program
29
36
  .command('status')
30
37
  .description('Check FORGE status and environment')
31
38
  .action(async () => {
32
39
  await (0, status_js_1.statusCommand)();
33
40
  });
41
+ program
42
+ .command('update')
43
+ .description('Update FORGE to the latest version')
44
+ .action(async () => {
45
+ await (0, status_js_1.updateCommand)();
46
+ });
34
47
  // Show logo on help
35
48
  program.on('--help', () => {
36
49
  console.log(ascii_js_1.logo);
50
+ console.log('\nCommands:');
51
+ console.log(' init Create new Anchor projects');
52
+ console.log(' generate-sdk Generate TypeScript SDK from program');
53
+ console.log(' status Check environment & versions');
54
+ console.log(' update Update FORGE to latest version');
55
+ console.log(' deploy Deploy to Solana network');
37
56
  console.log('\nFORGE does not:');
38
57
  console.log('- host your code');
39
58
  console.log('- manage your keys');
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,yCAAkC;AAClC,gDAAiD;AACjD,oDAAqD;AACrD,oDAAqD;AAErD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,8CAA8C,CAAC;KAC3D,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,oBAAoB,CAAC;KAC7B,WAAW,CAAC,gCAAgC,CAAC;KAC7C,MAAM,CAAC,uBAAuB,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AAQ,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,eAAI,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEH,kBAAkB;AAClB,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function generateSdkCommand(outputDir?: string): Promise<void>;
2
+ //# sourceMappingURL=generate-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-sdk.d.ts","sourceRoot":"","sources":["../../src/commands/generate-sdk.ts"],"names":[],"mappings":"AAsCA,wBAAsB,kBAAkB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyD1E"}