@wuwei-labs/srsly 2.0.0-beta.2 → 2.0.0-beta.21

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 (188) hide show
  1. package/README.md +305 -110
  2. package/dist/cjs/codama/accounts/config.js +88 -0
  3. package/dist/cjs/codama/accounts/config.js.map +1 -0
  4. package/dist/cjs/codama/accounts/contractState.js +17 -39
  5. package/dist/cjs/codama/accounts/contractState.js.map +1 -1
  6. package/dist/cjs/codama/accounts/index.js +1 -1
  7. package/dist/cjs/codama/accounts/index.js.map +1 -1
  8. package/dist/cjs/codama/accounts/rentalState.js +18 -33
  9. package/dist/cjs/codama/accounts/rentalState.js.map +1 -1
  10. package/dist/cjs/codama/accounts/thread.js +15 -32
  11. package/dist/cjs/codama/accounts/thread.js.map +1 -1
  12. package/dist/cjs/codama/errors/srsly.js +24 -3
  13. package/dist/cjs/codama/errors/srsly.js.map +1 -1
  14. package/dist/cjs/codama/instructions/acceptRental.js +202 -224
  15. package/dist/cjs/codama/instructions/acceptRental.js.map +1 -1
  16. package/dist/cjs/codama/instructions/cancelRental.js +100 -136
  17. package/dist/cjs/codama/instructions/cancelRental.js.map +1 -1
  18. package/dist/cjs/codama/instructions/closeContract.js +95 -116
  19. package/dist/cjs/codama/instructions/closeContract.js.map +1 -1
  20. package/dist/cjs/codama/instructions/closeRental.js +119 -132
  21. package/dist/cjs/codama/instructions/closeRental.js.map +1 -1
  22. package/dist/cjs/codama/instructions/createContract.js +127 -143
  23. package/dist/cjs/codama/instructions/createContract.js.map +1 -1
  24. package/dist/cjs/codama/instructions/index.js +2 -1
  25. package/dist/cjs/codama/instructions/index.js.map +1 -1
  26. package/dist/cjs/codama/instructions/initializeConfig.js +131 -0
  27. package/dist/cjs/codama/instructions/initializeConfig.js.map +1 -0
  28. package/dist/cjs/codama/instructions/payRental.js +125 -129
  29. package/dist/cjs/codama/instructions/payRental.js.map +1 -1
  30. package/dist/cjs/codama/instructions/resetRental.js +55 -77
  31. package/dist/cjs/codama/instructions/resetRental.js.map +1 -1
  32. package/dist/cjs/codama/instructions/updateConfig.js +145 -0
  33. package/dist/cjs/codama/instructions/updateConfig.js.map +1 -0
  34. package/dist/cjs/codama/programs/srsly.js +12 -8
  35. package/dist/cjs/codama/programs/srsly.js.map +1 -1
  36. package/dist/cjs/codama/shared/index.js +6 -2
  37. package/dist/cjs/codama/shared/index.js.map +1 -1
  38. package/dist/cjs/codama/types/trigger.js +1 -1
  39. package/dist/cjs/codama/types/trigger.js.map +1 -1
  40. package/dist/cjs/codama/types/triggerContext.js +1 -1
  41. package/dist/cjs/codama/types/triggerContext.js.map +1 -1
  42. package/dist/cjs/contract/close.js +75 -34
  43. package/dist/cjs/contract/close.js.map +1 -1
  44. package/dist/cjs/contract/create.js +59 -43
  45. package/dist/cjs/contract/create.js.map +1 -1
  46. package/dist/cjs/index.js +7 -1
  47. package/dist/cjs/index.js.map +1 -1
  48. package/dist/cjs/package.json +54 -0
  49. package/dist/cjs/rental/accept.js +68 -40
  50. package/dist/cjs/rental/accept.js.map +1 -1
  51. package/dist/cjs/rental/cancel.js +36 -28
  52. package/dist/cjs/rental/cancel.js.map +1 -1
  53. package/dist/cjs/rental/close.js +37 -29
  54. package/dist/cjs/rental/close.js.map +1 -1
  55. package/dist/cjs/rental/reset.js +46 -42
  56. package/dist/cjs/rental/reset.js.map +1 -1
  57. package/dist/cjs/utils/config.js +319 -0
  58. package/dist/cjs/utils/config.js.map +1 -0
  59. package/dist/cjs/utils/constants.js +69 -9
  60. package/dist/cjs/utils/constants.js.map +1 -1
  61. package/dist/cjs/utils/index.js +1 -0
  62. package/dist/cjs/utils/index.js.map +1 -1
  63. package/dist/cjs/utils/profiles.js +96 -95
  64. package/dist/cjs/utils/profiles.js.map +1 -1
  65. package/dist/esm/codama/accounts/config.js +76 -0
  66. package/dist/esm/codama/accounts/config.js.map +1 -0
  67. package/dist/esm/codama/accounts/contractState.js +3 -7
  68. package/dist/esm/codama/accounts/contractState.js.map +1 -1
  69. package/dist/esm/codama/accounts/index.js +1 -1
  70. package/dist/esm/codama/accounts/index.js.map +1 -1
  71. package/dist/esm/codama/accounts/rentalState.js +3 -1
  72. package/dist/esm/codama/accounts/rentalState.js.map +1 -1
  73. package/dist/esm/codama/errors/srsly.js +23 -2
  74. package/dist/esm/codama/errors/srsly.js.map +1 -1
  75. package/dist/esm/codama/instructions/acceptRental.js +30 -39
  76. package/dist/esm/codama/instructions/acceptRental.js.map +1 -1
  77. package/dist/esm/codama/instructions/cancelRental.js +10 -33
  78. package/dist/esm/codama/instructions/cancelRental.js.map +1 -1
  79. package/dist/esm/codama/instructions/closeContract.js +17 -25
  80. package/dist/esm/codama/instructions/closeContract.js.map +1 -1
  81. package/dist/esm/codama/instructions/closeRental.js +19 -19
  82. package/dist/esm/codama/instructions/closeRental.js.map +1 -1
  83. package/dist/esm/codama/instructions/createContract.js +13 -16
  84. package/dist/esm/codama/instructions/createContract.js.map +1 -1
  85. package/dist/esm/codama/instructions/index.js +2 -1
  86. package/dist/esm/codama/instructions/index.js.map +1 -1
  87. package/dist/esm/codama/instructions/initializeConfig.js +121 -0
  88. package/dist/esm/codama/instructions/initializeConfig.js.map +1 -0
  89. package/dist/esm/codama/instructions/payRental.js +34 -25
  90. package/dist/esm/codama/instructions/payRental.js.map +1 -1
  91. package/dist/esm/codama/instructions/resetRental.js +0 -9
  92. package/dist/esm/codama/instructions/resetRental.js.map +1 -1
  93. package/dist/esm/codama/instructions/updateConfig.js +135 -0
  94. package/dist/esm/codama/instructions/updateConfig.js.map +1 -0
  95. package/dist/esm/codama/programs/srsly.js +12 -8
  96. package/dist/esm/codama/programs/srsly.js.map +1 -1
  97. package/dist/esm/contract/close.js +68 -16
  98. package/dist/esm/contract/close.js.map +1 -1
  99. package/dist/esm/contract/create.js +60 -33
  100. package/dist/esm/contract/create.js.map +1 -1
  101. package/dist/esm/index.js +5 -1
  102. package/dist/esm/index.js.map +1 -1
  103. package/dist/esm/package.json +54 -0
  104. package/dist/esm/rental/accept.js +70 -31
  105. package/dist/esm/rental/accept.js.map +1 -1
  106. package/dist/esm/rental/cancel.js +37 -18
  107. package/dist/esm/rental/cancel.js.map +1 -1
  108. package/dist/esm/rental/close.js +38 -19
  109. package/dist/esm/rental/close.js.map +1 -1
  110. package/dist/esm/rental/reset.js +48 -33
  111. package/dist/esm/rental/reset.js.map +1 -1
  112. package/dist/esm/utils/config.js +277 -0
  113. package/dist/esm/utils/config.js.map +1 -0
  114. package/dist/esm/utils/constants.js +60 -7
  115. package/dist/esm/utils/constants.js.map +1 -1
  116. package/dist/esm/utils/index.js +1 -0
  117. package/dist/esm/utils/index.js.map +1 -1
  118. package/dist/esm/utils/profiles.js +39 -19
  119. package/dist/esm/utils/profiles.js.map +1 -1
  120. package/dist/types/codama/accounts/config.d.ts +52 -0
  121. package/dist/types/codama/accounts/config.d.ts.map +1 -0
  122. package/dist/types/codama/accounts/contractState.d.ts +2 -4
  123. package/dist/types/codama/accounts/contractState.d.ts.map +1 -1
  124. package/dist/types/codama/accounts/index.d.ts +1 -1
  125. package/dist/types/codama/accounts/index.d.ts.map +1 -1
  126. package/dist/types/codama/accounts/rentalState.d.ts +2 -0
  127. package/dist/types/codama/accounts/rentalState.d.ts.map +1 -1
  128. package/dist/types/codama/errors/srsly.d.ts +16 -2
  129. package/dist/types/codama/errors/srsly.d.ts.map +1 -1
  130. package/dist/types/codama/instructions/acceptRental.d.ts +41 -34
  131. package/dist/types/codama/instructions/acceptRental.d.ts.map +1 -1
  132. package/dist/types/codama/instructions/cancelRental.d.ts +14 -10
  133. package/dist/types/codama/instructions/cancelRental.d.ts.map +1 -1
  134. package/dist/types/codama/instructions/closeContract.d.ts +29 -21
  135. package/dist/types/codama/instructions/closeContract.d.ts.map +1 -1
  136. package/dist/types/codama/instructions/closeRental.d.ts +20 -12
  137. package/dist/types/codama/instructions/closeRental.d.ts.map +1 -1
  138. package/dist/types/codama/instructions/createContract.d.ts +27 -23
  139. package/dist/types/codama/instructions/createContract.d.ts.map +1 -1
  140. package/dist/types/codama/instructions/index.d.ts +2 -1
  141. package/dist/types/codama/instructions/index.d.ts.map +1 -1
  142. package/dist/types/codama/instructions/initializeConfig.d.ts +60 -0
  143. package/dist/types/codama/instructions/initializeConfig.d.ts.map +1 -0
  144. package/dist/types/codama/instructions/payRental.d.ts +28 -13
  145. package/dist/types/codama/instructions/payRental.d.ts.map +1 -1
  146. package/dist/types/codama/instructions/resetRental.d.ts +3 -3
  147. package/dist/types/codama/instructions/resetRental.d.ts.map +1 -1
  148. package/dist/types/codama/instructions/updateConfig.d.ts +93 -0
  149. package/dist/types/codama/instructions/updateConfig.d.ts.map +1 -0
  150. package/dist/types/codama/programs/srsly.d.ts +11 -8
  151. package/dist/types/codama/programs/srsly.d.ts.map +1 -1
  152. package/dist/types/contract/close.d.ts +20 -24
  153. package/dist/types/contract/close.d.ts.map +1 -1
  154. package/dist/types/contract/create.d.ts +34 -22
  155. package/dist/types/contract/create.d.ts.map +1 -1
  156. package/dist/types/index.d.ts +4 -1
  157. package/dist/types/index.d.ts.map +1 -1
  158. package/dist/types/rental/accept.d.ts +42 -20
  159. package/dist/types/rental/accept.d.ts.map +1 -1
  160. package/dist/types/rental/cancel.d.ts +16 -11
  161. package/dist/types/rental/cancel.d.ts.map +1 -1
  162. package/dist/types/rental/close.d.ts +16 -11
  163. package/dist/types/rental/close.d.ts.map +1 -1
  164. package/dist/types/rental/reset.d.ts +17 -20
  165. package/dist/types/rental/reset.d.ts.map +1 -1
  166. package/dist/types/utils/config.d.ts +167 -0
  167. package/dist/types/utils/config.d.ts.map +1 -0
  168. package/dist/types/utils/constants.d.ts +23 -7
  169. package/dist/types/utils/constants.d.ts.map +1 -1
  170. package/dist/types/utils/index.d.ts +1 -0
  171. package/dist/types/utils/index.d.ts.map +1 -1
  172. package/dist/types/utils/profiles.d.ts +14 -8
  173. package/dist/types/utils/profiles.d.ts.map +1 -1
  174. package/package.json +36 -14
  175. package/target/idl/srsly.json +3279 -0
  176. package/target/types/srsly.ts +1 -0
  177. package/dist/cjs/codama/accounts/fleet.js +0 -94
  178. package/dist/cjs/codama/accounts/fleet.js.map +0 -1
  179. package/dist/cjs/codama/instructions/normalizeAdmin.js +0 -165
  180. package/dist/cjs/codama/instructions/normalizeAdmin.js.map +0 -1
  181. package/dist/esm/codama/accounts/fleet.js +0 -64
  182. package/dist/esm/codama/accounts/fleet.js.map +0 -1
  183. package/dist/esm/codama/instructions/normalizeAdmin.js +0 -142
  184. package/dist/esm/codama/instructions/normalizeAdmin.js.map +0 -1
  185. package/dist/types/codama/accounts/fleet.d.ts +0 -38
  186. package/dist/types/codama/accounts/fleet.d.ts.map +0 -1
  187. package/dist/types/codama/instructions/normalizeAdmin.d.ts +0 -67
  188. package/dist/types/codama/instructions/normalizeAdmin.d.ts.map +0 -1
@@ -1,49 +1,88 @@
1
- import { getAcceptRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
2
- import { deriveGameAccounts, DEFAULT_GAME_ID, } from '../utils';
1
+ import { getModule, createConfigSelector } from '../utils/config';
2
+ import { getSageGameId, ATLAS_TO_STARDUST, toAddress } from '../utils/constants';
3
+ import { deriveGameAccounts, } from '../utils';
3
4
  /**
4
- * Asynchronously creates an instruction to accept a rental with minimal required parameters.
5
- * Derives borrowerProfileFaction, starbase, and starbasePlayer automatically.
5
+ * Internal function to accept a rental instruction with configuration options
6
+ */
7
+ async function _acceptRental(params, config) {
8
+ const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId, rate, duration, referralTokenAccount, } = params;
9
+ // Get the actual game ID to use (param override, config override, or network default)
10
+ const actualGameId = gameId ? toAddress(gameId) : await getSageGameId(config);
11
+ // Calculate the total amount from rate and duration
12
+ // Convert ATLAS to stardust (smallest unit): 1 ATLAS = 100,000,000 stardust
13
+ const amount = BigInt(rate) * BigInt(duration) * BigInt(ATLAS_TO_STARDUST);
14
+ // Derive the three accounts we need
15
+ const { profileFaction, starbase, starbasePlayer } = await deriveGameAccounts(toAddress(borrowerProfile), borrowerFaction, actualGameId, 0, // starbaseSeqId
16
+ config);
17
+ // Let codama derive the rest (rentalThread, rentalState, rentalAuthority, etc.)
18
+ const input = {
19
+ borrower,
20
+ borrowerProfile: toAddress(borrowerProfile),
21
+ borrowerProfileFaction: profileFaction,
22
+ fleet: toAddress(fleet),
23
+ contract: toAddress(contract),
24
+ gameId: actualGameId,
25
+ starbase,
26
+ starbasePlayer,
27
+ amount,
28
+ duration,
29
+ referralTokenAccount: referralTokenAccount ? toAddress(referralTokenAccount) : undefined,
30
+ };
31
+ // Get network-specific codama functions from centralized config
32
+ const instructionsModule = getModule('instructions');
33
+ const programsModule = getModule('programs');
34
+ const { getAcceptRentalInstructionAsync } = instructionsModule;
35
+ const { SRSLY_PROGRAM_ADDRESS } = programsModule;
36
+ return getAcceptRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
37
+ }
38
+ /**
39
+ * Creates an instruction to accept a rental with fluent configuration.
6
40
  *
7
41
  * @example
8
42
  * ```typescript
9
- * // Create the instruction with automatic account derivation
43
+ * // Use devnet defaults
10
44
  * const ix = await acceptRental({
11
45
  * borrower: wallet,
12
46
  * borrowerProfile: profileAddress,
13
47
  * borrowerFaction: 1, // 1 = mud, 2 = oni, 3 = ustur
14
48
  * fleet: fleetAddress,
15
49
  * contract: contractAddress,
16
- * amount: 1000,
17
- * duration: 86400 // 1 day in seconds
18
- * // gameId is optional and will default to the standard game ID
50
+ * rate: 1000, // ATLAS tokens
51
+ * duration: 86400 // 1 day in seconds (total: 1000 * 86400 * 100M stardust)
19
52
  * });
20
53
  *
21
- * // Add to transaction and sign
22
- * const tx = new Transaction().add(ix);
23
- * await sendAndConfirmTransaction(connection, tx, [wallet]);
54
+ * // With referral (referrer gets 5% of platform fees)
55
+ * const ix = await acceptRental({
56
+ * borrower: wallet,
57
+ * borrowerProfile: profileAddress,
58
+ * borrowerFaction: 1,
59
+ * fleet: fleetAddress,
60
+ * contract: contractAddress,
61
+ * rate: 1000,
62
+ * duration: 86400,
63
+ * referralTokenAccount: referrerTokenAddress
64
+ * });
65
+ *
66
+ * // Use mainnet configuration
67
+ * const ix = await acceptRental(params).set({ network: 'mainnet' });
68
+ *
69
+ * // Override specific constants
70
+ * const ix = await acceptRental(params).set({
71
+ * network: 'mainnet',
72
+ * gameId: 'custom-game-id...'
73
+ * });
24
74
  * ```
25
75
  *
26
76
  * @param params The simplified parameters for accepting a rental
27
- * @returns A promise that resolves to the instruction to accept a rental
77
+ * @returns A ConfigSelector that can be configured with .set() or awaited directly
28
78
  */
29
- export async function acceptRental(params) {
30
- const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId = DEFAULT_GAME_ID, amount, duration, } = params;
31
- // Derive the three accounts we need
32
- const { profileFaction, starbase, starbasePlayer } = await deriveGameAccounts(borrowerProfile, borrowerFaction, gameId);
33
- // Let codama derive the rest (rentalThread, rentalState, rentalAuthority, etc.)
34
- const input = {
35
- borrower,
36
- borrowerProfile,
37
- borrowerProfileFaction: profileFaction,
38
- fleet,
39
- contract,
40
- gameId,
41
- starbase,
42
- starbasePlayer,
43
- amount,
44
- duration,
45
- };
46
- return getAcceptRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
79
+ export function acceptRental(params) {
80
+ return createConfigSelector((config) => _acceptRental(params, config));
81
+ }
82
+ export function getAcceptRentalInstructionAsync(input, options) {
83
+ return createConfigSelector(async (config) => {
84
+ const instructionsModule = getModule('instructions');
85
+ return instructionsModule.getAcceptRentalInstructionAsync(input, options);
86
+ });
47
87
  }
48
- export { getAcceptRentalInstructionAsync };
49
88
  //# sourceMappingURL=accept.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,eAAe,GAChB,MAAM,UAA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B;IAE1B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,33 +1,52 @@
1
- import { getCancelRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
1
+ import { getModule, createConfigSelector } from '../utils/config';
2
2
  /**
3
- * Asynchronously creates an instruction to cancel a rental with minimal required parameters.
4
- * Derives rentalState, rentalThread, borrowerTokenAccount, rentalTokenAccount and
5
- * rentalAuthority automatically if not provided.
3
+ * Internal function to cancel a rental instruction with configuration options
4
+ */
5
+ async function _cancelRental(params, config) {
6
+ const { borrower, contract, } = params;
7
+ // Let codama derive all the optional accounts
8
+ const input = {
9
+ borrower,
10
+ contract,
11
+ };
12
+ // Get network-specific codama functions from centralized config
13
+ const instructionsModule = getModule('instructions');
14
+ const programsModule = getModule('programs');
15
+ const { getCancelRentalInstructionAsync } = instructionsModule;
16
+ const { SRSLY_PROGRAM_ADDRESS } = programsModule;
17
+ return getCancelRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
18
+ }
19
+ /**
20
+ * Creates an instruction to cancel a rental with fluent configuration.
6
21
  *
7
22
  * @example
8
23
  * ```typescript
9
- * // Create the instruction with minimal parameters - just borrower and contract
24
+ * // Use devnet defaults
10
25
  * const ix = await cancelRental({
11
26
  * borrower: wallet,
12
27
  * contract: contractAddress
13
28
  * });
14
29
  *
15
- * // Add to transaction and sign
16
- * const tx = new Transaction().add(ix);
17
- * await sendAndConfirmTransaction(connection, tx, [wallet]);
30
+ * // Use mainnet configuration
31
+ * const ix = await cancelRental(params).set({ network: 'mainnet' });
32
+ *
33
+ * // Override specific constants
34
+ * const ix = await cancelRental(params).set({
35
+ * network: 'mainnet',
36
+ * sageProgramAddress: 'custom...'
37
+ * });
18
38
  * ```
19
39
  *
20
40
  * @param params The simplified parameters for canceling a rental
21
- * @returns A promise that resolves to the instruction to cancel a rental
41
+ * @returns A ConfigSelector that can be configured with .set() or awaited directly
22
42
  */
23
- export async function cancelRental(params) {
24
- const { borrower, contract, } = params;
25
- // Let codama derive all the optional accounts
26
- const input = {
27
- borrower,
28
- contract,
29
- };
30
- return getCancelRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
43
+ export function cancelRental(params) {
44
+ return createConfigSelector((config) => _cancelRental(params, config));
45
+ }
46
+ export function getCancelRentalInstructionAsync(input, options) {
47
+ return createConfigSelector(async (config) => {
48
+ const instructionsModule = getModule('instructions');
49
+ return instructionsModule.getCancelRentalInstructionAsync(input, options);
50
+ });
31
51
  }
32
- export { getCancelRentalInstructionAsync };
33
52
  //# sourceMappingURL=cancel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAiBnB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA0B;IAE1B,MAAM,EACJ,QAAQ,EACR,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,8CAA8C;IAC9C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,QAAQ;KACT,CAAC;IAEF,OAAO,+BAA+B,CACpC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
1
+ {"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AAoB3G;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA0B,EAC1B,MAAsB;IAEtB,MAAM,EACJ,QAAQ,EACR,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,8CAA8C;IAC9C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,QAAQ;KACT,CAAC;IAEF,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,EAAE,+BAA+B,EAAE,GAAG,kBAAkB,CAAC;IAC/D,MAAM,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAAC;IAEjD,OAAO,+BAA+B,CACpC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA0B;IAE1B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,35 +1,54 @@
1
- import { getCloseRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
1
+ import { getModule, createConfigSelector } from '../utils/config';
2
2
  /**
3
- * Asynchronously creates an instruction to close a rental with minimal required parameters.
4
- * This is called by an owner to close a rental that was previously accepted by a borrower.
5
- * Derives rentalState, rentalThread, rentalTokenAccount and rentalAuthority automatically if not provided.
3
+ * Internal function to close a rental instruction with configuration options
4
+ */
5
+ async function _closeRental(params, config) {
6
+ const { borrower, ownerTokenAccount, contract, } = params;
7
+ // Let codama derive the optional accounts
8
+ const input = {
9
+ borrower,
10
+ ownerTokenAccount,
11
+ contract,
12
+ };
13
+ // Get network-specific codama functions from centralized config
14
+ const instructionsModule = getModule('instructions');
15
+ const programsModule = getModule('programs');
16
+ const { getCloseRentalInstructionAsync } = instructionsModule;
17
+ const { SRSLY_PROGRAM_ADDRESS } = programsModule;
18
+ return getCloseRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
19
+ }
20
+ /**
21
+ * Creates an instruction to close a rental with fluent configuration.
6
22
  *
7
23
  * @example
8
24
  * ```typescript
9
- * // Create the instruction with minimal parameters
25
+ * // Use devnet defaults
10
26
  * const ix = await closeRental({
11
27
  * borrower: borrowerAddress,
12
28
  * ownerTokenAccount: ownerTokenAccountAddress,
13
29
  * contract: contractAddress
14
30
  * });
15
31
  *
16
- * // Add to transaction and sign
17
- * const tx = new Transaction().add(ix);
18
- * await sendAndConfirmTransaction(connection, tx, [owner]);
32
+ * // Use mainnet configuration
33
+ * const ix = await closeRental(params).set({ network: 'mainnet' });
34
+ *
35
+ * // Override specific constants
36
+ * const ix = await closeRental(params).set({
37
+ * network: 'mainnet',
38
+ * sageProgramAddress: 'custom...'
39
+ * });
19
40
  * ```
20
41
  *
21
42
  * @param params The simplified parameters for closing a rental
22
- * @returns A promise that resolves to the instruction to close a rental
43
+ * @returns A ConfigSelector that can be configured with .set() or awaited directly
23
44
  */
24
- export async function closeRental(params) {
25
- const { borrower, ownerTokenAccount, contract, } = params;
26
- // Let codama derive the optional accounts
27
- const input = {
28
- borrower,
29
- ownerTokenAccount,
30
- contract,
31
- };
32
- return getCloseRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
45
+ export function closeRental(params) {
46
+ return createConfigSelector((config) => _closeRental(params, config));
47
+ }
48
+ export function getCloseRentalInstructionAsync(input, options) {
49
+ return createConfigSelector(async (config) => {
50
+ const instructionsModule = getModule('instructions');
51
+ return instructionsModule.getCloseRentalInstructionAsync(input, options);
52
+ });
33
53
  }
34
- export { getCloseRentalInstructionAsync };
35
54
  //# sourceMappingURL=close.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAsBnB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAyB;IAEzB,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,0CAA0C;IAC1C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,iBAAiB;QACjB,QAAQ;KACT,CAAC;IAEF,OAAO,8BAA8B,CACnC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
1
+ {"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AAyB3G;;GAEG;AACH,KAAK,UAAU,YAAY,CACzB,MAAyB,EACzB,MAAsB;IAEtB,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,0CAA0C;IAC1C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,iBAAiB;QACjB,QAAQ;KACT,CAAC;IAEF,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,EAAE,8BAA8B,EAAE,GAAG,kBAAkB,CAAC;IAC9D,MAAM,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAAC;IAEjD,OAAO,8BAA8B,CACnC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,WAAW,CACzB,MAAyB;IAEzB,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAU,EAAE,OAAa;IACtE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,8BAA8B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,13 +1,38 @@
1
- import { getResetRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
2
- import { DEFAULT_GAME_ID, deriveGameAccounts, } from '../utils';
1
+ import { getModule, createConfigSelector } from '../utils/config';
2
+ import { getSageGameId } from '../utils/constants';
3
+ import { deriveGameAccounts, } from '../utils';
3
4
  /**
4
- * Asynchronously creates an instruction to reset a rental with minimal required parameters.
5
- * This is used to reset a fleet's rental state after a rental has ended.
6
- * Can derive starbase, starbasePlayer, and rentalAuthority automatically.
5
+ * Internal function to reset a rental instruction with configuration options
6
+ */
7
+ async function _resetRental(params, config) {
8
+ const { fleet, contract, rentalState, gameId, faction, ownerProfile, } = params;
9
+ // Get the actual game ID to use (param override, config override, or network default)
10
+ const actualGameId = gameId || await getSageGameId(config);
11
+ // Derive the three accounts we need
12
+ const { starbase, starbasePlayer } = await deriveGameAccounts(ownerProfile, faction, actualGameId, 0, // starbaseSeqId
13
+ config);
14
+ // Get network-specific codama functions from centralized config
15
+ const instructionsModule = getModule('instructions');
16
+ const programsModule = getModule('programs');
17
+ const { getResetRentalInstructionAsync } = instructionsModule;
18
+ const { SRSLY_PROGRAM_ADDRESS } = programsModule;
19
+ // Let codama derive the rest (rentalAuthority)
20
+ const input = {
21
+ fleet,
22
+ contract,
23
+ rentalState,
24
+ gameId: actualGameId,
25
+ starbase,
26
+ starbasePlayer,
27
+ };
28
+ return getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
29
+ }
30
+ /**
31
+ * Creates an instruction to reset a rental with fluent configuration.
7
32
  *
8
33
  * @example
9
34
  * ```typescript
10
- * // Create the instruction with minimum required parameters and faction
35
+ * // Use devnet defaults
11
36
  * const ix = await resetRental({
12
37
  * fleet: fleetAddress,
13
38
  * contract: contractAddress,
@@ -16,37 +41,27 @@ import { DEFAULT_GAME_ID, deriveGameAccounts, } from '../utils';
16
41
  * ownerProfile: ownerProfileAddress
17
42
  * });
18
43
  *
19
- * // Or with explicit starbase and starbasePlayer
20
- * const ix = await resetRental({
21
- * fleet: fleetAddress,
22
- * contract: contractAddress,
23
- * rentalState: rentalStateAddress,
24
- * starbase: starbaseAddress,
25
- * starbasePlayer: starbasePlayerAddress
26
- * });
44
+ * // Use mainnet configuration
45
+ * const ix = await resetRental(params).set({ network: 'mainnet' });
27
46
  *
28
- * // Add to transaction and sign
29
- * const tx = new Transaction().add(ix);
30
- * await sendAndConfirmTransaction(connection, tx, [owner]);
47
+ * // Override specific constants
48
+ * const ix = await resetRental(params).set({
49
+ * network: 'mainnet',
50
+ * gameId: 'custom-game-id...',
51
+ * sageProgramAddress: 'custom...'
52
+ * });
31
53
  * ```
32
54
  *
33
55
  * @param params The simplified parameters for resetting a rental
34
- * @returns A promise that resolves to the instruction to reset a rental
56
+ * @returns A ConfigSelector that can be configured with .set() or awaited directly
35
57
  */
36
- export async function resetRental(params) {
37
- const { fleet, contract, rentalState, gameId = DEFAULT_GAME_ID, faction, ownerProfile, } = params;
38
- // Derive the three accounts we need
39
- const { starbase, starbasePlayer } = await deriveGameAccounts(ownerProfile, faction, gameId);
40
- // Let codama derive the rest (rentalAuthority)
41
- const input = {
42
- fleet,
43
- contract,
44
- rentalState,
45
- gameId,
46
- starbase,
47
- starbasePlayer,
48
- };
49
- return getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
58
+ export function resetRental(params) {
59
+ return createConfigSelector((config) => _resetRental(params, config));
60
+ }
61
+ export function getResetRentalInstructionAsync(input, options) {
62
+ return createConfigSelector(async (config) => {
63
+ const instructionsModule = getModule('instructions');
64
+ return instructionsModule.getResetRentalInstructionAsync(input, options);
65
+ });
50
66
  }
51
- export { getResetRentalInstructionAsync };
52
67
  //# sourceMappingURL=reset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reset.js","sourceRoot":"","sources":["../../../src/rental/reset.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAyClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAyB;IAEzB,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,WAAW,EACX,MAAM,GAAG,eAAkC,EAC3C,OAAO,EACP,YAAY,GACb,GAAG,MAAM,CAAC;IAEX,oCAAoC;IACpC,MAAM,EACJ,QAAQ,EACR,cAAc,EACf,GAAG,MAAM,kBAAkB,CAC1B,YAAY,EACZ,OAAO,EACP,MAAM,CACP,CAAC;IAEF,+CAA+C;IAC/C,MAAM,KAAK,GAAG;QACZ,KAAK;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