@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,7 +1,19 @@
1
1
  "use strict";
2
2
  /**
3
- * Unified contract creation - works with both @solana/kit and @solana/web3.js
4
- * Uses strings for all addresses to eliminate library-specific type complexity
3
+ * # Contract Creation Module
4
+ *
5
+ * This module provides functionality for creating rental contracts on the SRSLY program.
6
+ * It offers a unified API that works with both @solana/kit and @solana/web3.js libraries,
7
+ * using strings for all addresses to eliminate library-specific type complexity.
8
+ *
9
+ * ## Features
10
+ *
11
+ * - **Universal Compatibility**: Works with both major Solana libraries
12
+ * - **Fluent API**: Chainable configuration and format conversion
13
+ * - **Validation**: Built-in parameter validation and duration alignment checking
14
+ * - **Network Agnostic**: Supports mainnet, devnet, and custom configurations
15
+ *
16
+ * @module Contract/Create
5
17
  */
6
18
  Object.defineProperty(exports, "__esModule", { value: true });
7
19
  exports.createContract = createContract;
@@ -11,22 +23,39 @@ const paymentFrequency_1 = require("../utils/paymentFrequency");
11
23
  const paymentFrequency_2 = require("../types/paymentFrequency");
12
24
  const instruction_converter_1 = require("../utils/instruction-converter");
13
25
  /**
14
- * Internal function to create a rental contract instruction with configuration options
26
+ * Internal function to create a rental contract instruction with configuration options.
27
+ *
28
+ * This function handles the core logic of creating a contract instruction, including
29
+ * parameter validation, address resolution, and instruction generation. It's used
30
+ * internally by the public createContract function.
31
+ *
32
+ * @internal
33
+ * @param params - The contract creation parameters
34
+ * @param config - Optional configuration for network and program settings
35
+ * @returns Promise resolving to a fluent instruction object
36
+ * @throws Error when validation fails or required parameters are missing
15
37
  */
16
38
  async function _createContract(params, config) {
17
- const { owner, fleet, ownerProfile, rate, durationMax, paymentsFreq, ownerKeyIndex = 0, } = params;
39
+ const { owner, fleet, ownerProfile, rate, durationMin: customDurationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, } = params;
18
40
  // Validate payment frequency
19
41
  if (!(0, paymentFrequency_2.isValidPaymentFrequency)(paymentsFreq)) {
20
42
  throw new Error(`Invalid payment frequency: "${paymentsFreq}". Valid values are: ${JSON.stringify(Object.keys({ daily: true, weekly: true, monthly: true, hourly: true }))}`);
21
43
  }
22
- // Validate duration alignment
44
+ // Get the payment frequency interval
45
+ const paymentFrequencySeconds = (0, paymentFrequency_1.paymentFrequencyStringToSeconds)(paymentsFreq);
46
+ // Use custom durationMin if provided, otherwise default to 1 payment frequency period
47
+ const durationMin = customDurationMin ?? paymentFrequencySeconds;
48
+ // Validate duration alignment for both min and max
49
+ (0, paymentFrequency_1.validateDurationAlignment)(Number(durationMin), paymentsFreq);
23
50
  (0, paymentFrequency_1.validateDurationAlignment)(Number(durationMax), paymentsFreq);
24
- // Get the payment frequency interval (this will be the minimum duration)
25
- const durationMin = (0, paymentFrequency_1.paymentFrequencyStringToSeconds)(paymentsFreq);
51
+ // Validate that max is greater than or equal to min
52
+ if (durationMax < durationMin) {
53
+ throw new Error(`Maximum duration (${durationMax}s) must be greater than or equal to minimum duration (${durationMin}s)`);
54
+ }
26
55
  // Convert the payment frequency to the format expected by the Rust program (with @ prefix)
27
56
  const paymentsFreqWithPrefix = `@${paymentsFreq}`;
28
57
  // Get the resolved addresses from config (including network-specific addresses)
29
- const resolvedAddresses = (0, config_1.resolveProgramAddresses)(config || {});
58
+ const resolvedAddresses = await (0, config_1.resolveProgramAddresses)(config || {});
30
59
  const input = {
31
60
  owner, // Pass as-is (string or signer)
32
61
  fleet: (0, constants_1.toAddress)(fleet), // Convert fleet to Address
@@ -50,23 +79,59 @@ async function _createContract(params, config) {
50
79
  }
51
80
  /**
52
81
  * Creates an instruction to create a rental contract with fluent configuration.
53
- * This unified version works with both @solana/kit and @solana/web3.js using strings for addresses.
82
+ *
83
+ * This is the main function for creating rental contracts on the SRSLY program.
84
+ * It provides a unified API that works with both @solana/kit and @solana/web3.js
85
+ * libraries, using strings for all addresses to eliminate compatibility issues.
86
+ *
87
+ * ## Features
88
+ *
89
+ * - **Universal Library Support**: Works with both @solana/kit and @solana/web3.js
90
+ * - **Fluent Configuration**: Chain configuration options with `.set()`
91
+ * - **Format Conversion**: Convert between library formats with `.web3js()`
92
+ * - **Validation**: Built-in parameter validation and duration alignment
93
+ * - **Network Support**: Configurable for different Solana networks
94
+ *
95
+ * ## Validation
96
+ *
97
+ * The function automatically validates:
98
+ * - Payment frequency is supported
99
+ * - Duration alignment with payment frequency
100
+ * - Required parameters are provided
101
+ *
102
+ * ## Process
103
+ *
104
+ * 1. **Validate Parameters**: Checks payment frequency and duration alignment
105
+ * 2. **Resolve Addresses**: Gets network-specific program and mint addresses
106
+ * 3. **Generate Instruction**: Creates the contract creation instruction
107
+ * 4. **Return Fluent Object**: Allows for configuration and format conversion
54
108
  *
55
109
  * @example
56
110
  * ```typescript
57
- * // Works with any library - just use strings for addresses!
111
+ * import { createContract, days, hours } from '@srsly/sdk';
58
112
  *
59
- * // Default returns @solana/kit format
60
- * const kitInstruction = await createContract({
113
+ * // Basic usage - returns @solana/kit format by default
114
+ * const instruction = await createContract({
61
115
  * owner: wallet, // Can be signer object or string
62
116
  * fleet: "FleetAddress123...", // String address
63
117
  * ownerProfile: "ProfileAddr...", // String address
64
- * rate: 1000,
65
- * durationMax: days(7),
66
- * paymentsFreq: 'daily'
118
+ * rate: 1000, // 1000 ATLAS per payment period
119
+ * durationMax: days(7), // 7 days maximum rental
120
+ * paymentsFreq: 'daily' // Daily payments
121
+ * });
122
+ *
123
+ * // With custom minimum duration
124
+ * const customMinInstruction = await createContract({
125
+ * owner: wallet,
126
+ * fleet: "FleetAddress123...",
127
+ * ownerProfile: "ProfileAddr...",
128
+ * rate: 100, // 100 ATLAS per hour
129
+ * durationMin: hours(10), // 10 hours minimum rental
130
+ * durationMax: hours(24), // 24 hours maximum rental
131
+ * paymentsFreq: 'hourly' // Hourly payments
67
132
  * });
68
133
  *
69
- * // Convert to @solana/web3.js format using fluent interface
134
+ * // Convert to @solana/web3.js format
70
135
  * const web3jsInstruction = await createContract({
71
136
  * owner: wallet,
72
137
  * fleet: "FleetAddress123...",
@@ -76,8 +141,8 @@ async function _createContract(params, config) {
76
141
  * paymentsFreq: 'daily'
77
142
  * }).web3js();
78
143
  *
79
- * // Chain configuration and format conversion
80
- * const web3jsInstructionWithConfig = await createContract({
144
+ * // Configure network and convert format
145
+ * const mainnetInstruction = await createContract({
81
146
  * owner: wallet,
82
147
  * fleet: "FleetAddress123...",
83
148
  * ownerProfile: "ProfileAddr...",
@@ -88,13 +153,15 @@ async function _createContract(params, config) {
88
153
  *
89
154
  * // Use with your preferred Solana library
90
155
  * const transaction = new Transaction().add(web3jsInstruction);
156
+ * await sendAndConfirmTransaction(connection, transaction, [wallet]);
91
157
  * ```
92
158
  *
93
- * @param params The simplified parameters for creating a rental contract
94
- * @returns A ConfigSelector that can be configured with .set() or awaited directly
159
+ * @param params - The contract creation parameters including owner, fleet, rate, and duration
160
+ * @returns A FluentConfigSelector that can be configured with .set() or awaited directly
161
+ * @throws Error when payment frequency is invalid or duration alignment fails
95
162
  */
96
163
  function createContract(params) {
97
164
  const baseSelector = (0, config_1.createConfigSelector)((config) => _createContract(params, config));
98
- return (0, instruction_converter_1.createFluentConfigSelector)(baseSelector);
165
+ return (0, instruction_converter_1.createSmartFluentConfigSelector)(baseSelector);
99
166
  }
100
167
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA6HH,wCAGC;AA9HD,4CAA+G;AAC/G,kDAA+C;AAC/C,gEAAuG;AACvG,gEAA4F;AAC5F,0EAAwJ;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,aAAa,GAAG,CAAC,GAClB,GAAG,MAAM,CAAC;IAEX,6BAA6B;IAC7B,IAAI,CAAC,IAAA,0CAAuB,EAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KA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jE,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,IAAA,+CAAuB,EAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,SAAgB,cAAc,CAAC,MAA4B;IACzD,MAAM,YAAY,GAAG,IAAA,6BAAoB,EAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvF,OAAO,IAAA,uDAA+B,EAAC,YAAY,CAAC,CAAC;AACvD,CAAC"}
@@ -1,4 +1,49 @@
1
1
  "use strict";
2
+ /**
3
+ * # Contract Management Module
4
+ *
5
+ * This module provides comprehensive functionality for managing rental contracts
6
+ * on the SRSLY program. It includes functions for creating and closing contracts,
7
+ * with full support for both @solana/kit and @solana/web3.js libraries.
8
+ *
9
+ * ## Available Functions
10
+ *
11
+ * - **createContract**: Create a new rental contract for a fleet
12
+ * - **closeContract**: Permanently close an existing rental contract
13
+ *
14
+ * ## Features
15
+ *
16
+ * - **Universal Library Support**: Works with both major Solana libraries
17
+ * - **String-Based Addresses**: Eliminates library-specific type conflicts
18
+ * - **Fluent API**: Chainable configuration and format conversion
19
+ * - **Network Agnostic**: Supports different Solana networks
20
+ * - **Validation**: Built-in parameter validation and error checking
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { createContract, closeContract, days } from '@srsly/sdk';
25
+ *
26
+ * // Create a rental contract
27
+ * const createInstruction = await createContract({
28
+ * owner: wallet,
29
+ * fleet: "FleetAddress123...",
30
+ * ownerProfile: "ProfileAddr...",
31
+ * rate: 1000,
32
+ * durationMax: days(30),
33
+ * paymentsFreq: 'daily'
34
+ * });
35
+ *
36
+ * // Close the contract later
37
+ * const closeInstruction = await closeContract({
38
+ * owner: wallet,
39
+ * fleet: "FleetAddress123...",
40
+ * contract: "ContractAddr...",
41
+ * faction: 'mud'
42
+ * });
43
+ * ```
44
+ *
45
+ * @module Contract
46
+ */
2
47
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
48
  if (k2 === undefined) k2 = k;
4
49
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,2CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;;;;;;;;;;;;;;;;AAEH,0CAAuB;AACvB,2CAAwB"}
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,55 @@
1
1
  "use strict";
2
+ /**
3
+ * # SRSLY SDK - Solana Rental System Library
4
+ *
5
+ * A comprehensive TypeScript SDK for interacting with the SRSLY Solana program,
6
+ * which facilitates fleet rentals in the Star Atlas ecosystem. This SDK provides
7
+ * a fluent, developer-friendly interface that works with both @solana/kit and
8
+ * @solana/web3.js libraries.
9
+ *
10
+ * ## Features
11
+ *
12
+ * - **Universal Compatibility**: Works with both @solana/kit and @solana/web3.js
13
+ * - **Fluent API**: Chainable methods for intuitive development experience
14
+ * - **String-Based Addresses**: Uses strings for all addresses to eliminate library conflicts
15
+ * - **Network Agnostic**: Supports mainnet, devnet, and custom RPC endpoints
16
+ * - **Type Safety**: Full TypeScript support with comprehensive type definitions
17
+ * - **Auto-Generated Types**: Types generated from Solana program IDL for accuracy
18
+ *
19
+ * ## Quick Start
20
+ *
21
+ * ```typescript
22
+ * import { createContract, acceptRental, days } from '@srsly/sdk';
23
+ *
24
+ * // Create a rental contract
25
+ * const instruction = await createContract({
26
+ * owner: wallet,
27
+ * fleet: "FleetAddress123...",
28
+ * ownerProfile: "ProfileAddr...",
29
+ * rate: 1000,
30
+ * durationMax: days(7),
31
+ * paymentsFreq: 'daily'
32
+ * });
33
+ *
34
+ * // Accept a rental
35
+ * const rentalInstruction = await acceptRental({
36
+ * borrower: borrowerWallet,
37
+ * contract: contractAddress,
38
+ * amount: 7000,
39
+ * duration: days(7)
40
+ * });
41
+ * ```
42
+ *
43
+ * ## Architecture
44
+ *
45
+ * The SDK is organized into several main modules:
46
+ * - **Contract**: Functions for creating and managing rental contracts
47
+ * - **Rental**: Functions for rental operations (accept, cancel, close)
48
+ * - **Utils**: Helper functions for duration, payment frequency, and account management
49
+ * - **Types**: TypeScript type definitions and interfaces
50
+ *
51
+ * @packageDocumentation
52
+ */
2
53
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
54
  if (k2 === undefined) k2 = k;
4
55
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -14,35 +65,87 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
65
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
66
  };
16
67
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.duration = exports.months = exports.weeks = exports.days = exports.hours = exports.minutes = exports.decaseconds = exports.validateDurationAlignment = exports.paymentFrequencyStringToSeconds = exports.paymentFrequencyToSeconds = exports.isValidPaymentFrequency = exports.getPaymentFrequencyFromString = exports.PAYMENT_FREQUENCY_CONSTANTS = exports.PAYMENT_FREQUENCY_MAP = exports.VALID_PAYMENT_FREQUENCIES = exports.PaymentFrequency = exports.fetchMultipleRentalStates = exports.fetchMultipleContractStates = exports.fetchRentalState = exports.fetchContractState = void 0;
68
+ exports.duration = exports.months = exports.weeks = exports.days = exports.hours = exports.minutes = exports.validateDurationAlignment = exports.paymentFrequencyStringToSeconds = exports.paymentFrequencyToSeconds = exports.isValidPaymentFrequency = exports.getPaymentFrequencyFromString = exports.PAYMENT_FREQUENCY_CONSTANTS = exports.PAYMENT_FREQUENCY_MAP = exports.VALID_PAYMENT_FREQUENCIES = exports.PaymentFrequency = exports.fetchMultipleRentalStates = exports.fetchMultipleContractStates = exports.fetchRentalState = exports.fetchContractState = void 0;
18
69
  // Export main SDK functions
19
70
  __exportStar(require("./contract"), exports);
20
71
  __exportStar(require("./rental"), exports);
21
72
  __exportStar(require("./utils"), exports);
22
- // Export account fetch functions that accept RPC URL strings
73
+ /**
74
+ * Account fetch functions that work with any RPC endpoint.
75
+ *
76
+ * These functions accept RPC URL strings and return account data,
77
+ * making it easy to fetch program state from any network.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const contract = await fetchContractState(
82
+ * "https://api.mainnet-beta.solana.com",
83
+ * contractAddress
84
+ * );
85
+ * ```
86
+ */
23
87
  var fetch_accounts_1 = require("./utils/fetch-accounts");
24
88
  Object.defineProperty(exports, "fetchContractState", { enumerable: true, get: function () { return fetch_accounts_1.fetchContractState; } });
25
89
  Object.defineProperty(exports, "fetchRentalState", { enumerable: true, get: function () { return fetch_accounts_1.fetchRentalState; } });
26
90
  Object.defineProperty(exports, "fetchMultipleContractStates", { enumerable: true, get: function () { return fetch_accounts_1.fetchMultipleContractStates; } });
27
91
  Object.defineProperty(exports, "fetchMultipleRentalStates", { enumerable: true, get: function () { return fetch_accounts_1.fetchMultipleRentalStates; } });
28
- // Export PaymentFrequency from codama (generated from Rust)
92
+ /**
93
+ * Payment frequency enum generated from the Rust program.
94
+ *
95
+ * This enum mirrors the Rust PaymentFrequency type and provides
96
+ * type-safe payment frequency values for contract creation.
97
+ */
29
98
  var paymentFrequency_1 = require("./codama/types/paymentFrequency");
30
99
  Object.defineProperty(exports, "PaymentFrequency", { enumerable: true, get: function () { return paymentFrequency_1.PaymentFrequency; } });
31
- // Export auto-generated payment frequency types and utilities
100
+ /**
101
+ * Payment frequency types and validation utilities.
102
+ *
103
+ * These exports provide string-based payment frequency handling,
104
+ * validation functions, and mapping between different representations.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * if (isValidPaymentFrequency('daily')) {
109
+ * const frequency = getPaymentFrequencyFromString('daily');
110
+ * }
111
+ * ```
112
+ */
32
113
  var paymentFrequency_2 = require("./types/paymentFrequency");
33
114
  Object.defineProperty(exports, "VALID_PAYMENT_FREQUENCIES", { enumerable: true, get: function () { return paymentFrequency_2.VALID_PAYMENT_FREQUENCIES; } });
34
115
  Object.defineProperty(exports, "PAYMENT_FREQUENCY_MAP", { enumerable: true, get: function () { return paymentFrequency_2.PAYMENT_FREQUENCY_MAP; } });
35
116
  Object.defineProperty(exports, "PAYMENT_FREQUENCY_CONSTANTS", { enumerable: true, get: function () { return paymentFrequency_2.PAYMENT_FREQUENCY_CONSTANTS; } });
36
117
  Object.defineProperty(exports, "getPaymentFrequencyFromString", { enumerable: true, get: function () { return paymentFrequency_2.getPaymentFrequencyFromString; } });
37
118
  Object.defineProperty(exports, "isValidPaymentFrequency", { enumerable: true, get: function () { return paymentFrequency_2.isValidPaymentFrequency; } });
38
- // Export payment frequency utilities that mirror Rust implementation
119
+ /**
120
+ * Payment frequency utilities that mirror the Rust program implementation.
121
+ *
122
+ * These functions provide conversion between payment frequencies and time durations,
123
+ * ensuring consistency with the on-chain program logic.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const seconds = paymentFrequencyStringToSeconds('weekly');
128
+ * validateDurationAlignment(duration, 'daily');
129
+ * ```
130
+ */
39
131
  var paymentFrequency_3 = require("./utils/paymentFrequency");
40
132
  Object.defineProperty(exports, "paymentFrequencyToSeconds", { enumerable: true, get: function () { return paymentFrequency_3.paymentFrequencyToSeconds; } });
41
133
  Object.defineProperty(exports, "paymentFrequencyStringToSeconds", { enumerable: true, get: function () { return paymentFrequency_3.paymentFrequencyStringToSeconds; } });
42
134
  Object.defineProperty(exports, "validateDurationAlignment", { enumerable: true, get: function () { return paymentFrequency_3.validateDurationAlignment; } });
43
- // Export duration helper functions for convenient time unit conversion
135
+ /**
136
+ * Duration helper functions for convenient time unit conversion.
137
+ *
138
+ * These functions make it easy to specify durations in human-readable terms
139
+ * and convert them to the seconds required by the program.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const rentalDuration = days(7); // 7 days in seconds
144
+ * const paymentPeriod = hours(6); // 6 hours in seconds
145
+ * const longRental = duration(2, 'weeks'); // 2 weeks in seconds
146
+ * ```
147
+ */
44
148
  var duration_1 = require("./utils/duration");
45
- Object.defineProperty(exports, "decaseconds", { enumerable: true, get: function () { return duration_1.decaseconds; } });
46
149
  Object.defineProperty(exports, "minutes", { enumerable: true, get: function () { return duration_1.minutes; } });
47
150
  Object.defineProperty(exports, "hours", { enumerable: true, get: function () { return duration_1.hours; } });
48
151
  Object.defineProperty(exports, "days", { enumerable: true, get: function () { return duration_1.days; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AAsBxB,6DAA6D;AAC7D,yDAKgC;AAJ9B,oHAAA,kBAAkB,OAAA;AAClB,kHAAA,gBAAgB,OAAA;AAChB,6HAAA,2BAA2B,OAAA;AAC3B,2HAAA,yBAAyB,OAAA;AAG3B,4DAA4D;AAC5D,oEAAmE;AAA1D,oHAAA,gBAAgB,OAAA;AAEzB,8DAA8D;AAC9D,6DAOkC;AALhC,6HAAA,yBAAyB,OAAA;AACzB,yHAAA,qBAAqB,OAAA;AACrB,+HAAA,2BAA2B,OAAA;AAC3B,iIAAA,6BAA6B,OAAA;AAC7B,2HAAA,uBAAuB,OAAA;AAGzB,qEAAqE;AACrE,6DAIkC;AAHhC,6HAAA,yBAAyB,OAAA;AACzB,mIAAA,+BAA+B,OAAA;AAC/B,6HAAA,yBAAyB,OAAA;AAG3B,uEAAuE;AACvE,6CAQ0B;AAPxB,uGAAA,WAAW,OAAA;AACX,mGAAA,OAAO,OAAA;AACP,iGAAA,KAAK,OAAA;AACL,gGAAA,IAAI,OAAA;AACJ,iGAAA,KAAK,OAAA;AACL,kGAAA,MAAM,OAAA;AACN,oGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;;;;;;;;;;;;;;;AAEH,4BAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AAyBxB;;;;;;;;;;;;;GAaG;AACH,yDAKgC;AAJ9B,oHAAA,kBAAkB,OAAA;AAClB,kHAAA,gBAAgB,OAAA;AAChB,6HAAA,2BAA2B,OAAA;AAC3B,2HAAA,yBAAyB,OAAA;AAG3B;;;;;GAKG;AACH,oEAAmE;AAA1D,oHAAA,gBAAgB,OAAA;AAEzB;;;;;;;;;;;;GAYG;AACH,6DAOkC;AALhC,6HAAA,yBAAyB,OAAA;AACzB,yHAAA,qBAAqB,OAAA;AACrB,+HAAA,2BAA2B,OAAA;AAC3B,iIAAA,6BAA6B,OAAA;AAC7B,2HAAA,uBAAuB,OAAA;AAGzB;;;;;;;;;;;GAWG;AACH,6DAIkC;AAHhC,6HAAA,yBAAyB,OAAA;AACzB,mIAAA,+BAA+B,OAAA;AAC/B,6HAAA,yBAAyB,OAAA;AAG3B;;;;;;;;;;;;GAYG;AACH,6CAO0B;AANxB,mGAAA,OAAO,OAAA;AACP,iGAAA,KAAK,OAAA;AACL,gGAAA,IAAI,OAAA;AACJ,iGAAA,KAAK,OAAA;AACL,kGAAA,MAAM,OAAA;AACN,oGAAA,QAAQ,OAAA"}
@@ -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",