@wuwei-labs/srsly 2.0.0-beta.26 → 2.0.0-beta.28

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.
Files changed (72) hide show
  1. package/README.md +189 -97
  2. package/dist/cjs/contract/close.js +33 -24
  3. package/dist/cjs/contract/close.js.map +1 -1
  4. package/dist/cjs/contract/create.js +67 -52
  5. package/dist/cjs/contract/create.js.map +1 -1
  6. package/dist/cjs/package.json +2 -13
  7. package/dist/cjs/rental/accept.js +35 -29
  8. package/dist/cjs/rental/accept.js.map +1 -1
  9. package/dist/cjs/rental/cancel.js +13 -9
  10. package/dist/cjs/rental/cancel.js.map +1 -1
  11. package/dist/cjs/rental/close.js +15 -11
  12. package/dist/cjs/rental/close.js.map +1 -1
  13. package/dist/cjs/rental/reset.js +20 -17
  14. package/dist/cjs/rental/reset.js.map +1 -1
  15. package/dist/cjs/utils/config.js +0 -88
  16. package/dist/cjs/utils/config.js.map +1 -1
  17. package/dist/cjs/utils/index.js +1 -0
  18. package/dist/cjs/utils/index.js.map +1 -1
  19. package/dist/cjs/utils/instruction-converter.js +49 -0
  20. package/dist/cjs/utils/instruction-converter.js.map +1 -0
  21. package/dist/esm/contract/close.js +34 -25
  22. package/dist/esm/contract/close.js.map +1 -1
  23. package/dist/esm/contract/create.js +67 -51
  24. package/dist/esm/contract/create.js.map +1 -1
  25. package/dist/esm/package.json +2 -13
  26. package/dist/esm/rental/accept.js +36 -30
  27. package/dist/esm/rental/accept.js.map +1 -1
  28. package/dist/esm/rental/cancel.js +13 -9
  29. package/dist/esm/rental/cancel.js.map +1 -1
  30. package/dist/esm/rental/close.js +15 -11
  31. package/dist/esm/rental/close.js.map +1 -1
  32. package/dist/esm/rental/reset.js +22 -19
  33. package/dist/esm/rental/reset.js.map +1 -1
  34. package/dist/esm/utils/config.js +0 -88
  35. package/dist/esm/utils/config.js.map +1 -1
  36. package/dist/esm/utils/index.js +1 -0
  37. package/dist/esm/utils/index.js.map +1 -1
  38. package/dist/esm/utils/instruction-converter.js +45 -0
  39. package/dist/esm/utils/instruction-converter.js.map +1 -0
  40. package/dist/types/contract/close.d.ts +12 -11
  41. package/dist/types/contract/close.d.ts.map +1 -1
  42. package/dist/types/contract/create.d.ts +49 -65
  43. package/dist/types/contract/create.d.ts.map +1 -1
  44. package/dist/types/rental/accept.d.ts +32 -28
  45. package/dist/types/rental/accept.d.ts.map +1 -1
  46. package/dist/types/rental/cancel.d.ts +16 -12
  47. package/dist/types/rental/cancel.d.ts.map +1 -1
  48. package/dist/types/rental/close.d.ts +16 -13
  49. package/dist/types/rental/close.d.ts.map +1 -1
  50. package/dist/types/rental/reset.d.ts +19 -16
  51. package/dist/types/rental/reset.d.ts.map +1 -1
  52. package/dist/types/utils/config.d.ts +0 -95
  53. package/dist/types/utils/config.d.ts.map +1 -1
  54. package/dist/types/utils/index.d.ts +1 -0
  55. package/dist/types/utils/index.d.ts.map +1 -1
  56. package/dist/types/utils/instruction-converter.d.ts +76 -0
  57. package/dist/types/utils/instruction-converter.d.ts.map +1 -0
  58. package/dist/types/utils/types.d.ts +0 -8
  59. package/dist/types/utils/types.d.ts.map +1 -1
  60. package/package.json +2 -13
  61. package/dist/cjs/utils/pack-functions.js +0 -148
  62. package/dist/cjs/utils/pack-functions.js.map +0 -1
  63. package/dist/cjs/utils/solana-adapter.js +0 -120
  64. package/dist/cjs/utils/solana-adapter.js.map +0 -1
  65. package/dist/esm/utils/pack-functions.js +0 -110
  66. package/dist/esm/utils/pack-functions.js.map +0 -1
  67. package/dist/esm/utils/solana-adapter.js +0 -82
  68. package/dist/esm/utils/solana-adapter.js.map +0 -1
  69. package/dist/types/utils/pack-functions.d.ts +0 -18
  70. package/dist/types/utils/pack-functions.d.ts.map +0 -1
  71. package/dist/types/utils/solana-adapter.d.ts +0 -26
  72. package/dist/types/utils/solana-adapter.d.ts.map +0 -1
package/README.md CHANGED
@@ -4,154 +4,134 @@
4
4
  [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
5
5
  [![Solana](https://img.shields.io/badge/Solana-000?style=flat&logo=solana&logoColor=9945FF)](https://solana.com/)
6
6
 
7
- A flexible TypeScript SDK for building and sending Solana transactions to interact with the SRSLY (Space Rental from SLY) program - a decentralized rental system for Star Atlas fleets.
7
+ A flexible TypeScript SDK for building Solana instructions to interact with the SRSLY (Space Rental from SLY) program - a decentralized rental system for Star Atlas fleets.
8
8
 
9
9
  ## What This SDK Does
10
10
 
11
- The SRSLY SDK is a complete toolkit that helps you create Solana transactions for fleet rentals. It provides:
11
+ The SRSLY SDK is a focused instruction builder that helps you create Solana instructions for fleet rentals. It provides:
12
12
 
13
- - ✅ **Flexible Dependencies** - Choose your preferred Solana library (`@solana/kit` or `@solana/web3.js`)
14
- - ✅ **Three Pack Methods** - `packKit()`, `packWeb3js()`, or `pack()` (auto-detect)
15
- - ✅ Account derivation and validation
16
- - ✅ Instruction data encoding
17
- - ✅ Type-safe parameter handling
18
- - ✅ Direct transaction sending via `.send()` (server/CLI)
19
- - ✅ Unsigned transaction building via `.pack*()` (browser/wallets)
20
- - ✅ Wallet-agnostic design (works with any signing method)
21
- - ✅ Duration helper functions (`days()`, `weeks()`, `months()`)
13
+ - ✅ **Universal Compatibility** - Works with both `@solana/kit` and `@solana/web3.js` using string addresses
14
+ - ✅ **Instruction Building** - Creates properly formatted Solana instructions
15
+ - ✅ **Account derivation and validation** - Automatically derives required accounts
16
+ - ✅ **Instruction data encoding** - Handles all the complex encoding for you
17
+ - ✅ **Type-safe parameter handling** - Full TypeScript support with validation
18
+ - ✅ **Format conversion utilities** - Easy conversion between library formats
19
+ - ✅ **Duration helper functions** - `days()`, `weeks()`, `months()` for time calculations
20
+ - ✅ **Network configuration** - Support for mainnet, atlasnet, and holosim
22
21
 
23
- **Current Status**: Full instruction building, transaction packing, and direct sending support with dual library compatibility.
22
+ **Current Status**: Instruction building with universal compatibility. Users handle transaction packing and sending with their preferred Solana library.
24
23
 
25
24
  ## Installation
26
25
 
27
26
  ```bash
28
- # 1. Install the SDK
27
+ # Install the SDK
29
28
  npm install @wuwei-labs/srsly
30
29
 
31
- # 2. Install your preferred Solana library (peer dependency)
30
+ # Install your preferred Solana library
32
31
  # Option A: Modern @solana/kit (recommended)
33
32
  npm install @solana/kit
34
33
 
35
- # Option B: Legacy @solana/web3.js (wallet adapter compatibility)
34
+ # Option B: Legacy @solana/web3.js (wallet adapter compatibility)
36
35
  npm install @solana/web3.js
37
36
 
38
37
  # Option C: Both libraries (for maximum flexibility)
39
38
  npm install @solana/kit @solana/web3.js
40
39
  ```
41
40
 
42
- The SDK uses **peer dependencies** to give you control over which Solana library to use, reducing bundle size and avoiding version conflicts.
41
+ The SDK creates **universal instructions** that work with any Solana library using string addresses.
43
42
 
44
43
  ## Quick Start
45
44
 
46
45
  ### Option 1: Using @solana/kit (Modern, Recommended)
47
46
 
48
47
  ```typescript
49
- import { createContract, setConfig, days, weeks } from '@wuwei-labs/srsly';
50
- import { createKeyPairSignerFromBytes } from '@solana/kit';
48
+ import { createContract, setConfig, days, convertKitToWeb3js } from '@wuwei-labs/srsly';
49
+ import { createKeyPairSignerFromBytes, createTransactionMessage, pipe } from '@solana/kit';
51
50
 
52
- // 1. Configure SDK with RPC endpoint
51
+ // 1. Configure SDK for your network
53
52
  setConfig({
54
- programs: 'atlasnet',
55
- rpcUrl: 'https://api.atlasnet.solana.com',
56
- solanaLibrary: 'kit' // Optional: specify preferred library
53
+ programs: 'atlasnet' // or 'mainnet', 'holosim'
57
54
  });
58
55
 
59
- // 2. Create signer from keypair
60
- const signer = await createKeyPairSignerFromBytes(keypairBytes);
61
-
62
- // 3. Pack and send using @solana/kit (chainable!)
63
- const signature = await createContract({
64
- owner: signer,
65
- fleet: fleetAddress,
66
- ownerProfile: profileAddress,
67
- rate: 1000000, // ATLAS tokens per payment period
68
- durationMax: days(7), // 7 days using helper function
69
- paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
70
- }).packKit(signer.address).send(signer); // Uses @solana/kit
71
-
72
- console.log('Transaction signature:', signature);
73
-
74
- // Alternative: Auto-detect library (prefers @solana/kit when available)
75
- const signature2 = await createContract(params)
76
- .pack(signer.address) // Auto-detects and uses @solana/kit
77
- .send(signer);
56
+ // 2. Create an instruction
57
+ const instruction = await createContract({
58
+ owner: signer, // Can be a signer object or string address
59
+ fleet: "FleetAddress123...", // String address
60
+ ownerProfile: "ProfileAddr...", // String address
61
+ rate: 1000000, // ATLAS tokens per payment period
62
+ durationMax: days(7), // 7 days using helper function
63
+ paymentsFreq: 'daily' // Payment frequency
64
+ });
78
65
 
79
- // Two-step approach
80
- const packedTx = await createContract(params).packKit(signer.address);
81
- const signature3 = await packedTx.send(signer);
66
+ // 3. Use with @solana/kit (instruction is already in kit format)
67
+ const transaction = pipe(
68
+ createTransactionMessage({ version: 0 }),
69
+ // ... add instruction to transaction and send with @solana/kit
70
+ );
82
71
  ```
83
72
 
84
73
  ### Option 2: Using @solana/web3.js (Wallet Adapter Compatible)
85
74
 
86
75
  ```typescript
87
- import { createContract, setConfig, days } from '@wuwei-labs/srsly';
76
+ import { createContract, setConfig, days, convertKitToWeb3js } from '@wuwei-labs/srsly';
77
+ import { Transaction, PublicKey } from '@solana/web3.js';
88
78
 
89
- // 1. Configure SDK with RPC endpoint
90
- setConfig({
91
- programs: 'atlasnet',
92
- rpcUrl: 'https://api.atlasnet.solana.com',
93
- solanaLibrary: 'web3js' // Optional: specify web3.js preference
79
+ // 1. Configure SDK
80
+ setConfig({ programs: 'atlasnet' });
81
+
82
+ // 2. Create an instruction
83
+ const kitInstruction = await createContract({
84
+ owner: wallet.publicKey.toString(), // String address
85
+ fleet: "FleetAddress123...",
86
+ ownerProfile: "ProfileAddr...",
87
+ rate: 1000000,
88
+ durationMax: days(7),
89
+ paymentsFreq: 'daily'
94
90
  });
95
91
 
96
- // 2. Pack using web3.js-optimized method
97
- const packedTx = await createContract({
98
- owner: walletPublicKey,
99
- fleet: fleetAddress,
100
- ownerProfile: profileAddress,
101
- rate: 1000000, // ATLAS tokens per payment period
102
- durationMax: days(7), // 7 days using helper function
103
- paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
104
- }).packWeb3js(walletPublicKey); // Creates web3.js Transaction object
92
+ // 3. Convert to web3.js format and use
93
+ const web3jsInstruction = convertKitToWeb3js(kitInstruction);
94
+ const transaction = new Transaction().add(web3jsInstruction);
105
95
 
106
- // Option A: Use SDK's built-in send (handles signing + sending)
107
- const signature = await packedTx.send(walletSigner);
96
+ // Sign and send with your preferred method
97
+ const signature = await wallet.sendTransaction(transaction, connection);
98
+ ```
108
99
 
109
- // Option B: Direct wallet adapter integration
110
- import { useWallet } from '@solana/wallet-adapter-react';
111
- import { Connection } from '@solana/web3.js';
100
+ ## Core Features
112
101
 
113
- const wallet = useWallet();
114
- const connection = new Connection(rpcUrl);
102
+ ### Universal Instructions
115
103
 
116
- // Use the ready-to-go Transaction object directly
117
- const signedTx = await wallet.signTransaction(packedTx.transaction);
118
- const signature = await connection.sendRawTransaction(signedTx.serialize());
104
+ The SDK creates **universal instructions** that work with both @solana/kit and @solana/web3.js:
119
105
 
120
- // Option C: Auto-detect library (will use web3.js if kit isn't available)
121
- const packedTx2 = await createContract(params)
122
- .pack(walletPublicKey); // Auto-detects and uses best available library
123
- ```
106
+ - **🔄 Format Conversion**: Built-in utilities to convert between library formats
107
+ - **📦 Instruction-Only**: Focus on instruction building, users handle transaction packing/sending
108
+ - **🎯 String Addresses**: Simple string-based addressing eliminates type complexity
109
+ - **⚡ Lightweight**: No bundled Solana libraries, users choose their own
124
110
 
125
- ### Option 3: Manual Instruction Building
111
+ ### Format Conversion Example
126
112
 
127
113
  ```typescript
128
- import { createContract } from '@wuwei-labs/srsly';
114
+ import { createContract, convertKitToWeb3js } from '@wuwei-labs/srsly';
129
115
 
130
- // Build instruction only (no RPC calls)
131
- const instruction = await createContract({
132
- owner: walletPublicKey,
133
- fleet: fleetAddress,
134
- ownerProfile: profileAddress,
135
- rate: 1000000,
136
- durationMin: 86400,
137
- durationMax: 604800,
138
- paymentsFreq: 'daily'
139
- });
140
-
141
- // Handle transaction building and submission yourself
142
- // ... use instruction with your preferred transaction building method
143
- ```
144
-
145
- ## Core Features
116
+ // Create instruction (returns @solana/kit format by default)
117
+ const kitInstruction = await createContract(params);
146
118
 
147
- ### Dual Compatibility
119
+ // Convert to @solana/web3.js format when needed
120
+ const web3jsInstruction = convertKitToWeb3js(kitInstruction);
148
121
 
149
- The SDK provides two optimized paths for different environments:
122
+ // Now compatible with any @solana/web3.js workflow
123
+ const transaction = new Transaction().add(web3jsInstruction);
124
+ ```
150
125
 
151
- - **🌐 Browser/Wallet Adapter Path**: Uses `.pack()` to create raw `messageBytes` that can be converted to `web3.js` format when needed
152
- - **🖥️ Server/CLI Path**: Uses `.pack().send()` with `@solana/kit` for direct transaction submission
126
+ You can control the auto-detection behavior via configuration:
153
127
 
154
- The SDK is lightweight and doesn't force web3.js as a dependency - users only install it if they need wallet adapter compatibility.
128
+ ```typescript
129
+ setConfig({
130
+ programs: 'atlasnet',
131
+ rpcUrl: 'https://api.atlasnet.com',
132
+ solanaLibrary: 'kit' // 'auto' | 'kit' | 'web3js'
133
+ });
134
+ ```
155
135
 
156
136
  ### Flexible Address Input
157
137
 
@@ -288,6 +268,9 @@ setConfig({
288
268
  // RPC Configuration - Required for creating transactions
289
269
  rpcUrl: 'https://your-rpc-provider.com/api-key', // Your RPC endpoint
290
270
 
271
+ // Solana Library Preference - Control which library to use for pack methods
272
+ solanaLibrary: 'auto', // 'auto' | 'kit' | 'web3js' (auto prefers @solana/kit)
273
+
291
274
  // Program Address Overrides - Customize specific program addresses
292
275
  srslyProgramAddress: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT', // SRSLY program
293
276
  profileFactionProgramAddress: 'PprofUW1pURCnMW2si88GWPXEEK3Bvh9Tksy8WtnoYJ', // Profile Faction program
@@ -306,6 +289,10 @@ setConfig({ programs: 'mainnet' }); // Uses mainnet programs + default RPC
306
289
  setConfig({ programs: 'atlasnet', rpcUrl: 'https://your-rpc.com' }); // Atlasnet + custom RPC
307
290
  setConfig({ programs: 'holosim', rpcUrl: 'https://your-rpc.com' }); // Holosim + custom RPC
308
291
 
292
+ // Library preference configurations
293
+ setConfig({ programs: 'atlasnet', rpcUrl: 'https://your-rpc.com', solanaLibrary: 'kit' }); // Force @solana/kit
294
+ setConfig({ programs: 'atlasnet', rpcUrl: 'https://your-rpc.com', solanaLibrary: 'web3js' }); // Force @solana/web3.js
295
+
309
296
  // Check current configuration
310
297
  console.log(getConfig());
311
298
 
@@ -319,6 +306,7 @@ clearConfig();
319
306
  |--------|------|-------------|---------|
320
307
  | `programs` | `'mainnet' \| 'atlasnet' \| 'holosim'` | Predefined program address set | `'atlasnet'` |
321
308
  | `rpcUrl` | `string` | Solana RPC endpoint URL (required for pack/send) | `undefined` |
309
+ | `solanaLibrary` | `'auto' \| 'kit' \| 'web3js'` | Preferred Solana library for pack methods | `'auto'` |
322
310
  | `srslyProgramAddress` | `string` | SRSLY program address override | From program set |
323
311
  | `profileFactionProgramAddress` | `string` | Profile Faction program override | From program set |
324
312
  | `gameId` | `string` | SAGE game ID override | From program set |
@@ -332,12 +320,13 @@ clearConfig();
332
320
  // Override global config for specific instructions
333
321
  const ix = await createContract(params).set({
334
322
  programs: 'mainnet',
323
+ solanaLibrary: 'kit',
335
324
  transactionOptions: { commitment: 'finalized' }
336
325
  });
337
326
 
338
327
  // Chain multiple configurations
339
328
  const ix2 = await acceptRental(params)
340
- .set({ programs: 'holosim', rpcUrl: 'https://custom-rpc.com' })
329
+ .set({ programs: 'holosim', rpcUrl: 'https://custom-rpc.com', solanaLibrary: 'web3js' })
341
330
  .set({ gameId: 'custom-game-id...', atlasMint: 'custom-mint...' });
342
331
  ```
343
332
 
@@ -499,6 +488,109 @@ The SDK provides optimized builds for different environments:
499
488
  - **Types**: `./dist/types/` (TypeScript definitions)
500
489
  - **Shared**: `./dist/shared/codama/` (Optimized codama exports)
501
490
 
491
+ ## Troubleshooting
492
+
493
+ ### Webpack Build Errors with Peer Dependencies
494
+
495
+ If you encounter `Can't resolve '@solana/kit'` or `Can't resolve '@solana/web3.js'` errors during webpack builds, this is because webpack tries to resolve all imports at build time, even for optional peer dependencies you haven't installed.
496
+
497
+ #### Solution 1: Use Library-Specific Entry Points (Recommended)
498
+
499
+ Use library-specific imports to avoid webpack trying to resolve libraries you don't have installed:
500
+
501
+ ```javascript
502
+ // ✅ Best: Only bundles @solana/kit dependencies
503
+ import { createContract, setConfig } from '@wuwei-labs/srsly/kit';
504
+
505
+ // ✅ Best: Only bundles @solana/web3.js dependencies
506
+ import { createContract, setConfig } from '@wuwei-labs/srsly/web3js';
507
+
508
+ // ❌ Avoid if you only have one library: May try to resolve both
509
+ import { createContract, setConfig } from '@wuwei-labs/srsly';
510
+ ```
511
+
512
+ **Benefits:**
513
+ - ✅ Webpack only bundles the dependencies you actually need
514
+ - ✅ No resolution errors for missing peer dependencies
515
+ - ✅ Smaller bundle sizes due to better tree-shaking
516
+
517
+ #### Solution 2: Use ES Modules
518
+
519
+ Use ES module imports instead of CommonJS `require()` to enable proper tree-shaking:
520
+
521
+ ```javascript
522
+ // ✅ Good: ESM imports (allows tree-shaking)
523
+ import { createContract, setConfig } from '@wuwei-labs/srsly';
524
+
525
+ // ❌ Avoid: CommonJS requires (bundles everything)
526
+ const { createContract, setConfig } = require('@wuwei-labs/srsly');
527
+ ```
528
+
529
+ #### Solution 3: Install the Missing Library
530
+
531
+ If you must use CommonJS or get resolution errors:
532
+
533
+ ```bash
534
+ # Install the library webpack is complaining about
535
+ npm install @solana/kit
536
+
537
+ # Or if you only want web3.js:
538
+ npm install @solana/web3.js
539
+ ```
540
+
541
+ #### Solution 4: Webpack Configuration
542
+
543
+ Configure webpack to ignore optional peer dependencies you don't need (may still be needed in some webpack configurations):
544
+
545
+ ```javascript
546
+ // webpack.config.js
547
+ module.exports = {
548
+ // ... other config
549
+ externals: {
550
+ // Only ignore the library you're NOT using
551
+ '@solana/kit': 'commonjs @solana/kit', // If you only use web3.js
552
+ '@solana/web3.js': 'commonjs @solana/web3.js' // If you only use @solana/kit
553
+ },
554
+ // Alternative: use IgnorePlugin for dynamic imports
555
+ plugins: [
556
+ new webpack.IgnorePlugin({
557
+ resourceRegExp: /@solana\/kit$/, // Ignore @solana/kit if you only use web3.js
558
+ // OR
559
+ resourceRegExp: /@solana\/web3\.js$/ // Ignore web3.js if you only use @solana/kit
560
+ })
561
+ ]
562
+ };
563
+ ```
564
+
565
+ #### Solution 5: Use Specific Pack Methods
566
+
567
+ Use only the pack method for your installed library:
568
+
569
+ ```typescript
570
+ // If you only have @solana/web3.js installed:
571
+ const packedTx = await createContract(params).packWeb3js(feePayer);
572
+
573
+ // If you only have @solana/kit installed:
574
+ const packedTx = await createContract(params).packKit(feePayer);
575
+
576
+ // Avoid .pack() auto-detection if you want to minimize bundle analysis issues
577
+ ```
578
+
579
+ ### Library Not Found at Runtime
580
+
581
+ If you get runtime errors about missing libraries, ensure you've installed the peer dependency:
582
+
583
+ ```bash
584
+ # For modern Solana development (recommended):
585
+ npm install @solana/kit
586
+
587
+ # For wallet adapter compatibility:
588
+ npm install @solana/web3.js
589
+
590
+ # For maximum compatibility:
591
+ npm install @solana/kit @solana/web3.js
592
+ ```
593
+
502
594
  ## Links
503
595
 
504
596
  - **NPM Package**: [@wuwei-labs/srsly](https://www.npmjs.com/package/@wuwei-labs/srsly)
@@ -5,38 +5,42 @@ exports.getCloseContractInstructionAsync = getCloseContractInstructionAsync;
5
5
  const config_1 = require("../utils/config");
6
6
  const constants_1 = require("../utils/constants");
7
7
  const utils_1 = require("../utils");
8
+ const instruction_converter_1 = require("../utils/instruction-converter");
8
9
  /**
9
10
  * Asynchronously creates an instruction to close a rental contract with minimal required parameters.
10
11
  * Derives rentalAuthority automatically and handles optional parameters.
11
12
  *
12
13
  * @example
13
14
  * ```typescript
14
- * // Create the instruction with default devnet settings
15
- * const ix = await closeContract({
16
- * owner: wallet,
17
- * fleet: fleetAddress,
18
- * contract: contractAddress,
15
+ * // Works with any library - just use strings for addresses!
16
+ * const instruction = await closeContract({
17
+ * owner: wallet, // Can be signer object or string
18
+ * fleet: "FleetAddress123...", // String address
19
+ * contract: "ContractAddr...", // String address
19
20
  * faction: 'mud',
20
21
  * });
21
22
  *
22
23
  * // Use mainnet configuration
23
- * const ix = await closeContract({
24
+ * const instruction = await closeContract({
24
25
  * owner: wallet,
25
- * fleet: fleetAddress,
26
- * contract: contractAddress,
26
+ * fleet: "FleetAddress123...",
27
+ * contract: "ContractAddr...",
27
28
  * faction: 'mud',
28
- * }).set({ network: 'mainnet' });
29
+ * }).set({ programs: 'mainnet' });
29
30
  *
30
31
  * // Override specific constants
31
- * const ix = await closeContract({
32
+ * const instruction = await closeContract({
32
33
  * owner: wallet,
33
- * fleet: fleetAddress,
34
- * contract: contractAddress,
34
+ * fleet: "FleetAddress123...",
35
+ * contract: "ContractAddr...",
35
36
  * faction: 'mud',
36
37
  * }).set({
37
- * network: 'mainnet',
38
+ * programs: 'mainnet',
38
39
  * gameId: 'custom-game-id...'
39
40
  * });
41
+ *
42
+ * // Use the instruction with your preferred Solana library
43
+ * // instruction is compatible with both @solana/kit and @solana/web3.js
40
44
  * ```
41
45
  *
42
46
  * @param params The simplified parameters for closing a rental contract
@@ -49,7 +53,10 @@ async function _closeContract(params, config) {
49
53
  const { owner, fleet, contract, faction, gameId, } = params;
50
54
  // Get the actual game ID to use (param override, config override, or network default)
51
55
  const actualGameId = gameId ? (0, constants_1.toAddress)(gameId) : await (0, constants_1.getSageGameId)(config);
52
- const derivedAccounts = await (0, utils_1.deriveGameAccounts)(owner.address, faction, actualGameId, 0, // starbaseSeqId
56
+ // Extract owner address (handle both string and signer object)
57
+ const ownerAddress = typeof owner === 'string' ? owner :
58
+ (owner && typeof owner === 'object' && 'address' in owner) ? owner.address : owner;
59
+ const derivedAccounts = await (0, utils_1.deriveGameAccounts)(ownerAddress, faction, actualGameId, 0, // starbaseSeqId
53
60
  config);
54
61
  const starbase = derivedAccounts.starbase;
55
62
  const starbasePlayer = derivedAccounts.starbasePlayer;
@@ -60,14 +67,15 @@ async function _closeContract(params, config) {
60
67
  const { SRSLY_PROGRAM_ADDRESS } = programsModule;
61
68
  // Let codama derive the rest (rentalAuthority, ownerTokenAccount, etc.)
62
69
  const input = {
63
- owner,
64
- fleet: (0, constants_1.toAddress)(fleet),
65
- contract: (0, constants_1.toAddress)(contract),
66
- starbase,
67
- starbasePlayer,
68
- gameId: actualGameId,
70
+ owner, // Pass as-is (string or signer)
71
+ fleet: (0, constants_1.toAddress)(fleet), // Ensure string
72
+ contract: (0, constants_1.toAddress)(contract), // Ensure string
73
+ starbase, // Already string from deriveGameAccounts
74
+ starbasePlayer, // Already string from deriveGameAccounts
75
+ gameId: actualGameId, // Already string
69
76
  };
70
- return getCloseContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
77
+ const rawInstruction = await getCloseContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
78
+ return (0, instruction_converter_1.createFluentInstruction)(rawInstruction);
71
79
  }
72
80
  /**
73
81
  * Creates an instruction to close a rental contract with fluent configuration.
@@ -77,18 +85,19 @@ async function _closeContract(params, config) {
77
85
  *
78
86
  * @example
79
87
  * ```typescript
80
- * // Use devnet defaults
88
+ * // Use atlasnet defaults (instruction building only)
81
89
  * await closeContract(params);
82
90
  *
83
91
  * // Use mainnet
84
- * await closeContract(params).set({ network: 'mainnet' });
92
+ * await closeContract(params).set({ programs: 'mainnet' });
85
93
  *
86
94
  * // Override game ID
87
95
  * await closeContract(params).set({ gameId: 'custom...' });
88
96
  * ```
89
97
  */
90
98
  function closeContract(params) {
91
- return (0, config_1.createConfigSelector)((config) => _closeContract(params, config));
99
+ const baseSelector = (0, config_1.createConfigSelector)((config) => _closeContract(params, config));
100
+ return (0, instruction_converter_1.createFluentConfigSelector)(baseSelector);
92
101
  }
93
102
  // Export config selector for getCloseContractInstructionAsync
94
103
  function getCloseContractInstructionAsync(input, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":";;AAyJA,sCAIC;AAGD,4EAKC;AAhKD,4CAA2G;AAC3G,kDAA8D;AAK9D,oCAEkB;AAkClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH;;GAEG;AACH,KAAK,UAAU,cAAc,CAC3B,MAA2B,EAC3B,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,GACP,GAAG,MAAM,CAAC;IAEX,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,IAAA,qBAAS,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAA,yBAAa,EAAC,MAAM,CAAC,CAAC;IAE9E,MAAM,eAAe,GAAG,MAAM,IAAA,0BAAkB,EAC9C,KAAK,CAAC,OAAO,EACb,OAAQ,EACR,YAAY,EACZ,CAAC,EAAE,gBAAgB;IACnB,MAAM,CACP,CAAC;IAEF,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IAC1C,MAAM,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;IAEtD,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,IAAA,kBAAS,EAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,EAAE,gCAAgC,EAAE,GAAG,kBAAkB,CAAC;IAChE,MAAM,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAAC;IAEjD,wEAAwE;IACxE,MAAM,KAAK,GAAG;QACZ,KAAK;QACL,KAAK,EAAE,IAAA,qBAAS,EAAC,KAAK,CAAC;QACvB,QAAQ,EAAE,IAAA,qBAAS,EAAC,QAAQ,CAAC;QAC7B,QAAQ;Q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