@sly-rentals/core 1.0.0 → 1.1.0

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 (44) hide show
  1. package/README.md +76 -163
  2. package/dist/api.json +7636 -3857
  3. package/dist/cjs/audit/events-registry.js +86 -0
  4. package/dist/cjs/audit/events-registry.js.map +1 -0
  5. package/dist/cjs/audit/index.js +8 -1
  6. package/dist/cjs/audit/index.js.map +1 -1
  7. package/dist/cjs/audit/listener.js +219 -0
  8. package/dist/cjs/audit/listener.js.map +1 -0
  9. package/dist/cjs/kit/index.js +10 -1
  10. package/dist/cjs/kit/index.js.map +1 -1
  11. package/dist/cjs/legacy/index.js +7 -1
  12. package/dist/cjs/legacy/index.js.map +1 -1
  13. package/dist/cjs/package.json +1 -1
  14. package/dist/cjs/utils/config.js +16 -0
  15. package/dist/cjs/utils/config.js.map +1 -1
  16. package/dist/cjs/version.js +1 -1
  17. package/dist/esm/audit/events-registry.js +83 -0
  18. package/dist/esm/audit/events-registry.js.map +1 -0
  19. package/dist/esm/audit/index.js +2 -0
  20. package/dist/esm/audit/index.js.map +1 -1
  21. package/dist/esm/audit/listener.js +213 -0
  22. package/dist/esm/audit/listener.js.map +1 -0
  23. package/dist/esm/kit/index.js +5 -0
  24. package/dist/esm/kit/index.js.map +1 -1
  25. package/dist/esm/legacy/index.js +2 -0
  26. package/dist/esm/legacy/index.js.map +1 -1
  27. package/dist/esm/package.json +1 -1
  28. package/dist/esm/utils/config.js +14 -0
  29. package/dist/esm/utils/config.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/types/audit/events-registry.d.ts +71 -0
  32. package/dist/types/audit/events-registry.d.ts.map +1 -0
  33. package/dist/types/audit/index.d.ts +4 -0
  34. package/dist/types/audit/index.d.ts.map +1 -1
  35. package/dist/types/audit/listener.d.ts +127 -0
  36. package/dist/types/audit/listener.d.ts.map +1 -0
  37. package/dist/types/kit/index.d.ts +2 -0
  38. package/dist/types/kit/index.d.ts.map +1 -1
  39. package/dist/types/legacy/index.d.ts +3 -0
  40. package/dist/types/legacy/index.d.ts.map +1 -1
  41. package/dist/types/utils/config.d.ts +29 -0
  42. package/dist/types/utils/config.d.ts.map +1 -1
  43. package/dist/types/version.d.ts +1 -1
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -1,205 +1,120 @@
1
1
  # @sly-rentals/core
2
2
 
3
- > Simplified TypeScript SDK for SRSLY
3
+ > TypeScript SDK for the [`srsly`](https://github.com/wuwei-labs/srsly) rental program on Solana.
4
4
 
5
- **Status**: pre-1.0. Surface area is stable for the current instruction set but may grow as new program features ship.
5
+ **Status**: pre-1.0. The instruction surface tracks the on-chain program; expect minor additions as new program features ship. See [`CHANGELOG.md`](./CHANGELOG.md) for release history.
6
6
 
7
- ## What is this?
7
+ ## What it does
8
8
 
9
- This is a simplified TypeScript SDK for SRSLY. It's a thin convenience wrapper around Codama-generated TypeScript clients, focusing on simplicity and maintainability.
9
+ Builds and serializes instruction byte buffers for the `srsly` rental program. Generated by [Codama](https://github.com/codama-idl/codama) from the Anchor IDL, with thin convenience wrappers around the most-used flows (creating contracts, accepting rentals, claiming payments, settling discounts).
10
10
 
11
- ## Key Differences from `@sly-rentals/core`
11
+ Dual-protocol exports pick the entry point that matches your existing stack:
12
12
 
13
- ### Simpler (80% less code)
14
- - **Old**: 4,000+ lines of custom abstractions
15
- - **New**: ~800 lines of thin wrappers
13
+ | Import | Returns | When to use |
14
+ | --- | --- | --- |
15
+ | `@sly-rentals/core` | `@solana/kit` instructions | New code; ESM-first, smaller bundle |
16
+ | `@sly-rentals/core/legacy` | `@solana/web3.js` `TransactionInstruction[]` | Existing wallet-adapter / web3.js stacks |
17
+ | `@sly-rentals/core/audit` | Decoded events + history helpers | Indexers, dashboards, accounting flows |
18
+ | `@sly-rentals/core/idl` | Raw Anchor IDL JSON | Custom client generation, tx decoders |
16
19
 
17
- ### Clearer Purpose
18
- - **Old**: Framework with fluent APIs, factories, builders
19
- - **New**: Convenience wrapper around Codama
20
-
21
- ### Easier Configuration
22
- - **Old**: Fluent selectors, chainable configs, network modules
23
- - **New**: Simple global config + optional overrides
24
-
25
- ### Better Maintenance
26
- - **Old**: Complex abstractions break when Codama updates
27
- - **New**: Thin wrappers adapt easily to Codama changes
28
-
29
- ## Installation
20
+ ## Install
30
21
 
31
22
  ```bash
32
23
  pnpm add @sly-rentals/core
33
24
  ```
34
25
 
35
- ## Quick Start
26
+ ## Quick start (kit)
36
27
 
37
- ### With @solana/kit (default)
28
+ ```ts
29
+ import { setSdkConfig, createContract, acceptRental } from '@sly-rentals/core';
38
30
 
39
- ```typescript
40
- import { setSdkConfig, createContract } from '@sly-rentals/core';
31
+ setSdkConfig({ network: 'mainnet-beta' });
41
32
 
42
- // Set global config once
43
- setSdkConfig({ network: 'atlasnet' });
44
-
45
- // Create a contract - returns @solana/kit instruction
46
- const instruction = await createContract({
47
- owner: walletAddress, // string address
33
+ // Owner: list a fleet for rent
34
+ const create = await createContract({
35
+ owner: ownerSigner,
48
36
  fleet: fleetAddress,
49
37
  ownerProfile: profileAddress,
50
- gameId: gameAddress,
51
- rate: 100, // 100 ATLAS per payment
38
+ rate: 100, // 100 ATLAS per period
52
39
  durationMax: { days: 30 },
53
- paymentsFreq: '@daily'
40
+ paymentsFreq: '@daily',
41
+ });
42
+
43
+ // Borrower: rent a listed fleet
44
+ const accept = await acceptRental({
45
+ borrower: borrowerSigner,
46
+ contract: contractAddress,
47
+ duration: { days: 7 },
54
48
  });
55
49
  ```
56
50
 
57
- ### With @solana/web3.js
51
+ ## Quick start (legacy / web3.js)
58
52
 
59
- ```typescript
60
- import { PublicKey } from '@solana/web3.js';
61
- import { setSdkConfig, createContract } from '@sly-rentals/core';
53
+ ```ts
54
+ import { createContract } from '@sly-rentals/core/legacy';
62
55
 
63
- // Set global config with PublicKey constructor
64
- setSdkConfig({
65
- network: 'mainnet-beta',
66
- PublicKey // Enable web3.js mode
67
- });
68
-
69
- // Create a contract - returns web3.js TransactionInstruction
70
- const instruction = await createContract({
71
- owner: keypair, // Accepts web3.js Keypair
72
- fleet: fleetPubkey, // Accepts web3.js PublicKey
56
+ const instructions = await createContract({
57
+ owner: ownerKeypair,
58
+ fleet: fleetPubkey,
73
59
  ownerProfile: profilePubkey,
74
- gameId: gamePubkey,
75
60
  rate: 100,
76
61
  durationMax: { days: 30 },
77
- paymentsFreq: '@daily'
62
+ paymentsFreq: '@daily',
78
63
  });
79
64
 
80
- // instruction.keys[0].pubkey is a PublicKey instance
65
+ transaction.add(...instructions);
81
66
  ```
82
67
 
83
68
  ## Configuration
84
69
 
85
- ### Basic Configuration
70
+ ```ts
71
+ import { setSdkConfig } from '@sly-rentals/core';
86
72
 
87
- ```typescript
88
- import { setSdkConfig, getSdkConfig, clearSdkConfig } from '@sly-rentals/core';
89
-
90
- // Set global config
91
73
  setSdkConfig({
92
- network: 'atlasnet' | 'mainnet-beta' | 'localnet',
93
- rpcUrl: 'https://custom-rpc.com', // Optional
94
- programId: 'custom-program-id', // Optional
95
- commitment: 'confirmed', // Optional
96
- PublicKey: PublicKey // Optional for web3.js mode
97
- });
98
-
99
- // Get current config
100
- const config = getSdkConfig();
101
-
102
- // Clear config (reset to defaults)
103
- clearSdkConfig();
104
-
105
- // Override per-call
106
- const ix = await createContract(params, {
107
- rpcUrl: 'https://temporary-rpc.com'
74
+ network: 'mainnet-beta', // 'mainnet-beta' | 'atlasnet' | 'localnet'
75
+ rpcUrl: 'https://your-rpc.com', // optional override
76
+ commitment: 'confirmed', // optional
108
77
  });
109
78
  ```
110
79
 
111
- ### Network Addresses
112
-
113
- The SDK provides centralized address management for different networks:
80
+ Per-call overrides take precedence over global config:
114
81
 
115
- ```typescript
116
- import { getAddresses, ATLASNET_ADDRESSES, MAINNET_ADDRESSES } from '@sly-rentals/core';
117
-
118
- // Get addresses for current network (from global config)
119
- const addresses = getAddresses();
120
- console.log(addresses.atlasMint); // ATLAS token mint
121
- console.log(addresses.sage); // SAGE program
122
- console.log(addresses.srsly); // SRSLY program
123
-
124
- // Override for specific network
125
- const mainnetAddrs = getAddresses({ network: 'mainnet-beta' });
126
-
127
- // Custom SRSLY program
128
- const customAddrs = getAddresses({ programId: 'MyCustomSRSLY...' });
129
- console.log(customAddrs.srsly); // 'MyCustomSRSLY...'
130
-
131
- // Direct access to network addresses
132
- console.log(ATLASNET_ADDRESSES); // All atlasnet addresses
133
- console.log(MAINNET_ADDRESSES); // All mainnet addresses
82
+ ```ts
83
+ const ix = await createContract(params, { rpcUrl: 'https://temporary-rpc.com' });
134
84
  ```
135
85
 
136
- **Available Networks:**
137
- - `'atlasnet'` - Star Atlas testnet (default)
138
- - `'mainnet-beta'` - Solana mainnet / Star Atlas production
139
- - `'localnet'` - Local development
140
-
141
- **Network Addresses:**
142
- - `srsly` - SRSLY rental program
143
- - `sage` - Star Atlas SAGE program
144
- - `atlasMint` - ATLAS token mint
145
- - `profileFaction` - Profile Faction program
146
- - `gameId` - Star Atlas game ID
147
- ```
148
-
149
- ## API Reference
150
-
151
- ### Instructions
152
-
153
- - `createContract(params, config?)` - Create a rental contract
154
- - `closeContract(params, config?)` - Close a rental contract
155
- - `acceptRental(params, config?)` - Accept a rental
156
- - `cancelRental(params, config?)` - Cancel a rental
157
- - _(More to come)_
86
+ ## Parameters
158
87
 
159
- ### Parameters
88
+ Instruction params accept multiple forms — pick what your stack uses:
160
89
 
161
- All instruction params accept:
90
+ - **Signers**: string addresses, `@solana/kit` signers, or `@solana/web3.js` `Keypair`
91
+ - **Addresses**: strings or `PublicKey`
92
+ - **Rates**: numbers (ATLAS) or `{ atlas: 1.5 }` / `{ stardust: 150_000_000 }`
93
+ - **Durations**: `{ days: 7 }`, `{ hours: 24 }`, `{ weeks: 2 }`, etc.
94
+ - **Schedules**: `'@hourly'`, `'@daily'`, `'@weekly'`, `'@monthly'`, or a cron expression
162
95
 
163
- - **Signers**: String addresses, web3.js Keypairs, or @solana/kit signers
164
- - **Addresses**: String addresses or web3.js PublicKeys
165
- - **Rates**: Numbers (ATLAS) or objects `{ atlas: 1.5 }` or `{ stardust: 150_000_000 }`
166
- - **Durations**: Objects `{ days: 7 }`, `{ hours: 24 }`, `{ weeks: 2 }`, etc.
167
- - **Schedules**: Strings `'@daily'`, `'@hourly'`, or cron expressions
96
+ ## Discount authorization
168
97
 
169
- ### Return Types
98
+ The SDK includes a server-side helper for affiliate discounts:
170
99
 
171
- - **Without PublicKey in config**: Returns @solana/kit instruction
172
- - **With PublicKey in config**: Returns web3.js TransactionInstruction
173
-
174
- ### Discount Authorization
175
-
176
- The SDK provides a `createDiscount` helper for server-side discount authorization. This is useful when an affiliate wants to offer discounts to borrowers.
177
-
178
- #### Server-side
179
-
180
- ```typescript
181
- import { setSdkConfig, createDiscount } from '@sly-rentals/core';
182
-
183
- // Can be set once globally (e.g., at app startup)
184
- setSdkConfig({ rpcUrl: 'https://your-rpc-url.com' });
100
+ ```ts
101
+ // Server: sign a discount attestation
102
+ import { createDiscount } from '@sly-rentals/core';
185
103
 
186
104
  const discountAuth = await createDiscount({
187
- address: 'AFFILIATE_MEMBER_PDA',
188
- discount: 10, // 10% discount
189
- expirySlots: 1000, // ~6-7 minutes from now
105
+ address: affiliateMemberAddress,
106
+ discount: 10, // 10% off
107
+ expirySlots: 1000, // ~67 minutes
190
108
  discountAuthority: serverKeypair,
191
109
  });
192
110
 
193
- // Already JSON-safe - return directly via API
194
- return discountAuth;
111
+ return discountAuth; // JSON-safe; return directly via your API
195
112
  ```
196
113
 
197
- #### Client-side
198
-
199
- ```typescript
114
+ ```ts
115
+ // Client: redeem at acceptRental
200
116
  import { acceptRental } from '@sly-rentals/core';
201
117
 
202
- // Pass directly from server response - no deserialization needed
203
118
  const ix = await acceptRental({
204
119
  borrower: wallet,
205
120
  contract: contractAddress,
@@ -209,27 +124,25 @@ const ix = await acceptRental({
209
124
  });
210
125
  ```
211
126
 
212
- ## Development Status
127
+ ## Network addresses
213
128
 
214
- - ✅ Core config system
215
- - Centralized address management
216
- - ✅ Signer handling (web3.js + kit)
217
- - web3.js conversion
218
- - Parameter converters (amount, duration, schedule)
219
- - First instruction: `createContract`
220
- - 🚧 Additional contract instructions
221
- - 🚧 Rental instructions
222
- - 🚧 Other instructions
223
- - 🚧 Tests
129
+ ```ts
130
+ import { getAddresses } from '@sly-rentals/core';
131
+
132
+ const addrs = getAddresses(); // current network
133
+ addrs.atlasMint; // ATLAS token mint
134
+ addrs.sage; // SAGE program
135
+ addrs.srsly; // SRSLY program
136
+ ```
224
137
 
225
- ## Migration from `@sly-rentals/core`
138
+ ## API reference
226
139
 
227
- Coming soon - see migration guide once this package reaches 1.0.0.
140
+ Full TypeDoc reference for every exported function: <https://wuwei-labs.github.io/srsly/api/core/>.
228
141
 
229
- ## Contributing
142
+ ## Repository
230
143
 
231
- This package is currently in beta. Please report issues on GitHub.
144
+ Source, on-chain program, integration tests, and the playground UI live in the monorepo: <https://github.com/wuwei-labs/srsly>.
232
145
 
233
146
  ## License
234
147
 
235
- ISC
148
+ [MIT](./LICENSE). The on-chain program (`srsly`) is AGPL-3.0-only; this SDK talks to it over RPC and is not a derivative work. See the workspace [`LICENSING.md`](https://github.com/wuwei-labs/srsly/blob/main/LICENSING.md) for the rationale.