@wuwei-labs/srsly 2.0.0-beta.4 → 2.0.0-beta.5

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 (86) hide show
  1. package/README.md +214 -68
  2. package/dist/cjs/codama/devnet/constants.js +32 -0
  3. package/dist/cjs/codama/devnet/constants.js.map +1 -0
  4. package/dist/cjs/codama/mainnet/constants.js +32 -0
  5. package/dist/cjs/codama/mainnet/constants.js.map +1 -0
  6. package/dist/cjs/contract/close.js +51 -19
  7. package/dist/cjs/contract/close.js.map +1 -1
  8. package/dist/cjs/contract/create.js +31 -19
  9. package/dist/cjs/contract/create.js.map +1 -1
  10. package/dist/cjs/index.js +0 -2
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/rental/accept.js +46 -33
  13. package/dist/cjs/rental/accept.js.map +1 -1
  14. package/dist/cjs/rental/cancel.js +30 -24
  15. package/dist/cjs/rental/cancel.js.map +1 -1
  16. package/dist/cjs/rental/close.js +31 -25
  17. package/dist/cjs/rental/close.js.map +1 -1
  18. package/dist/cjs/rental/reset.js +40 -38
  19. package/dist/cjs/rental/reset.js.map +1 -1
  20. package/dist/cjs/utils/config.js +204 -0
  21. package/dist/cjs/utils/config.js.map +1 -0
  22. package/dist/cjs/utils/constants.js +66 -13
  23. package/dist/cjs/utils/constants.js.map +1 -1
  24. package/dist/cjs/utils/index.js +1 -0
  25. package/dist/cjs/utils/index.js.map +1 -1
  26. package/dist/cjs/utils/profiles.js +38 -18
  27. package/dist/cjs/utils/profiles.js.map +1 -1
  28. package/dist/esm/codama/devnet/constants.js +29 -0
  29. package/dist/esm/codama/devnet/constants.js.map +1 -0
  30. package/dist/esm/codama/mainnet/constants.js +29 -0
  31. package/dist/esm/codama/mainnet/constants.js.map +1 -0
  32. package/dist/esm/contract/close.js +52 -20
  33. package/dist/esm/contract/close.js.map +1 -1
  34. package/dist/esm/contract/create.js +31 -19
  35. package/dist/esm/contract/create.js.map +1 -1
  36. package/dist/esm/index.js +0 -2
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/rental/accept.js +47 -34
  39. package/dist/esm/rental/accept.js.map +1 -1
  40. package/dist/esm/rental/cancel.js +30 -24
  41. package/dist/esm/rental/cancel.js.map +1 -1
  42. package/dist/esm/rental/close.js +31 -25
  43. package/dist/esm/rental/close.js.map +1 -1
  44. package/dist/esm/rental/reset.js +41 -39
  45. package/dist/esm/rental/reset.js.map +1 -1
  46. package/dist/esm/utils/config.js +161 -0
  47. package/dist/esm/utils/config.js.map +1 -0
  48. package/dist/esm/utils/constants.js +60 -10
  49. package/dist/esm/utils/constants.js.map +1 -1
  50. package/dist/esm/utils/index.js +1 -0
  51. package/dist/esm/utils/index.js.map +1 -1
  52. package/dist/esm/utils/profiles.js +39 -19
  53. package/dist/esm/utils/profiles.js.map +1 -1
  54. package/dist/types/codama/devnet/constants.d.ts +33 -0
  55. package/dist/types/codama/devnet/constants.d.ts.map +1 -0
  56. package/dist/types/codama/mainnet/constants.d.ts +33 -0
  57. package/dist/types/codama/mainnet/constants.d.ts.map +1 -0
  58. package/dist/types/contract/close.d.ts +20 -5
  59. package/dist/types/contract/close.d.ts.map +1 -1
  60. package/dist/types/contract/create.d.ts +23 -13
  61. package/dist/types/contract/create.d.ts.map +1 -1
  62. package/dist/types/index.d.ts +0 -1
  63. package/dist/types/index.d.ts.map +1 -1
  64. package/dist/types/rental/accept.d.ts +35 -6
  65. package/dist/types/rental/accept.d.ts.map +1 -1
  66. package/dist/types/rental/cancel.d.ts +27 -3
  67. package/dist/types/rental/cancel.d.ts.map +1 -1
  68. package/dist/types/rental/close.d.ts +28 -3
  69. package/dist/types/rental/close.d.ts.map +1 -1
  70. package/dist/types/rental/reset.d.ts +32 -4
  71. package/dist/types/rental/reset.d.ts.map +1 -1
  72. package/dist/types/utils/config.d.ts +112 -0
  73. package/dist/types/utils/config.d.ts.map +1 -0
  74. package/dist/types/utils/constants.d.ts +9 -7
  75. package/dist/types/utils/constants.d.ts.map +1 -1
  76. package/dist/types/utils/index.d.ts +1 -0
  77. package/dist/types/utils/index.d.ts.map +1 -1
  78. package/dist/types/utils/profiles.d.ts +14 -8
  79. package/dist/types/utils/profiles.d.ts.map +1 -1
  80. package/package.json +4 -2
  81. package/dist/cjs/network.js +0 -107
  82. package/dist/cjs/network.js.map +0 -1
  83. package/dist/esm/network.js +0 -67
  84. package/dist/esm/network.js.map +0 -1
  85. package/dist/types/network.d.ts +0 -58
  86. package/dist/types/network.d.ts.map +0 -1
package/README.md CHANGED
@@ -4,7 +4,7 @@
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 interacting with the SRSLY (Space Rental from SLY) Solana program - a decentralized rental system for Star Atlas.
7
+ A TypeScript SDK for interacting with the SRSLY (Space Rental from SLY) Solana program - a decentralized rental system for Star Atlas fleets with network-specific configuration support.
8
8
 
9
9
  ## Installation
10
10
 
@@ -31,14 +31,17 @@ yarn add @wuwei-labs/srsly
31
31
  ```typescript
32
32
  import {
33
33
  createContract,
34
- acceptRental,
35
- setNetwork
34
+ acceptRental,
35
+ setConfig,
36
+ setNetwork,
37
+ ATLAS_TO_STARDUST
36
38
  } from '@wuwei-labs/srsly';
37
39
 
38
- // Set global network (optional - defaults to devnet)
39
- setNetwork('mainnet');
40
+ // Option 1: Set global configuration (recommended for most apps)
41
+ setConfig({ network: 'mainnet' });
42
+ // or use the convenience function: setNetwork('mainnet');
40
43
 
41
- // Create a rental contract using global network setting (direct await)
44
+ // Now all operations use mainnet by default
42
45
  const contractInstruction = await createContract({
43
46
  owner: wallet,
44
47
  fleet: fleetAddress,
@@ -48,23 +51,34 @@ const contractInstruction = await createContract({
48
51
  durationMax: 604800, // 1 week in seconds
49
52
  paymentsFreq: 'daily',
50
53
  ownerKeyIndex: 0
51
- });
54
+ }); // Uses mainnet from global config
55
+
56
+ // Accept a rental with automatic ATLAS to stardust conversion
57
+ const acceptInstruction = await acceptRental({
58
+ borrower: borrowerWallet,
59
+ borrowerProfile: borrowerProfileAddress,
60
+ borrowerFaction: 'mud', // or 1, 2, 3
61
+ fleet: fleetAddress,
62
+ contract: contractAddress,
63
+ rate: 100, // ATLAS tokens per duration
64
+ duration: 86400 // 1 day in seconds
65
+ // amount is automatically calculated: rate * duration * ATLAS_TO_STARDUST
66
+ }); // Uses mainnet from global config
52
67
 
53
- // Or override network for specific instruction
54
- const mainnetInstruction = await createContract(params).mainnet();
55
- const devnetInstruction = await createContract(params).devnet();
68
+ // Option 2: Override global config for specific instructions
69
+ const devnetInstruction = await createContract(params).set({ network: 'devnet' });
56
70
  ```
57
71
 
58
72
  ## Core Features
59
73
 
60
74
  ### Contract Management
61
75
 
62
- Create and manage rental contracts for Star Atlas:
76
+ Create and manage rental contracts for Star Atlas fleets:
63
77
 
64
78
  ```typescript
65
79
  import { createContract, closeContract } from '@wuwei-labs/srsly';
66
80
 
67
- // Create a new rental contract with network selection
81
+ // Create a new rental contract with network configuration
68
82
  const createIx = await createContract({
69
83
  owner: wallet,
70
84
  fleet: fleetAddress,
@@ -74,60 +88,69 @@ const createIx = await createContract({
74
88
  durationMax: 2592000, // Maximum 30 days
75
89
  paymentsFreq: 'daily',
76
90
  ownerKeyIndex: 0
77
- }).mainnet(); // Use mainnet for this instruction
91
+ }).set({ network: 'mainnet' }); // Use mainnet configuration
78
92
 
79
- // Close an existing contract using global network setting (direct await)
93
+ // Close an existing contract using devnet defaults (direct await)
80
94
  const closeIx = await closeContract({
81
95
  owner: wallet,
82
96
  fleet: fleetAddress,
83
97
  contract: contractAddress,
84
- faction: 'mud',
85
- ownerProfile: profileAddress
98
+ faction: 'mud' // or faction number: 1, 2, 3
86
99
  });
87
100
  ```
88
101
 
89
102
  ### Rental Operations
90
103
 
91
- Handle rental lifecycle operations:
104
+ Handle rental lifecycle operations with automatic token conversion:
92
105
 
93
106
  ```typescript
94
107
  import {
95
108
  acceptRental,
96
109
  cancelRental,
97
110
  closeRental,
98
- resetRental
111
+ resetRental,
112
+ ATLAS_TO_STARDUST
99
113
  } from '@wuwei-labs/srsly';
100
114
 
101
- // Accept a rental offer on devnet
115
+ // Accept a rental offer on devnet (rate-based with automatic conversion)
102
116
  const acceptIx = await acceptRental({
103
117
  borrower: borrowerWallet,
104
118
  borrowerProfile: borrowerProfileAddress,
119
+ borrowerFaction: 'oni', // or faction number: 1=mud, 2=oni, 3=ustur
120
+ fleet: fleetAddress,
105
121
  contract: contractAddress,
106
- borrowerFaction: 'oni',
107
- duration: 86400,
108
- amount: 1000000
109
- }).devnet();
122
+ rate: 100, // ATLAS tokens (not per second, just ATLAS)
123
+ duration: 86400 // 1 day in seconds
124
+ // amount = rate * duration * ATLAS_TO_STARDUST automatically calculated
125
+ }).set({ network: 'devnet' });
110
126
 
111
- // Cancel an active rental using current network setting (direct await)
127
+ // Cancel an active rental using devnet defaults (direct await)
112
128
  const cancelIx = await cancelRental({
113
129
  borrower: borrowerWallet,
114
- rental: rentalAddress
130
+ contract: contractAddress,
131
+ rentalState: rentalStateAddress
115
132
  });
116
133
 
117
134
  // Close a completed rental on mainnet
118
135
  const closeIx = await closeRental({
119
136
  borrower: borrowerWallet,
120
- rental: rentalAddress
121
- }).mainnet();
137
+ contract: contractAddress,
138
+ rentalState: rentalStateAddress,
139
+ ownerTokenAccount: ownerTokenAccountAddress
140
+ }).set({ network: 'mainnet' });
122
141
 
123
- // Reset rental state (admin only) with specific network
142
+ // Reset rental state with custom configuration
124
143
  const resetIx = await resetRental({
125
144
  fleet: fleetAddress,
126
145
  contract: contractAddress,
127
146
  rentalState: rentalStateAddress,
128
147
  faction: 'mud',
129
148
  ownerProfile: ownerProfileAddress
130
- }).network('mainnet');
149
+ }).set({
150
+ network: 'mainnet',
151
+ sageProgramAddress: 'custom...',
152
+ gameId: 'custom...'
153
+ });
131
154
  ```
132
155
 
133
156
  ### Account State Management
@@ -135,15 +158,15 @@ const resetIx = await resetRental({
135
158
  Fetch and decode account states using network-specific functions:
136
159
 
137
160
  ```typescript
138
- import { getCachedNetworkModule, setNetwork } from '@wuwei-labs/srsly';
139
-
140
- // Set the network first
141
- setNetwork('mainnet');
161
+ import { getCachedNetworkModule } from '@wuwei-labs/srsly';
142
162
 
143
- // Get network-specific account functions
163
+ // Get network-specific account functions (defaults to devnet)
144
164
  const accountsModule = await getCachedNetworkModule('accounts');
145
165
  const { fetchContractState, fetchRentalState } = accountsModule;
146
166
 
167
+ // Or specify network explicitly
168
+ const mainnetAccountsModule = await getCachedNetworkModule('accounts', 'mainnet');
169
+
147
170
  // Fetch contract state
148
171
  const contractState = await fetchContractState(rpc, contractPublicKey);
149
172
  console.log('Contract rate:', contractState.rate.toString());
@@ -155,6 +178,21 @@ console.log('Rental status:', rentalState.status);
155
178
  console.log('Start time:', new Date(rentalState.startTime.toNumber() * 1000));
156
179
  ```
157
180
 
181
+ ### Token Conversion
182
+
183
+ The SDK includes automatic ATLAS to stardust conversion for rental operations:
184
+
185
+ ```typescript
186
+ import { ATLAS_TO_STARDUST } from '@wuwei-labs/srsly';
187
+
188
+ // ATLAS_TO_STARDUST = 100_000_000 (1 ATLAS = 100 million stardust)
189
+ console.log('Conversion rate:', ATLAS_TO_STARDUST);
190
+
191
+ // When using acceptRental with rate and duration:
192
+ // Final amount = rate * duration * ATLAS_TO_STARDUST
193
+ // Example: 100 ATLAS * 86400 seconds * 100_000_000 = 864,000,000,000,000 stardust
194
+ ```
195
+
158
196
  ## Program Information
159
197
 
160
198
  - **Program ID**: `SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT`
@@ -188,67 +226,125 @@ try {
188
226
 
189
227
  ## Network Configuration
190
228
 
191
- The SDK supports both Solana mainnet and devnet with network-specific program configurations. You can configure networks globally or per instruction.
229
+ The SDK supports both Solana mainnet and devnet with network-specific program configurations. You can set global configuration for convenience or override per instruction for flexibility.
192
230
 
193
- ### Global Network Configuration
231
+ ### Global Configuration (Recommended)
194
232
 
195
- Set the default network for all SDK operations:
233
+ Set default configuration once for all SDK operations:
196
234
 
197
235
  ```typescript
198
- import { setNetwork, getNetwork } from '@wuwei-labs/srsly';
236
+ import { setConfig, setNetwork, getConfig, createContract } from '@wuwei-labs/srsly';
199
237
 
200
- // Set global network (defaults to 'devnet')
238
+ // Option 1: Full configuration
239
+ setConfig({
240
+ network: 'mainnet',
241
+ gameId: 'custom-game-id...'
242
+ });
243
+
244
+ // Option 2: Network-only (convenience function)
201
245
  setNetwork('mainnet');
202
246
 
203
- // Check current network
204
- console.log(getNetwork()); // 'mainnet'
247
+ // Check current configuration
248
+ console.log(getConfig()); // { network: 'mainnet' }
205
249
 
206
- // All instructions will now use mainnet by default (direct await)
207
- const ix = await createContract(params);
250
+ // All operations now use mainnet by default
251
+ const ix1 = await createContract(params);
252
+ const ix2 = await acceptRental(params);
208
253
  ```
209
254
 
210
- ### Per-Instruction Network Selection
255
+ ### Per-Instruction Configuration
211
256
 
212
- Override the network for specific instructions using the fluent interface:
257
+ Override global configuration for specific instructions using the fluent `.set()` interface:
213
258
 
214
259
  ```typescript
215
- import { createContract } from '@wuwei-labs/srsly';
260
+ import { createContract, acceptRental } from '@wuwei-labs/srsly';
216
261
 
217
- // Use mainnet for this specific instruction
218
- const mainnetIx = await createContract(params).mainnet();
262
+ // Assume global config is set to mainnet
263
+ setConfig({ network: 'mainnet' });
219
264
 
220
- // Use devnet for this specific instruction
221
- const devnetIx = await createContract(params).devnet();
265
+ // Use global mainnet config
266
+ const mainnetIx = await createContract(params);
222
267
 
223
- // Use a specific network
224
- const specificIx = await createContract(params).network('mainnet');
268
+ // Override to use devnet for this specific instruction
269
+ const devnetIx = await createContract(params).set({ network: 'devnet' });
225
270
 
226
- // Use global network setting (direct await - no .build() needed!)
227
- const globalIx = await createContract(params);
271
+ // Override specific constants while keeping global network
272
+ const customIx = await createContract(params).set({
273
+ sageProgramAddress: 'custom...',
274
+ gameId: 'custom...'
275
+ // network: 'mainnet' inherited from global config
276
+ });
228
277
  ```
229
278
 
230
- ### Network Selection Methods
279
+ ### Configuration Options
231
280
 
232
281
  All SDK functions support these usage patterns:
233
282
 
234
- **Direct await (uses global network):**
283
+ **Direct await (uses global config or devnet fallback):**
284
+
235
285
  ```typescript
286
+ // Uses global configuration if set, otherwise devnet
236
287
  await createContract(params);
237
288
  await acceptRental(params);
238
289
  ```
239
290
 
240
- **Network-specific methods:**
241
- - `.mainnet()` - Build with mainnet configuration
242
- - `.devnet()` - Build with devnet configuration
243
- - `.network(network)` - Build with specified network
244
- - `.build()` - Build with current global network setting (explicit)
291
+ **Global configuration functions:**
292
+
293
+ - `setConfig({ network: 'mainnet', gameId: '...' })` - Set full global config
294
+ - `setNetwork('mainnet')` - Set global network only (convenience)
295
+ - `getConfig()` - Get current global configuration
296
+ - `clearConfig()` - Reset to devnet defaults
297
+
298
+ **Per-instruction overrides with `.set()` method:**
299
+
300
+ - `.set({ network: 'mainnet' })` - Override global network
301
+ - `.set({ sageProgramAddress: '...' })` - Override specific constants only
302
+ - `.set({ network: 'mainnet', sageProgramAddress: '...' })` - Multiple overrides
303
+
304
+ **Chainable configurations:**
305
+
306
+ ```typescript
307
+ // Chain multiple configurations (later ones override earlier ones)
308
+ await createContract(params)
309
+ .set({ network: 'devnet' })
310
+ .set({ sageProgramAddress: 'override...' });
311
+
312
+ // Examples with global config
313
+ setConfig({ network: 'mainnet' });
314
+ await createContract(params); // Uses mainnet
315
+ await acceptRental(params).set({ network: 'devnet' }); // Override to devnet
316
+ await closeContract(params).set({ gameId: 'custom...' }); // Custom gameId, mainnet network
317
+ ```
318
+
319
+ ### Available Configuration Options
320
+
321
+ ```typescript
322
+ interface ConfigOptions {
323
+ network?: 'mainnet' | 'devnet'; // Set/override network
324
+ sageProgramAddress?: string; // Set/override SAGE program address
325
+ profileFactionProgramAddress?: string; // Set/override Profile Faction program address
326
+ gameId?: string; // Set/override SAGE game ID
327
+ }
328
+ ```
329
+
330
+ ### Network-Specific Constants
331
+
332
+ The SDK automatically resolves network-specific constants:
245
333
 
246
334
  ```typescript
247
- // Examples across different functions
248
- await createContract(params).mainnet();
249
- await acceptRental(params).devnet();
250
- await closeContract(params).network('mainnet');
251
- await resetRental(params); // Direct await uses global network
335
+ import {
336
+ getSageProgramAddress,
337
+ getProfileFactionProgramAddress,
338
+ getSageGameId
339
+ } from '@wuwei-labs/srsly';
340
+
341
+ // Get constants for devnet (default)
342
+ const sageProgram = await getSageProgramAddress();
343
+ const gameId = await getSageGameId();
344
+
345
+ // Get constants for specific network
346
+ const mainnetSageProgram = await getSageProgramAddress({ network: 'mainnet' });
347
+ const mainnetGameId = await getSageGameId({ network: 'mainnet' });
252
348
  ```
253
349
 
254
350
  ## IDL and Types
@@ -279,7 +375,8 @@ import type {
279
375
  RentalState,
280
376
  PaymentFrequency,
281
377
  ClockData,
282
- ThreadResponse
378
+ ThreadResponse,
379
+ ConfigOptions
283
380
  } from '@wuwei-labs/srsly';
284
381
 
285
382
  // Import network-specific Anchor types
@@ -287,6 +384,55 @@ import type { Srsly as SrslyMainnet } from '@wuwei-labs/srsly/types/mainnet';
287
384
  import type { Srsly as SrslyDevnet } from '@wuwei-labs/srsly/types/devnet';
288
385
  ```
289
386
 
387
+ ## Constants and Utilities
388
+
389
+ ### Available Constants
390
+
391
+ ```typescript
392
+ import {
393
+ ATLAS_TO_STARDUST,
394
+ STARBASE_SEED,
395
+ STARBASE_PLAYER_SEED,
396
+ SAGE_PLAYER_PROFILE_SEED,
397
+ PROFILE_FACTION_SEED,
398
+ FACTION_MAPPING,
399
+ FACTION_SPECIFIC_CSS
400
+ } from '@wuwei-labs/srsly';
401
+
402
+ // Token conversion
403
+ console.log(ATLAS_TO_STARDUST); // 100_000_000
404
+
405
+ // Faction mappings
406
+ console.log(FACTION_MAPPING[1]); // 'mud'
407
+ console.log(FACTION_MAPPING[2]); // 'oni'
408
+ console.log(FACTION_MAPPING[3]); // 'ustur'
409
+ ```
410
+
411
+ ### Profile Derivation
412
+
413
+ ```typescript
414
+ import {
415
+ deriveProfileFaction,
416
+ deriveSagePlayerProfile,
417
+ deriveStarbase,
418
+ deriveStarbasePlayer,
419
+ deriveGameAccounts
420
+ } from '@wuwei-labs/srsly';
421
+
422
+ // Derive individual accounts with network configuration
423
+ const profileFaction = await deriveProfileFaction(profile, { network: 'mainnet' });
424
+ const starbase = await deriveStarbase('mud', gameId, { network: 'mainnet' });
425
+
426
+ // Derive all game accounts at once
427
+ const gameAccounts = await deriveGameAccounts(
428
+ profile,
429
+ 'mud',
430
+ gameId,
431
+ 0, // starbaseSeqId
432
+ { network: 'mainnet' }
433
+ );
434
+ ```
435
+
290
436
  ## Documentation
291
437
 
292
438
  - **TypeDoc Documentation**: [API Reference](https://wuwei-labs.github.io/srsly/)
@@ -295,4 +441,4 @@ import type { Srsly as SrslyDevnet } from '@wuwei-labs/srsly/types/devnet';
295
441
 
296
442
  - **Star Atlas**: The metaverse gaming ecosystem
297
443
  - **Solana**: The blockchain platform powering SRSLY
298
- - **Anchor**: The framework used to build the SRSLY program
444
+ - **Anchor**: The framework used to build the SRSLY program
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Network-specific constants for devnet
4
+ *
5
+ * This file is auto-generated from network-configs.mjs
6
+ * DO NOT EDIT MANUALLY - your changes will be overwritten
7
+ *
8
+ * To update these constants:
9
+ * 1. Edit network-configs.mjs
10
+ * 2. Run `pnpm build` to regenerate
11
+ *
12
+ * Generated on: 2025-06-21T19:10:08.579Z
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NETWORK_CONFIG = exports.ATLAS_TOKEN_MINT = exports.SRSLY_PROGRAM_ADDRESS = exports.SAGE_GAME_ID = exports.PROFILE_FACTION_PROGRAM_ADDRESS = exports.SAGE_PROGRAM_ADDRESS = void 0;
16
+ exports.SAGE_PROGRAM_ADDRESS = 'sAgeDEVzwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi';
17
+ exports.PROFILE_FACTION_PROGRAM_ADDRESS = 'pFACDEVobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq';
18
+ exports.SAGE_GAME_ID = 'GAMEDEVJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr';
19
+ exports.SRSLY_PROGRAM_ADDRESS = 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT';
20
+ exports.ATLAS_TOKEN_MINT = 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx';
21
+ /**
22
+ * Complete network configuration object
23
+ * Useful for runtime access to all constants
24
+ */
25
+ exports.NETWORK_CONFIG = {
26
+ SAGE_PROGRAM_ADDRESS: 'sAgeDEVzwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi',
27
+ PROFILE_FACTION_PROGRAM_ADDRESS: 'pFACDEVobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq',
28
+ SAGE_GAME_ID: 'GAMEDEVJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr',
29
+ SRSLY_PROGRAM_ADDRESS: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT',
30
+ ATLAS_TOKEN_MINT: 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx',
31
+ };
32
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/codama/devnet/constants.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEU,QAAA,oBAAoB,GAAG,gDAAgD,CAAC;AACxE,QAAA,+BAA+B,GAAG,6CAA6C,CAAC;AAChF,QAAA,YAAY,GAAG,+CAA+C,CAAC;AAC/D,QAAA,qBAAqB,GAAG,6CAA6C,CAAC;AACtE,QAAA,gBAAgB,GAAG,8CAA8C,CAAC;AAE/E;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,oBAAoB,EAAE,gDAAgD;IACtE,+BAA+B,EAAE,6CAA6C;IAC9E,YAAY,EAAE,+CAA+C;IAC7D,qBAAqB,EAAE,6CAA6C;IACpE,gBAAgB,EAAE,8CAA8C;CACxD,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Network-specific constants for mainnet
4
+ *
5
+ * This file is auto-generated from network-configs.mjs
6
+ * DO NOT EDIT MANUALLY - your changes will be overwritten
7
+ *
8
+ * To update these constants:
9
+ * 1. Edit network-configs.mjs
10
+ * 2. Run `pnpm build` to regenerate
11
+ *
12
+ * Generated on: 2025-06-21T19:10:03.037Z
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NETWORK_CONFIG = exports.ATLAS_TOKEN_MINT = exports.SRSLY_PROGRAM_ADDRESS = exports.SAGE_GAME_ID = exports.PROFILE_FACTION_PROGRAM_ADDRESS = exports.SAGE_PROGRAM_ADDRESS = void 0;
16
+ exports.SAGE_PROGRAM_ADDRESS = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi';
17
+ exports.PROFILE_FACTION_PROGRAM_ADDRESS = 'pFACSRuobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq';
18
+ exports.SAGE_GAME_ID = 'GAMEzqJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr';
19
+ exports.SRSLY_PROGRAM_ADDRESS = 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT';
20
+ exports.ATLAS_TOKEN_MINT = 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx';
21
+ /**
22
+ * Complete network configuration object
23
+ * Useful for runtime access to all constants
24
+ */
25
+ exports.NETWORK_CONFIG = {
26
+ SAGE_PROGRAM_ADDRESS: 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi',
27
+ PROFILE_FACTION_PROGRAM_ADDRESS: 'pFACSRuobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq',
28
+ SAGE_GAME_ID: 'GAMEzqJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr',
29
+ SRSLY_PROGRAM_ADDRESS: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT',
30
+ ATLAS_TOKEN_MINT: 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx',
31
+ };
32
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/codama/mainnet/constants.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEU,QAAA,oBAAoB,GAAG,6CAA6C,CAAC;AACrE,QAAA,+BAA+B,GAAG,6CAA6C,CAAC;AAChF,QAAA,YAAY,GAAG,8CAA8C,CAAC;AAC9D,QAAA,qBAAqB,GAAG,6CAA6C,CAAC;AACtE,QAAA,gBAAgB,GAAG,8CAA8C,CAAC;AAE/E;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,oBAAoB,EAAE,6CAA6C;IACnE,+BAA+B,EAAE,6CAA6C;IAC9E,YAAY,EAAE,8CAA8C;IAC5D,qBAAqB,EAAE,6CAA6C;IACpE,gBAAgB,EAAE,8CAA8C;CACxD,CAAC"}
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.closeContract = closeContract;
4
4
  exports.getCloseContractInstructionAsync = getCloseContractInstructionAsync;
5
- const network_1 = require("../network");
5
+ const config_1 = require("../utils/config");
6
+ const constants_1 = require("../utils/constants");
6
7
  const utils_1 = require("../utils");
7
8
  /**
8
9
  * Asynchronously creates an instruction to close a rental contract with minimal required parameters.
@@ -10,34 +11,50 @@ const utils_1 = require("../utils");
10
11
  *
11
12
  * @example
12
13
  * ```typescript
13
- * // Create the instruction with automatic account derivation
14
+ * // Create the instruction with default devnet settings
14
15
  * const ix = await closeContract({
15
16
  * owner: wallet,
16
17
  * fleet: fleetAddress,
17
18
  * contract: contractAddress,
18
- * faction: 'mud', // Only needed if starbase and starbasePlayer not provided
19
- * // Optional: provide explicit starbase and starbasePlayer if you have them
20
- * // Optional: provide rentalState and rentalTokenAccount if active rental exists
19
+ * faction: 'mud',
21
20
  * });
22
21
  *
23
- * // Add to transaction and sign
24
- * const tx = new Transaction().add(ix);
25
- * await sendAndConfirmTransaction(connection, tx, [wallet]);
22
+ * // Use mainnet configuration
23
+ * const ix = await closeContract({
24
+ * owner: wallet,
25
+ * fleet: fleetAddress,
26
+ * contract: contractAddress,
27
+ * faction: 'mud',
28
+ * }).set({ network: 'mainnet' });
29
+ *
30
+ * // Override specific constants
31
+ * const ix = await closeContract({
32
+ * owner: wallet,
33
+ * fleet: fleetAddress,
34
+ * contract: contractAddress,
35
+ * faction: 'mud',
36
+ * }).set({
37
+ * network: 'mainnet',
38
+ * gameId: 'custom-game-id...'
39
+ * });
26
40
  * ```
27
41
  *
28
42
  * @param params The simplified parameters for closing a rental contract
29
43
  * @returns A promise that resolves to the instruction to close a contract
30
44
  */
31
45
  /**
32
- * Internal function to close a contract instruction for a specific network
46
+ * Internal function to close a contract instruction with configuration options
33
47
  */
34
- async function _closeContract(params, network) {
35
- const { owner, fleet, contract, faction, gameId = utils_1.DEFAULT_GAME_ID, } = params;
36
- const derivedAccounts = await (0, utils_1.deriveGameAccounts)(owner.address, faction, gameId);
48
+ async function _closeContract(params, config) {
49
+ const { owner, fleet, contract, faction, gameId, } = params;
50
+ // Get the actual game ID to use (param override, config override, or network default)
51
+ const actualGameId = gameId || await (0, constants_1.getSageGameId)(config);
52
+ const derivedAccounts = await (0, utils_1.deriveGameAccounts)(owner.address, faction, actualGameId, 0, // starbaseSeqId
53
+ config);
37
54
  const starbase = derivedAccounts.starbase;
38
55
  const starbasePlayer = derivedAccounts.starbasePlayer;
39
56
  // Dynamically import network-specific codama functions
40
- const codamaModule = await (0, network_1.getCachedNetworkModule)('instructions', network);
57
+ const codamaModule = await (0, config_1.getCachedNetworkModule)('instructions', config?.network);
41
58
  const { getCloseContractInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
42
59
  // Let codama derive the rest (rentalAuthority, ownerTokenAccount, etc.)
43
60
  const input = {
@@ -46,20 +63,35 @@ async function _closeContract(params, network) {
46
63
  contract,
47
64
  starbase,
48
65
  starbasePlayer,
49
- gameId,
66
+ gameId: actualGameId,
50
67
  };
51
68
  return getCloseContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
52
69
  }
53
70
  /**
54
- * Creates an instruction to close a rental contract with fluent network selection.
71
+ * Creates an instruction to close a rental contract with fluent configuration.
72
+ *
73
+ * @param params The contract closing parameters
74
+ * @returns A ConfigSelector that can be configured with .set() or awaited directly
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Use devnet defaults
79
+ * await closeContract(params);
80
+ *
81
+ * // Use mainnet
82
+ * await closeContract(params).set({ network: 'mainnet' });
83
+ *
84
+ * // Override game ID
85
+ * await closeContract(params).set({ gameId: 'custom...' });
86
+ * ```
55
87
  */
56
88
  function closeContract(params) {
57
- return (0, network_1.createNetworkSelector)((network) => _closeContract(params, network));
89
+ return (0, config_1.createConfigSelector)((config) => _closeContract(params, config));
58
90
  }
59
- // Export network selector for getCloseContractInstructionAsync
91
+ // Export config selector for getCloseContractInstructionAsync
60
92
  function getCloseContractInstructionAsync(input, options) {
61
- return (0, network_1.createNetworkSelector)(async (network) => {
62
- const codamaModule = await (0, network_1.getCachedNetworkModule)('instructions', network);
93
+ return (0, config_1.createConfigSelector)(async (config) => {
94
+ const codamaModule = await (0, config_1.getCachedNetworkModule)('instructions', config?.network);
63
95
  return codamaModule.getCloseContractInstructionAsync(input, options);
64
96
  });
65
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":";;AAsHA,sCAIC;AAGD,4EAKC;AA7HD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