@wuwei-labs/srsly 2.0.0-beta.15 → 2.0.0-beta.17
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 +164 -927
- 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/contract/close.js +3 -3
- package/dist/cjs/contract/close.js.map +1 -1
- package/dist/cjs/contract/create.js +12 -8
- package/dist/cjs/contract/create.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/rental/accept.js +6 -6
- package/dist/cjs/rental/accept.js.map +1 -1
- package/dist/cjs/utils/config.js +12 -0
- package/dist/cjs/utils/config.js.map +1 -1
- package/dist/cjs/utils/constants.js +20 -4
- package/dist/cjs/utils/constants.js.map +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/contract/close.js +4 -4
- package/dist/esm/contract/close.js.map +1 -1
- package/dist/esm/contract/create.js +13 -9
- package/dist/esm/contract/create.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/rental/accept.js +7 -7
- package/dist/esm/rental/accept.js.map +1 -1
- package/dist/esm/utils/config.js +12 -0
- package/dist/esm/utils/config.js.map +1 -1
- package/dist/esm/utils/constants.js +18 -4
- package/dist/esm/utils/constants.js.map +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/dist/types/contract/close.d.ts +3 -3
- package/dist/types/contract/close.d.ts.map +1 -1
- package/dist/types/contract/create.d.ts +8 -3
- package/dist/types/contract/create.d.ts.map +1 -1
- package/dist/types/rental/accept.d.ts +5 -5
- package/dist/types/rental/accept.d.ts.map +1 -1
- package/dist/types/utils/config.d.ts +11 -0
- package/dist/types/utils/config.d.ts.map +1 -1
- package/dist/types/utils/constants.d.ts +12 -6
- package/dist/types/utils/constants.d.ts.map +1 -1
- package/package.json +13 -3
- package/target/idl/srsly.json +54 -54
package/README.md
CHANGED
|
@@ -4,1073 +4,310 @@
|
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://solana.com/)
|
|
6
6
|
|
|
7
|
-
A TypeScript SDK for building Solana
|
|
7
|
+
A TypeScript SDK for building and sending Solana transactions to interact with the SRSLY (Space Rental from SLY) program - a decentralized rental system for Star Atlas fleets.
|
|
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 provides:
|
|
12
12
|
|
|
13
|
-
- ✅
|
|
14
|
-
- ✅ Account derivation and validation
|
|
13
|
+
- ✅ Account derivation and validation
|
|
15
14
|
- ✅ Instruction data encoding
|
|
16
15
|
- ✅ Type-safe parameter handling
|
|
16
|
+
- 🚧 Transaction building and submission (coming soon)
|
|
17
|
+
- 🚧 RPC connection management (coming soon)
|
|
17
18
|
|
|
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
|
|
19
|
+
**Current Status**: Full instruction building support. Transaction submission via `.send()` is planned for a future release.
|
|
26
20
|
|
|
27
21
|
## Installation
|
|
28
22
|
|
|
29
|
-
### NPM
|
|
30
|
-
|
|
31
23
|
```bash
|
|
32
24
|
npm install @wuwei-labs/srsly
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### PNPM
|
|
36
|
-
|
|
37
|
-
```bash
|
|
25
|
+
# or
|
|
38
26
|
pnpm add @wuwei-labs/srsly
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Yarn
|
|
42
|
-
|
|
43
|
-
```bash
|
|
27
|
+
# or
|
|
44
28
|
yarn add @wuwei-labs/srsly
|
|
45
29
|
```
|
|
46
30
|
|
|
47
31
|
## Quick Start
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
import {
|
|
51
|
-
createContract,
|
|
52
|
-
setConfig
|
|
53
|
-
} from '@wuwei-labs/srsly';
|
|
54
|
-
|
|
55
|
-
import {
|
|
56
|
-
createDefaultSolanaRpc,
|
|
57
|
-
createTransaction,
|
|
58
|
-
appendInstructions,
|
|
59
|
-
signAndSendTransaction,
|
|
60
|
-
pipe
|
|
61
|
-
} from '@solana/kit';
|
|
33
|
+
### Current: Instruction Building
|
|
62
34
|
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
35
|
+
```typescript
|
|
36
|
+
import { createContract, setConfig } from '@wuwei-labs/srsly';
|
|
37
|
+
import { Connection, Transaction } from '@solana/web3.js';
|
|
69
38
|
|
|
70
|
-
//
|
|
71
|
-
setConfig({
|
|
39
|
+
// 1. Configure SDK for your network
|
|
40
|
+
setConfig({ programs: 'atlasnet' });
|
|
72
41
|
|
|
73
|
-
//
|
|
74
|
-
const
|
|
75
|
-
owner:
|
|
42
|
+
// 2. Build instruction
|
|
43
|
+
const instruction = await createContract({
|
|
44
|
+
owner: walletPublicKey,
|
|
76
45
|
fleet: fleetAddress,
|
|
77
46
|
ownerProfile: profileAddress,
|
|
78
|
-
rate: 1000000, //
|
|
79
|
-
durationMin: 86400, // 1 day
|
|
80
|
-
durationMax: 604800, // 1 week
|
|
81
|
-
paymentsFreq: 'daily'
|
|
82
|
-
ownerKeyIndex: 0
|
|
47
|
+
rate: 1000000, // ATLAS tokens
|
|
48
|
+
durationMin: 86400, // 1 day
|
|
49
|
+
durationMax: 604800, // 1 week
|
|
50
|
+
paymentsFreq: 'daily'
|
|
83
51
|
});
|
|
84
52
|
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
// Sign and send using wallet extension
|
|
92
|
-
const signature = await signAndSendTransaction(rpc, transaction, wallet);
|
|
93
|
-
console.log('Transaction signature:', signature);
|
|
53
|
+
// 3. Build and send transaction yourself
|
|
54
|
+
const connection = new Connection('https://api.atlasnet.solana.com');
|
|
55
|
+
const transaction = new Transaction().add(instruction);
|
|
56
|
+
const signature = await wallet.signAndSendTransaction(transaction);
|
|
94
57
|
```
|
|
95
58
|
|
|
96
|
-
|
|
59
|
+
### Future: Transaction Sending (Coming Soon)
|
|
97
60
|
|
|
98
61
|
```typescript
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
62
|
+
// This will be available in a future release:
|
|
63
|
+
const signature = await createContract({
|
|
64
|
+
owner: walletPublicKey,
|
|
65
|
+
fleet: fleetAddress,
|
|
66
|
+
ownerProfile: profileAddress,
|
|
67
|
+
rate: 1000000, // ATLAS tokens
|
|
68
|
+
durationMin: 86400, // 1 day
|
|
69
|
+
durationMax: 604800, // 1 week
|
|
70
|
+
paymentsFreq: 'daily'
|
|
71
|
+
}).send(signer); // 🚧 Not yet implemented
|
|
106
72
|
```
|
|
107
73
|
|
|
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
|
|
74
|
+
## Core Features
|
|
113
75
|
|
|
114
|
-
|
|
76
|
+
### Flexible Address Input
|
|
115
77
|
|
|
116
|
-
|
|
78
|
+
The SDK accepts both string and Address types for all address parameters, automatically converting them to the proper format:
|
|
117
79
|
|
|
118
|
-
|
|
80
|
+
```typescript
|
|
81
|
+
import { createContract, address } from '@wuwei-labs/srsly';
|
|
119
82
|
|
|
120
|
-
|
|
83
|
+
// Mixed usage allowed
|
|
84
|
+
const createIx = await createContract({
|
|
85
|
+
owner: wallet,
|
|
86
|
+
fleet: "123abc...", // string
|
|
87
|
+
ownerProfile: address("456def..."), // Address<string>
|
|
88
|
+
rate: 5000000,
|
|
89
|
+
durationMin: 86400,
|
|
90
|
+
durationMax: 2592000,
|
|
91
|
+
paymentsFreq: 'daily'
|
|
92
|
+
});
|
|
93
|
+
```
|
|
121
94
|
|
|
122
|
-
|
|
95
|
+
### Contract Management
|
|
123
96
|
|
|
124
97
|
```typescript
|
|
125
98
|
import { createContract, closeContract } from '@wuwei-labs/srsly';
|
|
126
99
|
|
|
127
|
-
// Create
|
|
100
|
+
// Create rental contract instruction
|
|
128
101
|
const createIx = await createContract({
|
|
129
102
|
owner: wallet,
|
|
130
103
|
fleet: fleetAddress,
|
|
131
104
|
ownerProfile: profileAddress,
|
|
132
|
-
rate: 5000000,
|
|
133
|
-
durationMin: 86400,
|
|
134
|
-
durationMax: 2592000,
|
|
135
|
-
paymentsFreq: 'daily'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Close an existing contract using atlasnet programs (direct await)
|
|
105
|
+
rate: 5000000,
|
|
106
|
+
durationMin: 86400,
|
|
107
|
+
durationMax: 2592000,
|
|
108
|
+
paymentsFreq: 'daily'
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Close contract instruction
|
|
140
112
|
const closeIx = await closeContract({
|
|
141
113
|
owner: wallet,
|
|
142
114
|
fleet: fleetAddress,
|
|
143
|
-
contract: contractAddress
|
|
144
|
-
faction: 'mud' // or faction number: 1, 2, 3
|
|
115
|
+
contract: contractAddress
|
|
145
116
|
});
|
|
146
117
|
```
|
|
147
118
|
|
|
148
119
|
### Rental Operations
|
|
149
120
|
|
|
150
|
-
Handle rental lifecycle operations with automatic token conversion:
|
|
151
|
-
|
|
152
121
|
```typescript
|
|
153
|
-
import {
|
|
154
|
-
acceptRental,
|
|
155
|
-
cancelRental,
|
|
156
|
-
closeRental,
|
|
157
|
-
resetRental,
|
|
158
|
-
ATLAS_TO_STARDUST
|
|
159
|
-
} from '@wuwei-labs/srsly';
|
|
122
|
+
import { acceptRental, cancelRental, closeRental } from '@wuwei-labs/srsly';
|
|
160
123
|
|
|
161
|
-
// Accept
|
|
124
|
+
// Accept rental offer instruction
|
|
162
125
|
const acceptIx = await acceptRental({
|
|
163
126
|
borrower: borrowerWallet,
|
|
164
127
|
borrowerProfile: borrowerProfileAddress,
|
|
165
|
-
borrowerFaction: '
|
|
128
|
+
borrowerFaction: 'mud', // or 1, 2, 3
|
|
166
129
|
fleet: fleetAddress,
|
|
167
130
|
contract: contractAddress,
|
|
168
|
-
rate: 100, // ATLAS
|
|
131
|
+
rate: 100, // ATLAS per day
|
|
169
132
|
duration: 86400 // 1 day in seconds
|
|
170
|
-
|
|
171
|
-
}).set({ network: 'atlasnet' });
|
|
133
|
+
});
|
|
172
134
|
|
|
173
|
-
// Cancel
|
|
135
|
+
// Cancel active rental instruction
|
|
174
136
|
const cancelIx = await cancelRental({
|
|
175
137
|
borrower: borrowerWallet,
|
|
176
138
|
contract: contractAddress,
|
|
177
139
|
rentalState: rentalStateAddress
|
|
178
140
|
});
|
|
179
141
|
|
|
180
|
-
// Close
|
|
142
|
+
// Close completed rental instruction
|
|
181
143
|
const closeIx = await closeRental({
|
|
182
144
|
borrower: borrowerWallet,
|
|
183
145
|
contract: contractAddress,
|
|
184
146
|
rentalState: rentalStateAddress,
|
|
185
147
|
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
|
-
});
|
|
324
|
-
```
|
|
325
|
-
|
|
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
148
|
});
|
|
415
149
|
```
|
|
416
150
|
|
|
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
151
|
## Network Configuration
|
|
502
152
|
|
|
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
|
|
153
|
+
The SDK supports multiple network configurations:
|
|
511
154
|
|
|
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:
|
|
155
|
+
### Global Configuration
|
|
526
156
|
|
|
527
157
|
```typescript
|
|
528
|
-
import { setConfig, getConfig,
|
|
529
|
-
|
|
530
|
-
// Example 1: Use mainnet IDL with default mainnet program addresses
|
|
531
|
-
setConfig({
|
|
532
|
-
network: 'mainnet'
|
|
533
|
-
});
|
|
158
|
+
import { setConfig, getConfig, clearConfig } from '@wuwei-labs/srsly';
|
|
534
159
|
|
|
535
|
-
//
|
|
536
|
-
setConfig({
|
|
537
|
-
network: 'atlasnet'
|
|
538
|
-
});
|
|
160
|
+
// Use mainnet programs (includes default RPC URL)
|
|
161
|
+
setConfig({ programs: 'mainnet' });
|
|
539
162
|
|
|
540
|
-
//
|
|
163
|
+
// Use atlasnet programs (default) - requires explicit RPC URL
|
|
541
164
|
setConfig({
|
|
542
|
-
|
|
543
|
-
|
|
165
|
+
programs: 'atlasnet',
|
|
166
|
+
rpcUrl: 'https://api.atlasnet.solana.com' // Required for atlasnet
|
|
544
167
|
});
|
|
545
168
|
|
|
546
|
-
//
|
|
169
|
+
// Use holosim test programs - requires explicit RPC URL
|
|
547
170
|
setConfig({
|
|
548
|
-
network: 'atlasnet',
|
|
549
171
|
programs: 'holosim',
|
|
550
|
-
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
// Example 5: Use mainnet IDL with atlasnet program addresses
|
|
554
|
-
setConfig({
|
|
555
|
-
network: 'mainnet',
|
|
556
|
-
programs: 'atlasnet'
|
|
172
|
+
rpcUrl: 'https://api.atlasnet.solana.com' // Required for holosim
|
|
557
173
|
});
|
|
558
174
|
|
|
559
|
-
//
|
|
175
|
+
// Custom configuration
|
|
560
176
|
setConfig({
|
|
561
|
-
|
|
562
|
-
srslyProgramAddress: 'custom-srsly-program
|
|
563
|
-
|
|
564
|
-
|
|
177
|
+
programs: 'mainnet',
|
|
178
|
+
srslyProgramAddress: 'custom-srsly-program...',
|
|
179
|
+
gameId: 'custom-game-id...',
|
|
180
|
+
atlasMint: 'custom-atlas-mint...'
|
|
181
|
+
// mainnet includes default RPC URL
|
|
565
182
|
});
|
|
566
183
|
|
|
567
|
-
// Check current
|
|
184
|
+
// Check current config
|
|
568
185
|
console.log(getConfig());
|
|
569
186
|
|
|
570
|
-
//
|
|
571
|
-
|
|
572
|
-
const ix2 = await acceptRental(params); // Uses configured SAGE program
|
|
187
|
+
// Reset to defaults
|
|
188
|
+
clearConfig();
|
|
573
189
|
```
|
|
574
190
|
|
|
575
191
|
### Per-Instruction Configuration
|
|
576
192
|
|
|
577
|
-
Override global program address configuration for specific instructions using the fluent `.set()` interface:
|
|
578
|
-
|
|
579
|
-
```typescript
|
|
580
|
-
import { createContract, acceptRental } from '@wuwei-labs/srsly';
|
|
581
|
-
|
|
582
|
-
// Assume global config is set to mainnet program addresses
|
|
583
|
-
setConfig({ network: 'mainnet' });
|
|
584
|
-
|
|
585
|
-
// Use global mainnet program addresses
|
|
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
|
-
});
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
### Configuration Options
|
|
600
|
-
|
|
601
|
-
All SDK functions support these usage patterns:
|
|
602
|
-
|
|
603
|
-
**Direct await (uses global config or atlasnet fallback):**
|
|
604
|
-
|
|
605
|
-
```typescript
|
|
606
|
-
// Uses global program addresses if set, otherwise atlasnet programs
|
|
607
|
-
await createContract(params);
|
|
608
|
-
await acceptRental(params);
|
|
609
|
-
```
|
|
610
|
-
|
|
611
|
-
**Global configuration functions:**
|
|
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
193
|
```typescript
|
|
654
|
-
//
|
|
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:
|
|
695
|
-
|
|
696
|
-
```typescript
|
|
697
|
-
import {
|
|
698
|
-
getSageProgramAddress,
|
|
699
|
-
getProfileFactionProgramAddress,
|
|
700
|
-
getSageGameId
|
|
701
|
-
} from '@wuwei-labs/srsly';
|
|
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
|
|
194
|
+
// Override global config for specific instructions
|
|
195
|
+
const ix = await createContract(params).set({ programs: 'mainnet' });
|
|
715
196
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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';
|
|
197
|
+
// Chain multiple configurations
|
|
198
|
+
const ix2 = await acceptRental(params)
|
|
199
|
+
.set({ programs: 'holosim' })
|
|
200
|
+
.set({ gameId: 'custom-game-id...' });
|
|
747
201
|
```
|
|
748
202
|
|
|
749
|
-
|
|
203
|
+
## Payment System
|
|
750
204
|
|
|
751
|
-
|
|
205
|
+
SRSLY implements an escrow-based payment system:
|
|
752
206
|
|
|
753
|
-
|
|
207
|
+
1. **Escrow**: Borrower deposits full rental amount upfront
|
|
208
|
+
2. **Periodic Payments**: Automated payments based on frequency (daily/weekly/monthly)
|
|
209
|
+
3. **Fees**: 10% platform fee, optional 10% referral sharing
|
|
210
|
+
4. **Refunds**: Pro-rata refunds for early cancellation (24-hour minimum)
|
|
754
211
|
|
|
755
212
|
```typescript
|
|
756
|
-
//
|
|
757
|
-
const
|
|
758
|
-
const
|
|
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
|
|
213
|
+
// Payment calculation
|
|
214
|
+
const rate = 1000; // ATLAS per day
|
|
215
|
+
const duration = 86400; // 1 day in seconds
|
|
216
|
+
const totalAmount = rate * duration * ATLAS_TO_STARDUST; // in stardust
|
|
776
217
|
```
|
|
777
218
|
|
|
778
|
-
|
|
219
|
+
## Available Networks
|
|
779
220
|
|
|
780
221
|
```typescript
|
|
781
|
-
//
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
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"
|
|
222
|
+
// Program address sets
|
|
223
|
+
const networks = {
|
|
224
|
+
mainnet: {
|
|
225
|
+
sageProgram: 'SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE',
|
|
226
|
+
gameId: 'GAMEzqJehF8yAnKiTARUuhZMvLvkZVAsCVri5vSfemLr',
|
|
227
|
+
atlasMint: 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx',
|
|
228
|
+
rpcUrl: 'https://api.mainnet-beta.solana.com' // Default RPC for mainnet
|
|
815
229
|
},
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
230
|
+
atlasnet: {
|
|
231
|
+
sageProgram: 'SAgeTraQfBMdvGVDJYoEvjnbq5szW7RJPi6obDTDQUF',
|
|
232
|
+
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k',
|
|
233
|
+
atlasMint: 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx'
|
|
234
|
+
// No default RPC - must provide rpcUrl required permissions
|
|
235
|
+
},
|
|
236
|
+
holosim: {
|
|
237
|
+
sageProgram: 'SAgeTraQfBMdvGVDJYoEvjnbq5szW7RJPi6obDTDQUF',
|
|
238
|
+
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k',
|
|
239
|
+
atlasMint: 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx'
|
|
240
|
+
// No default RPC - must provide rpcUrl required permissions
|
|
241
|
+
}
|
|
242
|
+
};
|
|
820
243
|
```
|
|
821
244
|
|
|
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
|
|
245
|
+
**Note**: Atlasnet and holosim networks require you to explicitly provide an `rpcUrl` in your configuration since they don't have default RPC endpoints.
|
|
829
246
|
|
|
830
|
-
|
|
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:
|
|
247
|
+
## Types and Constants
|
|
843
248
|
|
|
844
249
|
```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
|
|
250
|
+
import type {
|
|
251
|
+
ContractState,
|
|
252
|
+
RentalState,
|
|
862
253
|
ConfigOptions,
|
|
863
|
-
|
|
254
|
+
PaymentFrequency
|
|
864
255
|
} 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
|
-
|
|
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
256
|
|
|
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
257
|
import {
|
|
982
258
|
ATLAS_TO_STARDUST,
|
|
983
|
-
STARBASE_SEED,
|
|
984
|
-
STARBASE_PLAYER_SEED,
|
|
985
|
-
SAGE_PLAYER_PROFILE_SEED,
|
|
986
|
-
PROFILE_FACTION_SEED,
|
|
987
259
|
FACTION_MAPPING,
|
|
988
|
-
|
|
260
|
+
toAddress
|
|
989
261
|
} from '@wuwei-labs/srsly';
|
|
990
262
|
|
|
991
|
-
//
|
|
263
|
+
// Conversion rate: 1 ATLAS = 100,000,000 stardust
|
|
992
264
|
console.log(ATLAS_TO_STARDUST); // 100_000_000
|
|
993
265
|
|
|
994
266
|
// Faction mappings
|
|
995
267
|
console.log(FACTION_MAPPING[1]); // 'mud'
|
|
996
|
-
console.log(FACTION_MAPPING[2]); // 'oni'
|
|
268
|
+
console.log(FACTION_MAPPING[2]); // 'oni'
|
|
997
269
|
console.log(FACTION_MAPPING[3]); // 'ustur'
|
|
270
|
+
|
|
271
|
+
// Address conversion utility
|
|
272
|
+
const addressObj = toAddress("123abc..."); // converts string to Address<string>
|
|
273
|
+
console.log(addressObj); // Address<string>
|
|
998
274
|
```
|
|
999
275
|
|
|
1000
|
-
|
|
276
|
+
## IDL and Program Information
|
|
1001
277
|
|
|
1002
278
|
```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
|
-
);
|
|
279
|
+
// Access program IDLs
|
|
280
|
+
import mainnetIdl from '@wuwei-labs/srsly/idl/mainnet';
|
|
281
|
+
import atlasnetIdl from '@wuwei-labs/srsly/idl/atlasnet';
|
|
1023
282
|
```
|
|
1024
283
|
|
|
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:
|
|
1036
|
-
|
|
1037
|
-
- `sideEffects: false` for better tree-shaking
|
|
1038
|
-
- Proper CommonJS exports with `.cjs` extensions for webpack bundling
|
|
1039
|
-
- ES module interoperability
|
|
1040
|
-
- Correct module resolution for mixed ESM/CommonJS environments
|
|
284
|
+
## Error Handling
|
|
1041
285
|
|
|
1042
|
-
|
|
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
|
|
286
|
+
```typescript
|
|
287
|
+
import { SrslyError } from '@wuwei-labs/srsly';
|
|
1057
288
|
|
|
1058
|
-
|
|
1059
|
-
|
|
289
|
+
try {
|
|
290
|
+
const instruction = await createContract(params);
|
|
291
|
+
// Add to transaction and send...
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (error instanceof SrslyError) {
|
|
294
|
+
console.error('SRSLY SDK Error:', error.message, error.code);
|
|
295
|
+
} else {
|
|
296
|
+
console.error('Other Error:', error);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
1060
299
|
```
|
|
1061
300
|
|
|
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
|
|
301
|
+
## Package Structure
|
|
1067
302
|
|
|
1068
|
-
|
|
303
|
+
The SDK provides optimized builds for different environments:
|
|
1069
304
|
|
|
1070
|
-
- **
|
|
305
|
+
- **CommonJS**: `./dist/cjs/` (Node.js, webpack)
|
|
306
|
+
- **ESM**: `./dist/esm/` (Modern ES modules)
|
|
307
|
+
- **Types**: `./dist/types/` (TypeScript definitions)
|
|
308
|
+
- **Shared**: `./dist/shared/codama/` (Optimized codama exports)
|
|
1071
309
|
|
|
1072
|
-
##
|
|
310
|
+
## Links
|
|
1073
311
|
|
|
1074
|
-
- **
|
|
1075
|
-
- **
|
|
1076
|
-
- **Anchor**: The framework used to build the SRSLY program
|
|
312
|
+
- **NPM Package**: [@wuwei-labs/srsly](https://www.npmjs.com/package/@wuwei-labs/srsly)
|
|
313
|
+
- **TypeDoc Documentation**: [API Reference](https://wuwei-labs.github.io/srsly/)
|