@wuwei-labs/srsly 2.0.0-beta.25 → 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 (70) hide show
  1. package/README.md +200 -99
  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 -6
  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 +1 -180
  16. package/dist/cjs/utils/config.js.map +1 -1
  17. package/dist/cjs/utils/constants.js +2 -2
  18. package/dist/cjs/utils/constants.js.map +1 -1
  19. package/dist/cjs/utils/index.js +1 -0
  20. package/dist/cjs/utils/index.js.map +1 -1
  21. package/dist/cjs/utils/instruction-converter.js +49 -0
  22. package/dist/cjs/utils/instruction-converter.js.map +1 -0
  23. package/dist/cjs/utils/types.js +6 -0
  24. package/dist/cjs/utils/types.js.map +1 -0
  25. package/dist/esm/contract/close.js +34 -25
  26. package/dist/esm/contract/close.js.map +1 -1
  27. package/dist/esm/contract/create.js +67 -51
  28. package/dist/esm/contract/create.js.map +1 -1
  29. package/dist/esm/package.json +2 -6
  30. package/dist/esm/rental/accept.js +36 -30
  31. package/dist/esm/rental/accept.js.map +1 -1
  32. package/dist/esm/rental/cancel.js +13 -9
  33. package/dist/esm/rental/cancel.js.map +1 -1
  34. package/dist/esm/rental/close.js +15 -11
  35. package/dist/esm/rental/close.js.map +1 -1
  36. package/dist/esm/rental/reset.js +22 -19
  37. package/dist/esm/rental/reset.js.map +1 -1
  38. package/dist/esm/utils/config.js +1 -181
  39. package/dist/esm/utils/config.js.map +1 -1
  40. package/dist/esm/utils/constants.js +2 -2
  41. package/dist/esm/utils/constants.js.map +1 -1
  42. package/dist/esm/utils/index.js +1 -0
  43. package/dist/esm/utils/index.js.map +1 -1
  44. package/dist/esm/utils/instruction-converter.js +45 -0
  45. package/dist/esm/utils/instruction-converter.js.map +1 -0
  46. package/dist/esm/utils/types.js +5 -0
  47. package/dist/esm/utils/types.js.map +1 -0
  48. package/dist/types/contract/close.d.ts +12 -11
  49. package/dist/types/contract/close.d.ts.map +1 -1
  50. package/dist/types/contract/create.d.ts +49 -65
  51. package/dist/types/contract/create.d.ts.map +1 -1
  52. package/dist/types/rental/accept.d.ts +32 -28
  53. package/dist/types/rental/accept.d.ts.map +1 -1
  54. package/dist/types/rental/cancel.d.ts +16 -12
  55. package/dist/types/rental/cancel.d.ts.map +1 -1
  56. package/dist/types/rental/close.d.ts +16 -13
  57. package/dist/types/rental/close.d.ts.map +1 -1
  58. package/dist/types/rental/reset.d.ts +19 -16
  59. package/dist/types/rental/reset.d.ts.map +1 -1
  60. package/dist/types/utils/config.d.ts +6 -84
  61. package/dist/types/utils/config.d.ts.map +1 -1
  62. package/dist/types/utils/constants.d.ts +8 -8
  63. package/dist/types/utils/constants.d.ts.map +1 -1
  64. package/dist/types/utils/index.d.ts +1 -0
  65. package/dist/types/utils/index.d.ts.map +1 -1
  66. package/dist/types/utils/instruction-converter.d.ts +76 -0
  67. package/dist/types/utils/instruction-converter.d.ts.map +1 -0
  68. package/dist/types/utils/types.d.ts +6 -0
  69. package/dist/types/utils/types.d.ts.map +1 -0
  70. package/package.json +2 -6
package/README.md CHANGED
@@ -4,145 +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 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
- - ✅ Account derivation and validation
14
- - ✅ Instruction data encoding
15
- - ✅ Type-safe parameter handling
16
- - ✅ Direct transaction sending via `.send()` (server/CLI)
17
- - ✅ Unsigned transaction building via `.pack()` (browser/wallets)
18
- - ✅ Wallet-agnostic design (works with any signing method)
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
19
21
 
20
- **Current Status**: Full instruction building, transaction packing, and direct sending support.
22
+ **Current Status**: Instruction building with universal compatibility. Users handle transaction packing and sending with their preferred Solana library.
21
23
 
22
24
  ## Installation
23
25
 
24
26
  ```bash
27
+ # Install the SDK
25
28
  npm install @wuwei-labs/srsly
26
- # or
27
- pnpm add @wuwei-labs/srsly
28
- # or
29
- yarn add @wuwei-labs/srsly
29
+
30
+ # Install your preferred Solana library
31
+ # Option A: Modern @solana/kit (recommended)
32
+ npm install @solana/kit
33
+
34
+ # Option B: Legacy @solana/web3.js (wallet adapter compatibility)
35
+ npm install @solana/web3.js
36
+
37
+ # Option C: Both libraries (for maximum flexibility)
38
+ npm install @solana/kit @solana/web3.js
30
39
  ```
31
40
 
41
+ The SDK creates **universal instructions** that work with any Solana library using string addresses.
42
+
32
43
  ## Quick Start
33
44
 
34
- ### Option 1: Pack and Send (Server/CLI)
45
+ ### Option 1: Using @solana/kit (Modern, Recommended)
35
46
 
36
47
  ```typescript
37
- import { createContract, setConfig, days, weeks } from '@wuwei-labs/srsly';
38
- import { createKeyPairSignerFromBytes } from '@solana/kit';
48
+ import { createContract, setConfig, days, convertKitToWeb3js } from '@wuwei-labs/srsly';
49
+ import { createKeyPairSignerFromBytes, createTransactionMessage, pipe } from '@solana/kit';
39
50
 
40
- // 1. Configure SDK with RPC endpoint
51
+ // 1. Configure SDK for your network
41
52
  setConfig({
42
- programs: 'atlasnet',
43
- rpcUrl: 'https://api.atlasnet.solana.com'
53
+ programs: 'atlasnet' // or 'mainnet', 'holosim'
44
54
  });
45
55
 
46
- // 2. Create signer from keypair
47
- const signer = await createKeyPairSignerFromBytes(keypairBytes);
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
+ });
48
65
 
49
- // 3. Pack and send in one chain (NEW: No double await needed!)
50
- const signature = await createContract({
51
- owner: signer,
52
- fleet: fleetAddress,
53
- ownerProfile: profileAddress,
54
- rate: 1000000, // ATLAS tokens per payment period
55
- durationMax: days(7), // 7 days using helper function
56
- paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
57
- }).pack(signer.address).send(signer); // Now chainable!
58
-
59
- console.log('Transaction signature:', signature);
60
-
61
- // Or still use two steps if preferred
62
- const packedTx = await createContract(params).pack(signer.address);
63
- const signature2 = await packedTx.send(signer);
64
-
65
- // With custom transaction options (also chainable!)
66
- const signature3 = await createContract(params)
67
- .set({
68
- transactionOptions: {
69
- commitment: 'finalized',
70
- skipPreflight: true
71
- }
72
- })
73
- .pack(signer.address)
74
- .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
+ );
75
71
  ```
76
72
 
77
- ### Option 2: Pack for Wallet Adapters (Browser)
73
+ ### Option 2: Using @solana/web3.js (Wallet Adapter Compatible)
78
74
 
79
75
  ```typescript
80
- import { createContract, setConfig } from '@wuwei-labs/srsly';
76
+ import { createContract, setConfig, days, convertKitToWeb3js } from '@wuwei-labs/srsly';
77
+ import { Transaction, PublicKey } from '@solana/web3.js';
81
78
 
82
- // 1. Configure SDK with RPC endpoint for blockhash
83
- setConfig({
84
- programs: 'atlasnet',
85
- rpcUrl: 'https://api.atlasnet.solana.com'
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'
86
90
  });
87
91
 
88
- // 2. Pack transaction for wallet adapter
89
- const packedTx = await createContract({
90
- owner: walletPublicKey,
91
- fleet: fleetAddress,
92
- ownerProfile: profileAddress,
93
- rate: 1000000, // ATLAS tokens per payment period
94
- durationMax: days(7), // 7 days using helper function
95
- paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
96
- }).pack(walletPublicKey); // Pack with fee payer address
92
+ // 3. Convert to web3.js format and use
93
+ const web3jsInstruction = convertKitToWeb3js(kitInstruction);
94
+ const transaction = new Transaction().add(web3jsInstruction);
97
95
 
98
- // 3. Sign and send with wallet adapter
99
- import { useWallet } from '@solana/wallet-adapter-react';
100
- import { VersionedTransaction, VersionedMessage } from '@solana/web3.js';
96
+ // Sign and send with your preferred method
97
+ const signature = await wallet.sendTransaction(transaction, connection);
98
+ ```
101
99
 
102
- const wallet = useWallet();
100
+ ## Core Features
103
101
 
104
- // Convert raw messageBytes to web3.js format
105
- const versionedMessage = VersionedMessage.deserialize(packedTx.messageBytes);
106
- const versionedTx = new VersionedTransaction(versionedMessage);
107
- const signedTx = await wallet.signTransaction(versionedTx);
102
+ ### Universal Instructions
108
103
 
109
- // Send the signed transaction
110
- const signature = await connection.sendRawTransaction(signedTx.serialize());
104
+ The SDK creates **universal instructions** that work with both @solana/kit and @solana/web3.js:
111
105
 
112
- // Note: packedTx also has a .send() method, but it requires a TransactionSigner
113
- // which wallet adapters don't provide directly
114
- ```
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
115
110
 
116
- ### Option 3: Manual Instruction Building
111
+ ### Format Conversion Example
117
112
 
118
113
  ```typescript
119
- import { createContract } from '@wuwei-labs/srsly';
120
-
121
- // Build instruction only (no RPC calls)
122
- const instruction = await createContract({
123
- owner: walletPublicKey,
124
- fleet: fleetAddress,
125
- ownerProfile: profileAddress,
126
- rate: 1000000,
127
- durationMin: 86400,
128
- durationMax: 604800,
129
- paymentsFreq: 'daily'
130
- });
131
-
132
- // Handle transaction building and submission yourself
133
- // ... use instruction with your preferred transaction building method
134
- ```
114
+ import { createContract, convertKitToWeb3js } from '@wuwei-labs/srsly';
135
115
 
136
- ## Core Features
116
+ // Create instruction (returns @solana/kit format by default)
117
+ const kitInstruction = await createContract(params);
137
118
 
138
- ### Dual Compatibility
119
+ // Convert to @solana/web3.js format when needed
120
+ const web3jsInstruction = convertKitToWeb3js(kitInstruction);
139
121
 
140
- 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
+ ```
141
125
 
142
- - **🌐 Browser/Wallet Adapter Path**: Uses `.pack()` to create raw `messageBytes` that can be converted to `web3.js` format when needed
143
- - **🖥️ Server/CLI Path**: Uses `.pack().send()` with `@solana/kit` for direct transaction submission
126
+ You can control the auto-detection behavior via configuration:
144
127
 
145
- 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
+ ```
146
135
 
147
136
  ### Flexible Address Input
148
137
 
@@ -279,6 +268,9 @@ setConfig({
279
268
  // RPC Configuration - Required for creating transactions
280
269
  rpcUrl: 'https://your-rpc-provider.com/api-key', // Your RPC endpoint
281
270
 
271
+ // Solana Library Preference - Control which library to use for pack methods
272
+ solanaLibrary: 'auto', // 'auto' | 'kit' | 'web3js' (auto prefers @solana/kit)
273
+
282
274
  // Program Address Overrides - Customize specific program addresses
283
275
  srslyProgramAddress: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT', // SRSLY program
284
276
  profileFactionProgramAddress: 'PprofUW1pURCnMW2si88GWPXEEK3Bvh9Tksy8WtnoYJ', // Profile Faction program
@@ -297,6 +289,10 @@ setConfig({ programs: 'mainnet' }); // Uses mainnet programs + default RPC
297
289
  setConfig({ programs: 'atlasnet', rpcUrl: 'https://your-rpc.com' }); // Atlasnet + custom RPC
298
290
  setConfig({ programs: 'holosim', rpcUrl: 'https://your-rpc.com' }); // Holosim + custom RPC
299
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
+
300
296
  // Check current configuration
301
297
  console.log(getConfig());
302
298
 
@@ -310,6 +306,7 @@ clearConfig();
310
306
  |--------|------|-------------|---------|
311
307
  | `programs` | `'mainnet' \| 'atlasnet' \| 'holosim'` | Predefined program address set | `'atlasnet'` |
312
308
  | `rpcUrl` | `string` | Solana RPC endpoint URL (required for pack/send) | `undefined` |
309
+ | `solanaLibrary` | `'auto' \| 'kit' \| 'web3js'` | Preferred Solana library for pack methods | `'auto'` |
313
310
  | `srslyProgramAddress` | `string` | SRSLY program address override | From program set |
314
311
  | `profileFactionProgramAddress` | `string` | Profile Faction program override | From program set |
315
312
  | `gameId` | `string` | SAGE game ID override | From program set |
@@ -323,12 +320,13 @@ clearConfig();
323
320
  // Override global config for specific instructions
324
321
  const ix = await createContract(params).set({
325
322
  programs: 'mainnet',
323
+ solanaLibrary: 'kit',
326
324
  transactionOptions: { commitment: 'finalized' }
327
325
  });
328
326
 
329
327
  // Chain multiple configurations
330
328
  const ix2 = await acceptRental(params)
331
- .set({ programs: 'holosim', rpcUrl: 'https://custom-rpc.com' })
329
+ .set({ programs: 'holosim', rpcUrl: 'https://custom-rpc.com', solanaLibrary: 'web3js' })
332
330
  .set({ gameId: 'custom-game-id...', atlasMint: 'custom-mint...' });
333
331
  ```
334
332
 
@@ -490,6 +488,109 @@ The SDK provides optimized builds for different environments:
490
488
  - **Types**: `./dist/types/` (TypeScript definitions)
491
489
  - **Shared**: `./dist/shared/codama/` (Optimized codama exports)
492
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
+
493
594
  ## Links
494
595
 
495
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,E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