@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,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.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
@@ -1,10 +1,120 @@
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 * from "./contract";
2
53
  export * from "./rental";
3
54
  export * from "./utils";
55
+ export type { KitInstruction, FluentInstruction } from "./utils/instruction-converter";
4
56
  export type { ContractState, RentalState, CreateContractInstruction, AcceptRentalInstruction, CancelRentalInstruction, CloseRentalInstruction, CloseContractInstruction, ResetRentalInstruction, ClockData, ThreadResponse } from "./codama";
57
+ /**
58
+ * Account fetch functions that work with any RPC endpoint.
59
+ *
60
+ * These functions accept RPC URL strings and return account data,
61
+ * making it easy to fetch program state from any network.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const contract = await fetchContractState(
66
+ * "https://api.mainnet-beta.solana.com",
67
+ * contractAddress
68
+ * );
69
+ * ```
70
+ */
5
71
  export { fetchContractState, fetchRentalState, fetchMultipleContractStates, fetchMultipleRentalStates } from "./utils/fetch-accounts";
72
+ /**
73
+ * Payment frequency enum generated from the Rust program.
74
+ *
75
+ * This enum mirrors the Rust PaymentFrequency type and provides
76
+ * type-safe payment frequency values for contract creation.
77
+ */
6
78
  export { PaymentFrequency } from "./codama/types/paymentFrequency";
79
+ /**
80
+ * Payment frequency types and validation utilities.
81
+ *
82
+ * These exports provide string-based payment frequency handling,
83
+ * validation functions, and mapping between different representations.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * if (isValidPaymentFrequency('daily')) {
88
+ * const frequency = getPaymentFrequencyFromString('daily');
89
+ * }
90
+ * ```
91
+ */
7
92
  export { PaymentFrequencyString, VALID_PAYMENT_FREQUENCIES, PAYMENT_FREQUENCY_MAP, PAYMENT_FREQUENCY_CONSTANTS, getPaymentFrequencyFromString, isValidPaymentFrequency } from "./types/paymentFrequency";
93
+ /**
94
+ * Payment frequency utilities that mirror the Rust program implementation.
95
+ *
96
+ * These functions provide conversion between payment frequencies and time durations,
97
+ * ensuring consistency with the on-chain program logic.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const seconds = paymentFrequencyStringToSeconds('weekly');
102
+ * validateDurationAlignment(duration, 'daily');
103
+ * ```
104
+ */
8
105
  export { paymentFrequencyToSeconds, paymentFrequencyStringToSeconds, validateDurationAlignment } from "./utils/paymentFrequency";
9
- export { decaseconds, minutes, hours, days, weeks, months, duration } from "./utils/duration";
106
+ /**
107
+ * Duration helper functions for convenient time unit conversion.
108
+ *
109
+ * These functions make it easy to specify durations in human-readable terms
110
+ * and convert them to the seconds required by the program.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const rentalDuration = days(7); // 7 days in seconds
115
+ * const paymentPeriod = hours(6); // 6 hours in seconds
116
+ * const longRental = duration(2, 'weeks'); // 2 weeks in seconds
117
+ * ```
118
+ */
119
+ export { minutes, hours, days, weeks, months, duration } from "./utils/duration";
10
120
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAIxB,YAAY,EAEV,aAAa,EACb,WAAW,EAGX,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EAGtB,SAAS,EACT,cAAc,EACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGnE,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,WAAW,EACX,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACT,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAGxB,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAIvF,YAAY,EAEV,aAAa,EACb,WAAW,EAGX,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EAGtB,SAAS,EACT,cAAc,EACf,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACT,MAAM,kBAAkB,CAAC"}
@@ -1,91 +1,162 @@
1
1
  import { type ConfigSelector } from '../utils/config';
2
- import { type FluentInstruction, type FluentConfigSelector } from '../utils/instruction-converter';
2
+ import { type FluentInstruction, type SmartFluentConfigSelector } from '../utils/instruction-converter';
3
3
  type UniversalAddress = string;
4
4
  type UniversalSigner = any;
5
5
  /**
6
- * Simplified parameters for accepting a rental - strings only!
6
+ * Parameters for accepting a rental contract.
7
+ *
8
+ * This interface defines the required parameters for a borrower to accept an existing
9
+ * rental contract. The SDK automatically fetches contract details and calculates the
10
+ * required payment amount based on the contract's rate and payment frequency.
11
+ *
12
+ * @interface AcceptRentalParams
7
13
  */
8
14
  export interface AcceptRentalParams {
9
15
  /**
10
- * The borrower wallet that will sign the transaction (can be signer or string)
16
+ * The borrower who will rent the fleet (must be a signer object).
17
+ * This account will control the fleet during the rental period and make payments.
11
18
  */
12
- borrower: UniversalSigner | UniversalAddress;
19
+ borrower: UniversalSigner;
13
20
  /**
14
- * The borrower's profile account address
21
+ * String address of the borrower's profile in the Star Atlas game.
22
+ * Used for SAGE integration to transfer fleet control to the borrower.
15
23
  */
16
24
  borrowerProfile: UniversalAddress;
17
25
  /**
18
- * The borrower's faction (1 = mud, 2 = oni, 3 = ustur)
19
- * Or as string: 'mud', 'oni', 'ustur'
26
+ * Faction identifier for the borrower in Star Atlas.
27
+ * Can be provided as a number (1 = MUD, 2 = ONI, 3 = Ustur) or string ('mud', 'oni', 'ustur').
28
+ * Used for deriving faction-specific game accounts required by SAGE.
29
+ * @example 'mud' // or 1
20
30
  */
21
31
  borrowerFaction: number | string;
22
32
  /**
23
- * The fleet account address that will be rented
24
- */
25
- fleet: UniversalAddress;
26
- /**
27
- * The rental contract account address
33
+ * String address of the rental contract to accept.
34
+ * The SDK will automatically fetch the contract state to retrieve:
35
+ * - Fleet address and ownership details
36
+ * - Rental rate per payment period
37
+ * - Payment frequency (hourly, daily, weekly, monthly)
38
+ * - Duration constraints (minimum and maximum)
39
+ * - Owner information for payment routing
28
40
  */
29
41
  contract: UniversalAddress;
30
42
  /**
31
- * The rental rate (in ATLAS tokens)
32
- */
33
- rate: number | bigint;
34
- /**
35
- * The rental duration (in seconds)
43
+ * Rental duration in seconds.
44
+ * Must be within the contract's minimum and maximum duration limits.
45
+ * Must also be a multiple of the payment frequency interval.
46
+ * @example 604800 // 7 days in seconds
36
47
  */
37
48
  duration: number | bigint;
38
- /**
39
- * Optional referral token account address
40
- * If provided, referrer will receive 5% of the platform fees
41
- */
42
- referralTokenAccount?: UniversalAddress;
43
49
  }
44
50
  /**
45
- * Creates an instruction to accept a rental with fluent configuration.
51
+ * Creates an instruction to accept a rental contract with fluent configuration.
52
+ *
53
+ * This function allows a borrower to accept an existing rental contract, automatically
54
+ * calculating the required payment amount based on the contract's rate and payment frequency.
55
+ * The SDK fetches contract details, validates duration constraints, and derives all
56
+ * necessary accounts for the rental operation.
57
+ *
58
+ * ## Features
59
+ *
60
+ * - **Automatic Payment Calculation**: Fetches contract state and calculates exact payment amount
61
+ * - **Duration Validation**: Ensures rental duration meets contract constraints
62
+ * - **Account Derivation**: Automatically derives all required game accounts
63
+ * - **SAGE Integration**: Sets up fleet ownership transfer in the Star Atlas ecosystem
64
+ * - **Clockwork Integration**: Configures automated payment scheduling
65
+ * - **Universal Library Support**: Works with both @solana/kit and @solana/web3.js
66
+ *
67
+ * ## Process
68
+ *
69
+ * 1. **Fetch Contract**: Retrieves contract state from the blockchain
70
+ * 2. **Validate Duration**: Checks that rental duration meets contract constraints
71
+ * 3. **Calculate Payment**: Computes payment amount using contract rate and payment frequency
72
+ * 4. **Derive Accounts**: Generates required game accounts (starbase, faction, etc.)
73
+ * 5. **Create Instruction**: Builds the rental acceptance instruction
74
+ * 6. **Setup Threading**: Configures automated payment processing
75
+ *
76
+ * ## Payment Calculation
77
+ *
78
+ * The payment amount is calculated using the formula:
79
+ * ```text
80
+ * payment = rate × payment_periods × stardust_to_atlas_conversion
81
+ * ```
82
+ *
83
+ * Where:
84
+ * - `rate`: Contract's rental rate per payment period
85
+ * - `payment_periods`: Duration divided by payment frequency interval
86
+ * - `stardust_to_atlas_conversion`: Network-specific conversion factor
87
+ *
88
+ * ## Requirements
89
+ *
90
+ * - Contract must exist and be active
91
+ * - Duration must be within contract's min/max limits
92
+ * - Duration must be multiple of payment frequency
93
+ * - Borrower must have sufficient ATLAS tokens for payment
46
94
  *
47
95
  * @example
48
96
  * ```typescript
49
- * // Works with any library - just use strings for addresses!
97
+ * import { acceptRental, days } from '@srsly/sdk';
98
+ *
99
+ * // Basic rental acceptance
50
100
  * const instruction = await acceptRental({
51
- * borrower: wallet, // Can be signer object or string
52
- * borrowerProfile: "ProfileAddr...", // String address
53
- * borrowerFaction: 1, // 1 = mud, 2 = oni, 3 = ustur
54
- * fleet: "FleetAddress123...", // String address
55
- * contract: "ContractAddr...", // String address
56
- * rate: 1000, // ATLAS tokens
57
- * duration: 86400 // 1 day in seconds (total: 1000 * 86400 * 100M stardust)
101
+ * borrower: wallet, // Borrower's wallet
102
+ * borrowerProfile: "ProfileAddr...", // Borrower's Star Atlas profile
103
+ * borrowerFaction: 'mud', // Faction: 'mud', 'oni', or 'ustur'
104
+ * contract: "ContractAddr...", // Contract to accept
105
+ * duration: days(7) // 7 days rental duration
58
106
  * });
59
107
  *
60
- * // With referral (referrer gets 5% of platform fees)
61
- * const instruction = await acceptRental({
108
+ * // Configure for mainnet
109
+ * const mainnetInstruction = await acceptRental({
62
110
  * borrower: wallet,
63
111
  * borrowerProfile: "ProfileAddr...",
64
- * borrowerFaction: 1,
65
- * fleet: "FleetAddress123...",
112
+ * borrowerFaction: 1, // Can use numbers: 1=mud, 2=oni, 3=ustur
66
113
  * contract: "ContractAddr...",
67
- * rate: 1000,
68
- * duration: 86400,
69
- * referralTokenAccount: "ReferralAddr..."
70
- * });
114
+ * duration: days(7)
115
+ * }).set({ programs: 'mainnet' });
71
116
  *
72
- * // Use mainnet configuration
73
- * const instruction = await acceptRental(params).set({ programs: 'mainnet' });
74
- *
75
- * // Override specific constants
76
- * const instruction = await acceptRental(params).set({
117
+ * // Override specific game configuration
118
+ * const customInstruction = await acceptRental({
119
+ * borrower: wallet,
120
+ * borrowerProfile: "ProfileAddr...",
121
+ * borrowerFaction: 'mud',
122
+ * contract: "ContractAddr...",
123
+ * duration: days(7)
124
+ * }).set({
77
125
  * programs: 'mainnet',
78
- * gameId: 'custom-game-id...' // gameId configured via .set()
126
+ * gameId: 'custom-game-id...'
79
127
  * });
80
128
  *
81
- * // Use the instruction with your preferred Solana library
82
- * // instruction is compatible with both @solana/kit and @solana/web3.js
129
+ * // Convert to @solana/web3.js format
130
+ * const web3jsInstruction = await acceptRental({
131
+ * borrower: wallet,
132
+ * borrowerProfile: "ProfileAddr...",
133
+ * borrowerFaction: 'mud',
134
+ * contract: "ContractAddr...",
135
+ * duration: days(7)
136
+ * }).web3js();
137
+ *
138
+ * // Use with your preferred Solana library
139
+ * const transaction = new Transaction().add(web3jsInstruction);
140
+ * await sendAndConfirmTransaction(connection, transaction, [wallet]);
83
141
  * ```
84
142
  *
85
- * @param params The simplified parameters for accepting a rental
86
- * @returns A ConfigSelector that can be configured with .set() or awaited directly
143
+ * @param params - The rental acceptance parameters including borrower, contract, and duration
144
+ * @returns A FluentConfigSelector that can be configured with .set() or awaited directly
145
+ * @throws Error when contract is not found, duration constraints are violated, or payment calculation fails
146
+ */
147
+ export declare function acceptRental(params: AcceptRentalParams): SmartFluentConfigSelector<FluentInstruction>;
148
+ /**
149
+ * Low-level function to create a rental acceptance instruction with raw input parameters.
150
+ *
151
+ * This function provides direct access to the underlying codama-generated instruction
152
+ * builder. It's primarily used internally by the SDK but can be used for advanced
153
+ * use cases where full control over instruction parameters is needed.
154
+ *
155
+ * @internal
156
+ * @param input - Raw instruction input parameters as expected by codama
157
+ * @param options - Optional instruction options including program address
158
+ * @returns A ConfigSelector for the raw instruction
87
159
  */
88
- export declare function acceptRental(params: AcceptRentalParams): FluentConfigSelector<FluentInstruction>;
89
160
  export declare function getAcceptRentalInstructionAsync(input: any, options?: any): ConfigSelector<any>;
90
161
  export {};
91
162
  //# sourceMappingURL=accept.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accept.d.ts","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4D,KAAK,cAAc,EAAsB,MAAM,iBAAiB,CAAC;AAGpI,OAAO,EAAuD,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,g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EAAE,gBAAgB,CAAC;IAElC;;;;;OAKG;IACH,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;IAEjC;;;;;;;;OAQG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAE3B;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAuID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,kBAAkB,GACzB,yBAAyB,CAAC,iBAAiB,CAAC,CAG9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAK9F"}
@@ -3,45 +3,109 @@ type UniversalAddress = string;
3
3
  type UniversalSigner = any;
4
4
  type CancelRentalInstruction = any;
5
5
  /**
6
- * Simplified parameters for canceling a rental - strings only!
6
+ * Parameters for canceling an active rental.
7
+ *
8
+ * This interface defines the required parameters for a borrower to cancel their
9
+ * active rental. Canceling a rental stops automated payments but typically
10
+ * incurs a penalty fee as defined in the contract terms.
11
+ *
12
+ * @interface CancelRentalParams
7
13
  */
8
14
  export interface CancelRentalParams {
9
15
  /**
10
- * The borrower wallet that will sign the transaction (can be signer or string)
16
+ * The borrower who wants to cancel the rental (must be a signer object).
17
+ * Must be the original borrower who accepted the rental contract.
18
+ * This account will pay any cancellation penalties.
11
19
  */
12
- borrower: UniversalSigner | UniversalAddress;
20
+ borrower: UniversalSigner;
13
21
  /**
14
- * The rental contract account address
22
+ * String address of the rental contract associated with the active rental.
23
+ * The rental state for this contract will be canceled and automated payments stopped.
15
24
  */
16
25
  contract: UniversalAddress;
17
26
  }
18
27
  /**
19
28
  * Creates an instruction to cancel a rental with fluent configuration.
20
29
  *
30
+ * This function allows a borrower to cancel their active rental before the
31
+ * rental period expires. Canceling a rental stops automated payments but
32
+ * may incur penalty fees as defined in the contract terms. The fleet ownership
33
+ * is immediately returned to the original owner.
34
+ *
35
+ * ## Features
36
+ *
37
+ * - **Immediate Cancellation**: Stops the rental and automated payments immediately
38
+ * - **Fleet Transfer**: Returns fleet control to the original owner
39
+ * - **Thread Cleanup**: Cancels the automated payment thread
40
+ * - **Penalty Processing**: Handles any cancellation fees as defined in the contract
41
+ * - **Universal Library Support**: Works with both @solana/kit and @solana/web3.js
42
+ *
43
+ * ## Process
44
+ *
45
+ * 1. **Validate Authority**: Ensures only the borrower can cancel their rental
46
+ * 2. **Calculate Penalties**: Computes any cancellation fees owed
47
+ * 3. **Transfer Fleet**: Returns fleet ownership to the original owner
48
+ * 4. **Cancel Thread**: Stops automated payment processing
49
+ * 5. **Update State**: Marks rental as canceled in the rental state account
50
+ *
51
+ * ## Requirements
52
+ *
53
+ * - Rental must be active (not already canceled or completed)
54
+ * - Caller must be the original borrower
55
+ * - Borrower must have sufficient funds for any cancellation penalties
56
+ *
57
+ * ## Cancellation Effects
58
+ *
59
+ * - **Fleet Control**: Immediately returned to owner
60
+ * - **Automated Payments**: Stopped permanently
61
+ * - **Rental State**: Marked as canceled
62
+ * - **Thread Account**: Cleaned up and closed
63
+ * - **Penalties**: Charged according to contract terms
64
+ *
21
65
  * @example
22
66
  * ```typescript
23
- * // Works with any library - just use strings for addresses!
67
+ * import { cancelRental } from '@srsly/sdk';
68
+ *
69
+ * // Basic rental cancellation
24
70
  * const instruction = await cancelRental({
25
- * borrower: wallet, // Can be signer object or string
26
- * contract: "ContractAddr..." // String address
71
+ * borrower: wallet, // Borrower's wallet (must be original borrower)
72
+ * contract: "ContractAddr..." // Contract address for the active rental
27
73
  * });
28
74
  *
29
- * // Use mainnet configuration
30
- * const instruction = await cancelRental(params).set({ programs: 'mainnet' });
75
+ * // Configure for mainnet
76
+ * const mainnetInstruction = await cancelRental({
77
+ * borrower: wallet,
78
+ * contract: "ContractAddr..."
79
+ * }).set({ programs: 'mainnet' });
31
80
  *
32
- * // Override specific constants
33
- * const instruction = await cancelRental(params).set({
34
- * programs: 'mainnet'
35
- * });
81
+ * // Convert to @solana/web3.js format
82
+ * const web3jsInstruction = await cancelRental({
83
+ * borrower: wallet,
84
+ * contract: "ContractAddr..."
85
+ * }).web3js();
36
86
  *
37
- * // Use the instruction with your preferred Solana library
38
- * // instruction is compatible with both @solana/kit and @solana/web3.js
87
+ * // Use with your preferred Solana library
88
+ * const transaction = new Transaction().add(web3jsInstruction);
89
+ * await sendAndConfirmTransaction(connection, transaction, [wallet]);
39
90
  * ```
40
91
  *
41
- * @param params The simplified parameters for canceling a rental
92
+ * @param params - The rental cancellation parameters including borrower and contract
42
93
  * @returns A ConfigSelector that can be configured with .set() or awaited directly
94
+ * @throws Error when rental is not active, caller is not the borrower, or instruction generation fails
43
95
  */
44
96
  export declare function cancelRental(params: CancelRentalParams): ConfigSelector<CancelRentalInstruction>;
97
+ /**
98
+ * Low-level function to create a rental cancellation instruction with raw input parameters.
99
+ *
100
+ * This function provides direct access to the underlying codama-generated instruction
101
+ * builder. It's primarily used internally by the SDK but can be used for advanced
102
+ * use cases where full control over instruction parameters is needed.
103
+ *
104
+ * @internal
105
+ * @param input - Raw instruction input parameters as expected by codama
106
+ * @param options - Optional instruction options including program address
107
+ * @returns A ConfigSelector for the raw instruction
108
+ */
45
109
  export declare function getCancelRentalInstructionAsync(input: any, options?: any): ConfigSelector<any>;
46
110
  export {};
47
111
  //# sourceMappingURL=cancel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4D,KAAK,cAAc,EAAsB,MAAM,iBAAiB,CAAC;AAIpI,KAAK,gBAAgB,GAAG,MAAM,CAAC;AAC/B,KAAK,eAAe,GAAG,GAAG,CAAC;AAC3B,KAAK,uBAAuB,GAAG,GAAG,CAAC;AAEnC;;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