@sly-rentals/core 0.1.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.
- package/README.md +76 -163
- package/dist/api.json +7636 -3857
- package/dist/cjs/audit/events-registry.js +86 -0
- package/dist/cjs/audit/events-registry.js.map +1 -0
- package/dist/cjs/audit/index.js +8 -1
- package/dist/cjs/audit/index.js.map +1 -1
- package/dist/cjs/audit/listener.js +219 -0
- package/dist/cjs/audit/listener.js.map +1 -0
- package/dist/cjs/kit/index.js +10 -1
- package/dist/cjs/kit/index.js.map +1 -1
- package/dist/cjs/legacy/index.js +7 -1
- package/dist/cjs/legacy/index.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/utils/config.js +16 -0
- package/dist/cjs/utils/config.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/audit/events-registry.js +83 -0
- package/dist/esm/audit/events-registry.js.map +1 -0
- package/dist/esm/audit/index.js +2 -0
- package/dist/esm/audit/index.js.map +1 -1
- package/dist/esm/audit/listener.js +213 -0
- package/dist/esm/audit/listener.js.map +1 -0
- package/dist/esm/kit/index.js +5 -0
- package/dist/esm/kit/index.js.map +1 -1
- package/dist/esm/legacy/index.js +2 -0
- package/dist/esm/legacy/index.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/utils/config.js +14 -0
- package/dist/esm/utils/config.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/audit/events-registry.d.ts +71 -0
- package/dist/types/audit/events-registry.d.ts.map +1 -0
- package/dist/types/audit/index.d.ts +4 -0
- package/dist/types/audit/index.d.ts.map +1 -1
- package/dist/types/audit/listener.d.ts +127 -0
- package/dist/types/audit/listener.d.ts.map +1 -0
- package/dist/types/kit/index.d.ts +2 -0
- package/dist/types/kit/index.d.ts.map +1 -1
- package/dist/types/legacy/index.d.ts +3 -0
- package/dist/types/legacy/index.d.ts.map +1 -1
- package/dist/types/utils/config.d.ts +29 -0
- package/dist/types/utils/config.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,205 +1,120 @@
|
|
|
1
1
|
# @sly-rentals/core
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> TypeScript SDK for the [`srsly`](https://github.com/wuwei-labs/srsly) rental program on Solana.
|
|
4
4
|
|
|
5
|
-
**Status**: pre-1.0.
|
|
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
|
|
7
|
+
## What it does
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
Dual-protocol exports — pick the entry point that matches your existing stack:
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
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
|
-
|
|
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
|
|
26
|
+
## Quick start (kit)
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
```ts
|
|
29
|
+
import { setSdkConfig, createContract, acceptRental } from '@sly-rentals/core';
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
import { setSdkConfig, createContract } from '@sly-rentals/core';
|
|
31
|
+
setSdkConfig({ network: 'mainnet-beta' });
|
|
41
32
|
|
|
42
|
-
//
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
+
## Quick start (legacy / web3.js)
|
|
58
52
|
|
|
59
|
-
```
|
|
60
|
-
import {
|
|
61
|
-
import { setSdkConfig, createContract } from '@sly-rentals/core';
|
|
53
|
+
```ts
|
|
54
|
+
import { createContract } from '@sly-rentals/core/legacy';
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
65
|
+
transaction.add(...instructions);
|
|
81
66
|
```
|
|
82
67
|
|
|
83
68
|
## Configuration
|
|
84
69
|
|
|
85
|
-
|
|
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: '
|
|
93
|
-
rpcUrl: 'https://
|
|
94
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
The SDK provides centralized address management for different networks:
|
|
80
|
+
Per-call overrides take precedence over global config:
|
|
114
81
|
|
|
115
|
-
```
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
88
|
+
Instruction params accept multiple forms — pick what your stack uses:
|
|
160
89
|
|
|
161
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
+
The SDK includes a server-side helper for affiliate discounts:
|
|
170
99
|
|
|
171
|
-
|
|
172
|
-
|
|
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:
|
|
188
|
-
discount: 10,
|
|
189
|
-
expirySlots: 1000,
|
|
105
|
+
address: affiliateMemberAddress,
|
|
106
|
+
discount: 10, // 10% off
|
|
107
|
+
expirySlots: 1000, // ~6–7 minutes
|
|
190
108
|
discountAuthority: serverKeypair,
|
|
191
109
|
});
|
|
192
110
|
|
|
193
|
-
//
|
|
194
|
-
return discountAuth;
|
|
111
|
+
return discountAuth; // JSON-safe; return directly via your API
|
|
195
112
|
```
|
|
196
113
|
|
|
197
|
-
|
|
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
|
-
##
|
|
127
|
+
## Network addresses
|
|
213
128
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
##
|
|
138
|
+
## API reference
|
|
226
139
|
|
|
227
|
-
|
|
140
|
+
Full TypeDoc reference for every exported function: <https://wuwei-labs.github.io/srsly/api/core/>.
|
|
228
141
|
|
|
229
|
-
##
|
|
142
|
+
## Repository
|
|
230
143
|
|
|
231
|
-
|
|
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
|
-
|
|
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.
|