@wuwei-labs/srsly 2.0.0-beta.45 → 2.0.0-beta.48
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/dist/cjs/codama/instructions/cancelRental.js +13 -23
- package/dist/cjs/codama/instructions/cancelRental.js.map +1 -1
- package/dist/cjs/contract/close.js +106 -21
- package/dist/cjs/contract/close.js.map +1 -1
- package/dist/cjs/contract/create.js +59 -5
- package/dist/cjs/contract/create.js.map +1 -1
- package/dist/cjs/demos.js +65 -0
- package/dist/cjs/demos.js.map +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/rental/accept.js +31 -0
- package/dist/cjs/rental/accept.js.map +1 -1
- package/dist/cjs/rental/cancel.js +60 -9
- package/dist/cjs/rental/cancel.js.map +1 -1
- package/dist/cjs/rental/close.js +35 -23
- package/dist/cjs/rental/close.js.map +1 -1
- package/dist/cjs/rental/reset-contract-temp.js +4 -1
- package/dist/cjs/rental/reset-contract-temp.js.map +1 -1
- package/dist/cjs/rental/reset.js +131 -26
- package/dist/cjs/rental/reset.js.map +1 -1
- package/dist/cjs/utils/fetch-accounts.js +26 -0
- package/dist/cjs/utils/fetch-accounts.js.map +1 -1
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/pda.js.map +1 -1
- package/dist/cjs/utils/sdk-helpers.js +122 -0
- package/dist/cjs/utils/sdk-helpers.js.map +1 -0
- package/dist/cjs/utils/signer.js +105 -10
- package/dist/cjs/utils/signer.js.map +1 -1
- package/dist/esm/codama/instructions/cancelRental.js +13 -23
- package/dist/esm/codama/instructions/cancelRental.js.map +1 -1
- package/dist/esm/contract/close.js +106 -22
- package/dist/esm/contract/close.js.map +1 -1
- package/dist/esm/contract/create.js +59 -6
- package/dist/esm/contract/create.js.map +1 -1
- package/dist/esm/demos.js +23 -0
- package/dist/esm/demos.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/rental/accept.js +30 -0
- package/dist/esm/rental/accept.js.map +1 -1
- package/dist/esm/rental/cancel.js +60 -10
- package/dist/esm/rental/cancel.js.map +1 -1
- package/dist/esm/rental/close.js +37 -26
- package/dist/esm/rental/close.js.map +1 -1
- package/dist/esm/rental/reset-contract-temp.js +4 -1
- package/dist/esm/rental/reset-contract-temp.js.map +1 -1
- package/dist/esm/rental/reset.js +131 -27
- package/dist/esm/rental/reset.js.map +1 -1
- package/dist/esm/utils/fetch-accounts.js +26 -1
- 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/pda.js.map +1 -1
- package/dist/esm/utils/sdk-helpers.js +113 -0
- package/dist/esm/utils/sdk-helpers.js.map +1 -0
- package/dist/esm/utils/signer.js +103 -11
- package/dist/esm/utils/signer.js.map +1 -1
- package/dist/types/codama/instructions/cancelRental.d.ts +2 -2
- package/dist/types/codama/instructions/cancelRental.d.ts.map +1 -1
- package/dist/types/contract/close.d.ts +17 -12
- package/dist/types/contract/close.d.ts.map +1 -1
- package/dist/types/contract/create.d.ts +8 -2
- package/dist/types/contract/create.d.ts.map +1 -1
- package/dist/types/demos.d.ts +58 -0
- package/dist/types/demos.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rental/accept.d.ts +6 -0
- package/dist/types/rental/accept.d.ts.map +1 -1
- package/dist/types/rental/cancel.d.ts +9 -3
- package/dist/types/rental/cancel.d.ts.map +1 -1
- package/dist/types/rental/close.d.ts +11 -5
- package/dist/types/rental/close.d.ts.map +1 -1
- package/dist/types/rental/reset-contract-temp.d.ts +1 -1
- package/dist/types/rental/reset-contract-temp.d.ts.map +1 -1
- package/dist/types/rental/reset.d.ts +35 -24
- package/dist/types/rental/reset.d.ts.map +1 -1
- package/dist/types/utils/fetch-accounts.d.ts +48 -1
- 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/pda.d.ts.map +1 -1
- package/dist/types/utils/sdk-helpers.d.ts +49 -0
- package/dist/types/utils/sdk-helpers.d.ts.map +1 -0
- package/dist/types/utils/signer.d.ts +39 -16
- package/dist/types/utils/signer.d.ts.map +1 -1
- package/package.json +7 -1
- package/target/idl/srsly.json +1 -23
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { getModule, createConfigSelector, resolveProgramAddresses } from '../utils/config';
|
|
1
|
+
import { getModule, createConfigSelector, resolveProgramAddresses, getConfig } from '../utils/config';
|
|
2
2
|
import { toAddress } from '../utils/constants';
|
|
3
3
|
import { deriveGameAccounts } from '../utils';
|
|
4
4
|
import { createFluentInstruction, createSmartFluentConfigSelector } from '../utils/instruction-converter';
|
|
5
|
+
import { fetchContractState } from '../utils/fetch-accounts';
|
|
6
|
+
import { createTransactionSigner } from '../utils/signer';
|
|
5
7
|
/**
|
|
6
8
|
* Asynchronously creates an instruction to close a rental contract with minimal required parameters.
|
|
7
9
|
* Derives rentalAuthority automatically and handles optional parameters.
|
|
@@ -9,17 +11,24 @@ import { createFluentInstruction, createSmartFluentConfigSelector } from '../uti
|
|
|
9
11
|
* @example
|
|
10
12
|
* ```typescript
|
|
11
13
|
* // Works with any library - just use strings for addresses!
|
|
14
|
+
* // Fleet will be automatically fetched from contract
|
|
12
15
|
* const instruction = await closeContract({
|
|
13
16
|
* owner: wallet, // Can be signer object or string
|
|
14
|
-
* fleet: "FleetAddress123...", // String address
|
|
15
17
|
* contract: "ContractAddr...", // String address
|
|
16
18
|
* faction: 'mud',
|
|
17
19
|
* });
|
|
18
20
|
*
|
|
21
|
+
* // Optionally provide fleet address to avoid fetching
|
|
22
|
+
* const instruction = await closeContract({
|
|
23
|
+
* owner: wallet,
|
|
24
|
+
* fleet: "FleetAddress123...", // Optional: will be fetched if omitted
|
|
25
|
+
* contract: "ContractAddr...",
|
|
26
|
+
* faction: 'mud',
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
19
29
|
* // Use mainnet configuration
|
|
20
30
|
* const instruction = await closeContract({
|
|
21
31
|
* owner: wallet,
|
|
22
|
-
* fleet: "FleetAddress123...",
|
|
23
32
|
* contract: "ContractAddr...",
|
|
24
33
|
* faction: 'mud',
|
|
25
34
|
* }).set({ programs: 'mainnet' });
|
|
@@ -27,7 +36,6 @@ import { createFluentInstruction, createSmartFluentConfigSelector } from '../uti
|
|
|
27
36
|
* // Override specific constants
|
|
28
37
|
* const instruction = await closeContract({
|
|
29
38
|
* owner: wallet,
|
|
30
|
-
* fleet: "FleetAddress123...",
|
|
31
39
|
* contract: "ContractAddr...",
|
|
32
40
|
* faction: 'mud',
|
|
33
41
|
* }).set({
|
|
@@ -58,29 +66,96 @@ import { createFluentInstruction, createSmartFluentConfigSelector } from '../uti
|
|
|
58
66
|
* @throws Error when account derivation fails or required parameters are missing
|
|
59
67
|
*/
|
|
60
68
|
async function _closeContract(params, config) {
|
|
69
|
+
console.log('🔒 Starting closeContract with params:', {
|
|
70
|
+
hasOwner: !!params.owner,
|
|
71
|
+
hasFleet: !!params.fleet,
|
|
72
|
+
contract: params.contract,
|
|
73
|
+
faction: params.faction
|
|
74
|
+
});
|
|
61
75
|
const { owner, fleet, contract, faction, } = params;
|
|
62
76
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
77
|
+
// Use global config as fallback, same pattern as acceptRental
|
|
78
|
+
const globalConfig = getConfig();
|
|
79
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
80
|
+
const resolvedAddresses = await resolveProgramAddresses(effectiveConfig);
|
|
81
|
+
// Handle owner using smart signer handler for universal compatibility
|
|
82
|
+
const ownerSigner = createTransactionSigner(owner);
|
|
83
|
+
console.log('✅ Owner processed with createTransactionSigner:', ownerSigner.address);
|
|
84
|
+
// Validate contract address before fetching
|
|
85
|
+
if (typeof contract === 'string' && (contract.includes('CONTRACT_ADDRESS') || contract.length < 32)) {
|
|
86
|
+
throw new Error(`Invalid contract address: "${contract}". Please provide a valid Solana address (32-44 characters).`);
|
|
87
|
+
}
|
|
88
|
+
// Fetch fleet from contract if not provided
|
|
89
|
+
let fleetAddress;
|
|
90
|
+
if (fleet) {
|
|
91
|
+
console.log('🚢 Using provided fleet address:', fleet);
|
|
92
|
+
// Validate provided fleet address
|
|
93
|
+
if (typeof fleet === 'string' && (fleet.includes('FLEET_ADDRESS') || fleet.length < 32)) {
|
|
94
|
+
throw new Error(`Invalid fleet address: "${fleet}". Please provide a valid Solana address (32-44 characters).`);
|
|
95
|
+
}
|
|
96
|
+
fleetAddress = fleet;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log('🔍 Fetching fleet from contract state...');
|
|
100
|
+
try {
|
|
101
|
+
const contractState = await fetchContractState(toAddress(contract));
|
|
102
|
+
fleetAddress = contractState.data.fleet;
|
|
103
|
+
console.log('✅ Contract state fetched:', {
|
|
104
|
+
fleet: fleetAddress,
|
|
105
|
+
owner: contractState.data.owner,
|
|
106
|
+
rate: contractState.data.rate?.toString(),
|
|
107
|
+
toClose: contractState.data.toClose,
|
|
108
|
+
currentRentalState: contractState.data.currentRentalState
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error('❌ Failed to fetch contract state:', error);
|
|
113
|
+
throw new Error(`Failed to fetch contract state for fleet derivation: ${error}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.log('🎮 Deriving game accounts...');
|
|
117
|
+
console.log('🎯 Derivation inputs:', {
|
|
118
|
+
ownerAddress: ownerSigner.address,
|
|
119
|
+
faction,
|
|
120
|
+
gameId: resolvedAddresses.gameId,
|
|
121
|
+
starbaseSeqId: 0
|
|
122
|
+
});
|
|
123
|
+
const derivedAccounts = await deriveGameAccounts(ownerSigner.address, faction, resolvedAddresses.gameId, 0, // starbaseSeqId
|
|
67
124
|
config);
|
|
125
|
+
console.log('✅ Game accounts derived:', {
|
|
126
|
+
starbase: derivedAccounts.starbase,
|
|
127
|
+
starbasePlayer: derivedAccounts.starbasePlayer,
|
|
128
|
+
profileFaction: derivedAccounts.profileFaction
|
|
129
|
+
});
|
|
68
130
|
// Get network-specific codama functions from centralized config
|
|
69
131
|
const instructionsModule = getModule('instructions');
|
|
70
|
-
const programsModule = getModule('programs');
|
|
71
132
|
const { getCloseContractInstructionAsync } = instructionsModule;
|
|
72
|
-
const { SRSLY_PROGRAM_ADDRESS } = programsModule;
|
|
73
133
|
// Let codama handle all the account derivation and instruction building
|
|
74
134
|
const input = {
|
|
75
|
-
owner, // Pass
|
|
76
|
-
fleet: toAddress(
|
|
135
|
+
owner: ownerSigner, // Pass TransactionSigner for proper handling
|
|
136
|
+
fleet: toAddress(fleetAddress), // Convert fleet to Address
|
|
77
137
|
contract: toAddress(contract), // Convert contract to Address
|
|
78
138
|
starbase: toAddress(derivedAccounts.starbase), // Convert starbase to Address
|
|
79
139
|
starbasePlayer: toAddress(derivedAccounts.starbasePlayer), // Convert starbasePlayer to Address
|
|
80
140
|
gameId: resolvedAddresses.gameId, // Already Address from resolved config or param override
|
|
81
141
|
sageProgram: resolvedAddresses.sageProgramAddress, // Already Address from resolveProgramAddresses
|
|
82
142
|
};
|
|
83
|
-
|
|
143
|
+
console.log('🏗️ Creating instruction with input:', {
|
|
144
|
+
ownerAddress: input.owner.address,
|
|
145
|
+
fleet: input.fleet,
|
|
146
|
+
contract: input.contract,
|
|
147
|
+
starbase: input.starbase,
|
|
148
|
+
starbasePlayer: input.starbasePlayer,
|
|
149
|
+
gameId: input.gameId,
|
|
150
|
+
sageProgram: input.sageProgram,
|
|
151
|
+
programAddress: resolvedAddresses.srslyProgramAddress
|
|
152
|
+
});
|
|
153
|
+
const rawInstruction = await getCloseContractInstructionAsync(input, { programAddress: resolvedAddresses.srslyProgramAddress });
|
|
154
|
+
console.log('✅ Raw instruction created:', {
|
|
155
|
+
programAddress: rawInstruction.programAddress,
|
|
156
|
+
accountCount: rawInstruction.accounts?.length || 0,
|
|
157
|
+
hasData: !!rawInstruction.data
|
|
158
|
+
});
|
|
84
159
|
return createFluentInstruction(rawInstruction);
|
|
85
160
|
}
|
|
86
161
|
/**
|
|
@@ -100,11 +175,12 @@ async function _closeContract(params, config) {
|
|
|
100
175
|
*
|
|
101
176
|
* ## Process
|
|
102
177
|
*
|
|
103
|
-
* 1. **
|
|
104
|
-
* 2. **
|
|
105
|
-
* 3. **
|
|
106
|
-
* 4. **
|
|
107
|
-
* 5. **
|
|
178
|
+
* 1. **Fetch Fleet**: Automatically fetches fleet address from contract if not provided
|
|
179
|
+
* 2. **Derive Accounts**: Automatically derives required game accounts (starbase, etc.)
|
|
180
|
+
* 3. **Validate Authority**: Ensures only the contract owner can close it
|
|
181
|
+
* 4. **Check State**: Verifies no active rentals exist
|
|
182
|
+
* 5. **Close Contract**: Removes rental capability and closes account
|
|
183
|
+
* 6. **Transfer Lamports**: Returns remaining SOL to the owner
|
|
108
184
|
*
|
|
109
185
|
* ## Requirements
|
|
110
186
|
*
|
|
@@ -116,10 +192,9 @@ async function _closeContract(params, config) {
|
|
|
116
192
|
* ```typescript
|
|
117
193
|
* import { closeContract } from '@srsly/sdk';
|
|
118
194
|
*
|
|
119
|
-
* // Basic contract closure
|
|
195
|
+
* // Basic contract closure (fleet automatically fetched)
|
|
120
196
|
* const instruction = await closeContract({
|
|
121
197
|
* owner: wallet, // Contract owner
|
|
122
|
-
* fleet: "FleetAddress123...", // Fleet address
|
|
123
198
|
* contract: "ContractAddr...", // Contract to close
|
|
124
199
|
* faction: 'mud' // Faction for game account derivation
|
|
125
200
|
* });
|
|
@@ -127,7 +202,6 @@ async function _closeContract(params, config) {
|
|
|
127
202
|
* // Configure for mainnet
|
|
128
203
|
* const mainnetInstruction = await closeContract({
|
|
129
204
|
* owner: wallet,
|
|
130
|
-
* fleet: "FleetAddress123...",
|
|
131
205
|
* contract: "ContractAddr...",
|
|
132
206
|
* faction: 'mud'
|
|
133
207
|
* }).set({ programs: 'mainnet' });
|
|
@@ -135,7 +209,6 @@ async function _closeContract(params, config) {
|
|
|
135
209
|
* // Override specific game configuration
|
|
136
210
|
* const customInstruction = await closeContract({
|
|
137
211
|
* owner: wallet,
|
|
138
|
-
* fleet: "FleetAddress123...",
|
|
139
212
|
* contract: "ContractAddr...",
|
|
140
213
|
* faction: 'mud'
|
|
141
214
|
* }).set({
|
|
@@ -163,4 +236,15 @@ export function getCloseContractInstructionAsync(input, options) {
|
|
|
163
236
|
return instructionsModule.getCloseContractInstructionAsync(input, options);
|
|
164
237
|
});
|
|
165
238
|
}
|
|
239
|
+
// Demo export for documentation site
|
|
240
|
+
export const closeContractDemo = {
|
|
241
|
+
tabName: "close",
|
|
242
|
+
description: "Close an existing rental contract",
|
|
243
|
+
imports: `import { closeContract } from '@wuwei-labs/srsly';`,
|
|
244
|
+
instruction: `const instruction = await closeContract({
|
|
245
|
+
owner: (signer || wallet).publicKey?.toBase58(),
|
|
246
|
+
contract: "CONTRACT_ADDRESS",
|
|
247
|
+
faction: "oni" // or 'mud', 'ustur'
|
|
248
|
+
});`
|
|
249
|
+
};
|
|
166
250
|
//# sourceMappingURL=close.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAA2C,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,SAAS,EAA2C,MAAM,iBAAiB,CAAC;AAC/I,OAAO,EAAE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C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,mCAAmC;IAChD,OAAO,EAAE,oDAAoD;IAC7D,WAAW,EAAE;;;;IAIX;CACH,CAAC"}
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module Contract/Create
|
|
16
16
|
*/
|
|
17
|
-
import { getModule, createConfigSelector, resolveProgramAddresses } from '../utils/config';
|
|
17
|
+
import { getModule, createConfigSelector, resolveProgramAddresses, getConfig } from '../utils/config';
|
|
18
18
|
import { toAddress } from '../utils/constants';
|
|
19
19
|
import { validateDurationAlignment, paymentFrequencyStringToSeconds } from '../utils/paymentFrequency';
|
|
20
20
|
import { isValidPaymentFrequency } from '../types/paymentFrequency';
|
|
21
21
|
import { createFluentInstruction, createSmartFluentConfigSelector } from '../utils/instruction-converter';
|
|
22
|
+
import { createTransactionSigner } from '../utils/signer';
|
|
22
23
|
/**
|
|
23
24
|
* Internal function to create a rental contract instruction with configuration options.
|
|
24
25
|
*
|
|
@@ -33,6 +34,14 @@ import { createFluentInstruction, createSmartFluentConfigSelector } from '../uti
|
|
|
33
34
|
* @throws Error when validation fails or required parameters are missing
|
|
34
35
|
*/
|
|
35
36
|
async function _createContract(params, config) {
|
|
37
|
+
console.log('🏗️ Starting createContract with params:', {
|
|
38
|
+
hasOwner: !!params.owner,
|
|
39
|
+
fleet: params.fleet,
|
|
40
|
+
ownerProfile: params.ownerProfile,
|
|
41
|
+
rate: params.rate,
|
|
42
|
+
durationMax: params.durationMax,
|
|
43
|
+
paymentsFreq: params.paymentsFreq
|
|
44
|
+
});
|
|
36
45
|
const { owner, fleet, ownerProfile, rate, durationMin: customDurationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, } = params;
|
|
37
46
|
// Validate payment frequency
|
|
38
47
|
if (!isValidPaymentFrequency(paymentsFreq)) {
|
|
@@ -52,9 +61,23 @@ async function _createContract(params, config) {
|
|
|
52
61
|
// Convert the payment frequency to the format expected by the Rust program (with @ prefix)
|
|
53
62
|
const paymentsFreqWithPrefix = `@${paymentsFreq}`;
|
|
54
63
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
55
|
-
|
|
64
|
+
// Use global config as fallback, same pattern as acceptRental
|
|
65
|
+
const globalConfig = getConfig();
|
|
66
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
67
|
+
const resolvedAddresses = await resolveProgramAddresses(effectiveConfig);
|
|
68
|
+
// Handle owner using smart signer handler for universal compatibility
|
|
69
|
+
const ownerSigner = createTransactionSigner(owner);
|
|
70
|
+
console.log('✅ Owner processed with createTransactionSigner:', ownerSigner.address);
|
|
71
|
+
// Validate fleet address
|
|
72
|
+
if (typeof fleet === 'string' && (fleet.includes('FLEET_NFT_ADDRESS') || fleet.length < 32)) {
|
|
73
|
+
throw new Error(`Invalid fleet address: "${fleet}". Please provide a valid Solana address (32-44 characters).`);
|
|
74
|
+
}
|
|
75
|
+
// Validate owner profile address
|
|
76
|
+
if (typeof ownerProfile === 'string' && (ownerProfile.includes('PROFILE_ADDRESS') || ownerProfile.length < 32)) {
|
|
77
|
+
throw new Error(`Invalid owner profile address: "${ownerProfile}". Please provide a valid Solana address (32-44 characters).`);
|
|
78
|
+
}
|
|
56
79
|
const input = {
|
|
57
|
-
owner, // Pass
|
|
80
|
+
owner: ownerSigner, // Pass TransactionSigner for proper handling
|
|
58
81
|
fleet: toAddress(fleet), // Convert fleet to Address
|
|
59
82
|
ownerProfile: toAddress(ownerProfile), // Convert ownerProfile to Address
|
|
60
83
|
gameId: resolvedAddresses.gameId, // Already Address from resolveProgramAddresses
|
|
@@ -66,12 +89,28 @@ async function _createContract(params, config) {
|
|
|
66
89
|
paymentsFeq: paymentsFreqWithPrefix, // Fixed: use paymentsFeq as expected by codama
|
|
67
90
|
ownerKeyIndex,
|
|
68
91
|
};
|
|
92
|
+
console.log('🏗️ Creating instruction with input:', {
|
|
93
|
+
ownerAddress: input.owner.address,
|
|
94
|
+
fleet: input.fleet,
|
|
95
|
+
ownerProfile: input.ownerProfile,
|
|
96
|
+
gameId: input.gameId,
|
|
97
|
+
sageProgram: input.sageProgram,
|
|
98
|
+
mint: input.mint,
|
|
99
|
+
rate: input.rate,
|
|
100
|
+
durationMin: input.durationMin,
|
|
101
|
+
durationMax: input.durationMax,
|
|
102
|
+
paymentsFeq: input.paymentsFeq,
|
|
103
|
+
programAddress: resolvedAddresses.srslyProgramAddress
|
|
104
|
+
});
|
|
69
105
|
// Get network-specific codama functions from centralized config
|
|
70
106
|
const instructionsModule = getModule('instructions');
|
|
71
|
-
const programsModule = getModule('programs');
|
|
72
107
|
const { getCreateContractInstructionAsync } = instructionsModule;
|
|
73
|
-
const {
|
|
74
|
-
|
|
108
|
+
const rawInstruction = await getCreateContractInstructionAsync(input, { programAddress: resolvedAddresses.srslyProgramAddress });
|
|
109
|
+
console.log('✅ Raw instruction created:', {
|
|
110
|
+
programAddress: rawInstruction.programAddress,
|
|
111
|
+
accountCount: rawInstruction.accounts?.length || 0,
|
|
112
|
+
hasData: !!rawInstruction.data
|
|
113
|
+
});
|
|
75
114
|
return createFluentInstruction(rawInstruction);
|
|
76
115
|
}
|
|
77
116
|
/**
|
|
@@ -161,4 +200,18 @@ export function createContract(params) {
|
|
|
161
200
|
const baseSelector = createConfigSelector((config) => _createContract(params, config));
|
|
162
201
|
return createSmartFluentConfigSelector(baseSelector);
|
|
163
202
|
}
|
|
203
|
+
// Demo export for documentation site
|
|
204
|
+
export const createContractDemo = {
|
|
205
|
+
tabName: "create",
|
|
206
|
+
description: "Create a new rental contract for your fleet",
|
|
207
|
+
imports: `import { createContract } from '@wuwei-labs/srsly';`,
|
|
208
|
+
instruction: `const instruction = await createContract({
|
|
209
|
+
owner: (signer || wallet).publicKey?.toBase58(),
|
|
210
|
+
fleet: "FLEET_NFT_ADDRESS",
|
|
211
|
+
ownerProfile: "YOUR_PROFILE_ADDRESS",
|
|
212
|
+
rate: 1, // ATLAS per payment period
|
|
213
|
+
durationMax: 86400, // 24 hours
|
|
214
|
+
paymentsFreq: "hourly" // or 'daily', 'weekly', or 'monthly'
|
|
215
|
+
});`
|
|
216
|
+
};
|
|
164
217
|
//# sourceMappingURL=create.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAsB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,SAAS,EAAsB,MAAM,iBAAiB,CAAC;AAC1H,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAA0B,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,+BAA+B,EAA0D,MAAM,gCAAgC,CAAC;AAClK,OAAO,EAAE,uBAAuB,EAAwB,MAAM,iBAAiB,CAAC;AAwEhF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,eAAe,CAAC,MAA4B,EAAE,MAAsB;IACjF,OAAO,CAAC,GAAG,CAAC,0CAA0C,EAAE;QACtD,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK;QACxB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC,CAAC;IAEH,MAAM,EACJ,KAAK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OX;CACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo exports for documentation site
|
|
3
|
+
*
|
|
4
|
+
* This module exports demo templates for all SRSLY SDK instructions.
|
|
5
|
+
* These templates are used in the documentation site to provide interactive examples.
|
|
6
|
+
*/
|
|
7
|
+
// Re-export demo templates from instruction files
|
|
8
|
+
export { createContractDemo } from './contract/create';
|
|
9
|
+
export { closeContractDemo } from './contract/close';
|
|
10
|
+
export { acceptRentalDemo } from './rental/accept';
|
|
11
|
+
export { cancelRentalDemo } from './rental/cancel';
|
|
12
|
+
export { closeRentalDemo } from './rental/close';
|
|
13
|
+
export { resetRentalDemo } from './rental/reset';
|
|
14
|
+
// Collect all demos for easy access
|
|
15
|
+
export const ALL_DEMOS = {
|
|
16
|
+
createContract: () => import('./contract/create').then(m => m.createContractDemo),
|
|
17
|
+
closeContract: () => import('./contract/close').then(m => m.closeContractDemo),
|
|
18
|
+
acceptRental: () => import('./rental/accept').then(m => m.acceptRentalDemo),
|
|
19
|
+
cancelRental: () => import('./rental/cancel').then(m => m.cancelRentalDemo),
|
|
20
|
+
closeRental: () => import('./rental/close').then(m => m.closeRentalDemo),
|
|
21
|
+
resetRental: () => import('./rental/reset').then(m => m.resetRentalDemo),
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=demos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demos.js","sourceRoot":"","sources":["../../src/demos.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAUjD,oCAAoC;AACpC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,cAAc,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC;IACjF,aAAa,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC;IAC9E,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAC3E,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAC3E,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;IACxE,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;CAChE,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -67,7 +67,7 @@ export * from "./utils";
|
|
|
67
67
|
* );
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
|
-
export { fetchContractState, fetchRentalState, fetchMultipleContractStates, fetchMultipleRentalStates } from "./utils/fetch-accounts";
|
|
70
|
+
export { fetchContractState, fetchRentalState, fetchConfigState, fetchMultipleContractStates, fetchMultipleRentalStates } from "./utils/fetch-accounts";
|
|
71
71
|
/**
|
|
72
72
|
* Payment frequency enum generated from the Rust program.
|
|
73
73
|
*
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,4BAA4B;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAyBxB;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,OAAO,EAEL,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACT,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,4BAA4B;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAyBxB;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,OAAO,EAEL,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACT,MAAM,kBAAkB,CAAC"}
|
package/dist/esm/package.json
CHANGED
|
@@ -22,6 +22,23 @@ import { createTransactionSigner } from '../utils/signer';
|
|
|
22
22
|
*/
|
|
23
23
|
async function _acceptRental(params, config) {
|
|
24
24
|
const { borrowerProfile, borrowerFaction, contract, duration, } = params;
|
|
25
|
+
// Validate that placeholder values have been replaced
|
|
26
|
+
if (contract === "CONTRACT_ADDRESS") {
|
|
27
|
+
throw new Error('Please replace "CONTRACT_ADDRESS" with a real contract address.\n\n' +
|
|
28
|
+
'To find contract addresses:\n' +
|
|
29
|
+
'1. Use the "Create Contract" operation to create a new contract\n' +
|
|
30
|
+
'2. Copy the contract address from the transaction result\n' +
|
|
31
|
+
'3. Replace "CONTRACT_ADDRESS" with the real address\n\n' +
|
|
32
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
33
|
+
}
|
|
34
|
+
if (borrowerProfile === "BORROWER_PROFILE_ADDRESS") {
|
|
35
|
+
throw new Error('Please replace "BORROWER_PROFILE_ADDRESS" with a real Star Atlas profile address.\n\n' +
|
|
36
|
+
'To find your profile address:\n' +
|
|
37
|
+
'1. Connect to Star Atlas SAGE with your wallet\n' +
|
|
38
|
+
'2. Your profile address will be displayed in the game\n' +
|
|
39
|
+
'3. Replace "BORROWER_PROFILE_ADDRESS" with the real address\n\n' +
|
|
40
|
+
'Example: "7CgMBZdvS8qXqv2fTQ9YZXPqJsKmn4TKEVa98MSTkHJ8"');
|
|
41
|
+
}
|
|
25
42
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
26
43
|
// Use global config as fallback, same pattern as constants.ts
|
|
27
44
|
const globalConfig = getConfig();
|
|
@@ -216,4 +233,17 @@ export function getAcceptRentalInstructionAsync(input, options) {
|
|
|
216
233
|
return instructionsModule.getAcceptRentalInstructionAsync(input, options);
|
|
217
234
|
});
|
|
218
235
|
}
|
|
236
|
+
// Demo export for documentation site
|
|
237
|
+
export const acceptRentalDemo = {
|
|
238
|
+
tabName: "accept",
|
|
239
|
+
description: "Accept a rental offer from an existing contract",
|
|
240
|
+
imports: `import { acceptRental, days } from '@wuwei-labs/srsly';`,
|
|
241
|
+
instruction: `const instruction = await acceptRental({
|
|
242
|
+
borrower: (signer || wallet).publicKey?.toBase58(),
|
|
243
|
+
borrowerProfile: "BORROWER_PROFILE_ADDRESS",
|
|
244
|
+
borrowerFaction: "oni", // or "mud", "ustur"
|
|
245
|
+
contract: "CONTRACT_ADDRESS",
|
|
246
|
+
duration: days(1) // or 86400 seconds
|
|
247
|
+
});`
|
|
248
|
+
};
|
|
219
249
|
//# sourceMappingURL=accept.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,SAAS,EAA2C,MAAM,iBAAiB,CAAC;AAC/I,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,+BAA+B,EAA0D,MAAM,gCAAgC,CAAC;AAClK,OAAO,EAAE,kBAAkB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GAAG,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACrF,OAAO,+BAA+B,CAAC,YAAY,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,oBAAoB,CAAC,KAAK,IAAI,EAAE;QACrC,MAAM,kBAAkB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qCAAqC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,iDAAiD;IAC9D,OAAO,EAAE,yDAAyD;IAClE,WAAW,EAAE;;;;;;IAMX;CACH,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { getModule, createConfigSelector } from '../utils/config';
|
|
1
|
+
import { getModule, createConfigSelector, resolveProgramAddresses, getConfig } from '../utils/config';
|
|
2
2
|
import { toAddress } from '../utils/constants';
|
|
3
3
|
import { createTransactionSigner } from '../utils/signer';
|
|
4
|
+
import { createFluentInstruction, createSmartFluentConfigSelector } from '../utils/instruction-converter';
|
|
5
|
+
import { fetchContractState, fetchConfigState } from '../utils/fetch-accounts';
|
|
6
|
+
import { deriveRentalState, deriveRentalAuthority, deriveRentalThread } from '../utils/pda';
|
|
4
7
|
/**
|
|
5
8
|
* Internal function to cancel a rental instruction with configuration options.
|
|
6
9
|
*
|
|
@@ -16,22 +19,58 @@ import { createTransactionSigner } from '../utils/signer';
|
|
|
16
19
|
*/
|
|
17
20
|
async function _cancelRental(params, config) {
|
|
18
21
|
const { contract, } = params;
|
|
22
|
+
// Validate that placeholder values have been replaced
|
|
23
|
+
if (contract === "CONTRACT_ADDRESS") {
|
|
24
|
+
throw new Error('Please replace "CONTRACT_ADDRESS" with a real contract address.\n\n' +
|
|
25
|
+
'To find contract addresses:\n' +
|
|
26
|
+
'1. Use the "Create Contract" operation to create a new contract\n' +
|
|
27
|
+
'2. Copy the contract address from the transaction result\n' +
|
|
28
|
+
'3. Replace "CONTRACT_ADDRESS" with the real address\n\n' +
|
|
29
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
30
|
+
}
|
|
31
|
+
// Additional validation for short strings that might cause issues
|
|
32
|
+
if (typeof contract === 'string' && contract.length < 32) {
|
|
33
|
+
throw new Error(`Invalid contract address: "${contract}" (length: ${contract.length})\n\n` +
|
|
34
|
+
'Solana addresses must be 32-44 characters long.\n' +
|
|
35
|
+
'Please provide a valid base58-encoded Solana address.\n\n' +
|
|
36
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
37
|
+
}
|
|
19
38
|
// Handle borrower using smart signer handler for universal compatibility
|
|
20
39
|
const borrower = createTransactionSigner(params.borrower);
|
|
21
40
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
// Use global config as fallback, same pattern as closeContract
|
|
42
|
+
const globalConfig = getConfig();
|
|
43
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
44
|
+
const resolvedAddresses = await resolveProgramAddresses(effectiveConfig);
|
|
45
|
+
// Fetch contract state using high-level function (same pattern as close contract)
|
|
46
|
+
const contractState = await fetchContractState(toAddress(contract));
|
|
47
|
+
// Fetch config state to get the authority using zero-argument overload
|
|
48
|
+
const configState = await fetchConfigState();
|
|
49
|
+
if (!configState.exists) {
|
|
50
|
+
throw new Error('Config not found');
|
|
51
|
+
}
|
|
52
|
+
const authorityAddress = configState.data.authority;
|
|
53
|
+
// Derive PDAs individually (same pattern as accept rental to ensure consistency)
|
|
54
|
+
const rentalStatePda = await deriveRentalState(toAddress(contract), toAddress(borrower.address), resolvedAddresses.srslyProgramAddress);
|
|
55
|
+
const rentalAuthorityPda = await deriveRentalAuthority(resolvedAddresses.srslyProgramAddress.toString());
|
|
56
|
+
const rentalThreadPda = await deriveRentalThread(rentalAuthorityPda, rentalStatePda, resolvedAddresses.antegenProgramAddress);
|
|
57
|
+
// Build the input with all required accounts (same pattern as accept rental)
|
|
25
58
|
const input = {
|
|
26
59
|
borrower: borrower, // TransactionSigner for Codama
|
|
27
|
-
|
|
60
|
+
owner: toAddress(contractState.data.owner),
|
|
61
|
+
contract: toAddress(contract),
|
|
62
|
+
authority: toAddress(authorityAddress),
|
|
63
|
+
mint: resolvedAddresses.atlasMint,
|
|
64
|
+
// Override the auto-generated PDAs with our manually derived ones (same as accept rental)
|
|
65
|
+
rentalState: rentalStatePda,
|
|
66
|
+
rentalAuthority: rentalAuthorityPda,
|
|
67
|
+
rentalThread: rentalThreadPda,
|
|
28
68
|
};
|
|
29
69
|
// Get network-specific codama functions from centralized config
|
|
30
70
|
const instructionsModule = getModule('instructions');
|
|
31
|
-
const programsModule = getModule('programs');
|
|
32
71
|
const { getCancelRentalInstructionAsync } = instructionsModule;
|
|
33
|
-
const {
|
|
34
|
-
return
|
|
72
|
+
const rawInstruction = await getCancelRentalInstructionAsync(input, { programAddress: resolvedAddresses.srslyProgramAddress });
|
|
73
|
+
return createFluentInstruction(rawInstruction);
|
|
35
74
|
}
|
|
36
75
|
/**
|
|
37
76
|
* Creates an instruction to cancel a rental with fluent configuration.
|
|
@@ -99,11 +138,12 @@ async function _cancelRental(params, config) {
|
|
|
99
138
|
* ```
|
|
100
139
|
*
|
|
101
140
|
* @param params - The rental cancellation parameters including borrower and contract
|
|
102
|
-
* @returns A
|
|
141
|
+
* @returns A SmartFluentConfigSelector that can be configured with .set() or awaited directly
|
|
103
142
|
* @throws Error when rental is not active, caller is not the borrower, or instruction generation fails
|
|
104
143
|
*/
|
|
105
144
|
export function cancelRental(params) {
|
|
106
|
-
|
|
145
|
+
const baseSelector = createConfigSelector((config) => _cancelRental(params, config));
|
|
146
|
+
return createSmartFluentConfigSelector(baseSelector);
|
|
107
147
|
}
|
|
108
148
|
/**
|
|
109
149
|
* Low-level function to create a rental cancellation instruction with raw input parameters.
|
|
@@ -123,4 +163,14 @@ export function getCancelRentalInstructionAsync(input, options) {
|
|
|
123
163
|
return instructionsModule.getCancelRentalInstructionAsync(input, options);
|
|
124
164
|
});
|
|
125
165
|
}
|
|
166
|
+
// Demo export for documentation site
|
|
167
|
+
export const cancelRentalDemo = {
|
|
168
|
+
tabName: "cancel",
|
|
169
|
+
description: "Cancel an active rental",
|
|
170
|
+
imports: `import { cancelRental } from '@wuwei-labs/srsly';`,
|
|
171
|
+
instruction: `const instruction = await cancelRental({
|
|
172
|
+
borrower: (signer || wallet).publicKey?.toBase58(),
|
|
173
|
+
contract: "CONTRACT_ADDRESS"
|
|
174
|
+
});`
|
|
175
|
+
};
|
|
126
176
|
//# sourceMappingURL=cancel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,SAAS,EAA2C,MAAM,iBAAiB,CAAC;AAC/I,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAwB,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,+BAA+B,EAA0D,MAAM,gCAAgC,CAAC;AAClK,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAA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