@wuwei-labs/srsly 2.0.0-beta.37 → 2.0.0-beta.41

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 (177) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/codama/accounts/config.js +0 -2
  3. package/dist/cjs/codama/accounts/config.js.map +1 -1
  4. package/dist/cjs/codama/accounts/contractState.js.map +1 -1
  5. package/dist/cjs/codama/accounts/rentalState.js +1 -3
  6. package/dist/cjs/codama/accounts/rentalState.js.map +1 -1
  7. package/dist/cjs/codama/errors/srsly.js +13 -1
  8. package/dist/cjs/codama/errors/srsly.js.map +1 -1
  9. package/dist/cjs/codama/instructions/acceptRental.js +1 -28
  10. package/dist/cjs/codama/instructions/acceptRental.js.map +1 -1
  11. package/dist/cjs/codama/instructions/closeRental.js +28 -13
  12. package/dist/cjs/codama/instructions/closeRental.js.map +1 -1
  13. package/dist/cjs/codama/instructions/index.js +1 -0
  14. package/dist/cjs/codama/instructions/index.js.map +1 -1
  15. package/dist/cjs/codama/instructions/payRental.js +1 -18
  16. package/dist/cjs/codama/instructions/payRental.js.map +1 -1
  17. package/dist/cjs/codama/instructions/resetContractTemp.js +146 -0
  18. package/dist/cjs/codama/instructions/resetContractTemp.js.map +1 -0
  19. package/dist/cjs/codama/instructions/resetRental.js +6 -1
  20. package/dist/cjs/codama/instructions/resetRental.js.map +1 -1
  21. package/dist/cjs/codama/instructions/updateConfig.js +0 -2
  22. package/dist/cjs/codama/instructions/updateConfig.js.map +1 -1
  23. package/dist/cjs/codama/programs/srsly.js +6 -2
  24. package/dist/cjs/codama/programs/srsly.js.map +1 -1
  25. package/dist/cjs/codama/types/paymentFrequency.js +31 -0
  26. package/dist/cjs/codama/types/paymentFrequency.js.map +1 -1
  27. package/dist/cjs/contract/close.js +71 -11
  28. package/dist/cjs/contract/close.js.map +1 -1
  29. package/dist/cjs/contract/create.js +88 -21
  30. package/dist/cjs/contract/create.js.map +1 -1
  31. package/dist/cjs/contract/index.js +45 -0
  32. package/dist/cjs/contract/index.js.map +1 -1
  33. package/dist/cjs/index.js +110 -7
  34. package/dist/cjs/index.js.map +1 -1
  35. package/dist/cjs/package.json +4 -4
  36. package/dist/cjs/rental/accept.js +164 -45
  37. package/dist/cjs/rental/accept.js.map +1 -1
  38. package/dist/cjs/rental/cancel.js +82 -16
  39. package/dist/cjs/rental/cancel.js.map +1 -1
  40. package/dist/cjs/rental/close.js +152 -27
  41. package/dist/cjs/rental/close.js.map +1 -1
  42. package/dist/cjs/rental/index.js +85 -0
  43. package/dist/cjs/rental/index.js.map +1 -1
  44. package/dist/cjs/rental/reset-contract-temp.js +103 -0
  45. package/dist/cjs/rental/reset-contract-temp.js.map +1 -0
  46. package/dist/cjs/rental/reset.js +102 -19
  47. package/dist/cjs/rental/reset.js.map +1 -1
  48. package/dist/cjs/utils/config.js +44 -9
  49. package/dist/cjs/utils/config.js.map +1 -1
  50. package/dist/cjs/utils/constants.js +16 -6
  51. package/dist/cjs/utils/constants.js.map +1 -1
  52. package/dist/cjs/utils/index.js +1 -0
  53. package/dist/cjs/utils/index.js.map +1 -1
  54. package/dist/cjs/utils/instruction-converter.js +60 -5
  55. package/dist/cjs/utils/instruction-converter.js.map +1 -1
  56. package/dist/cjs/utils/paymentFrequency.js +7 -2
  57. package/dist/cjs/utils/paymentFrequency.js.map +1 -1
  58. package/dist/cjs/utils/pda.js +191 -0
  59. package/dist/cjs/utils/pda.js.map +1 -0
  60. package/dist/esm/codama/accounts/config.js +0 -2
  61. package/dist/esm/codama/accounts/config.js.map +1 -1
  62. package/dist/esm/codama/accounts/contractState.js.map +1 -1
  63. package/dist/esm/codama/accounts/rentalState.js +1 -3
  64. package/dist/esm/codama/accounts/rentalState.js.map +1 -1
  65. package/dist/esm/codama/errors/srsly.js +12 -0
  66. package/dist/esm/codama/errors/srsly.js.map +1 -1
  67. package/dist/esm/codama/instructions/acceptRental.js +1 -28
  68. package/dist/esm/codama/instructions/acceptRental.js.map +1 -1
  69. package/dist/esm/codama/instructions/closeRental.js +28 -13
  70. package/dist/esm/codama/instructions/closeRental.js.map +1 -1
  71. package/dist/esm/codama/instructions/index.js +1 -0
  72. package/dist/esm/codama/instructions/index.js.map +1 -1
  73. package/dist/esm/codama/instructions/payRental.js +1 -18
  74. package/dist/esm/codama/instructions/payRental.js.map +1 -1
  75. package/dist/esm/codama/instructions/resetContractTemp.js +136 -0
  76. package/dist/esm/codama/instructions/resetContractTemp.js.map +1 -0
  77. package/dist/esm/codama/instructions/resetRental.js +6 -1
  78. package/dist/esm/codama/instructions/resetRental.js.map +1 -1
  79. package/dist/esm/codama/instructions/updateConfig.js +0 -2
  80. package/dist/esm/codama/instructions/updateConfig.js.map +1 -1
  81. package/dist/esm/codama/programs/srsly.js +6 -2
  82. package/dist/esm/codama/programs/srsly.js.map +1 -1
  83. package/dist/esm/codama/types/paymentFrequency.js +31 -0
  84. package/dist/esm/codama/types/paymentFrequency.js.map +1 -1
  85. package/dist/esm/contract/close.js +72 -12
  86. package/dist/esm/contract/close.js.map +1 -1
  87. package/dist/esm/contract/create.js +89 -22
  88. package/dist/esm/contract/create.js.map +1 -1
  89. package/dist/esm/contract/index.js +45 -0
  90. package/dist/esm/contract/index.js.map +1 -1
  91. package/dist/esm/index.js +110 -6
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/package.json +4 -4
  94. package/dist/esm/rental/accept.js +166 -47
  95. package/dist/esm/rental/accept.js.map +1 -1
  96. package/dist/esm/rental/cancel.js +83 -17
  97. package/dist/esm/rental/cancel.js.map +1 -1
  98. package/dist/esm/rental/close.js +152 -27
  99. package/dist/esm/rental/close.js.map +1 -1
  100. package/dist/esm/rental/index.js +85 -0
  101. package/dist/esm/rental/index.js.map +1 -1
  102. package/dist/esm/rental/reset-contract-temp.js +100 -0
  103. package/dist/esm/rental/reset-contract-temp.js.map +1 -0
  104. package/dist/esm/rental/reset.js +102 -19
  105. package/dist/esm/rental/reset.js.map +1 -1
  106. package/dist/esm/utils/config.js +44 -9
  107. package/dist/esm/utils/config.js.map +1 -1
  108. package/dist/esm/utils/constants.js +16 -6
  109. package/dist/esm/utils/constants.js.map +1 -1
  110. package/dist/esm/utils/index.js +1 -0
  111. package/dist/esm/utils/index.js.map +1 -1
  112. package/dist/esm/utils/instruction-converter.js +59 -5
  113. package/dist/esm/utils/instruction-converter.js.map +1 -1
  114. package/dist/esm/utils/paymentFrequency.js +7 -2
  115. package/dist/esm/utils/paymentFrequency.js.map +1 -1
  116. package/dist/esm/utils/pda.js +185 -0
  117. package/dist/esm/utils/pda.js.map +1 -0
  118. package/dist/types/codama/accounts/config.d.ts +24 -2
  119. package/dist/types/codama/accounts/config.d.ts.map +1 -1
  120. package/dist/types/codama/accounts/contractState.d.ts +26 -0
  121. package/dist/types/codama/accounts/contractState.d.ts.map +1 -1
  122. package/dist/types/codama/accounts/rentalState.d.ts +20 -2
  123. package/dist/types/codama/accounts/rentalState.d.ts.map +1 -1
  124. package/dist/types/codama/errors/srsly.d.ts +9 -1
  125. package/dist/types/codama/errors/srsly.d.ts.map +1 -1
  126. package/dist/types/codama/instructions/acceptRental.d.ts +13 -20
  127. package/dist/types/codama/instructions/acceptRental.d.ts.map +1 -1
  128. package/dist/types/codama/instructions/closeRental.d.ts +33 -13
  129. package/dist/types/codama/instructions/closeRental.d.ts.map +1 -1
  130. package/dist/types/codama/instructions/index.d.ts +1 -0
  131. package/dist/types/codama/instructions/index.d.ts.map +1 -1
  132. package/dist/types/codama/instructions/payRental.d.ts +11 -18
  133. package/dist/types/codama/instructions/payRental.d.ts.map +1 -1
  134. package/dist/types/codama/instructions/resetContractTemp.d.ts +71 -0
  135. package/dist/types/codama/instructions/resetContractTemp.d.ts.map +1 -0
  136. package/dist/types/codama/instructions/resetRental.d.ts +21 -17
  137. package/dist/types/codama/instructions/resetRental.d.ts.map +1 -1
  138. package/dist/types/codama/instructions/updateConfig.d.ts +20 -4
  139. package/dist/types/codama/instructions/updateConfig.d.ts.map +1 -1
  140. package/dist/types/codama/programs/srsly.d.ts +6 -3
  141. package/dist/types/codama/programs/srsly.d.ts.map +1 -1
  142. package/dist/types/codama/types/paymentFrequency.d.ts +31 -0
  143. package/dist/types/codama/types/paymentFrequency.d.ts.map +1 -1
  144. package/dist/types/contract/close.d.ts +77 -16
  145. package/dist/types/contract/close.d.ts.map +1 -1
  146. package/dist/types/contract/create.d.ts +114 -17
  147. package/dist/types/contract/create.d.ts.map +1 -1
  148. package/dist/types/contract/index.d.ts +45 -0
  149. package/dist/types/contract/index.d.ts.map +1 -1
  150. package/dist/types/index.d.ts +111 -1
  151. package/dist/types/index.d.ts.map +1 -1
  152. package/dist/types/rental/accept.d.ts +121 -50
  153. package/dist/types/rental/accept.d.ts.map +1 -1
  154. package/dist/types/rental/cancel.d.ts +80 -16
  155. package/dist/types/rental/cancel.d.ts.map +1 -1
  156. package/dist/types/rental/close.d.ts +86 -26
  157. package/dist/types/rental/close.d.ts.map +1 -1
  158. package/dist/types/rental/index.d.ts +85 -0
  159. package/dist/types/rental/index.d.ts.map +1 -1
  160. package/dist/types/rental/reset-contract-temp.d.ts +77 -0
  161. package/dist/types/rental/reset-contract-temp.d.ts.map +1 -0
  162. package/dist/types/rental/reset.d.ts +114 -24
  163. package/dist/types/rental/reset.d.ts.map +1 -1
  164. package/dist/types/utils/config.d.ts +14 -2
  165. package/dist/types/utils/config.d.ts.map +1 -1
  166. package/dist/types/utils/constants.d.ts +1 -1
  167. package/dist/types/utils/constants.d.ts.map +1 -1
  168. package/dist/types/utils/index.d.ts +1 -0
  169. package/dist/types/utils/index.d.ts.map +1 -1
  170. package/dist/types/utils/instruction-converter.d.ts +70 -20
  171. package/dist/types/utils/instruction-converter.d.ts.map +1 -1
  172. package/dist/types/utils/paymentFrequency.d.ts +3 -3
  173. package/dist/types/utils/paymentFrequency.d.ts.map +1 -1
  174. package/dist/types/utils/pda.d.ts +120 -0
  175. package/dist/types/utils/pda.d.ts.map +1 -0
  176. package/package.json +5 -5
  177. package/target/idl/srsly.json +318 -94
@@ -1 +1 @@
1
- {"version":3,"file":"paymentFrequency.js","sourceRoot":"","sources":["../../../../src/codama/types/paymentFrequency.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,GAIf,MAAM,aAAa,CAAC;AAErB,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,2DAAM,CAAA;IACN,yDAAK,CAAA;IACL,+DAAQ,CAAA;IACR,2DAAM,CAAA;IACN,6DAAO,CAAA;IACP,mEAAU,CAAA;IACV,2DAAM,CAAA;AACR,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B;AAID,MAAM,UAAU,0BAA0B;IACxC,OAAO,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,wBAAwB;IAItC,OAAO,YAAY,CACjB,0BAA0B,EAAE,EAC5B,0BAA0B,EAAE,CAC7B,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"paymentFrequency.js","sourceRoot":"","sources":["../../../../src/codama/types/paymentFrequency.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,GAIf,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,2DAAM,CAAA;IACN,yDAAK,CAAA;IACL,+DAAQ,CAAA;IACR,2DAAM,CAAA;IACN,6DAAO,CAAA;IACP,mEAAU,CAAA;IACV,2DAAM,CAAA;AACR,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B;AAID,MAAM,UAAU,0BAA0B;IACxC,OAAO,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,wBAAwB;IAItC,OAAO,YAAY,CACjB,0BAA0B,EAAE,EAC5B,0BAA0B,EAAE,CAC7B,CAAC;AACJ,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { getModule, createConfigSelector, resolveProgramAddresses } from '../utils/config';
2
2
  import { toAddress } from '../utils/constants';
3
3
  import { deriveGameAccounts } from '../utils';
4
- import { createFluentInstruction, createFluentConfigSelector } from '../utils/instruction-converter';
4
+ import { createFluentInstruction, createSmartFluentConfigSelector } from '../utils/instruction-converter';
5
5
  /**
6
6
  * Asynchronously creates an instruction to close a rental contract with minimal required parameters.
7
7
  * Derives rentalAuthority automatically and handles optional parameters.
@@ -46,12 +46,21 @@ import { createFluentInstruction, createFluentConfigSelector } from '../utils/in
46
46
  * @returns A promise that resolves to the instruction to close a contract
47
47
  */
48
48
  /**
49
- * Internal function to close a contract instruction with configuration options
49
+ * Internal function to close a contract instruction with configuration options.
50
+ *
51
+ * This function handles the core logic of creating a contract closure instruction,
52
+ * including account derivation, address resolution, and instruction generation.
53
+ *
54
+ * @internal
55
+ * @param params - The contract closure parameters
56
+ * @param config - Optional configuration for network and program settings
57
+ * @returns Promise resolving to a fluent instruction object
58
+ * @throws Error when account derivation fails or required parameters are missing
50
59
  */
51
60
  async function _closeContract(params, config) {
52
61
  const { owner, fleet, contract, faction, } = params;
53
62
  // Get the resolved addresses from config (including network-specific addresses)
54
- const resolvedAddresses = resolveProgramAddresses(config || {});
63
+ const resolvedAddresses = await resolveProgramAddresses(config || {});
55
64
  const derivedAccounts = await deriveGameAccounts(toAddress(owner), faction, resolvedAddresses.gameId, 0, // starbaseSeqId
56
65
  config);
57
66
  // Get network-specific codama functions from centralized config
@@ -75,24 +84,75 @@ async function _closeContract(params, config) {
75
84
  /**
76
85
  * Creates an instruction to close a rental contract with fluent configuration.
77
86
  *
78
- * @param params The contract closing parameters
79
- * @returns A ConfigSelector that can be configured with .set() or awaited directly
87
+ * This function permanently closes an existing rental contract, making it unavailable
88
+ * for new rentals. The contract can only be closed by its original owner and only
89
+ * when there are no active rentals.
90
+ *
91
+ * ## Features
92
+ *
93
+ * - **Permanent Closure**: Irreversibly closes the contract
94
+ * - **Account Cleanup**: Closes contract account and returns lamports to owner
95
+ * - **SAGE Integration**: Removes rental capability from the fleet in SAGE
96
+ * - **Automatic Derivation**: Derives required game accounts automatically
97
+ * - **Network Agnostic**: Works with different Solana networks
98
+ *
99
+ * ## Process
100
+ *
101
+ * 1. **Derive Accounts**: Automatically derives required game accounts (starbase, etc.)
102
+ * 2. **Validate Authority**: Ensures only the contract owner can close it
103
+ * 3. **Check State**: Verifies no active rentals exist
104
+ * 4. **Close Contract**: Removes rental capability and closes account
105
+ * 5. **Transfer Lamports**: Returns remaining SOL to the owner
106
+ *
107
+ * ## Requirements
108
+ *
109
+ * - Contract must not have any active rentals
110
+ * - Caller must be the original contract owner
111
+ * - All pending payments must be completed
80
112
  *
81
113
  * @example
82
114
  * ```typescript
83
- * // Use atlasnet defaults (instruction building only)
84
- * await closeContract(params);
115
+ * import { closeContract } from '@srsly/sdk';
116
+ *
117
+ * // Basic contract closure
118
+ * const instruction = await closeContract({
119
+ * owner: wallet, // Contract owner
120
+ * fleet: "FleetAddress123...", // Fleet address
121
+ * contract: "ContractAddr...", // Contract to close
122
+ * faction: 'mud' // Faction for game account derivation
123
+ * });
124
+ *
125
+ * // Configure for mainnet
126
+ * const mainnetInstruction = await closeContract({
127
+ * owner: wallet,
128
+ * fleet: "FleetAddress123...",
129
+ * contract: "ContractAddr...",
130
+ * faction: 'mud'
131
+ * }).set({ programs: 'mainnet' });
85
132
  *
86
- * // Use mainnet
87
- * await closeContract(params).set({ programs: 'mainnet' });
133
+ * // Override specific game configuration
134
+ * const customInstruction = await closeContract({
135
+ * owner: wallet,
136
+ * fleet: "FleetAddress123...",
137
+ * contract: "ContractAddr...",
138
+ * faction: 'mud'
139
+ * }).set({
140
+ * programs: 'mainnet',
141
+ * gameId: 'custom-game-id...'
142
+ * });
88
143
  *
89
- * // Override game ID
90
- * await closeContract(params).set({ gameId: 'custom...' }); // gameId configured via .set()
144
+ * // Use with your preferred Solana library
145
+ * const transaction = new Transaction().add(instruction);
146
+ * await sendAndConfirmTransaction(connection, transaction, [wallet]);
91
147
  * ```
148
+ *
149
+ * @param params - The contract closing parameters including owner, fleet, and contract addresses
150
+ * @returns A FluentConfigSelector that can be configured with .set() or awaited directly
151
+ * @throws Error when account derivation fails or invalid parameters are provided
92
152
  */
93
153
  export function closeContract(params) {
94
154
  const baseSelector = createConfigSelector((config) => _closeContract(params, config));
95
- return createFluentConfigSelector(baseSelector);
155
+ return createSmartFluentConfigSelector(baseSelector);
96
156
  }
97
157
  // Export config selector for getCloseContractInstructionAsync
98
158
  export function getCloseContractInstructionAsync(input, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAA2C,MAAM,iBAAiB,CAAC;AACpI,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAqD,MAAM,gCAAgC,CAAC;AAgCxJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH;;GAEG;AACH,KAAK,UAAU,cAAc,CAC3B,MAA2B,EAC3B,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,GACR,GAAG,MAAM,CAAC;IAEX,gFAAgF;IAChF,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAEhE,MAAM,eAAe,GAAG,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}
@@ -1,29 +1,58 @@
1
1
  /**
2
- * Unified contract creation - works with both @solana/kit and @solana/web3.js
3
- * Uses strings for all addresses to eliminate library-specific type complexity
2
+ * # Contract Creation Module
3
+ *
4
+ * This module provides functionality for creating rental contracts on the SRSLY program.
5
+ * It offers a unified API that works with both @solana/kit and @solana/web3.js libraries,
6
+ * using strings for all addresses to eliminate library-specific type complexity.
7
+ *
8
+ * ## Features
9
+ *
10
+ * - **Universal Compatibility**: Works with both major Solana libraries
11
+ * - **Fluent API**: Chainable configuration and format conversion
12
+ * - **Validation**: Built-in parameter validation and duration alignment checking
13
+ * - **Network Agnostic**: Supports mainnet, devnet, and custom configurations
14
+ *
15
+ * @module Contract/Create
4
16
  */
5
17
  import { getModule, createConfigSelector, resolveProgramAddresses } from '../utils/config';
6
18
  import { toAddress } from '../utils/constants';
7
19
  import { validateDurationAlignment, paymentFrequencyStringToSeconds } from '../utils/paymentFrequency';
8
20
  import { isValidPaymentFrequency } from '../types/paymentFrequency';
9
- import { createFluentInstruction, createFluentConfigSelector } from '../utils/instruction-converter';
21
+ import { createFluentInstruction, createSmartFluentConfigSelector } from '../utils/instruction-converter';
10
22
  /**
11
- * Internal function to create a rental contract instruction with configuration options
23
+ * Internal function to create a rental contract instruction with configuration options.
24
+ *
25
+ * This function handles the core logic of creating a contract instruction, including
26
+ * parameter validation, address resolution, and instruction generation. It's used
27
+ * internally by the public createContract function.
28
+ *
29
+ * @internal
30
+ * @param params - The contract creation parameters
31
+ * @param config - Optional configuration for network and program settings
32
+ * @returns Promise resolving to a fluent instruction object
33
+ * @throws Error when validation fails or required parameters are missing
12
34
  */
13
35
  async function _createContract(params, config) {
14
- const { owner, fleet, ownerProfile, rate, durationMax, paymentsFreq, ownerKeyIndex = 0, } = params;
36
+ const { owner, fleet, ownerProfile, rate, durationMin: customDurationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, } = params;
15
37
  // Validate payment frequency
16
38
  if (!isValidPaymentFrequency(paymentsFreq)) {
17
39
  throw new Error(`Invalid payment frequency: "${paymentsFreq}". Valid values are: ${JSON.stringify(Object.keys({ daily: true, weekly: true, monthly: true, hourly: true }))}`);
18
40
  }
19
- // Validate duration alignment
41
+ // Get the payment frequency interval
42
+ const paymentFrequencySeconds = paymentFrequencyStringToSeconds(paymentsFreq);
43
+ // Use custom durationMin if provided, otherwise default to 1 payment frequency period
44
+ const durationMin = customDurationMin ?? paymentFrequencySeconds;
45
+ // Validate duration alignment for both min and max
46
+ validateDurationAlignment(Number(durationMin), paymentsFreq);
20
47
  validateDurationAlignment(Number(durationMax), paymentsFreq);
21
- // Get the payment frequency interval (this will be the minimum duration)
22
- const durationMin = paymentFrequencyStringToSeconds(paymentsFreq);
48
+ // Validate that max is greater than or equal to min
49
+ if (durationMax < durationMin) {
50
+ throw new Error(`Maximum duration (${durationMax}s) must be greater than or equal to minimum duration (${durationMin}s)`);
51
+ }
23
52
  // Convert the payment frequency to the format expected by the Rust program (with @ prefix)
24
53
  const paymentsFreqWithPrefix = `@${paymentsFreq}`;
25
54
  // Get the resolved addresses from config (including network-specific addresses)
26
- const resolvedAddresses = resolveProgramAddresses(config || {});
55
+ const resolvedAddresses = await resolveProgramAddresses(config || {});
27
56
  const input = {
28
57
  owner, // Pass as-is (string or signer)
29
58
  fleet: toAddress(fleet), // Convert fleet to Address
@@ -47,23 +76,59 @@ async function _createContract(params, config) {
47
76
  }
48
77
  /**
49
78
  * Creates an instruction to create a rental contract with fluent configuration.
50
- * This unified version works with both @solana/kit and @solana/web3.js using strings for addresses.
79
+ *
80
+ * This is the main function for creating rental contracts on the SRSLY program.
81
+ * It provides a unified API that works with both @solana/kit and @solana/web3.js
82
+ * libraries, using strings for all addresses to eliminate compatibility issues.
83
+ *
84
+ * ## Features
85
+ *
86
+ * - **Universal Library Support**: Works with both @solana/kit and @solana/web3.js
87
+ * - **Fluent Configuration**: Chain configuration options with `.set()`
88
+ * - **Format Conversion**: Convert between library formats with `.web3js()`
89
+ * - **Validation**: Built-in parameter validation and duration alignment
90
+ * - **Network Support**: Configurable for different Solana networks
91
+ *
92
+ * ## Validation
93
+ *
94
+ * The function automatically validates:
95
+ * - Payment frequency is supported
96
+ * - Duration alignment with payment frequency
97
+ * - Required parameters are provided
98
+ *
99
+ * ## Process
100
+ *
101
+ * 1. **Validate Parameters**: Checks payment frequency and duration alignment
102
+ * 2. **Resolve Addresses**: Gets network-specific program and mint addresses
103
+ * 3. **Generate Instruction**: Creates the contract creation instruction
104
+ * 4. **Return Fluent Object**: Allows for configuration and format conversion
51
105
  *
52
106
  * @example
53
107
  * ```typescript
54
- * // Works with any library - just use strings for addresses!
108
+ * import { createContract, days, hours } from '@srsly/sdk';
55
109
  *
56
- * // Default returns @solana/kit format
57
- * const kitInstruction = await createContract({
110
+ * // Basic usage - returns @solana/kit format by default
111
+ * const instruction = await createContract({
58
112
  * owner: wallet, // Can be signer object or string
59
113
  * fleet: "FleetAddress123...", // String address
60
114
  * ownerProfile: "ProfileAddr...", // String address
61
- * rate: 1000,
62
- * durationMax: days(7),
63
- * paymentsFreq: 'daily'
115
+ * rate: 1000, // 1000 ATLAS per payment period
116
+ * durationMax: days(7), // 7 days maximum rental
117
+ * paymentsFreq: 'daily' // Daily payments
118
+ * });
119
+ *
120
+ * // With custom minimum duration
121
+ * const customMinInstruction = await createContract({
122
+ * owner: wallet,
123
+ * fleet: "FleetAddress123...",
124
+ * ownerProfile: "ProfileAddr...",
125
+ * rate: 100, // 100 ATLAS per hour
126
+ * durationMin: hours(10), // 10 hours minimum rental
127
+ * durationMax: hours(24), // 24 hours maximum rental
128
+ * paymentsFreq: 'hourly' // Hourly payments
64
129
  * });
65
130
  *
66
- * // Convert to @solana/web3.js format using fluent interface
131
+ * // Convert to @solana/web3.js format
67
132
  * const web3jsInstruction = await createContract({
68
133
  * owner: wallet,
69
134
  * fleet: "FleetAddress123...",
@@ -73,8 +138,8 @@ async function _createContract(params, config) {
73
138
  * paymentsFreq: 'daily'
74
139
  * }).web3js();
75
140
  *
76
- * // Chain configuration and format conversion
77
- * const web3jsInstructionWithConfig = await createContract({
141
+ * // Configure network and convert format
142
+ * const mainnetInstruction = await createContract({
78
143
  * owner: wallet,
79
144
  * fleet: "FleetAddress123...",
80
145
  * ownerProfile: "ProfileAddr...",
@@ -85,13 +150,15 @@ async function _createContract(params, config) {
85
150
  *
86
151
  * // Use with your preferred Solana library
87
152
  * const transaction = new Transaction().add(web3jsInstruction);
153
+ * await sendAndConfirmTransaction(connection, transaction, [wallet]);
88
154
  * ```
89
155
  *
90
- * @param params The simplified parameters for creating a rental contract
91
- * @returns A ConfigSelector that can be configured with .set() or awaited directly
156
+ * @param params - The contract creation parameters including owner, fleet, rate, and duration
157
+ * @returns A FluentConfigSelector that can be configured with .set() or awaited directly
158
+ * @throws Error when payment frequency is invalid or duration alignment fails
92
159
  */
93
160
  export function createContract(params) {
94
161
  const baseSelector = createConfigSelector((config) => _createContract(params, config));
95
- return createFluentConfigSelector(baseSelector);
162
+ return createSmartFluentConfigSelector(baseSelector);
96
163
  }
97
164
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAsB,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAA0B,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAqD,MAAM,gCAAgC,CAAC;AAmBxJ;;GAEG;AACH,KAAK,UAAU,eAAe,CAAC,MAA4B,EAAE,MAAsB;IACjF,MAAM,EACJ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,aAA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QACJ,WAAW,EAAE,sBAAsB,EAAM,+CAA+C;QACxF,aAAa;KACd,CAAC;IAEF,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,EAAE,iCAAiC,EAAE,GAAG,kBAAkB,CAAC;IACjE,MAAM,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAAC;IAEjD,MAAM,cAAc,GAAG,MAAM,iCAAiC,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACjH,OAAO,uBAAuB,CAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,MAAM,UAAU,cAAc,CAAC,MAA4B;IACzD,MAAM,YAAY,GAAG,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvF,OAAO,+BAA+B,CAAC,YAAY,CAAC,CAAC;AACvD,CAAC"}
@@ -1,3 +1,48 @@
1
+ /**
2
+ * # Contract Management Module
3
+ *
4
+ * This module provides comprehensive functionality for managing rental contracts
5
+ * on the SRSLY program. It includes functions for creating and closing contracts,
6
+ * with full support for both @solana/kit and @solana/web3.js libraries.
7
+ *
8
+ * ## Available Functions
9
+ *
10
+ * - **createContract**: Create a new rental contract for a fleet
11
+ * - **closeContract**: Permanently close an existing rental contract
12
+ *
13
+ * ## Features
14
+ *
15
+ * - **Universal Library Support**: Works with both major Solana libraries
16
+ * - **String-Based Addresses**: Eliminates library-specific type conflicts
17
+ * - **Fluent API**: Chainable configuration and format conversion
18
+ * - **Network Agnostic**: Supports different Solana networks
19
+ * - **Validation**: Built-in parameter validation and error checking
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { createContract, closeContract, days } from '@srsly/sdk';
24
+ *
25
+ * // Create a rental contract
26
+ * const createInstruction = await createContract({
27
+ * owner: wallet,
28
+ * fleet: "FleetAddress123...",
29
+ * ownerProfile: "ProfileAddr...",
30
+ * rate: 1000,
31
+ * durationMax: days(30),
32
+ * paymentsFreq: 'daily'
33
+ * });
34
+ *
35
+ * // Close the contract later
36
+ * const closeInstruction = await closeContract({
37
+ * owner: wallet,
38
+ * fleet: "FleetAddress123...",
39
+ * contract: "ContractAddr...",
40
+ * faction: 'mud'
41
+ * });
42
+ * ```
43
+ *
44
+ * @module Contract
45
+ */
1
46
  export * from "./close";
2
47
  export * from "./create";
3
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,15 +1,119 @@
1
+ /**
2
+ * # SRSLY SDK - Solana Rental System Library
3
+ *
4
+ * A comprehensive TypeScript SDK for interacting with the SRSLY Solana program,
5
+ * which facilitates fleet rentals in the Star Atlas ecosystem. This SDK provides
6
+ * a fluent, developer-friendly interface that works with both @solana/kit and
7
+ * @solana/web3.js libraries.
8
+ *
9
+ * ## Features
10
+ *
11
+ * - **Universal Compatibility**: Works with both @solana/kit and @solana/web3.js
12
+ * - **Fluent API**: Chainable methods for intuitive development experience
13
+ * - **String-Based Addresses**: Uses strings for all addresses to eliminate library conflicts
14
+ * - **Network Agnostic**: Supports mainnet, devnet, and custom RPC endpoints
15
+ * - **Type Safety**: Full TypeScript support with comprehensive type definitions
16
+ * - **Auto-Generated Types**: Types generated from Solana program IDL for accuracy
17
+ *
18
+ * ## Quick Start
19
+ *
20
+ * ```typescript
21
+ * import { createContract, acceptRental, days } from '@srsly/sdk';
22
+ *
23
+ * // Create a rental contract
24
+ * const instruction = await createContract({
25
+ * owner: wallet,
26
+ * fleet: "FleetAddress123...",
27
+ * ownerProfile: "ProfileAddr...",
28
+ * rate: 1000,
29
+ * durationMax: days(7),
30
+ * paymentsFreq: 'daily'
31
+ * });
32
+ *
33
+ * // Accept a rental
34
+ * const rentalInstruction = await acceptRental({
35
+ * borrower: borrowerWallet,
36
+ * contract: contractAddress,
37
+ * amount: 7000,
38
+ * duration: days(7)
39
+ * });
40
+ * ```
41
+ *
42
+ * ## Architecture
43
+ *
44
+ * The SDK is organized into several main modules:
45
+ * - **Contract**: Functions for creating and managing rental contracts
46
+ * - **Rental**: Functions for rental operations (accept, cancel, close)
47
+ * - **Utils**: Helper functions for duration, payment frequency, and account management
48
+ * - **Types**: TypeScript type definitions and interfaces
49
+ *
50
+ * @packageDocumentation
51
+ */
1
52
  // Export main SDK functions
2
53
  export * from "./contract";
3
54
  export * from "./rental";
4
55
  export * from "./utils";
5
- // Export account fetch functions that accept RPC URL strings
56
+ /**
57
+ * Account fetch functions that work with any RPC endpoint.
58
+ *
59
+ * These functions accept RPC URL strings and return account data,
60
+ * making it easy to fetch program state from any network.
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const contract = await fetchContractState(
65
+ * "https://api.mainnet-beta.solana.com",
66
+ * contractAddress
67
+ * );
68
+ * ```
69
+ */
6
70
  export { fetchContractState, fetchRentalState, fetchMultipleContractStates, fetchMultipleRentalStates } from "./utils/fetch-accounts";
7
- // Export PaymentFrequency from codama (generated from Rust)
71
+ /**
72
+ * Payment frequency enum generated from the Rust program.
73
+ *
74
+ * This enum mirrors the Rust PaymentFrequency type and provides
75
+ * type-safe payment frequency values for contract creation.
76
+ */
8
77
  export { PaymentFrequency } from "./codama/types/paymentFrequency";
9
- // Export auto-generated payment frequency types and utilities
78
+ /**
79
+ * Payment frequency types and validation utilities.
80
+ *
81
+ * These exports provide string-based payment frequency handling,
82
+ * validation functions, and mapping between different representations.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * if (isValidPaymentFrequency('daily')) {
87
+ * const frequency = getPaymentFrequencyFromString('daily');
88
+ * }
89
+ * ```
90
+ */
10
91
  export { VALID_PAYMENT_FREQUENCIES, PAYMENT_FREQUENCY_MAP, PAYMENT_FREQUENCY_CONSTANTS, getPaymentFrequencyFromString, isValidPaymentFrequency } from "./types/paymentFrequency";
11
- // Export payment frequency utilities that mirror Rust implementation
92
+ /**
93
+ * Payment frequency utilities that mirror the Rust program implementation.
94
+ *
95
+ * These functions provide conversion between payment frequencies and time durations,
96
+ * ensuring consistency with the on-chain program logic.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const seconds = paymentFrequencyStringToSeconds('weekly');
101
+ * validateDurationAlignment(duration, 'daily');
102
+ * ```
103
+ */
12
104
  export { paymentFrequencyToSeconds, paymentFrequencyStringToSeconds, validateDurationAlignment } from "./utils/paymentFrequency";
13
- // Export duration helper functions for convenient time unit conversion
14
- export { decaseconds, minutes, hours, days, weeks, months, duration } from "./utils/duration";
105
+ /**
106
+ * Duration helper functions for convenient time unit conversion.
107
+ *
108
+ * These functions make it easy to specify durations in human-readable terms
109
+ * and convert them to the seconds required by the program.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const rentalDuration = days(7); // 7 days in seconds
114
+ * const paymentPeriod = hours(6); // 6 hours in seconds
115
+ * const longRental = duration(2, 'weeks'); // 2 weeks in seconds
116
+ * ```
117
+ */
118
+ export { minutes, hours, days, weeks, months, duration } from "./utils/duration";
15
119
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CA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AC;AAElC;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACT,MAAM,kBAAkB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuwei-labs/srsly",
3
- "version": "2.0.0-beta.37",
3
+ "version": "2.0.0-beta.41",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -21,12 +21,12 @@
21
21
  "sdk"
22
22
  ],
23
23
  "scripts": {
24
- "package": "pnpm run clean && pnpm build && pnpm run package:cjs && pnpm run package:esm && pnpm run generate",
24
+ "build": "anchor run build && pnpm run package:cjs && pnpm run package:esm && pnpm run generate",
25
+ "build:clean": "pnpm run clean && pnpm run build",
25
26
  "package:cjs": "tsc -p tsconfig.cjs.json && tsconfig-to-dual-package tsconfig.cjs.json",
26
27
  "package:esm": "tsc -p tsconfig.esm.json && tsconfig-to-dual-package tsconfig.esm.json",
27
28
  "clean": "rm -rf dist && cargo clean && pnpm install",
28
29
  "generate": "node generate.mjs",
29
- "build": "anchor build && pnpm run generate",
30
30
  "docs": "typedoc",
31
31
  "test": "vitest run",
32
32
  "test:watch": "vitest",
@@ -36,7 +36,7 @@
36
36
  "license": "ISC",
37
37
  "packageManager": "pnpm@10.6.5",
38
38
  "dependencies": {
39
- "@solana/kit": "^2.0.0"
39
+ "@solana/kit": "^2.1.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@codama/nodes-from-anchor": "^1.1.13",