@wuwei-labs/srsly 2.0.0-beta.15 → 2.0.0-beta.16
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 +115 -937
- package/dist/cjs/codama/accounts/config.js +88 -0
- package/dist/cjs/codama/accounts/config.js.map +1 -0
- package/dist/cjs/codama/accounts/contractState.js +87 -0
- package/dist/cjs/codama/accounts/contractState.js.map +1 -0
- package/dist/cjs/codama/accounts/fleet.js +77 -0
- package/dist/cjs/codama/accounts/fleet.js.map +1 -0
- package/dist/cjs/codama/accounts/index.js +29 -0
- package/dist/cjs/codama/accounts/index.js.map +1 -0
- package/dist/cjs/codama/accounts/rentalState.js +87 -0
- package/dist/cjs/codama/accounts/rentalState.js.map +1 -0
- package/dist/cjs/codama/accounts/thread.js +89 -0
- package/dist/cjs/codama/accounts/thread.js.map +1 -0
- package/dist/cjs/codama/errors/index.js +25 -0
- package/dist/cjs/codama/errors/index.js.map +1 -0
- package/dist/cjs/codama/errors/srsly.js +86 -0
- package/dist/cjs/codama/errors/srsly.js.map +1 -0
- package/dist/cjs/codama/index.js +29 -0
- package/dist/cjs/codama/index.js.map +1 -0
- package/dist/cjs/codama/instructions/acceptRental.js +354 -0
- package/dist/cjs/codama/instructions/acceptRental.js.map +1 -0
- package/dist/cjs/codama/instructions/cancelRental.js +202 -0
- package/dist/cjs/codama/instructions/cancelRental.js.map +1 -0
- package/dist/cjs/codama/instructions/closeContract.js +211 -0
- package/dist/cjs/codama/instructions/closeContract.js.map +1 -0
- package/dist/cjs/codama/instructions/closeRental.js +233 -0
- package/dist/cjs/codama/instructions/closeRental.js.map +1 -0
- package/dist/cjs/codama/instructions/createContract.js +258 -0
- package/dist/cjs/codama/instructions/createContract.js.map +1 -0
- package/dist/cjs/codama/instructions/index.js +33 -0
- package/dist/cjs/codama/instructions/index.js.map +1 -0
- package/dist/cjs/codama/instructions/initializeConfig.js +131 -0
- package/dist/cjs/codama/instructions/initializeConfig.js.map +1 -0
- package/dist/cjs/codama/instructions/payRental.js +245 -0
- package/dist/cjs/codama/instructions/payRental.js.map +1 -0
- package/dist/cjs/codama/instructions/resetRental.js +146 -0
- package/dist/cjs/codama/instructions/resetRental.js.map +1 -0
- package/dist/cjs/codama/instructions/updateConfig.js +145 -0
- package/dist/cjs/codama/instructions/updateConfig.js.map +1 -0
- package/dist/cjs/codama/programs/index.js +25 -0
- package/dist/cjs/codama/programs/index.js.map +1 -0
- package/dist/cjs/codama/programs/srsly.js +85 -0
- package/dist/cjs/codama/programs/srsly.js.map +1 -0
- package/dist/cjs/codama/shared/index.js +95 -0
- package/dist/cjs/codama/shared/index.js.map +1 -0
- package/dist/cjs/codama/types/clockData.js +31 -0
- package/dist/cjs/codama/types/clockData.js.map +1 -0
- package/dist/cjs/codama/types/equality.js +30 -0
- package/dist/cjs/codama/types/equality.js.map +1 -0
- package/dist/cjs/codama/types/execContext.js +38 -0
- package/dist/cjs/codama/types/execContext.js.map +1 -0
- package/dist/cjs/codama/types/index.js +33 -0
- package/dist/cjs/codama/types/index.js.map +1 -0
- package/dist/cjs/codama/types/paymentFrequency.js +34 -0
- package/dist/cjs/codama/types/paymentFrequency.js.map +1 -0
- package/dist/cjs/codama/types/serializableAccount.js +31 -0
- package/dist/cjs/codama/types/serializableAccount.js.map +1 -0
- package/dist/cjs/codama/types/serializableInstruction.js +32 -0
- package/dist/cjs/codama/types/serializableInstruction.js.map +1 -0
- package/dist/cjs/codama/types/threadResponse.js +38 -0
- package/dist/cjs/codama/types/threadResponse.js.map +1 -0
- package/dist/cjs/codama/types/trigger.js +90 -0
- package/dist/cjs/codama/types/trigger.js.map +1 -0
- package/dist/cjs/codama/types/triggerContext.js +49 -0
- package/dist/cjs/codama/types/triggerContext.js.map +1 -0
- package/dist/cjs/package.json +1 -1
- package/dist/esm/codama/accounts/config.js +76 -0
- package/dist/esm/codama/accounts/config.js.map +1 -0
- package/dist/esm/codama/accounts/contractState.js +75 -0
- package/dist/esm/codama/accounts/contractState.js.map +1 -0
- package/dist/esm/codama/accounts/fleet.js +64 -0
- package/dist/esm/codama/accounts/fleet.js.map +1 -0
- package/dist/esm/codama/accounts/index.js +13 -0
- package/dist/esm/codama/accounts/index.js.map +1 -0
- package/dist/esm/codama/accounts/rentalState.js +74 -0
- package/dist/esm/codama/accounts/rentalState.js.map +1 -0
- package/dist/esm/codama/accounts/thread.js +77 -0
- package/dist/esm/codama/accounts/thread.js.map +1 -0
- package/dist/esm/codama/errors/index.js +9 -0
- package/dist/esm/codama/errors/index.js.map +1 -0
- package/dist/esm/codama/errors/srsly.js +81 -0
- package/dist/esm/codama/errors/srsly.js.map +1 -0
- package/dist/esm/codama/index.js +13 -0
- package/dist/esm/codama/index.js.map +1 -0
- package/dist/esm/codama/instructions/acceptRental.js +344 -0
- package/dist/esm/codama/instructions/acceptRental.js.map +1 -0
- package/dist/esm/codama/instructions/cancelRental.js +192 -0
- package/dist/esm/codama/instructions/cancelRental.js.map +1 -0
- package/dist/esm/codama/instructions/closeContract.js +201 -0
- package/dist/esm/codama/instructions/closeContract.js.map +1 -0
- package/dist/esm/codama/instructions/closeRental.js +223 -0
- package/dist/esm/codama/instructions/closeRental.js.map +1 -0
- package/dist/esm/codama/instructions/createContract.js +248 -0
- package/dist/esm/codama/instructions/createContract.js.map +1 -0
- package/dist/esm/codama/instructions/index.js +17 -0
- package/dist/esm/codama/instructions/index.js.map +1 -0
- package/dist/esm/codama/instructions/initializeConfig.js +121 -0
- package/dist/esm/codama/instructions/initializeConfig.js.map +1 -0
- package/dist/esm/codama/instructions/payRental.js +235 -0
- package/dist/esm/codama/instructions/payRental.js.map +1 -0
- package/dist/esm/codama/instructions/resetRental.js +136 -0
- package/dist/esm/codama/instructions/resetRental.js.map +1 -0
- package/dist/esm/codama/instructions/updateConfig.js +135 -0
- package/dist/esm/codama/instructions/updateConfig.js.map +1 -0
- package/dist/esm/codama/programs/index.js +9 -0
- package/dist/esm/codama/programs/index.js.map +1 -0
- package/dist/esm/codama/programs/srsly.js +80 -0
- package/dist/esm/codama/programs/srsly.js.map +1 -0
- package/dist/esm/codama/shared/index.js +87 -0
- package/dist/esm/codama/shared/index.js.map +1 -0
- package/dist/esm/codama/types/clockData.js +26 -0
- package/dist/esm/codama/types/clockData.js.map +1 -0
- package/dist/esm/codama/types/equality.js +24 -0
- package/dist/esm/codama/types/equality.js.map +1 -0
- package/dist/esm/codama/types/execContext.js +33 -0
- package/dist/esm/codama/types/execContext.js.map +1 -0
- package/dist/esm/codama/types/index.js +17 -0
- package/dist/esm/codama/types/index.js.map +1 -0
- package/dist/esm/codama/types/paymentFrequency.js +28 -0
- package/dist/esm/codama/types/paymentFrequency.js.map +1 -0
- package/dist/esm/codama/types/serializableAccount.js +26 -0
- package/dist/esm/codama/types/serializableAccount.js.map +1 -0
- package/dist/esm/codama/types/serializableInstruction.js +27 -0
- package/dist/esm/codama/types/serializableInstruction.js.map +1 -0
- package/dist/esm/codama/types/threadResponse.js +33 -0
- package/dist/esm/codama/types/threadResponse.js.map +1 -0
- package/dist/esm/codama/types/trigger.js +83 -0
- package/dist/esm/codama/types/trigger.js.map +1 -0
- package/dist/esm/codama/types/triggerContext.js +42 -0
- package/dist/esm/codama/types/triggerContext.js.map +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/types/codama/accounts/config.d.ts +52 -0
- package/dist/types/codama/accounts/config.d.ts.map +1 -0
- package/dist/types/codama/accounts/contractState.d.ts +51 -0
- package/dist/types/codama/accounts/contractState.d.ts.map +1 -0
- package/dist/types/codama/accounts/fleet.d.ts +38 -0
- package/dist/types/codama/accounts/fleet.d.ts.map +1 -0
- package/dist/types/codama/accounts/index.d.ts +13 -0
- package/dist/types/codama/accounts/index.d.ts.map +1 -0
- package/dist/types/codama/accounts/rentalState.d.ts +48 -0
- package/dist/types/codama/accounts/rentalState.d.ts.map +1 -0
- package/dist/types/codama/accounts/thread.d.ts +74 -0
- package/dist/types/codama/accounts/thread.d.ts.map +1 -0
- package/dist/types/codama/errors/index.d.ts +9 -0
- package/dist/types/codama/errors/index.d.ts.map +1 -0
- package/dist/types/codama/errors/srsly.d.ts +58 -0
- package/dist/types/codama/errors/srsly.d.ts.map +1 -0
- package/dist/types/codama/index.d.ts +13 -0
- package/dist/types/codama/index.d.ts.map +1 -0
- package/dist/types/codama/instructions/acceptRental.d.ts +135 -0
- package/dist/types/codama/instructions/acceptRental.d.ts.map +1 -0
- package/dist/types/codama/instructions/cancelRental.d.ts +75 -0
- package/dist/types/codama/instructions/cancelRental.d.ts.map +1 -0
- package/dist/types/codama/instructions/closeContract.d.ts +104 -0
- package/dist/types/codama/instructions/closeContract.d.ts.map +1 -0
- package/dist/types/codama/instructions/closeRental.d.ts +87 -0
- package/dist/types/codama/instructions/closeRental.d.ts.map +1 -0
- package/dist/types/codama/instructions/createContract.d.ts +112 -0
- package/dist/types/codama/instructions/createContract.d.ts.map +1 -0
- package/dist/types/codama/instructions/index.d.ts +17 -0
- package/dist/types/codama/instructions/index.d.ts.map +1 -0
- package/dist/types/codama/instructions/initializeConfig.d.ts +60 -0
- package/dist/types/codama/instructions/initializeConfig.d.ts.map +1 -0
- package/dist/types/codama/instructions/payRental.d.ts +114 -0
- package/dist/types/codama/instructions/payRental.d.ts.map +1 -0
- package/dist/types/codama/instructions/resetRental.d.ts +71 -0
- package/dist/types/codama/instructions/resetRental.d.ts.map +1 -0
- package/dist/types/codama/instructions/updateConfig.d.ts +93 -0
- package/dist/types/codama/instructions/updateConfig.d.ts.map +1 -0
- package/dist/types/codama/programs/index.d.ts +9 -0
- package/dist/types/codama/programs/index.d.ts.map +1 -0
- package/dist/types/codama/programs/srsly.d.ts +54 -0
- package/dist/types/codama/programs/srsly.d.ts.map +1 -0
- package/dist/types/codama/shared/index.d.ts +50 -0
- package/dist/types/codama/shared/index.d.ts.map +1 -0
- package/dist/types/codama/types/clockData.d.ts +29 -0
- package/dist/types/codama/types/clockData.d.ts.map +1 -0
- package/dist/types/codama/types/equality.d.ts +18 -0
- package/dist/types/codama/types/equality.d.ts.map +1 -0
- package/dist/types/codama/types/execContext.d.ts +48 -0
- package/dist/types/codama/types/execContext.d.ts.map +1 -0
- package/dist/types/codama/types/index.d.ts +17 -0
- package/dist/types/codama/types/index.d.ts.map +1 -0
- package/dist/types/codama/types/paymentFrequency.d.ts +22 -0
- package/dist/types/codama/types/paymentFrequency.d.ts.map +1 -0
- package/dist/types/codama/types/serializableAccount.d.ts +22 -0
- package/dist/types/codama/types/serializableAccount.d.ts.map +1 -0
- package/dist/types/codama/types/serializableInstruction.d.ts +30 -0
- package/dist/types/codama/types/serializableInstruction.d.ts.map +1 -0
- package/dist/types/codama/types/threadResponse.d.ts +42 -0
- package/dist/types/codama/types/threadResponse.d.ts.map +1 -0
- package/dist/types/codama/types/trigger.d.ts +98 -0
- package/dist/types/codama/types/trigger.d.ts.map +1 -0
- package/dist/types/codama/types/triggerContext.d.ts +75 -0
- package/dist/types/codama/types/triggerContext.d.ts.map +1 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -8,1069 +8,247 @@ A TypeScript SDK for building Solana instructions to interact with the SRSLY (Sp
|
|
|
8
8
|
|
|
9
9
|
## What This SDK Does
|
|
10
10
|
|
|
11
|
-
The SRSLY SDK is an **instruction builder** that helps you create properly formatted Solana instructions for
|
|
11
|
+
The SRSLY SDK is an **instruction builder** that helps you create properly formatted Solana instructions for fleet rentals. It handles:
|
|
12
12
|
|
|
13
|
-
- ✅
|
|
14
|
-
- ✅ Account derivation and validation
|
|
13
|
+
- ✅ Account derivation and validation
|
|
15
14
|
- ✅ Instruction data encoding
|
|
16
15
|
- ✅ Type-safe parameter handling
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
The SDK **does not** handle transaction creation, signing, or submission. You'll need to:
|
|
21
|
-
|
|
22
|
-
- 🔧 Choose a transaction library (`@solana/web3.js` or `@solana/kit`)
|
|
23
|
-
- 🔧 Connect to a Solana RPC endpoint
|
|
24
|
-
- 🔧 Handle wallet integration (Phantom, Solflare, etc.)
|
|
25
|
-
- 🔧 Build, sign, and send transactions
|
|
17
|
+
**What you provide**: RPC connection, wallet integration, transaction handling.
|
|
26
18
|
|
|
27
19
|
## Installation
|
|
28
20
|
|
|
29
|
-
### NPM
|
|
30
|
-
|
|
31
21
|
```bash
|
|
32
22
|
npm install @wuwei-labs/srsly
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### PNPM
|
|
36
|
-
|
|
37
|
-
```bash
|
|
23
|
+
# or
|
|
38
24
|
pnpm add @wuwei-labs/srsly
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Yarn
|
|
42
|
-
|
|
43
|
-
```bash
|
|
25
|
+
# or
|
|
44
26
|
yarn add @wuwei-labs/srsly
|
|
45
27
|
```
|
|
46
28
|
|
|
47
29
|
## Quick Start
|
|
48
30
|
|
|
49
31
|
```typescript
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
setConfig
|
|
53
|
-
} from '@wuwei-labs/srsly';
|
|
54
|
-
|
|
55
|
-
import {
|
|
56
|
-
createDefaultSolanaRpc,
|
|
57
|
-
createTransaction,
|
|
58
|
-
appendInstructions,
|
|
59
|
-
signAndSendTransaction,
|
|
60
|
-
pipe
|
|
61
|
-
} from '@solana/kit';
|
|
62
|
-
|
|
63
|
-
// Step 1: Set up RPC connection
|
|
64
|
-
const rpc = createDefaultSolanaRpc('https://api.atlasnet.solana.com');
|
|
65
|
-
|
|
66
|
-
// Step 2: Get wallet from browser extension (Phantom, Solflare, etc.)
|
|
67
|
-
// Assumes you've already connected to the user's wallet
|
|
68
|
-
const wallet = window.solana; // or your wallet adapter
|
|
32
|
+
import { createContract, setConfig } from '@wuwei-labs/srsly';
|
|
33
|
+
import { Connection, Transaction } from '@solana/web3.js';
|
|
69
34
|
|
|
70
|
-
//
|
|
71
|
-
setConfig({
|
|
35
|
+
// 1. Configure SDK for your network
|
|
36
|
+
setConfig({ programs: 'atlasnet' });
|
|
72
37
|
|
|
73
|
-
//
|
|
74
|
-
const
|
|
75
|
-
owner:
|
|
38
|
+
// 2. Build instruction
|
|
39
|
+
const instruction = await createContract({
|
|
40
|
+
owner: walletPublicKey,
|
|
76
41
|
fleet: fleetAddress,
|
|
77
42
|
ownerProfile: profileAddress,
|
|
78
|
-
rate: 1000000, //
|
|
79
|
-
durationMin: 86400, // 1 day
|
|
80
|
-
durationMax: 604800, // 1 week
|
|
81
|
-
paymentsFreq: 'daily'
|
|
82
|
-
ownerKeyIndex: 0
|
|
43
|
+
rate: 1000000, // ATLAS tokens
|
|
44
|
+
durationMin: 86400, // 1 day
|
|
45
|
+
durationMax: 604800, // 1 week
|
|
46
|
+
paymentsFreq: 'daily'
|
|
83
47
|
});
|
|
84
48
|
|
|
85
|
-
//
|
|
86
|
-
const transaction = pipe(
|
|
87
|
-
createTransaction({ version: 0 }),
|
|
88
|
-
tx => appendInstructions([contractInstruction], tx)
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
// Sign and send using wallet extension
|
|
92
|
-
const signature = await signAndSendTransaction(rpc, transaction, wallet);
|
|
93
|
-
console.log('Transaction signature:', signature);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**Alternative with @solana/web3.js:**
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
import { Connection, Transaction } from '@solana/web3.js';
|
|
100
|
-
|
|
49
|
+
// 3. Build and send transaction
|
|
101
50
|
const connection = new Connection('https://api.atlasnet.solana.com');
|
|
102
|
-
const transaction = new Transaction().add(
|
|
103
|
-
|
|
104
|
-
// Sign and send with wallet extension
|
|
105
|
-
const signature = await window.solana.signAndSendTransaction(transaction);
|
|
51
|
+
const transaction = new Transaction().add(instruction);
|
|
52
|
+
const signature = await wallet.signAndSendTransaction(transaction);
|
|
106
53
|
```
|
|
107
54
|
|
|
108
|
-
|
|
109
|
-
> - Setting up RPC connections
|
|
110
|
-
> - Managing wallet connections (Phantom, Solflare, etc.)
|
|
111
|
-
> - Building, signing, and sending transactions
|
|
112
|
-
> - Handling transaction confirmation and errors
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
## SDK Features
|
|
117
|
-
|
|
118
|
-
The following examples show how to use the SRSLY SDK to build instructions. Add these instructions to transactions using your preferred Solana library (`@solana/web3.js` or `@solana/kit`).
|
|
55
|
+
## Core Features
|
|
119
56
|
|
|
120
57
|
### Contract Management
|
|
121
58
|
|
|
122
|
-
Create and manage rental contracts for Star Atlas fleets:
|
|
123
|
-
|
|
124
59
|
```typescript
|
|
125
60
|
import { createContract, closeContract } from '@wuwei-labs/srsly';
|
|
126
61
|
|
|
127
|
-
// Create
|
|
62
|
+
// Create rental contract
|
|
128
63
|
const createIx = await createContract({
|
|
129
64
|
owner: wallet,
|
|
130
65
|
fleet: fleetAddress,
|
|
131
66
|
ownerProfile: profileAddress,
|
|
132
|
-
rate: 5000000,
|
|
133
|
-
durationMin: 86400,
|
|
134
|
-
durationMax: 2592000,
|
|
135
|
-
paymentsFreq: 'daily'
|
|
136
|
-
|
|
137
|
-
}).set({ network: 'mainnet' }); // Use mainnet configuration
|
|
67
|
+
rate: 5000000,
|
|
68
|
+
durationMin: 86400,
|
|
69
|
+
durationMax: 2592000,
|
|
70
|
+
paymentsFreq: 'daily'
|
|
71
|
+
});
|
|
138
72
|
|
|
139
|
-
// Close
|
|
73
|
+
// Close contract
|
|
140
74
|
const closeIx = await closeContract({
|
|
141
75
|
owner: wallet,
|
|
142
76
|
fleet: fleetAddress,
|
|
143
|
-
contract: contractAddress
|
|
144
|
-
faction: 'mud' // or faction number: 1, 2, 3
|
|
77
|
+
contract: contractAddress
|
|
145
78
|
});
|
|
146
79
|
```
|
|
147
80
|
|
|
148
81
|
### Rental Operations
|
|
149
82
|
|
|
150
|
-
Handle rental lifecycle operations with automatic token conversion:
|
|
151
|
-
|
|
152
83
|
```typescript
|
|
153
|
-
import {
|
|
154
|
-
acceptRental,
|
|
155
|
-
cancelRental,
|
|
156
|
-
closeRental,
|
|
157
|
-
resetRental,
|
|
158
|
-
ATLAS_TO_STARDUST
|
|
159
|
-
} from '@wuwei-labs/srsly';
|
|
84
|
+
import { acceptRental, cancelRental, closeRental } from '@wuwei-labs/srsly';
|
|
160
85
|
|
|
161
|
-
// Accept
|
|
86
|
+
// Accept rental offer
|
|
162
87
|
const acceptIx = await acceptRental({
|
|
163
88
|
borrower: borrowerWallet,
|
|
164
89
|
borrowerProfile: borrowerProfileAddress,
|
|
165
|
-
borrowerFaction: '
|
|
90
|
+
borrowerFaction: 'mud', // or 1, 2, 3
|
|
166
91
|
fleet: fleetAddress,
|
|
167
92
|
contract: contractAddress,
|
|
168
|
-
rate: 100, // ATLAS
|
|
93
|
+
rate: 100, // ATLAS per day
|
|
169
94
|
duration: 86400 // 1 day in seconds
|
|
170
|
-
|
|
171
|
-
}).set({ network: 'atlasnet' });
|
|
95
|
+
});
|
|
172
96
|
|
|
173
|
-
// Cancel
|
|
97
|
+
// Cancel active rental
|
|
174
98
|
const cancelIx = await cancelRental({
|
|
175
99
|
borrower: borrowerWallet,
|
|
176
100
|
contract: contractAddress,
|
|
177
101
|
rentalState: rentalStateAddress
|
|
178
102
|
});
|
|
179
103
|
|
|
180
|
-
// Close
|
|
104
|
+
// Close completed rental
|
|
181
105
|
const closeIx = await closeRental({
|
|
182
106
|
borrower: borrowerWallet,
|
|
183
107
|
contract: contractAddress,
|
|
184
108
|
rentalState: rentalStateAddress,
|
|
185
109
|
ownerTokenAccount: ownerTokenAccountAddress
|
|
186
|
-
}).set({ network: 'mainnet' });
|
|
187
|
-
|
|
188
|
-
// Reset rental state with custom configuration
|
|
189
|
-
const resetIx = await resetRental({
|
|
190
|
-
fleet: fleetAddress,
|
|
191
|
-
contract: contractAddress,
|
|
192
|
-
rentalState: rentalStateAddress,
|
|
193
|
-
faction: 'mud',
|
|
194
|
-
ownerProfile: ownerProfileAddress
|
|
195
|
-
}).set({
|
|
196
|
-
network: 'mainnet',
|
|
197
|
-
sageProgramAddress: 'custom...',
|
|
198
|
-
gameId: 'custom...'
|
|
199
|
-
});
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Account State Management
|
|
203
|
-
|
|
204
|
-
Fetch and decode account states using network-specific functions:
|
|
205
|
-
|
|
206
|
-
```typescript
|
|
207
|
-
import { getCachedNetworkModule } from '@wuwei-labs/srsly';
|
|
208
|
-
|
|
209
|
-
// Get network-specific account functions (programs to atlasnet)
|
|
210
|
-
const accountsModule = await getCachedNetworkModule('accounts');
|
|
211
|
-
const { fetchContractState, fetchRentalState } = accountsModule;
|
|
212
|
-
|
|
213
|
-
// Or specify network explicitly
|
|
214
|
-
const mainnetAccountsModule = await getCachedNetworkModule('accounts', 'mainnet');
|
|
215
|
-
|
|
216
|
-
// Fetch contract state
|
|
217
|
-
const contractState = await fetchContractState(rpc, contractPublicKey);
|
|
218
|
-
console.log('Contract rate:', contractState.rate.toString());
|
|
219
|
-
console.log('Duration range:', contractState.durationMin.toString(), '-', contractState.durationMax.toString());
|
|
220
|
-
|
|
221
|
-
// Fetch rental state
|
|
222
|
-
const rentalState = await fetchRentalState(rpc, rentalPublicKey);
|
|
223
|
-
console.log('Rental status:', rentalState.status);
|
|
224
|
-
console.log('Start time:', new Date(rentalState.startTime.toNumber() * 1000));
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Error Handling
|
|
228
|
-
|
|
229
|
-
The SDK provides custom error types for better debugging:
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
import { SrslyError } from '@wuwei-labs/srsly';
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
const instruction = await createContract(params);
|
|
236
|
-
// Add to transaction and send...
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error instanceof SrslyError) {
|
|
239
|
-
console.error('SRSLY SDK Error:', error.message, error.code);
|
|
240
|
-
} else {
|
|
241
|
-
console.error('Other Error:', error);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Token Conversion
|
|
247
|
-
|
|
248
|
-
The SDK includes automatic ATLAS to stardust conversion for rental operations:
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
import { ATLAS_TO_STARDUST } from '@wuwei-labs/srsly';
|
|
252
|
-
|
|
253
|
-
// ATLAS_TO_STARDUST = 100_000_000 (1 ATLAS = 100 million stardust)
|
|
254
|
-
console.log('Conversion rate:', ATLAS_TO_STARDUST);
|
|
255
|
-
|
|
256
|
-
// When using acceptRental with rate and duration:
|
|
257
|
-
// Final amount = rate * duration * ATLAS_TO_STARDUST
|
|
258
|
-
// Example: 100 ATLAS * 86400 seconds * 100_000_000 = 864,000,000,000,000 stardust
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Program Information
|
|
262
|
-
|
|
263
|
-
- **Program ID**: `SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT`
|
|
264
|
-
- **Network**: Solana Mainnet or Atlasnet
|
|
265
|
-
- **Built with**: Anchor Framework
|
|
266
|
-
|
|
267
|
-
## Payment Structure
|
|
268
|
-
|
|
269
|
-
The SRSLY program implements a comprehensive payment system with escrow deposits, periodic payments, fees, and refunds. Understanding this structure is crucial for integrating rental functionality.
|
|
270
|
-
|
|
271
|
-
### Overview
|
|
272
|
-
|
|
273
|
-
```text
|
|
274
|
-
Rental Lifecycle:
|
|
275
|
-
1. Escrow Deposit (Full Payment Upfront)
|
|
276
|
-
2. Periodic Payments (Based on Payment Frequency)
|
|
277
|
-
3. Fee Collection (Platform + Referral Fees)
|
|
278
|
-
4. Owner Payments (After Fee Deduction)
|
|
279
|
-
5. Refunds (For Early Cancellation)
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### 1. Escrow Deposit
|
|
283
|
-
|
|
284
|
-
When a borrower accepts a rental, they deposit the **full rental amount upfront** into an escrow account:
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
// Example: 1000 ATLAS for 10 days = 10,000 ATLAS total
|
|
288
|
-
const acceptIx = await acceptRental({
|
|
289
|
-
borrower: wallet,
|
|
290
|
-
borrowerProfile: profileAddress,
|
|
291
|
-
borrowerFaction: 'mud',
|
|
292
|
-
fleet: fleetAddress,
|
|
293
|
-
contract: contractAddress,
|
|
294
|
-
rate: 1000, // ATLAS tokens per day
|
|
295
|
-
duration: 864000, // 10 days in seconds
|
|
296
|
-
referralTokenAccount: referrerAddress // Optional referral
|
|
297
|
-
});
|
|
298
|
-
// Total escrowed: 1000 * 10 * 100,000,000 = 1,000,000,000,000 stardust
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
**Key Points:**
|
|
302
|
-
|
|
303
|
-
- Full payment calculated as: `rate × duration × ATLAS_TO_STARDUST`
|
|
304
|
-
- Funds are held in a rental-specific escrow account
|
|
305
|
-
- Escrow is controlled by the rental state PDA
|
|
306
|
-
- No payments to owner until periodic execution
|
|
307
|
-
- **Minimum enforcement**: 24 hours from start time (if no payments) or last payment time
|
|
308
|
-
|
|
309
|
-
### 2. Periodic Payments
|
|
310
|
-
|
|
311
|
-
The system creates an automated thread that executes payments based on the contract's payment frequency:
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
// Contract with daily payments
|
|
315
|
-
const contractIx = await createContract({
|
|
316
|
-
owner: wallet,
|
|
317
|
-
fleet: fleetAddress,
|
|
318
|
-
ownerProfile: profileAddress,
|
|
319
|
-
rate: 1000,
|
|
320
|
-
durationMin: 86400, // 1 day minimum
|
|
321
|
-
durationMax: 2592000, // 30 days maximum
|
|
322
|
-
paymentsFreq: 'daily' // Payments every 24 hours
|
|
323
110
|
});
|
|
324
111
|
```
|
|
325
112
|
|
|
326
|
-
**Payment Schedule:**
|
|
327
|
-
|
|
328
|
-
- **Daily**: Payments execute daily at 00:00 UTC (not every 24 hours from creation)
|
|
329
|
-
- **Weekly**: Payments execute weekly at specific day/time
|
|
330
|
-
- **Monthly**: Payments execute monthly at specific day/time
|
|
331
|
-
|
|
332
|
-
**Pro-rata Calculation:**
|
|
333
|
-
|
|
334
|
-
Each payment is calculated based on elapsed time since the last payment:
|
|
335
|
-
|
|
336
|
-
```text
|
|
337
|
-
payment_amount = (elapsed_time / frequency_seconds) × rate × ATLAS_TO_STARDUST
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
### 3. Fee Structure
|
|
341
|
-
|
|
342
|
-
Each payment is subject to a **10% platform fee** with optional **10% referral sharing**:
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
// Constants from the program
|
|
346
|
-
const SERVICE_FEE_BPS = 1000; // 10% platform fee
|
|
347
|
-
const REFERRAL_BPS = 1000; // 10% of total fee to referral
|
|
348
|
-
const BASE_BPS = 10000; // 100% in basis points
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
**Fee Calculation:**
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
// For each payment amount
|
|
355
|
-
const totalFee = paymentAmount * SERVICE_FEE_BPS / BASE_BPS; // 10% of payment
|
|
356
|
-
const referralFee = totalFee * REFERRAL_BPS / BASE_BPS; // 10% of total fee
|
|
357
|
-
const platformFee = totalFee - referralFee; // 90% of total fee
|
|
358
|
-
const ownerPayment = paymentAmount - totalFee; // 90% of payment
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
**Example Payment Breakdown:**
|
|
362
|
-
|
|
363
|
-
```text
|
|
364
|
-
Payment Amount: 1000 ATLAS
|
|
365
|
-
├── Total Fee (10%): 100 ATLAS
|
|
366
|
-
│ ├── Referral Fee (10% of total fee): 10 ATLAS → Referrer
|
|
367
|
-
│ └── Platform Fee (90% of total fee): 90 ATLAS → Platform
|
|
368
|
-
└── Owner Payment (90%): 900 ATLAS → Fleet Owner
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### 4. Payment Distribution
|
|
372
|
-
|
|
373
|
-
Each periodic payment is distributed in this order:
|
|
374
|
-
|
|
375
|
-
1. **Referral Payment** (if referrer exists and ≠ system_program::ID)
|
|
376
|
-
- Amount: `total_fee × REFERRAL_BPS ÷ BASE_BPS`
|
|
377
|
-
- Destination: Referrer's token account
|
|
378
|
-
|
|
379
|
-
2. **Platform Fee Payment**
|
|
380
|
-
- Amount: `total_fee - referral_payment`
|
|
381
|
-
- Destination: Platform fee account
|
|
382
|
-
|
|
383
|
-
3. **Owner Payment**
|
|
384
|
-
- Amount: `payment_amount - total_fee`
|
|
385
|
-
- Destination: Fleet owner's token account
|
|
386
|
-
|
|
387
|
-
**Code Example:**
|
|
388
|
-
|
|
389
|
-
```typescript
|
|
390
|
-
// Accept rental with referral
|
|
391
|
-
const acceptIx = await acceptRental({
|
|
392
|
-
borrower: wallet,
|
|
393
|
-
borrowerProfile: profileAddress,
|
|
394
|
-
borrowerFaction: 'mud',
|
|
395
|
-
fleet: fleetAddress,
|
|
396
|
-
contract: contractAddress,
|
|
397
|
-
rate: 1000,
|
|
398
|
-
duration: 86400,
|
|
399
|
-
referralTokenAccount: referrerTokenAccount // 10% of fees
|
|
400
|
-
});
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
### 5. Refund Mechanism
|
|
404
|
-
|
|
405
|
-
Refunds occur when rentals are cancelled early or when contracts are closed. **Important: All rentals enforce a minimum 24-hour active period from either the start time (if no payments made) or the last payment time.**
|
|
406
|
-
|
|
407
|
-
**Early Cancellation:**
|
|
408
|
-
|
|
409
|
-
```typescript
|
|
410
|
-
const cancelIx = await cancelRental({
|
|
411
|
-
borrower: wallet,
|
|
412
|
-
contract: contractAddress,
|
|
413
|
-
rentalState: rentalStateAddress
|
|
414
|
-
});
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
**Refund Scenarios:**
|
|
418
|
-
|
|
419
|
-
- **Before First Payment**: Rental remains active for 24 hours from start time, pro-rata refund for remaining time
|
|
420
|
-
- **After Payment(s) Made**: Rental remains active for 24 hours from last payment time, pro-rata refund for remaining time
|
|
421
|
-
- **Contract Closure**: Any remaining escrow returned to borrower
|
|
422
|
-
|
|
423
|
-
### 6. Payment Timeline Example
|
|
424
|
-
|
|
425
|
-
**Scenario**: 10-day rental with daily payments, 1000 ATLAS/day rate
|
|
426
|
-
|
|
427
|
-
```text
|
|
428
|
-
Day 0: Rental Accepted
|
|
429
|
-
├── Escrow: 10,000 ATLAS deposited
|
|
430
|
-
├── Thread: Created for daily execution at 00:00 UTC
|
|
431
|
-
├── Fleet: Transferred to borrower
|
|
432
|
-
└── Minimum 24-hour commitment begins (from start time)
|
|
433
|
-
|
|
434
|
-
00:00 UTC Next Day: First Payment
|
|
435
|
-
├── Amount: 1,000 ATLAS from escrow
|
|
436
|
-
├── Total Fee (10%): 100 ATLAS
|
|
437
|
-
│ ├── Referrer: 10 ATLAS (10% of total fee)
|
|
438
|
-
│ └── Platform: 90 ATLAS (90% of total fee)
|
|
439
|
-
├── Owner: 900 ATLAS (90% of payment)
|
|
440
|
-
├── Escrow: 9,000 ATLAS remaining
|
|
441
|
-
└── New 24-hour minimum period begins (from payment time)
|
|
442
|
-
|
|
443
|
-
Daily at 00:00 UTC: Subsequent Payments
|
|
444
|
-
├── Same distribution pattern
|
|
445
|
-
├── Escrow decreases by 1,000 ATLAS each day
|
|
446
|
-
└── Each payment resets 24-hour minimum period
|
|
447
|
-
|
|
448
|
-
Final Day at 00:00 UTC: Final Payment & Cleanup
|
|
449
|
-
├── Final payment processed
|
|
450
|
-
├── Thread: Automatically closed
|
|
451
|
-
├── Rental State: Closed, lamports to borrower
|
|
452
|
-
└── Fleet: Returned to owner or contract
|
|
453
|
-
|
|
454
|
-
Early Cancellation Examples:
|
|
455
|
-
|
|
456
|
-
Scenario A - Cancel before first payment (Day 0 at 6 PM):
|
|
457
|
-
├── Cancelled 6 hours after start
|
|
458
|
-
├── Rental extends until 24 hours from start time (Day 1 at start time)
|
|
459
|
-
├── Pro-rata refund calculated from Day 1 extended end onwards
|
|
460
|
-
└── Borrower receives refund for Days 1-10
|
|
461
|
-
|
|
462
|
-
Scenario B - Cancel after payments made (Day 3 at 6 PM):
|
|
463
|
-
├── Cancelled 18 hours after Day 3 payment (00:00 UTC)
|
|
464
|
-
├── Rental extends until 24 hours from last payment (Day 4 at 00:00 UTC)
|
|
465
|
-
├── Pro-rata refund calculated from Day 4 onwards
|
|
466
|
-
└── Borrower receives refund for Days 4-10
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
### 7. Edge Cases
|
|
470
|
-
|
|
471
|
-
**Insufficient Escrow Balance:**
|
|
472
|
-
|
|
473
|
-
- Payment amount is limited to available escrow balance
|
|
474
|
-
- Remaining balance distributed proportionally
|
|
475
|
-
|
|
476
|
-
**Early Termination:**
|
|
477
|
-
|
|
478
|
-
- **Cancellation Notice**: Must have more than one payment period remaining to cancel
|
|
479
|
-
- **Minimum Period Enforcement**:
|
|
480
|
-
- Before first payment: Active for 24 hours from start time
|
|
481
|
-
- After payment(s): Active for 24 hours from last payment time
|
|
482
|
-
- **Pro-rata Refund**: Refund calculated from the enforced minimum end time
|
|
483
|
-
- Fleet returned to owner when minimum period expires
|
|
484
|
-
- Payment thread continues until minimum period ends
|
|
485
|
-
|
|
486
|
-
**Contract Closure:**
|
|
487
|
-
|
|
488
|
-
- Final payment processed if rental active
|
|
489
|
-
- All remaining resources cleaned up
|
|
490
|
-
- Fleet rental capability removed
|
|
491
|
-
|
|
492
|
-
## Payment Frequencies
|
|
493
|
-
|
|
494
|
-
The SDK supports multiple payment frequencies:
|
|
495
|
-
|
|
496
|
-
- `daily` - Daily payments at 00:00 UTC
|
|
497
|
-
- `weekly` - Weekly payments at specific day/time
|
|
498
|
-
- `monthly` - Monthly payments at specific day/time
|
|
499
|
-
|
|
500
|
-
|
|
501
113
|
## Network Configuration
|
|
502
114
|
|
|
503
|
-
The SDK supports
|
|
504
|
-
|
|
505
|
-
### What `setConfig` Does:
|
|
506
|
-
|
|
507
|
-
**1. Network Selection (IDL/Module Loading):**
|
|
508
|
-
- ✅ Selects which IDL artifacts to use (`mainnet` vs `atlasnet`)
|
|
509
|
-
- ✅ Loads appropriate codama-generated instruction builders
|
|
510
|
-
- ✅ Determines default program addresses for the network
|
|
115
|
+
The SDK supports multiple network configurations:
|
|
511
116
|
|
|
512
|
-
|
|
513
|
-
- ✅ Select predefined program address sets (mainnet, atlasnet, holosim)
|
|
514
|
-
- ✅ Override specific program addresses (SRSLY, SAGE, Profile Faction)
|
|
515
|
-
- ✅ Override game IDs and other network constants
|
|
516
|
-
- ✅ Mix and match programs across networks if needed
|
|
517
|
-
|
|
518
|
-
**What it does NOT do:**
|
|
519
|
-
- ❌ Configure RPC endpoints
|
|
520
|
-
- ❌ Handle wallet connections
|
|
521
|
-
- ❌ Manage transactions
|
|
522
|
-
|
|
523
|
-
### Global Configuration (Recommended)
|
|
524
|
-
|
|
525
|
-
Set default configuration once for all SDK operations:
|
|
117
|
+
### Global Configuration
|
|
526
118
|
|
|
527
119
|
```typescript
|
|
528
|
-
import { setConfig, getConfig,
|
|
529
|
-
|
|
530
|
-
// Example 1: Use mainnet IDL with default mainnet program addresses
|
|
531
|
-
setConfig({
|
|
532
|
-
network: 'mainnet'
|
|
533
|
-
});
|
|
120
|
+
import { setConfig, getConfig, clearConfig } from '@wuwei-labs/srsly';
|
|
534
121
|
|
|
535
|
-
//
|
|
536
|
-
setConfig({
|
|
537
|
-
network: 'atlasnet'
|
|
538
|
-
});
|
|
122
|
+
// Use mainnet programs
|
|
123
|
+
setConfig({ programs: 'mainnet' });
|
|
539
124
|
|
|
540
|
-
//
|
|
541
|
-
setConfig({
|
|
542
|
-
network: 'atlasnet',
|
|
543
|
-
programs: 'holosim'
|
|
544
|
-
});
|
|
125
|
+
// Use atlasnet programs (default)
|
|
126
|
+
setConfig({ programs: 'atlasnet' });
|
|
545
127
|
|
|
546
|
-
//
|
|
547
|
-
setConfig({
|
|
548
|
-
network: 'atlasnet',
|
|
549
|
-
programs: 'holosim',
|
|
550
|
-
sageProgramAddress: 'custom-sage-program-id...'
|
|
551
|
-
});
|
|
128
|
+
// Use holosim test programs
|
|
129
|
+
setConfig({ programs: 'holosim' });
|
|
552
130
|
|
|
553
|
-
//
|
|
131
|
+
// Custom configuration
|
|
554
132
|
setConfig({
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
// Example 6: Custom overrides only
|
|
560
|
-
setConfig({
|
|
561
|
-
network: 'atlasnet',
|
|
562
|
-
srslyProgramAddress: 'custom-srsly-program-id...',
|
|
563
|
-
sageProgramAddress: 'custom-sage-program-id...',
|
|
133
|
+
programs: 'mainnet',
|
|
134
|
+
sageProgramAddress: 'custom-sage-program...',
|
|
564
135
|
gameId: 'custom-game-id...'
|
|
565
136
|
});
|
|
566
137
|
|
|
567
|
-
// Check current
|
|
138
|
+
// Check current config
|
|
568
139
|
console.log(getConfig());
|
|
569
140
|
|
|
570
|
-
//
|
|
571
|
-
|
|
572
|
-
const ix2 = await acceptRental(params); // Uses configured SAGE program
|
|
141
|
+
// Reset to defaults
|
|
142
|
+
clearConfig();
|
|
573
143
|
```
|
|
574
144
|
|
|
575
145
|
### Per-Instruction Configuration
|
|
576
146
|
|
|
577
|
-
Override global program address configuration for specific instructions using the fluent `.set()` interface:
|
|
578
|
-
|
|
579
147
|
```typescript
|
|
580
|
-
|
|
148
|
+
// Override global config for specific instructions
|
|
149
|
+
const ix = await createContract(params).set({ programs: 'mainnet' });
|
|
581
150
|
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const mainnetIx = await createContract(params);
|
|
587
|
-
|
|
588
|
-
// Override to use atlasnet program addresses for this specific instruction
|
|
589
|
-
const atlasnetIx = await createContract(params).set({ network: 'atlasnet' });
|
|
590
|
-
|
|
591
|
-
// Override specific program addresses while keeping global network
|
|
592
|
-
const customIx = await createContract(params).set({
|
|
593
|
-
sageProgramAddress: 'custom-sage-program-id...',
|
|
594
|
-
gameId: 'custom-game-id...'
|
|
595
|
-
// network: 'mainnet' inherited from global config
|
|
596
|
-
});
|
|
151
|
+
// Chain multiple configurations
|
|
152
|
+
const ix2 = await acceptRental(params)
|
|
153
|
+
.set({ programs: 'holosim' })
|
|
154
|
+
.set({ gameId: 'custom-game-id...' });
|
|
597
155
|
```
|
|
598
156
|
|
|
599
|
-
|
|
157
|
+
## Payment System
|
|
600
158
|
|
|
601
|
-
|
|
159
|
+
SRSLY implements an escrow-based payment system:
|
|
602
160
|
|
|
603
|
-
**
|
|
161
|
+
1. **Escrow**: Borrower deposits full rental amount upfront
|
|
162
|
+
2. **Periodic Payments**: Automated payments based on frequency (daily/weekly/monthly)
|
|
163
|
+
3. **Fees**: 10% platform fee, optional 10% referral sharing
|
|
164
|
+
4. **Refunds**: Pro-rata refunds for early cancellation (24-hour minimum)
|
|
604
165
|
|
|
605
166
|
```typescript
|
|
606
|
-
//
|
|
607
|
-
|
|
608
|
-
|
|
167
|
+
// Payment calculation
|
|
168
|
+
const rate = 1000; // ATLAS per day
|
|
169
|
+
const duration = 86400; // 1 day in seconds
|
|
170
|
+
const totalAmount = rate * duration * ATLAS_TO_STARDUST; // in stardust
|
|
609
171
|
```
|
|
610
172
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
- `setConfig({ network: 'mainnet', gameId: '...' })` - Set global program addresses
|
|
614
|
-
- `getConfig()` - Get current global configuration
|
|
615
|
-
- `clearConfig()` - Reset to atlasnet programs
|
|
616
|
-
|
|
617
|
-
**Per-instruction overrides with `.set()` method:**
|
|
618
|
-
|
|
619
|
-
- `.set({ network: 'mainnet' })` - Override to mainnet program addresses
|
|
620
|
-
- `.set({ sageProgramAddress: '...' })` - Override specific program address only
|
|
621
|
-
- `.set({ network: 'mainnet', sageProgramAddress: '...' })` - Multiple overrides
|
|
622
|
-
|
|
623
|
-
**Chainable configurations:**
|
|
624
|
-
|
|
625
|
-
```typescript
|
|
626
|
-
// Chain multiple configurations (later ones override earlier ones)
|
|
627
|
-
await createContract(params)
|
|
628
|
-
.set({ network: 'atlasnet' })
|
|
629
|
-
.set({ sageProgramAddress: 'override...' });
|
|
630
|
-
|
|
631
|
-
// Examples with global config
|
|
632
|
-
setConfig({ network: 'mainnet' });
|
|
633
|
-
await createContract(params); // Uses mainnet program addresses
|
|
634
|
-
await acceptRental(params).set({ network: 'atlasnet' }); // Override to atlasnet programs
|
|
635
|
-
await closeContract(params).set({ gameId: 'custom...' }); // Custom gameId, mainnet programs
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
### Available Configuration Options
|
|
639
|
-
|
|
640
|
-
```typescript
|
|
641
|
-
interface ConfigOptions {
|
|
642
|
-
network?: 'mainnet' | 'atlasnet'; // Which IDL artifacts to use
|
|
643
|
-
programs?: 'mainnet' | 'atlasnet' | 'holosim'; // Which program address set to use
|
|
644
|
-
srslyProgramAddress?: string; // Override SRSLY program address
|
|
645
|
-
sageProgramAddress?: string; // Override SAGE program address
|
|
646
|
-
profileFactionProgramAddress?: string; // Override Profile Faction program address
|
|
647
|
-
gameId?: string; // Override SAGE game ID
|
|
648
|
-
}
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
**Available Program Address Sets:**
|
|
652
|
-
|
|
653
|
-
```typescript
|
|
654
|
-
// mainnet
|
|
655
|
-
{
|
|
656
|
-
srslyProgram: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT',
|
|
657
|
-
sageProgram: 'SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE',
|
|
658
|
-
profileFactionProgram: 'pFACSRuobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq',
|
|
659
|
-
gameId: 'GAMEzqJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr'
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// atlasnet (default) - values currently empty, to be filled
|
|
663
|
-
{
|
|
664
|
-
srslyProgram: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT',
|
|
665
|
-
sageProgram: '',
|
|
666
|
-
profileFactionProgram: '',
|
|
667
|
-
gameId: ''
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
// holosim
|
|
671
|
-
{
|
|
672
|
-
srslyProgram: 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT',
|
|
673
|
-
sageProgram: 'SAgeTraQfBMdvGVDJYoEvjnbq5szW7RJPi6obDTDQUF',
|
|
674
|
-
profileFactionProgram: 'PprofUW1pURCnMW2si88GWPXEEK3Bvh9Tksy8WtnoYJ',
|
|
675
|
-
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k'
|
|
676
|
-
}
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
**Priority Order:**
|
|
680
|
-
1. Individual overrides (highest priority)
|
|
681
|
-
2. programs configuration
|
|
682
|
-
3. Network default (if programs not specified)
|
|
683
|
-
|
|
684
|
-
**Key Concepts:**
|
|
685
|
-
|
|
686
|
-
- **Network** = Which IDL/codama artifacts to load (affects instruction structure)
|
|
687
|
-
- **programs** = Which predefined program address set to use (mainnet, atlasnet, holosim)
|
|
688
|
-
- **Program Overrides** = Override individual program addresses (highest priority)
|
|
689
|
-
- **Default Behavior** = If programs not specified, uses network's program addresses
|
|
690
|
-
- **Flexibility** = Mix any IDL with any program set, plus individual overrides
|
|
691
|
-
|
|
692
|
-
### Network-Specific Constants
|
|
693
|
-
|
|
694
|
-
The SDK automatically resolves network-specific constants:
|
|
173
|
+
## Available Networks
|
|
695
174
|
|
|
696
175
|
```typescript
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
// Get constants for atlasnet (default)
|
|
704
|
-
const sageProgram = await getSageProgramAddress();
|
|
705
|
-
const gameId = await getSageGameId();
|
|
706
|
-
|
|
707
|
-
// Get constants for specific network
|
|
708
|
-
const mainnetSageProgram = await getSageProgramAddress({ network: 'mainnet' });
|
|
709
|
-
const mainnetGameId = await getSageGameId({ network: 'mainnet' });
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
## IDL and Types
|
|
713
|
-
|
|
714
|
-
### Network-Specific IDLs
|
|
715
|
-
|
|
716
|
-
The SDK provides network-specific IDLs since program configurations differ between networks:
|
|
717
|
-
|
|
718
|
-
```typescript
|
|
719
|
-
// Mainnet IDL
|
|
720
|
-
import mainnetIdl from '@wuwei-labs/srsly/idl/mainnet';
|
|
721
|
-
|
|
722
|
-
// Devnet IDL
|
|
723
|
-
import atlasnetIdl from '@wuwei-labs/srsly/idl/atlasnet';
|
|
724
|
-
|
|
725
|
-
// Use with Anchor
|
|
726
|
-
import { Program } from '@coral-xyz/anchor';
|
|
727
|
-
const program = new Program(mainnetIdl, provider);
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
### Network-Specific Types
|
|
731
|
-
|
|
732
|
-
Import TypeScript types that match your target network:
|
|
733
|
-
|
|
734
|
-
```typescript
|
|
735
|
-
import type {
|
|
736
|
-
ContractState,
|
|
737
|
-
RentalState,
|
|
738
|
-
PaymentFrequency,
|
|
739
|
-
ClockData,
|
|
740
|
-
ThreadResponse,
|
|
741
|
-
ConfigOptions
|
|
742
|
-
} from '@wuwei-labs/srsly';
|
|
743
|
-
|
|
744
|
-
// Import network-specific Anchor types
|
|
745
|
-
import type { Srsly as SrslyMainnet } from '@wuwei-labs/srsly/types/mainnet';
|
|
746
|
-
import type { Srsly as SrslyDevnet } from '@wuwei-labs/srsly/types/atlasnet';
|
|
747
|
-
```
|
|
748
|
-
|
|
749
|
-
### Accessing Packaged IDLs
|
|
750
|
-
|
|
751
|
-
The SDK includes pre-packaged IDL (Interface Definition Language) files for each network. These IDL files contain the complete program interface definition and can be accessed in multiple ways:
|
|
752
|
-
|
|
753
|
-
#### 1. Import IDL as JavaScript/TypeScript Module
|
|
754
|
-
|
|
755
|
-
```typescript
|
|
756
|
-
// CommonJS
|
|
757
|
-
const mainnetIdl = require('@wuwei-labs/srsly/idl/mainnet');
|
|
758
|
-
const atlasnetIdl = require('@wuwei-labs/srsly/idl/atlasnet');
|
|
759
|
-
|
|
760
|
-
// ES Modules
|
|
761
|
-
import mainnetIdl from '@wuwei-labs/srsly/idl/mainnet';
|
|
762
|
-
import atlasnetIdl from '@wuwei-labs/srsly/idl/atlasnet';
|
|
763
|
-
|
|
764
|
-
// Use with Anchor
|
|
765
|
-
import { Program } from '@coral-xyz/anchor';
|
|
766
|
-
const program = new Program(mainnetIdl, provider);
|
|
767
|
-
```
|
|
768
|
-
|
|
769
|
-
#### 2. Access Raw IDL JSON Files
|
|
770
|
-
|
|
771
|
-
The raw IDL JSON files are included in the npm package and can be found at:
|
|
772
|
-
|
|
773
|
-
```
|
|
774
|
-
node_modules/@wuwei-labs/srsly/target/idl/srsly-mainnet.json
|
|
775
|
-
node_modules/@wuwei-labs/srsly/target/idl/srsly-atlasnet.json
|
|
776
|
-
```
|
|
777
|
-
|
|
778
|
-
You can read these files directly if you need the raw JSON:
|
|
779
|
-
|
|
780
|
-
```typescript
|
|
781
|
-
// Using Node.js fs
|
|
782
|
-
import fs from 'fs';
|
|
783
|
-
import path from 'path';
|
|
784
|
-
|
|
785
|
-
const idlPath = path.join(
|
|
786
|
-
require.resolve('@wuwei-labs/srsly/package.json'),
|
|
787
|
-
'../target/idl/srsly-mainnet.json'
|
|
788
|
-
);
|
|
789
|
-
const idlJson = JSON.parse(fs.readFileSync(idlPath, 'utf-8'));
|
|
790
|
-
|
|
791
|
-
// Using dynamic import (works in browsers with bundlers)
|
|
792
|
-
const idlModule = await import('@wuwei-labs/srsly/idl/mainnet');
|
|
793
|
-
const idl = idlModule.default;
|
|
794
|
-
```
|
|
795
|
-
|
|
796
|
-
#### 3. IDL Structure
|
|
797
|
-
|
|
798
|
-
Each IDL file contains:
|
|
799
|
-
|
|
800
|
-
- **address**: The program's on-chain address
|
|
801
|
-
- **metadata**: Program name, version, and description
|
|
802
|
-
- **instructions**: All available program instructions with their discriminators
|
|
803
|
-
- **accounts**: Account structures used by the program
|
|
804
|
-
- **types**: Custom types and enums defined in the program
|
|
805
|
-
- **errors**: Custom error codes and messages
|
|
806
|
-
|
|
807
|
-
Example IDL structure:
|
|
808
|
-
```json
|
|
809
|
-
{
|
|
810
|
-
"address": "SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT",
|
|
811
|
-
"metadata": {
|
|
812
|
-
"name": "srsly",
|
|
813
|
-
"version": "0.1.0",
|
|
814
|
-
"spec": "0.1.0"
|
|
176
|
+
// Program address sets
|
|
177
|
+
const networks = {
|
|
178
|
+
mainnet: {
|
|
179
|
+
sageProgram: 'SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE',
|
|
180
|
+
gameId: 'GAMEzqJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr'
|
|
815
181
|
},
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
182
|
+
atlasnet: {
|
|
183
|
+
sageProgram: 'SAgeTraQfBMdvGVDJYoEvjnbq5szW7RJPi6obDTDQUF',
|
|
184
|
+
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k'
|
|
185
|
+
},
|
|
186
|
+
holosim: {
|
|
187
|
+
sageProgram: 'SAgeTraQfBMdvGVDJYoEvjnbq5szW7RJPi6obDTDQUF',
|
|
188
|
+
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k'
|
|
189
|
+
}
|
|
190
|
+
};
|
|
820
191
|
```
|
|
821
192
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
The main difference between network IDLs is the mint addresses used:
|
|
825
|
-
- **Mainnet**: Uses production ATLAS mint (`ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx`)
|
|
826
|
-
- **Atlasnet**: Uses test ATLAS mint (`ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx`)
|
|
827
|
-
|
|
828
|
-
#### 5. Using IDLs with Other Tools
|
|
829
|
-
|
|
830
|
-
The packaged IDLs are compatible with:
|
|
831
|
-
- **Anchor Framework**: Use directly with `new Program(idl, provider)`
|
|
832
|
-
- **Solana Playground**: Import the JSON for program interaction
|
|
833
|
-
- **Custom Clients**: Parse the IDL to generate your own client code
|
|
834
|
-
- **Testing Frameworks**: Use for mocking program interfaces
|
|
835
|
-
|
|
836
|
-
### Accessing Packaged TypeScript Types
|
|
837
|
-
|
|
838
|
-
The SDK includes comprehensive TypeScript type definitions that are automatically generated from the program IDL. These types ensure type safety when building instructions and handling program data.
|
|
839
|
-
|
|
840
|
-
#### 1. Import SDK Types
|
|
841
|
-
|
|
842
|
-
The main types are exported from the package root:
|
|
193
|
+
## Types and Constants
|
|
843
194
|
|
|
844
195
|
```typescript
|
|
845
|
-
import type {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
RentalState,
|
|
849
|
-
Fleet,
|
|
850
|
-
|
|
851
|
-
// Instruction types
|
|
852
|
-
CreateContractInstruction,
|
|
853
|
-
AcceptRentalInstruction,
|
|
854
|
-
CloseContractInstruction,
|
|
855
|
-
|
|
856
|
-
// Data types
|
|
857
|
-
ClockData,
|
|
858
|
-
ThreadResponse,
|
|
859
|
-
PaymentFrequency,
|
|
860
|
-
|
|
861
|
-
// Configuration types
|
|
196
|
+
import type {
|
|
197
|
+
ContractState,
|
|
198
|
+
RentalState,
|
|
862
199
|
ConfigOptions,
|
|
863
|
-
|
|
200
|
+
PaymentFrequency
|
|
864
201
|
} from '@wuwei-labs/srsly';
|
|
865
|
-
```
|
|
866
|
-
|
|
867
|
-
#### 2. Network-Specific Anchor Types
|
|
868
|
-
|
|
869
|
-
Access the complete Anchor-generated types for each network:
|
|
870
|
-
|
|
871
|
-
```typescript
|
|
872
|
-
// Import network-specific program types
|
|
873
|
-
import type { Srsly as SrslyMainnet } from '@wuwei-labs/srsly/types/mainnet';
|
|
874
|
-
import type { Srsly as SrslyAtlasnet } from '@wuwei-labs/srsly/types/atlasnet';
|
|
875
202
|
|
|
876
|
-
// These include all program types, accounts, and instructions
|
|
877
|
-
type MainnetProgram = SrslyMainnet;
|
|
878
|
-
type AtlasnetProgram = SrslyAtlasnet;
|
|
879
|
-
|
|
880
|
-
// Access specific account types
|
|
881
|
-
type MainnetContractAccount = SrslyMainnet['accounts']['contract'];
|
|
882
|
-
type AtlasnetRentalAccount = SrslyAtlasnet['accounts']['rental'];
|
|
883
|
-
```
|
|
884
|
-
|
|
885
|
-
#### 3. Codama-Generated Types
|
|
886
|
-
|
|
887
|
-
For advanced use cases, access the auto-generated Codama types directly:
|
|
888
|
-
|
|
889
|
-
```typescript
|
|
890
|
-
// Import specific codama-generated types
|
|
891
|
-
import type {
|
|
892
|
-
Contract,
|
|
893
|
-
Rental,
|
|
894
|
-
contractDiscriminator
|
|
895
|
-
} from '@wuwei-labs/srsly/dist/types/codama/mainnet/accounts';
|
|
896
|
-
|
|
897
|
-
import type {
|
|
898
|
-
createContract,
|
|
899
|
-
CreateContractInstructionAccounts,
|
|
900
|
-
CreateContractInstructionData
|
|
901
|
-
} from '@wuwei-labs/srsly/dist/types/codama/mainnet/instructions';
|
|
902
|
-
|
|
903
|
-
// Network-specific imports
|
|
904
|
-
import { SRSLY_PROGRAM_ADDRESS } from '@wuwei-labs/srsly/dist/types/codama/mainnet';
|
|
905
|
-
```
|
|
906
|
-
|
|
907
|
-
#### 4. Type File Locations in Package
|
|
908
|
-
|
|
909
|
-
The TypeScript definition files are distributed in the npm package at:
|
|
910
|
-
|
|
911
|
-
```
|
|
912
|
-
node_modules/@wuwei-labs/srsly/
|
|
913
|
-
├── dist/types/ # Compiled TypeScript definitions
|
|
914
|
-
│ ├── index.d.ts # Main entry point
|
|
915
|
-
│ ├── contract/ # Contract operation types
|
|
916
|
-
│ ├── rental/ # Rental operation types
|
|
917
|
-
│ ├── utils/ # Utility types and constants
|
|
918
|
-
│ └── codama/ # Auto-generated types
|
|
919
|
-
│ ├── mainnet/ # Mainnet-specific types
|
|
920
|
-
│ └── atlasnet/ # Atlasnet-specific types
|
|
921
|
-
└── target/types/ # Anchor-generated types
|
|
922
|
-
├── srsly-mainnet.ts # Mainnet Anchor types
|
|
923
|
-
└── srsly-atlasnet.ts # Atlasnet Anchor types
|
|
924
|
-
```
|
|
925
|
-
|
|
926
|
-
#### 5. Using Types in Your Application
|
|
927
|
-
|
|
928
|
-
```typescript
|
|
929
|
-
import { createContract } from '@wuwei-labs/srsly';
|
|
930
|
-
import type { ContractState, CreateContractInstruction } from '@wuwei-labs/srsly';
|
|
931
|
-
|
|
932
|
-
// Type-safe instruction building
|
|
933
|
-
async function buildContractInstruction(): Promise<CreateContractInstruction> {
|
|
934
|
-
const instruction = await createContract({
|
|
935
|
-
owner: ownerPublicKey,
|
|
936
|
-
fleet: fleetPublicKey,
|
|
937
|
-
ownerProfile: profilePublicKey,
|
|
938
|
-
rate: 1000000,
|
|
939
|
-
durationMin: 86400,
|
|
940
|
-
durationMax: 604800,
|
|
941
|
-
paymentsFreq: 'daily',
|
|
942
|
-
ownerKeyIndex: 0
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
return instruction; // Type: CreateContractInstruction
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
// Type-safe account decoding
|
|
949
|
-
function handleContract(account: ContractState) {
|
|
950
|
-
console.log('Rate:', account.rate.toString());
|
|
951
|
-
console.log('Owner:', account.owner.toBase58());
|
|
952
|
-
console.log('Fleet:', account.fleet.toBase58());
|
|
953
|
-
}
|
|
954
|
-
```
|
|
955
|
-
|
|
956
|
-
#### 6. Type Categories
|
|
957
|
-
|
|
958
|
-
The SDK types are organized into several categories:
|
|
959
|
-
|
|
960
|
-
- **Account Types**: Represent on-chain account data structures (`ContractState`, `RentalState`)
|
|
961
|
-
- **Instruction Types**: Type definitions for each program instruction
|
|
962
|
-
- **Utility Types**: Helper types like `PaymentFrequency`, `FactionType`
|
|
963
|
-
- **Configuration Types**: Types for SDK configuration (`ConfigOptions`, `NetworkType`)
|
|
964
|
-
- **Codama Types**: Low-level auto-generated types from the IDL
|
|
965
|
-
|
|
966
|
-
#### 7. Type Safety Benefits
|
|
967
|
-
|
|
968
|
-
Using the packaged types provides:
|
|
969
|
-
|
|
970
|
-
- **Compile-time validation** of instruction parameters
|
|
971
|
-
- **IntelliSense support** in your IDE
|
|
972
|
-
- **Automatic type inference** for decoded accounts
|
|
973
|
-
- **Network-specific type checking** to prevent cross-network errors
|
|
974
|
-
- **Version compatibility** between your client and the on-chain program
|
|
975
|
-
|
|
976
|
-
## Constants and Utilities
|
|
977
|
-
|
|
978
|
-
### Available Constants
|
|
979
|
-
|
|
980
|
-
```typescript
|
|
981
203
|
import {
|
|
982
204
|
ATLAS_TO_STARDUST,
|
|
983
|
-
|
|
984
|
-
STARBASE_PLAYER_SEED,
|
|
985
|
-
SAGE_PLAYER_PROFILE_SEED,
|
|
986
|
-
PROFILE_FACTION_SEED,
|
|
987
|
-
FACTION_MAPPING,
|
|
988
|
-
FACTION_SPECIFIC_CSS
|
|
205
|
+
FACTION_MAPPING
|
|
989
206
|
} from '@wuwei-labs/srsly';
|
|
990
207
|
|
|
991
|
-
//
|
|
208
|
+
// Conversion rate: 1 ATLAS = 100,000,000 stardust
|
|
992
209
|
console.log(ATLAS_TO_STARDUST); // 100_000_000
|
|
993
210
|
|
|
994
211
|
// Faction mappings
|
|
995
212
|
console.log(FACTION_MAPPING[1]); // 'mud'
|
|
996
|
-
console.log(FACTION_MAPPING[2]); // 'oni'
|
|
213
|
+
console.log(FACTION_MAPPING[2]); // 'oni'
|
|
997
214
|
console.log(FACTION_MAPPING[3]); // 'ustur'
|
|
998
215
|
```
|
|
999
216
|
|
|
1000
|
-
|
|
217
|
+
## IDL and Program Information
|
|
1001
218
|
|
|
1002
219
|
```typescript
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
deriveStarbase,
|
|
1007
|
-
deriveStarbasePlayer,
|
|
1008
|
-
deriveGameAccounts
|
|
1009
|
-
} from '@wuwei-labs/srsly';
|
|
1010
|
-
|
|
1011
|
-
// Derive individual accounts with network configuration
|
|
1012
|
-
const profileFaction = await deriveProfileFaction(profile, { network: 'mainnet' });
|
|
1013
|
-
const starbase = await deriveStarbase('mud', gameId, { network: 'mainnet' });
|
|
1014
|
-
|
|
1015
|
-
// Derive all game accounts at once
|
|
1016
|
-
const gameAccounts = await deriveGameAccounts(
|
|
1017
|
-
profile,
|
|
1018
|
-
'mud',
|
|
1019
|
-
gameId,
|
|
1020
|
-
0, // starbaseSeqId
|
|
1021
|
-
{ network: 'mainnet' }
|
|
1022
|
-
);
|
|
220
|
+
// Access program IDLs
|
|
221
|
+
import mainnetIdl from '@wuwei-labs/srsly/idl/mainnet';
|
|
222
|
+
import atlasnetIdl from '@wuwei-labs/srsly/idl/atlasnet';
|
|
1023
223
|
```
|
|
1024
224
|
|
|
1025
|
-
##
|
|
1026
|
-
|
|
1027
|
-
The SRSLY SDK is fully compatible with webpack bundlers. The package includes both CommonJS and ESM builds:
|
|
1028
|
-
|
|
1029
|
-
- **CommonJS**: `./dist/cjs/index.cjs` (default for Node.js and webpack)
|
|
1030
|
-
- **ESM**: `./dist/esm/index.js` (for modern ES modules)
|
|
1031
|
-
- **Types**: `./dist/types/index.d.ts` (TypeScript definitions)
|
|
1032
|
-
|
|
1033
|
-
### Webpack Configuration
|
|
1034
|
-
|
|
1035
|
-
For optimal webpack compatibility, the SDK includes:
|
|
225
|
+
## Error Handling
|
|
1036
226
|
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
- ES module interoperability
|
|
1040
|
-
- Correct module resolution for mixed ESM/CommonJS environments
|
|
1041
|
-
|
|
1042
|
-
No special webpack configuration is required. The SDK will work out-of-the-box with most webpack setups.
|
|
1043
|
-
|
|
1044
|
-
**Note**: As of version 2.0.0-beta.9, the CommonJS build uses `.cjs` file extensions to ensure proper module resolution in environments where the package.json contains `"type": "module"`.
|
|
1045
|
-
|
|
1046
|
-
### Testing Webpack Compatibility
|
|
1047
|
-
|
|
1048
|
-
```bash
|
|
1049
|
-
# Test local CommonJS exports (fast)
|
|
1050
|
-
npm run test:webpack
|
|
1051
|
-
|
|
1052
|
-
# Test actual npm package installation (comprehensive)
|
|
1053
|
-
npm run test:npm-install
|
|
1054
|
-
|
|
1055
|
-
# Test actual pnpm package installation with webpack bundling
|
|
1056
|
-
npm run test:pnpm-install
|
|
227
|
+
```typescript
|
|
228
|
+
import { SrslyError } from '@wuwei-labs/srsly';
|
|
1057
229
|
|
|
1058
|
-
|
|
1059
|
-
|
|
230
|
+
try {
|
|
231
|
+
const instruction = await createContract(params);
|
|
232
|
+
// Add to transaction and send...
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error instanceof SrslyError) {
|
|
235
|
+
console.error('SRSLY SDK Error:', error.message, error.code);
|
|
236
|
+
} else {
|
|
237
|
+
console.error('Other Error:', error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
1060
240
|
```
|
|
1061
241
|
|
|
1062
|
-
|
|
1063
|
-
- `test:webpack`: Tests local CommonJS exports that webpack uses
|
|
1064
|
-
- `test:npm-install`: Installs the actual published package via npm and tests functionality
|
|
1065
|
-
- `test:pnpm-install`: Installs via pnpm and includes a real webpack bundling test
|
|
1066
|
-
- `test:package-managers`: Runs both npm and pnpm tests
|
|
242
|
+
## Package Structure
|
|
1067
243
|
|
|
1068
|
-
|
|
244
|
+
The SDK provides optimized builds for different environments:
|
|
1069
245
|
|
|
1070
|
-
- **
|
|
246
|
+
- **CommonJS**: `./dist/cjs/` (Node.js, webpack)
|
|
247
|
+
- **ESM**: `./dist/esm/` (Modern ES modules)
|
|
248
|
+
- **Types**: `./dist/types/` (TypeScript definitions)
|
|
249
|
+
- **Shared**: `./dist/shared/codama/` (Optimized codama exports)
|
|
1071
250
|
|
|
1072
|
-
##
|
|
251
|
+
## Links
|
|
1073
252
|
|
|
1074
|
-
- **
|
|
1075
|
-
- **
|
|
1076
|
-
- **Anchor**: The framework used to build the SRSLY program
|
|
253
|
+
- **NPM Package**: [@wuwei-labs/srsly](https://www.npmjs.com/package/@wuwei-labs/srsly)
|
|
254
|
+
- **TypeDoc Documentation**: [API Reference](https://wuwei-labs.github.io/srsly/)
|