@wuwei-labs/srsly 2.0.0-beta.43 → 2.0.0-beta.45
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 +27 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/rental/accept.js +28 -33
- package/dist/cjs/rental/accept.js.map +1 -1
- package/dist/cjs/rental/cancel.js +5 -2
- package/dist/cjs/rental/cancel.js.map +1 -1
- package/dist/cjs/utils/config.js +13 -33
- package/dist/cjs/utils/config.js.map +1 -1
- package/dist/cjs/utils/fetch-accounts.js +30 -48
- package/dist/cjs/utils/fetch-accounts.js.map +1 -1
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/instruction-converter.js +5 -21
- package/dist/cjs/utils/instruction-converter.js.map +1 -1
- package/dist/cjs/utils/signer.js +61 -0
- package/dist/cjs/utils/signer.js.map +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/rental/accept.js +28 -33
- package/dist/esm/rental/accept.js.map +1 -1
- package/dist/esm/rental/cancel.js +5 -2
- package/dist/esm/rental/cancel.js.map +1 -1
- package/dist/esm/utils/config.js +13 -33
- package/dist/esm/utils/config.js.map +1 -1
- package/dist/esm/utils/fetch-accounts.js +30 -48
- package/dist/esm/utils/fetch-accounts.js.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/instruction-converter.js +5 -21
- package/dist/esm/utils/instruction-converter.js.map +1 -1
- package/dist/esm/utils/signer.js +56 -0
- package/dist/esm/utils/signer.js.map +1 -0
- package/dist/types/rental/accept.d.ts +23 -13
- package/dist/types/rental/accept.d.ts.map +1 -1
- package/dist/types/rental/cancel.d.ts +3 -2
- package/dist/types/rental/cancel.d.ts.map +1 -1
- package/dist/types/utils/config.d.ts +4 -6
- package/dist/types/utils/config.d.ts.map +1 -1
- package/dist/types/utils/fetch-accounts.d.ts +35 -6
- package/dist/types/utils/fetch-accounts.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/instruction-converter.d.ts +6 -12
- package/dist/types/utils/instruction-converter.d.ts.map +1 -1
- package/dist/types/utils/signer.d.ts +56 -0
- package/dist/types/utils/signer.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,13 +80,37 @@ const signature = await wallet.sendTransaction(transaction, connection);
|
|
|
80
80
|
|
|
81
81
|
## Core Features
|
|
82
82
|
|
|
83
|
+
### Universal Signer Pattern
|
|
84
|
+
|
|
85
|
+
The SDK supports both CLI/Node.js and browser usage patterns through its Universal Signer functionality:
|
|
86
|
+
|
|
87
|
+
**Browser Usage** (String Addresses):
|
|
88
|
+
```typescript
|
|
89
|
+
// Pass string addresses for browser wallets
|
|
90
|
+
const instruction = await acceptRental({
|
|
91
|
+
borrower: wallet.publicKey.toString(), // String address
|
|
92
|
+
// ... other params
|
|
93
|
+
});
|
|
94
|
+
// Browser wallet handles signing separately
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**CLI/Node.js Usage** (Signer Objects):
|
|
98
|
+
```typescript
|
|
99
|
+
// Pass signer objects for full signing capability
|
|
100
|
+
const instruction = await acceptRental({
|
|
101
|
+
borrower: wallet, // Signer object
|
|
102
|
+
// ... other params
|
|
103
|
+
});
|
|
104
|
+
// Can sign transactions directly
|
|
105
|
+
```
|
|
106
|
+
|
|
83
107
|
### Instruction Building & Format Conversion
|
|
84
108
|
|
|
85
109
|
The SDK creates @solana/kit compatible instructions with seamless web3.js conversion:
|
|
86
110
|
|
|
87
111
|
- **📦 Instruction-Only**: Focus on instruction building, users handle transaction assembly/sending
|
|
88
112
|
- **🔄 Format Conversion**: Built-in `.web3js(PublicKey)` method for wallet compatibility
|
|
89
|
-
- **🎯
|
|
113
|
+
- **🎯 Universal Signer**: Accepts both string addresses and signer objects
|
|
90
114
|
- **⚡ Lightweight**: Uses @solana/kit internally with optional web3.js conversion
|
|
91
115
|
|
|
92
116
|
### Web3.js Format Conversion
|
|
@@ -464,3 +488,5 @@ The SDK provides optimized builds for different environments:
|
|
|
464
488
|
|
|
465
489
|
- **NPM Package**: [@wuwei-labs/srsly](https://www.npmjs.com/package/@wuwei-labs/srsly)
|
|
466
490
|
- **TypeDoc Documentation**: [API Reference](https://wuwei-labs.github.io/srsly/)
|
|
491
|
+
- **Browser Usage Examples**: [Browser Integration Guide](./examples/browser-usage.md)
|
|
492
|
+
- **Universal Signer Tests**: [Test Examples](./tests/features/universal-signer.test.mjs)
|
package/dist/cjs/package.json
CHANGED
|
@@ -6,10 +6,10 @@ const config_1 = require("../utils/config");
|
|
|
6
6
|
const constants_1 = require("../utils/constants");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const instruction_converter_1 = require("../utils/instruction-converter");
|
|
9
|
-
const
|
|
10
|
-
const kit_1 = require("@solana/kit");
|
|
9
|
+
const fetch_accounts_1 = require("../utils/fetch-accounts");
|
|
11
10
|
const paymentFrequency_1 = require("../utils/paymentFrequency");
|
|
12
11
|
const pda_1 = require("../utils/pda");
|
|
12
|
+
const signer_1 = require("../utils/signer");
|
|
13
13
|
/**
|
|
14
14
|
* Internal function to accept a rental instruction with configuration options.
|
|
15
15
|
*
|
|
@@ -25,7 +25,7 @@ const pda_1 = require("../utils/pda");
|
|
|
25
25
|
* @throws Error when contract is not found, duration constraints are violated, or account derivation fails
|
|
26
26
|
*/
|
|
27
27
|
async function _acceptRental(params, config) {
|
|
28
|
-
const {
|
|
28
|
+
const { borrowerProfile, borrowerFaction, contract, duration, } = params;
|
|
29
29
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
30
30
|
// Use global config as fallback, same pattern as constants.ts
|
|
31
31
|
const globalConfig = (0, config_1.getConfig)();
|
|
@@ -34,23 +34,7 @@ async function _acceptRental(params, config) {
|
|
|
34
34
|
// Fetch contract state to get payment frequency and validate parameters
|
|
35
35
|
let contractState;
|
|
36
36
|
try {
|
|
37
|
-
|
|
38
|
-
let rpcClient;
|
|
39
|
-
if (effectiveConfig.connection) {
|
|
40
|
-
// Use provided Connection (bypasses @solana/kit completely)
|
|
41
|
-
rpcClient = effectiveConfig.connection;
|
|
42
|
-
}
|
|
43
|
-
else if (resolvedAddresses.rpcUrl) {
|
|
44
|
-
// Fall back to @solana/kit RPC creation
|
|
45
|
-
rpcClient = (0, kit_1.createSolanaRpc)(resolvedAddresses.rpcUrl);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
throw new Error('No RPC client available. Provide either a connection or rpcUrl.');
|
|
49
|
-
}
|
|
50
|
-
contractState = await (0, accounts_1.fetchMaybeContractState)(rpcClient, (0, constants_1.toAddress)(contract));
|
|
51
|
-
if (!contractState.exists) {
|
|
52
|
-
throw new Error(`Contract not found: ${contract}`);
|
|
53
|
-
}
|
|
37
|
+
contractState = await (0, fetch_accounts_1.fetchContractState)(contract);
|
|
54
38
|
}
|
|
55
39
|
catch (error) {
|
|
56
40
|
throw new Error(`Failed to fetch contract state: ${error}`);
|
|
@@ -74,15 +58,17 @@ async function _acceptRental(params, config) {
|
|
|
74
58
|
// Manually derive ALL game accounts - they all use different program addresses than main SAGE program
|
|
75
59
|
const { profileFaction, starbase, starbasePlayer } = await (0, utils_1.deriveGameAccounts)((0, constants_1.toAddress)(borrowerProfile), borrowerFaction, resolvedAddresses.gameId, 0, // starbaseSeqId
|
|
76
60
|
config);
|
|
61
|
+
// Handle borrower using smart signer handler for universal compatibility
|
|
62
|
+
const borrower = (0, signer_1.createTransactionSigner)(params.borrower);
|
|
77
63
|
// Manually derive PDAs with correct program IDs
|
|
78
|
-
const rentalStatePda = await (0, pda_1.deriveRentalState)((0, constants_1.toAddress)(contract), borrower.address, //
|
|
64
|
+
const rentalStatePda = await (0, pda_1.deriveRentalState)((0, constants_1.toAddress)(contract), borrower.address, // Use TransactionSigner.address for PDA derivation
|
|
79
65
|
resolvedAddresses.srslyProgramAddress);
|
|
80
66
|
const rentalAuthorityPda = await (0, pda_1.deriveRentalAuthority)(resolvedAddresses.srslyProgramAddress);
|
|
81
67
|
// 🔧 FIX: Derive rental thread PDA using Antegen program ID
|
|
82
68
|
const rentalThreadPda = await (0, pda_1.deriveRentalThread)(rentalAuthorityPda, rentalStatePda, resolvedAddresses.antegenProgramAddress);
|
|
83
69
|
// Create input with ALL manually derived game accounts - they use different program addresses
|
|
84
70
|
const input = {
|
|
85
|
-
borrower: borrower, //
|
|
71
|
+
borrower: borrower, // TransactionSigner for Codama
|
|
86
72
|
borrowerProfile: (0, constants_1.toAddress)(borrowerProfile), // Ensure string
|
|
87
73
|
borrowerProfileFaction: (0, constants_1.toAddress)(profileFaction), // Manually derived (Profile program)
|
|
88
74
|
fleet: (0, constants_1.toAddress)(fleet), // Ensure string
|
|
@@ -155,27 +141,36 @@ async function _acceptRental(params, config) {
|
|
|
155
141
|
* ```typescript
|
|
156
142
|
* import { acceptRental, days } from '@srsly/sdk';
|
|
157
143
|
*
|
|
158
|
-
* //
|
|
144
|
+
* // CLI usage with wallet/signer object
|
|
159
145
|
* const instruction = await acceptRental({
|
|
160
|
-
* borrower: wallet,
|
|
161
|
-
* borrowerProfile: "ProfileAddr...",
|
|
162
|
-
* borrowerFaction: 'mud',
|
|
163
|
-
* contract: "ContractAddr...",
|
|
164
|
-
* duration: days(7)
|
|
146
|
+
* borrower: wallet, // Wallet object for signing
|
|
147
|
+
* borrowerProfile: "ProfileAddr...", // Borrower's Star Atlas profile
|
|
148
|
+
* borrowerFaction: 'mud', // Faction: 'mud', 'oni', or 'ustur'
|
|
149
|
+
* contract: "ContractAddr...", // Contract to accept
|
|
150
|
+
* duration: days(7) // 7 days rental duration
|
|
165
151
|
* });
|
|
166
152
|
*
|
|
167
|
-
* //
|
|
153
|
+
* // Browser usage with address string
|
|
154
|
+
* const browserInstruction = await acceptRental({
|
|
155
|
+
* borrower: wallet.publicKey.toString(), // Address string for browser
|
|
156
|
+
* borrowerProfile: "ProfileAddr...", // Borrower's Star Atlas profile
|
|
157
|
+
* borrowerFaction: 'mud', // Faction: 'mud', 'oni', or 'ustur'
|
|
158
|
+
* contract: "ContractAddr...", // Contract to accept
|
|
159
|
+
* duration: days(7) // 7 days rental duration
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* // Configure for mainnet (both patterns work)
|
|
168
163
|
* const mainnetInstruction = await acceptRental({
|
|
169
|
-
* borrower: wallet,
|
|
164
|
+
* borrower: wallet, // Wallet object (CLI style)
|
|
170
165
|
* borrowerProfile: "ProfileAddr...",
|
|
171
|
-
* borrowerFaction: 1,
|
|
166
|
+
* borrowerFaction: 1, // Can use numbers: 1=mud, 2=oni, 3=ustur
|
|
172
167
|
* contract: "ContractAddr...",
|
|
173
168
|
* duration: days(7)
|
|
174
169
|
* }).set({ programs: 'mainnet' });
|
|
175
170
|
*
|
|
176
171
|
* // Override specific game configuration
|
|
177
172
|
* const customInstruction = await acceptRental({
|
|
178
|
-
* borrower:
|
|
173
|
+
* borrower: "BorrowerAddress123...", // Address string (browser style)
|
|
179
174
|
* borrowerProfile: "ProfileAddr...",
|
|
180
175
|
* borrowerFaction: 'mud',
|
|
181
176
|
* contract: "ContractAddr...",
|
|
@@ -187,7 +182,7 @@ async function _acceptRental(params, config) {
|
|
|
187
182
|
*
|
|
188
183
|
* // Convert to @solana/web3.js format
|
|
189
184
|
* const web3jsInstruction = await acceptRental({
|
|
190
|
-
* borrower: wallet,
|
|
185
|
+
* borrower: wallet, // Universal: works with both patterns
|
|
191
186
|
* borrowerProfile: "ProfileAddr...",
|
|
192
187
|
* borrowerFaction: 'mud',
|
|
193
188
|
* contract: "ContractAddr...",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":";;AA2SA,oCAKC;AAcD,0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AACH,SAAgB,YAAY,CAC1B,MAA0B;IAE1B,MAAM,YAAY,GAAG,IAAA,6BAAoB,EAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACrF,OAAO,IAAA,uDAA+B,EAAC,YAAY,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,IAAA,6BAAoB,EAAC,KAAK,IAAI,EAAE;QACrC,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.cancelRental = cancelRental;
|
|
|
4
4
|
exports.getCancelRentalInstructionAsync = getCancelRentalInstructionAsync;
|
|
5
5
|
const config_1 = require("../utils/config");
|
|
6
6
|
const constants_1 = require("../utils/constants");
|
|
7
|
+
const signer_1 = require("../utils/signer");
|
|
7
8
|
/**
|
|
8
9
|
* Internal function to cancel a rental instruction with configuration options.
|
|
9
10
|
*
|
|
@@ -18,13 +19,15 @@ const constants_1 = require("../utils/constants");
|
|
|
18
19
|
* @throws Error when instruction generation fails or required parameters are missing
|
|
19
20
|
*/
|
|
20
21
|
async function _cancelRental(params, config) {
|
|
21
|
-
const {
|
|
22
|
+
const { contract, } = params;
|
|
23
|
+
// Handle borrower using smart signer handler for universal compatibility
|
|
24
|
+
const borrower = (0, signer_1.createTransactionSigner)(params.borrower);
|
|
22
25
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
23
26
|
// Note: resolvedAddresses not currently needed for this instruction but kept for consistency
|
|
24
27
|
// const resolvedAddresses = resolveProgramAddresses(config || {});
|
|
25
28
|
// Let codama derive all the optional accounts
|
|
26
29
|
const input = {
|
|
27
|
-
borrower, //
|
|
30
|
+
borrower: borrower, // TransactionSigner for Codama
|
|
28
31
|
contract: (0, constants_1.toAddress)(contract), // Ensure string
|
|
29
32
|
};
|
|
30
33
|
// Get network-specific codama functions from centralized config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":";;AAoJA,oCAIC;AAcD,0EAKC;AA3KD,4CAAoI;AACpI,kDAA+C;AAC/C,4CAAgF;AA+BhF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA0B,EAC1B,MAAsB;IAEtB,MAAM,EACJ,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,yEAAyE;IACzE,MAAM,QAAQ,GAAG,IAAA,gCAAuB,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE1D,gFAAgF;IAChF,6FAA6F;IAC7F,mEAAmE;IAEnE,8CAA8C;IAC9C,MAAM,KAAK,GAAG;QACZ,QAAQ,EAAE,QAAQ,EAAE,+BAA+B;QACnD,QAAQ,EAAE,IAAA,qBAAS,EAAC,QAAQ,CAAC,EAAE,gBAAgB;KAChD,CAAC;IAEF,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,IAAA,kBAAS,EAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,EAAE,+BAA+B,EAAE,GAAG,kBAAkB,CAAC;IAC/D,MAAM,EAAE,qBAAqB,EAAE,GAAG,cAAc,CAAC;IAEjD,OAAO,+BAA+B,CACpC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,SAAgB,YAAY,CAC1B,MAA0B;IAE1B,OAAO,IAAA,6BAAoB,EAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,IAAA,6BAAoB,EAAC,KAAK,IAAI,EAAE;QACrC,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/utils/config.js
CHANGED
|
@@ -87,35 +87,16 @@ async function resolveProgramAddresses(config) {
|
|
|
87
87
|
if (!programConfig) {
|
|
88
88
|
throw new Error(`Unknown program set: ${programSet}. Available: ${Object.keys(PROGRAM_SETS).join(', ')}`);
|
|
89
89
|
}
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
throw new Error(`PublicKey required for web3js mode. Please provide: ` +
|
|
96
|
-
`setConfig({ library: 'web3js', PublicKey, connection })`);
|
|
97
|
-
}
|
|
98
|
-
if (!config.connection) {
|
|
99
|
-
throw new Error(`connection required for web3js mode. Please provide: ` +
|
|
100
|
-
`setConfig({ library: 'web3js', PublicKey, connection })`);
|
|
101
|
-
}
|
|
102
|
-
// rpcUrl is ignored in web3js mode
|
|
90
|
+
// RPC URL validation
|
|
91
|
+
const rpcUrl = config.rpcUrl;
|
|
92
|
+
if (!rpcUrl) {
|
|
93
|
+
throw new Error(`rpcUrl is required. Please provide: ` +
|
|
94
|
+
`setConfig({ rpcUrl: "https://your-rpc-url" })`);
|
|
103
95
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`setConfig({ library: 'kit', rpcUrl: "https://your-rpc-url" })`);
|
|
109
|
-
}
|
|
110
|
-
// PublicKey and connection are ignored in kit mode
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
// No library specified - fallback to current behavior
|
|
114
|
-
if (!config.connection && !rpcUrl) {
|
|
115
|
-
throw new Error(`Either 'connection' (web3js) or 'rpcUrl' (kit) must be provided. ` +
|
|
116
|
-
`Use: setConfig({ library: 'web3js', PublicKey, connection }) ` +
|
|
117
|
-
`or: setConfig({ library: 'kit', rpcUrl: "https://..." })`);
|
|
118
|
-
}
|
|
96
|
+
// PublicKey validation for web3js mode
|
|
97
|
+
if (config.library === 'web3js' && !config.PublicKey) {
|
|
98
|
+
throw new Error(`PublicKey required for web3js mode. Please provide: ` +
|
|
99
|
+
`setConfig({ library: 'web3js', PublicKey })`);
|
|
119
100
|
}
|
|
120
101
|
const srslyAddress = config.srslyProgramAddress || 'SRSLY1fq9TJqCk1gNSE7VZL2bztvTn9wm4VR8u8jMKT';
|
|
121
102
|
const sageAddress = programConfig.SAGE_PROGRAM_ADDRESS;
|
|
@@ -130,7 +111,7 @@ async function resolveProgramAddresses(config) {
|
|
|
130
111
|
antegenProgramAddress: (0, constants_1.toAddress)(antegenAddress),
|
|
131
112
|
gameId: (0, constants_1.toAddress)(gameIdAddress),
|
|
132
113
|
atlasMint: (0, constants_1.toAddress)(atlasMintAddress),
|
|
133
|
-
rpcUrl:
|
|
114
|
+
rpcUrl: rpcUrl, // Always return rpcUrl
|
|
134
115
|
};
|
|
135
116
|
}
|
|
136
117
|
/**
|
|
@@ -151,13 +132,12 @@ async function resolveProgramAddresses(config) {
|
|
|
151
132
|
* gameId: 'custom-game-id...'
|
|
152
133
|
* });
|
|
153
134
|
*
|
|
154
|
-
* // Configure for web3js
|
|
155
|
-
* import {
|
|
156
|
-
* const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
135
|
+
* // Configure for web3js
|
|
136
|
+
* import { PublicKey } from '@solana/web3.js';
|
|
157
137
|
* setConfig({
|
|
158
138
|
* library: 'web3js',
|
|
159
139
|
* PublicKey,
|
|
160
|
-
*
|
|
140
|
+
* rpcUrl: 'https://api.mainnet-beta.solana.com'
|
|
161
141
|
* });
|
|
162
142
|
*
|
|
163
143
|
* // Can still override per instruction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/utils/config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/utils/config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEH,0DA4CC;AAgCD,8BAEC;AAMD,8BAEC;AAKD,kCAEC;AAQD,gDAEC;AAOD,8BAaC;AAMD,wDAKC;AA2ED,oDAgBC;AAlSD,0CAA0C;AAC1C,qEAAuD;AACvD,6DAA+C;AAC/C,6DAA+C;AAC/C,qCAA8C;AAC9C,2CAAwC;AAIxC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE;QACP,oBAAoB,EAAE,6CAA6C;QACnE,+BAA+B,EAAE,6CAA6C;QAC9E,YAAY,EAAE,8CAA8C;QAC5D,UAAU,EAAE,8CAA8C;KAC3D;IACD,QAAQ,EAAE;QACR,oBAAoB,EAAE,6CAA6C;QACnE,+BAA+B,EAAE,6CAA6C;QAC9E,YAAY,EAAE,8CAA8C;QAC5D,UAAU,EAAE,8CAA8C;KAC3D;IACD,OAAO,EAAE;QACP,oBAAoB,EAAE,6CAA6C;QACnE,+BAA+B,EAAE,6CAA6C;QAC9E,YAAY,EAAE,8CAA8C;QAC5D,UAAU,EAAE,8CAA8C;KAC3D;CACO,CAAC;AA0BX,6CAA6C;AAC7C,MAAM,mBAAmB,GAAe,UAAU,CAAC;AAEnD,6BAA6B;AAC7B,IAAI,YAAY,GAAkB,EAAE,CAAC;AAErC;;;;GAI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CAAC,4BAA4B,UAAU,qCAAqC,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,SAAS,CAAC,UAAyC,CAAC,CAAC;AAC9D,CAAC;AAqBD;;;;;;;;;;;;;;GAcG;AACH,SAAS,6BAA6B,CACpC,SAAiD,EACjD,cAA6B;IAE7B,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,CAAC,iBAAgC,EAAE,EAAE,CACxC,6BAA6B,CAAC,SAAS,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,iBAAiB,EAAE,CAAC;QACvF,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC;QACtC,iDAAiD;QACjD,IAAI,CACF,WAAqE,EACrE,UAAuE;YAEvE,OAAO,SAAS,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,oBAAoB,CAClC,SAAiD;IAEjD,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,CAAC,OAAsB,EAAE,EAAE,CAAC,6BAA6B,CAAC,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACtG,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC;QAC5C,iDAAiD;QACjD,IAAI,CACF,WAAqE,EACrE,UAAuE;YAEvE,OAAO,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACvE,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -6,57 +6,39 @@ exports.fetchMultipleContractStates = fetchMultipleContractStates;
|
|
|
6
6
|
exports.fetchMultipleRentalStates = fetchMultipleRentalStates;
|
|
7
7
|
const kit_1 = require("@solana/kit");
|
|
8
8
|
const accounts_1 = require("../codama/accounts");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* 'ContractAddress123...'
|
|
25
|
-
* );
|
|
26
|
-
*
|
|
27
|
-
* console.log('Contract owner:', contractState.data.owner);
|
|
28
|
-
* console.log('Contract rate:', contractState.data.rate);
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
async function fetchContractState(rpcUrl, contractAddress) {
|
|
32
|
-
// Create RPC connection
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
// Implementation
|
|
12
|
+
async function fetchContractState(rpcUrlOrAddress, contractAddress) {
|
|
13
|
+
// If only one argument, it's the contract address using default RPC
|
|
14
|
+
if (contractAddress === undefined) {
|
|
15
|
+
const address = (0, constants_1.toAddress)(rpcUrlOrAddress);
|
|
16
|
+
const config = (0, config_1.getConfig)();
|
|
17
|
+
const resolved = await (0, config_1.resolveProgramAddresses)(config);
|
|
18
|
+
const rpc = (0, kit_1.createSolanaRpc)(resolved.rpcUrl);
|
|
19
|
+
return (0, accounts_1.fetchContractState)(rpc, address);
|
|
20
|
+
}
|
|
21
|
+
// If two arguments, first is rpcUrl, second is address
|
|
22
|
+
const rpcUrl = rpcUrlOrAddress;
|
|
23
|
+
const address = (0, constants_1.toAddress)(contractAddress);
|
|
33
24
|
const rpc = (0, kit_1.createSolanaRpc)(rpcUrl);
|
|
34
|
-
|
|
35
|
-
return (0, accounts_1.fetchContractState)(rpc, contractAddress);
|
|
25
|
+
return (0, accounts_1.fetchContractState)(rpc, address);
|
|
36
26
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
* console.log('Rental borrower:', rentalState.data.borrower);
|
|
52
|
-
* console.log('Rental start:', rentalState.data.start);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
async function fetchRentalState(rpcUrl, rentalAddress) {
|
|
56
|
-
// Create RPC connection
|
|
27
|
+
// Implementation
|
|
28
|
+
async function fetchRentalState(rpcUrlOrAddress, rentalAddress) {
|
|
29
|
+
// If only one argument, it's the rental address using default RPC
|
|
30
|
+
if (rentalAddress === undefined) {
|
|
31
|
+
const address = (0, constants_1.toAddress)(rpcUrlOrAddress);
|
|
32
|
+
const config = (0, config_1.getConfig)();
|
|
33
|
+
const resolved = await (0, config_1.resolveProgramAddresses)(config);
|
|
34
|
+
const rpc = (0, kit_1.createSolanaRpc)(resolved.rpcUrl);
|
|
35
|
+
return (0, accounts_1.fetchRentalState)(rpc, address);
|
|
36
|
+
}
|
|
37
|
+
// If two arguments, first is rpcUrl, second is address
|
|
38
|
+
const rpcUrl = rpcUrlOrAddress;
|
|
39
|
+
const address = (0, constants_1.toAddress)(rentalAddress);
|
|
57
40
|
const rpc = (0, kit_1.createSolanaRpc)(rpcUrl);
|
|
58
|
-
|
|
59
|
-
return (0, accounts_1.fetchRentalState)(rpc, rentalAddress);
|
|
41
|
+
return (0, accounts_1.fetchRentalState)(rpc, address);
|
|
60
42
|
}
|
|
61
43
|
/**
|
|
62
44
|
* Fetches multiple contract states in a single RPC call
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-accounts.js","sourceRoot":"","sources":["../../../src/utils/fetch-accounts.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"fetch-accounts.js","sourceRoot":"","sources":["../../../src/utils/fetch-accounts.ts"],"names":[],"mappings":";;AAwDA,gDAkBC;AA2CD,4CAkBC;AAuBD,kEASC;AAuBD,8DASC;AAvMD,qCAA4D;AAC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,MAAM,MAAM,GAAG,eAAyB,CAAC;IACzC,MAAM,OAAO,GAAG,IAAA,qBAAS,EAAC,aAAa,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,IAAA,qBAAe,EAAC,MAAM,CAAC,CAAC;IACpC,OAAO,IAAA,2BAAsB,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,2BAA2B,CAC/C,MAAc,EACd,iBAAsC;IAEtC,wBAAwB;IACxB,MAAM,GAAG,GAAG,IAAA,qBAAe,EAAC,MAAM,CAAC,CAAC;IAEpC,uCAAuC;IACvC,OAAO,IAAA,gCAAqB,EAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,yBAAyB,CAC7C,MAAc,EACd,eAAoC;IAEpC,wBAAwB;IACxB,MAAM,GAAG,GAAG,IAAA,qBAAe,EAAC,MAAM,CAAC,CAAC;IAEpC,qCAAqC;IACrC,OAAO,IAAA,8BAAmB,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -22,4 +22,5 @@ __exportStar(require("./duration"), exports);
|
|
|
22
22
|
__exportStar(require("./instruction-converter"), exports);
|
|
23
23
|
__exportStar(require("./fetch-accounts"), exports);
|
|
24
24
|
__exportStar(require("./pda"), exports);
|
|
25
|
+
__exportStar(require("./signer"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,qDAAmC;AACnC,6CAA2B;AAC3B,0DAAwC;AACxC,mDAAiC;AACjC,wCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,qDAAmC;AACnC,6CAA2B;AAC3B,0DAAwC;AACxC,mDAAiC;AACjC,wCAAsB;AACtB,2CAAyB"}
|
|
@@ -16,7 +16,7 @@ function createFluentInstruction(kitInstruction) {
|
|
|
16
16
|
function kit() {
|
|
17
17
|
return kitInstruction;
|
|
18
18
|
}
|
|
19
|
-
function web3js(PublicKey
|
|
19
|
+
function web3js(PublicKey) {
|
|
20
20
|
const accounts = kitInstruction.accounts || [];
|
|
21
21
|
if (PublicKey) {
|
|
22
22
|
// Return instruction with PublicKey instances
|
|
@@ -56,16 +56,8 @@ function createFluentInstruction(kitInstruction) {
|
|
|
56
56
|
* @returns FluentConfigSelector with additional format conversion methods
|
|
57
57
|
*/
|
|
58
58
|
function createFluentConfigSelector(baseSelector) {
|
|
59
|
-
async function web3js(PublicKey
|
|
60
|
-
|
|
61
|
-
if (connection) {
|
|
62
|
-
// Rebuild instruction with connection in config
|
|
63
|
-
const selectorWithConnection = baseSelector.set({ connection });
|
|
64
|
-
fluentInstruction = await selectorWithConnection.build();
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
fluentInstruction = await baseSelector.build();
|
|
68
|
-
}
|
|
59
|
+
async function web3js(PublicKey) {
|
|
60
|
+
const fluentInstruction = await baseSelector.build();
|
|
69
61
|
return fluentInstruction.web3js(PublicKey);
|
|
70
62
|
}
|
|
71
63
|
return {
|
|
@@ -120,16 +112,8 @@ function createSmartFluentConfigSelector(baseSelector) {
|
|
|
120
112
|
const fluentInstruction = await baseSelector.build();
|
|
121
113
|
return fluentInstruction.kit();
|
|
122
114
|
},
|
|
123
|
-
async web3js(PublicKey
|
|
124
|
-
|
|
125
|
-
if (connection) {
|
|
126
|
-
// Rebuild instruction with connection in config
|
|
127
|
-
const selectorWithConnection = baseSelector.set({ connection });
|
|
128
|
-
fluentInstruction = await selectorWithConnection.build();
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
fluentInstruction = await baseSelector.build();
|
|
132
|
-
}
|
|
115
|
+
async web3js(PublicKey) {
|
|
116
|
+
const fluentInstruction = await baseSelector.build();
|
|
133
117
|
return fluentInstruction.web3js(PublicKey);
|
|
134
118
|
}
|
|
135
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruction-converter.js","sourceRoot":"","sources":["../../../src/utils/instruction-converter.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"instruction-converter.js","sourceRoot":"","sources":["../../../src/utils/instruction-converter.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqKH,0DAsCC;AAQD,gEAkBC;AAOD,0EAmDC;AA7RD,qCAAmG;AA8JnG;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,cAA8B;IACpE,SAAS,GAAG;QACV,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,SAAS,MAAM,CAAa,SAA4C;QACtE,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,IAAI,EAAE,CAAC;QAE/C,IAAI,SAAS,EAAE,CAAC;YACd,8CAA8C;YAC9C,OAAO;gBACL,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;oBAC7B,MAAM,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;oBACtC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,+BAA+B;oBACrE,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,EAAI,6BAA6B;iBACpE,CAAC,CAAC;gBACH,SAAS,EAAE,IAAI,SAAS,CAAC,cAAc,CAAC,cAAc,CAAC;gBACvD,IAAI,EAAE,cAAc,CAAC,IAAI;aAC1B,C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KAC8B,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Universal signer handling utilities for cross-library compatibility
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities to handle different signer types across
|
|
6
|
+
* @solana/kit, @solana/web3.js, and plain address strings in a unified way.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createTransactionSigner = createTransactionSigner;
|
|
10
|
+
exports.isSignerObject = isSignerObject;
|
|
11
|
+
exports.isAddressString = isAddressString;
|
|
12
|
+
const kit_1 = require("@solana/kit");
|
|
13
|
+
/**
|
|
14
|
+
* Creates TransactionSigner from UniversalSigner input for universal compatibility
|
|
15
|
+
*
|
|
16
|
+
* This function provides universal compatibility by:
|
|
17
|
+
* - Converting string addresses to TransactionSigner using createNoopSigner
|
|
18
|
+
* - Passing through existing TransactionSigner objects unchanged
|
|
19
|
+
* - Safely handling different signer interfaces (kit, web3.js, etc.)
|
|
20
|
+
*
|
|
21
|
+
* The returned TransactionSigner has both .address property and signing capability,
|
|
22
|
+
* making it suitable for both PDA derivation and codama instruction building.
|
|
23
|
+
*
|
|
24
|
+
* @param signer - The signer input (string address or signer object)
|
|
25
|
+
* @returns TransactionSigner that can be used directly for codama and has .address property
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Browser usage with string address
|
|
30
|
+
* const borrower = createTransactionSigner("base58AddressString");
|
|
31
|
+
* // borrower.address → Address object for PDA derivation
|
|
32
|
+
* // borrower → TransactionSigner for codama
|
|
33
|
+
*
|
|
34
|
+
* // CLI usage with wallet object
|
|
35
|
+
* const borrower = createTransactionSigner(wallet);
|
|
36
|
+
* // borrower.address → wallet.address for PDA derivation
|
|
37
|
+
* // borrower → wallet signer for codama
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function createTransactionSigner(signer) {
|
|
41
|
+
// Handle string address case (browser usage)
|
|
42
|
+
if (typeof signer === 'string') {
|
|
43
|
+
return (0, kit_1.createNoopSigner)((0, kit_1.address)(signer)); // Returns TransactionSigner with .address property
|
|
44
|
+
}
|
|
45
|
+
// Handle signer object cases (CLI and other wallet interfaces)
|
|
46
|
+
// These should already be TransactionSigner objects with .address property
|
|
47
|
+
return signer;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Type guard to check if a value is a signer object (not a string)
|
|
51
|
+
*/
|
|
52
|
+
function isSignerObject(signer) {
|
|
53
|
+
return typeof signer !== 'string';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Type guard to check if a value is an address string
|
|
57
|
+
*/
|
|
58
|
+
function isAddressString(signer) {
|
|
59
|
+
return typeof signer === 'string';
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA2CH,0DASC;AAKD,wCAEC;AAKD,0CAEC;AAhED,qCAAgF;AAchF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,uBAAuB,CAAC,MAAuB;IAC7D,6CAA6C;IAC7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAA,sBAAgB,EAAC,IAAA,aAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,mDAAmD;IAChG,CAAC;IAED,+DAA+D;IAC/D,2EAA2E;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAuB;IACpD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAuB;IACrD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC"}
|