@wuwei-labs/srsly 2.0.0-beta.46 → 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 +19 -1
- 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 +19 -1
- 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.map +1 -1
- package/package.json +7 -1
- package/target/idl/srsly.json +1 -23
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.acceptRentalDemo = void 0;
|
|
3
4
|
exports.acceptRental = acceptRental;
|
|
4
5
|
exports.getAcceptRentalInstructionAsync = getAcceptRentalInstructionAsync;
|
|
5
6
|
const config_1 = require("../utils/config");
|
|
@@ -26,6 +27,23 @@ const signer_1 = require("../utils/signer");
|
|
|
26
27
|
*/
|
|
27
28
|
async function _acceptRental(params, config) {
|
|
28
29
|
const { borrowerProfile, borrowerFaction, contract, duration, } = params;
|
|
30
|
+
// Validate that placeholder values have been replaced
|
|
31
|
+
if (contract === "CONTRACT_ADDRESS") {
|
|
32
|
+
throw new Error('Please replace "CONTRACT_ADDRESS" with a real contract address.\n\n' +
|
|
33
|
+
'To find contract addresses:\n' +
|
|
34
|
+
'1. Use the "Create Contract" operation to create a new contract\n' +
|
|
35
|
+
'2. Copy the contract address from the transaction result\n' +
|
|
36
|
+
'3. Replace "CONTRACT_ADDRESS" with the real address\n\n' +
|
|
37
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
38
|
+
}
|
|
39
|
+
if (borrowerProfile === "BORROWER_PROFILE_ADDRESS") {
|
|
40
|
+
throw new Error('Please replace "BORROWER_PROFILE_ADDRESS" with a real Star Atlas profile address.\n\n' +
|
|
41
|
+
'To find your profile address:\n' +
|
|
42
|
+
'1. Connect to Star Atlas SAGE with your wallet\n' +
|
|
43
|
+
'2. Your profile address will be displayed in the game\n' +
|
|
44
|
+
'3. Replace "BORROWER_PROFILE_ADDRESS" with the real address\n\n' +
|
|
45
|
+
'Example: "7CgMBZdvS8qXqv2fTQ9YZXPqJsKmn4TKEVa98MSTkHJ8"');
|
|
46
|
+
}
|
|
29
47
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
30
48
|
// Use global config as fallback, same pattern as constants.ts
|
|
31
49
|
const globalConfig = (0, config_1.getConfig)();
|
|
@@ -220,4 +238,17 @@ function getAcceptRentalInstructionAsync(input, options) {
|
|
|
220
238
|
return instructionsModule.getAcceptRentalInstructionAsync(input, options);
|
|
221
239
|
});
|
|
222
240
|
}
|
|
241
|
+
// Demo export for documentation site
|
|
242
|
+
exports.acceptRentalDemo = {
|
|
243
|
+
tabName: "accept",
|
|
244
|
+
description: "Accept a rental offer from an existing contract",
|
|
245
|
+
imports: `import { acceptRental, days } from '@wuwei-labs/srsly';`,
|
|
246
|
+
instruction: `const instruction = await acceptRental({
|
|
247
|
+
borrower: (signer || wallet).publicKey?.toBase58(),
|
|
248
|
+
borrowerProfile: "BORROWER_PROFILE_ADDRESS",
|
|
249
|
+
borrowerFaction: "oni", // or "mud", "ustur"
|
|
250
|
+
contract: "CONTRACT_ADDRESS",
|
|
251
|
+
duration: days(1) // or 86400 seconds
|
|
252
|
+
});`
|
|
253
|
+
};
|
|
223
254
|
//# sourceMappingURL=accept.js.map
|
|
@@ -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":";;;AAkUA,oCAKC;AAcD,0EAKC;AA1VD,4CAA+I;AAC/I,kDAAkE;AAClE,oCAA8C;AAC9C,0EAAkK;AAClK,4DAA6D;AAC7D,gEAA4E;AAC5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,KAAY,EACZ,EAAE,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAC1D,CAAC;IACF,OAAO,IAAA,+CAAuB,EAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyGG;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;AAED,qCAAqC;AACxB,QAAA,gBAAgB,GAAG;IAC9B,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,iDAAiD;IAC9D,OAAO,EAAE,yDAAyD;IAClE,WAAW,EAAE;;;;;;IAMX;CACH,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cancelRentalDemo = void 0;
|
|
3
4
|
exports.cancelRental = cancelRental;
|
|
4
5
|
exports.getCancelRentalInstructionAsync = getCancelRentalInstructionAsync;
|
|
5
6
|
const config_1 = require("../utils/config");
|
|
6
7
|
const constants_1 = require("../utils/constants");
|
|
7
8
|
const signer_1 = require("../utils/signer");
|
|
9
|
+
const instruction_converter_1 = require("../utils/instruction-converter");
|
|
10
|
+
const fetch_accounts_1 = require("../utils/fetch-accounts");
|
|
11
|
+
const pda_1 = require("../utils/pda");
|
|
8
12
|
/**
|
|
9
13
|
* Internal function to cancel a rental instruction with configuration options.
|
|
10
14
|
*
|
|
@@ -20,22 +24,58 @@ const signer_1 = require("../utils/signer");
|
|
|
20
24
|
*/
|
|
21
25
|
async function _cancelRental(params, config) {
|
|
22
26
|
const { contract, } = params;
|
|
27
|
+
// Validate that placeholder values have been replaced
|
|
28
|
+
if (contract === "CONTRACT_ADDRESS") {
|
|
29
|
+
throw new Error('Please replace "CONTRACT_ADDRESS" with a real contract address.\n\n' +
|
|
30
|
+
'To find contract addresses:\n' +
|
|
31
|
+
'1. Use the "Create Contract" operation to create a new contract\n' +
|
|
32
|
+
'2. Copy the contract address from the transaction result\n' +
|
|
33
|
+
'3. Replace "CONTRACT_ADDRESS" with the real address\n\n' +
|
|
34
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
35
|
+
}
|
|
36
|
+
// Additional validation for short strings that might cause issues
|
|
37
|
+
if (typeof contract === 'string' && contract.length < 32) {
|
|
38
|
+
throw new Error(`Invalid contract address: "${contract}" (length: ${contract.length})\n\n` +
|
|
39
|
+
'Solana addresses must be 32-44 characters long.\n' +
|
|
40
|
+
'Please provide a valid base58-encoded Solana address.\n\n' +
|
|
41
|
+
'Example: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"');
|
|
42
|
+
}
|
|
23
43
|
// Handle borrower using smart signer handler for universal compatibility
|
|
24
44
|
const borrower = (0, signer_1.createTransactionSigner)(params.borrower);
|
|
25
45
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
// Use global config as fallback, same pattern as closeContract
|
|
47
|
+
const globalConfig = (0, config_1.getConfig)();
|
|
48
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
49
|
+
const resolvedAddresses = await (0, config_1.resolveProgramAddresses)(effectiveConfig);
|
|
50
|
+
// Fetch contract state using high-level function (same pattern as close contract)
|
|
51
|
+
const contractState = await (0, fetch_accounts_1.fetchContractState)((0, constants_1.toAddress)(contract));
|
|
52
|
+
// Fetch config state to get the authority using zero-argument overload
|
|
53
|
+
const configState = await (0, fetch_accounts_1.fetchConfigState)();
|
|
54
|
+
if (!configState.exists) {
|
|
55
|
+
throw new Error('Config not found');
|
|
56
|
+
}
|
|
57
|
+
const authorityAddress = configState.data.authority;
|
|
58
|
+
// Derive PDAs individually (same pattern as accept rental to ensure consistency)
|
|
59
|
+
const rentalStatePda = await (0, pda_1.deriveRentalState)((0, constants_1.toAddress)(contract), (0, constants_1.toAddress)(borrower.address), resolvedAddresses.srslyProgramAddress);
|
|
60
|
+
const rentalAuthorityPda = await (0, pda_1.deriveRentalAuthority)(resolvedAddresses.srslyProgramAddress.toString());
|
|
61
|
+
const rentalThreadPda = await (0, pda_1.deriveRentalThread)(rentalAuthorityPda, rentalStatePda, resolvedAddresses.antegenProgramAddress);
|
|
62
|
+
// Build the input with all required accounts (same pattern as accept rental)
|
|
29
63
|
const input = {
|
|
30
64
|
borrower: borrower, // TransactionSigner for Codama
|
|
31
|
-
|
|
65
|
+
owner: (0, constants_1.toAddress)(contractState.data.owner),
|
|
66
|
+
contract: (0, constants_1.toAddress)(contract),
|
|
67
|
+
authority: (0, constants_1.toAddress)(authorityAddress),
|
|
68
|
+
mint: resolvedAddresses.atlasMint,
|
|
69
|
+
// Override the auto-generated PDAs with our manually derived ones (same as accept rental)
|
|
70
|
+
rentalState: rentalStatePda,
|
|
71
|
+
rentalAuthority: rentalAuthorityPda,
|
|
72
|
+
rentalThread: rentalThreadPda,
|
|
32
73
|
};
|
|
33
74
|
// Get network-specific codama functions from centralized config
|
|
34
75
|
const instructionsModule = (0, config_1.getModule)('instructions');
|
|
35
|
-
const programsModule = (0, config_1.getModule)('programs');
|
|
36
76
|
const { getCancelRentalInstructionAsync } = instructionsModule;
|
|
37
|
-
const {
|
|
38
|
-
return
|
|
77
|
+
const rawInstruction = await getCancelRentalInstructionAsync(input, { programAddress: resolvedAddresses.srslyProgramAddress });
|
|
78
|
+
return (0, instruction_converter_1.createFluentInstruction)(rawInstruction);
|
|
39
79
|
}
|
|
40
80
|
/**
|
|
41
81
|
* Creates an instruction to cancel a rental with fluent configuration.
|
|
@@ -103,11 +143,12 @@ async function _cancelRental(params, config) {
|
|
|
103
143
|
* ```
|
|
104
144
|
*
|
|
105
145
|
* @param params - The rental cancellation parameters including borrower and contract
|
|
106
|
-
* @returns A
|
|
146
|
+
* @returns A SmartFluentConfigSelector that can be configured with .set() or awaited directly
|
|
107
147
|
* @throws Error when rental is not active, caller is not the borrower, or instruction generation fails
|
|
108
148
|
*/
|
|
109
149
|
function cancelRental(params) {
|
|
110
|
-
|
|
150
|
+
const baseSelector = (0, config_1.createConfigSelector)((config) => _cancelRental(params, config));
|
|
151
|
+
return (0, instruction_converter_1.createSmartFluentConfigSelector)(baseSelector);
|
|
111
152
|
}
|
|
112
153
|
/**
|
|
113
154
|
* Low-level function to create a rental cancellation instruction with raw input parameters.
|
|
@@ -127,4 +168,14 @@ function getCancelRentalInstructionAsync(input, options) {
|
|
|
127
168
|
return instructionsModule.getCancelRentalInstructionAsync(input, options);
|
|
128
169
|
});
|
|
129
170
|
}
|
|
171
|
+
// Demo export for documentation site
|
|
172
|
+
exports.cancelRentalDemo = {
|
|
173
|
+
tabName: "cancel",
|
|
174
|
+
description: "Cancel an active rental",
|
|
175
|
+
imports: `import { cancelRental } from '@wuwei-labs/srsly';`,
|
|
176
|
+
instruction: `const instruction = await cancelRental({
|
|
177
|
+
borrower: (signer || wallet).publicKey?.toBase58(),
|
|
178
|
+
contract: "CONTRACT_ADDRESS"
|
|
179
|
+
});`
|
|
180
|
+
};
|
|
130
181
|
//# sourceMappingURL=cancel.js.map
|
|
@@ -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":";;;AAkNA,oCAKC;AAcD,0EAKC;AA1OD,4CAA+I;AAC/I,kDAA+C;AAC/C,4CAAgF;AAChF,0EAAkK;AAClK,4DAA+E;AAC/E,sCAA4F;AA8B5F;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA0B,EAC1B,MAAsB;IAEtB,MAAM,EACJ,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,sDAAsD;IACtD,IAAI,QAAQ,KAAK,kBAAkB,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,qEAAqE;YACrE,+BAA+B;YAC/B,mEAAmE;YACnE,4DAA4D;YAC5D,yDAAyD;YACzD,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,kEAAkE;IAClE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CACb,8BAA8B,QAAQ,cAAc,QAAQ,CAAC,MAAM,OAAO;YAC1E,mDAAmD;YACnD,2DAA2D;YAC3D,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,yEAAyE;IACzE,MAAM,QAAQ,GAAG,IAAA,gCAAuB,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE1D,gFAAgF;IAChF,+DAA+D;IAC/D,MAAM,YAAY,GAAG,IAAA,kBAAS,GAAE,CAAC;IACjC,MAAM,eAAe,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,eAAe,CAAC,CAAC;IAEzE,kFAAkF;IAClF,MAAM,aAAa,GAAG,MAA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,EAAE,GAAG,kBAAkB,CAAC;IAE/D,MAAM,cAAc,GAAG,MAAM,+BAA+B,CAC1D,KAAK,EACL,EAAE,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAC1D,CAAC;IAEF,OAAO,IAAA,+CAAuB,EAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;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;AAED,qCAAqC;AACxB,QAAA,gBAAgB,GAAG;IAC9B,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,yBAAyB;IACtC,OAAO,EAAE,mDAAmD;IAC5D,WAAW,EAAE;;;IAGX;CACH,CAAC"}
|
package/dist/cjs/rental/close.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.closeRentalDemo = void 0;
|
|
3
4
|
exports.closeRental = closeRental;
|
|
4
5
|
exports.getCloseRentalInstructionAsync = getCloseRentalInstructionAsync;
|
|
5
6
|
const config_1 = require("../utils/config");
|
|
6
7
|
const constants_1 = require("../utils/constants");
|
|
7
8
|
const instruction_converter_1 = require("../utils/instruction-converter");
|
|
8
9
|
const accounts_1 = require("../codama/accounts");
|
|
10
|
+
const fetch_accounts_1 = require("../utils/fetch-accounts");
|
|
9
11
|
const kit_1 = require("@solana/kit");
|
|
10
12
|
const pda_1 = require("../utils/pda");
|
|
13
|
+
const signer_1 = require("../utils/signer");
|
|
11
14
|
/**
|
|
12
15
|
* Internal function to close a rental instruction with configuration options.
|
|
13
16
|
*
|
|
@@ -22,22 +25,25 @@ const pda_1 = require("../utils/pda");
|
|
|
22
25
|
* @throws Error when instruction generation fails or required parameters are missing
|
|
23
26
|
*/
|
|
24
27
|
async function _closeRental(params, config) {
|
|
25
|
-
const { payer,
|
|
28
|
+
const { payer, rentalState, } = params;
|
|
26
29
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
27
|
-
|
|
30
|
+
// Use global config as fallback, same pattern as acceptRental
|
|
31
|
+
const globalConfig = (0, config_1.getConfig)();
|
|
32
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
33
|
+
const resolvedAddresses = await (0, config_1.resolveProgramAddresses)(effectiveConfig);
|
|
28
34
|
// Create RPC from resolved addresses
|
|
29
35
|
if (!resolvedAddresses.rpcUrl) {
|
|
30
36
|
throw new Error('rpcUrl is required for close rental operation. Use setConfig({ library: "kit", rpcUrl: "https://..." })');
|
|
31
37
|
}
|
|
32
38
|
const rpc = (0, kit_1.createSolanaRpc)(resolvedAddresses.rpcUrl);
|
|
33
39
|
// Fetch rental state to get contract and borrower
|
|
34
|
-
let
|
|
40
|
+
let rentalStateAddress;
|
|
35
41
|
try {
|
|
36
|
-
if (!
|
|
37
|
-
throw new Error(`
|
|
42
|
+
if (!rentalState) {
|
|
43
|
+
throw new Error(`rentalState is ${rentalState}, cannot proceed`);
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
if (!
|
|
45
|
+
rentalStateAddress = await (0, accounts_1.fetchMaybeRentalState)(rpc, (0, constants_1.toAddress)(rentalState));
|
|
46
|
+
if (!rentalStateAddress.exists) {
|
|
41
47
|
throw new Error(`Rental state not found: ${rentalStateAddress}`);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
@@ -45,12 +51,12 @@ async function _closeRental(params, config) {
|
|
|
45
51
|
throw new Error(`Failed to fetch rental state: ${error}`);
|
|
46
52
|
}
|
|
47
53
|
// Extract required addresses from rental state
|
|
48
|
-
const contractAddress =
|
|
49
|
-
const borrower =
|
|
54
|
+
const contractAddress = rentalStateAddress.data.contract;
|
|
55
|
+
const borrower = rentalStateAddress.data.borrower;
|
|
50
56
|
// Derive PDAs similar to accept.ts
|
|
51
57
|
const rentalAuthorityPda = await (0, pda_1.deriveRentalAuthority)(resolvedAddresses.srslyProgramAddress.toString());
|
|
52
58
|
// 🔧 FIX: Derive rental thread PDA using Antegen program ID and the passed-in rental state address
|
|
53
|
-
const rentalThreadPda = await (0, pda_1.deriveRentalThread)(rentalAuthorityPda, (0, constants_1.toAddress)(
|
|
59
|
+
const rentalThreadPda = await (0, pda_1.deriveRentalThread)(rentalAuthorityPda, (0, constants_1.toAddress)(rentalState), // Use the passed-in rental state address
|
|
54
60
|
resolvedAddresses.antegenProgramAddress);
|
|
55
61
|
// Fetch contract state to get owner
|
|
56
62
|
let contractState;
|
|
@@ -63,26 +69,22 @@ async function _closeRental(params, config) {
|
|
|
63
69
|
catch (error) {
|
|
64
70
|
throw new Error(`Failed to fetch contract state: ${error}`);
|
|
65
71
|
}
|
|
66
|
-
// Fetch config state to get the authority
|
|
67
|
-
const [configPda] = await (0, kit_1.getProgramDerivedAddress)({
|
|
68
|
-
programAddress: resolvedAddresses.srslyProgramAddress,
|
|
69
|
-
seeds: [
|
|
70
|
-
(0, kit_1.getBytesEncoder)().encode(new Uint8Array([99, 111, 110, 102, 105, 103])), // "config"
|
|
71
|
-
],
|
|
72
|
-
});
|
|
72
|
+
// Fetch config state to get the authority using zero-argument overload
|
|
73
73
|
let configState;
|
|
74
74
|
try {
|
|
75
|
-
configState = await (0,
|
|
75
|
+
configState = await (0, fetch_accounts_1.fetchConfigState)();
|
|
76
76
|
if (!configState.exists) {
|
|
77
|
-
throw new Error(
|
|
77
|
+
throw new Error('Config not found');
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
81
81
|
throw new Error(`Failed to fetch config state: ${error}`);
|
|
82
82
|
}
|
|
83
|
+
// Handle payer using smart signer handler for universal compatibility
|
|
84
|
+
const payerSigner = (0, signer_1.createTransactionSigner)(payer);
|
|
83
85
|
// Only provide required fields - let Codama auto-generate the rest except rental_thread
|
|
84
86
|
const input = {
|
|
85
|
-
payer:
|
|
87
|
+
payer: payerSigner, // Pass TransactionSigner for proper handling
|
|
86
88
|
mint: resolvedAddresses.atlasMint, // Use resolved ATLAS mint from config
|
|
87
89
|
authority: (0, constants_1.toAddress)(configState.data.authority), // Config authority for fee collection
|
|
88
90
|
borrower: (0, constants_1.toAddress)(borrower),
|
|
@@ -142,19 +144,19 @@ async function _closeRental(params, config) {
|
|
|
142
144
|
* // Close a completed rental
|
|
143
145
|
* const instruction = await closeRental({
|
|
144
146
|
* payer: wallet, // Transaction payer
|
|
145
|
-
*
|
|
147
|
+
* rentalState: "RentalState..." // Rental state address
|
|
146
148
|
* });
|
|
147
149
|
*
|
|
148
150
|
* // Configure for mainnet
|
|
149
151
|
* const mainnetInstruction = await closeRental({
|
|
150
152
|
* payer: wallet,
|
|
151
|
-
*
|
|
153
|
+
* rentalState: "RentalState..."
|
|
152
154
|
* }).set({ programs: 'mainnet' });
|
|
153
155
|
*
|
|
154
156
|
* // Convert to @solana/web3.js format
|
|
155
157
|
* const web3jsInstruction = await closeRental({
|
|
156
158
|
* payer: wallet,
|
|
157
|
-
*
|
|
159
|
+
* rentalState: "RentalState..."
|
|
158
160
|
* }).web3js();
|
|
159
161
|
*
|
|
160
162
|
* // Use with your preferred Solana library
|
|
@@ -188,4 +190,14 @@ function getCloseRentalInstructionAsync(input, options) {
|
|
|
188
190
|
return instructionsModule.getCloseRentalInstructionAsync(input, options);
|
|
189
191
|
});
|
|
190
192
|
}
|
|
193
|
+
// Demo export for documentation site
|
|
194
|
+
exports.closeRentalDemo = {
|
|
195
|
+
tabName: "close",
|
|
196
|
+
description: "Close a completed rental",
|
|
197
|
+
imports: `import { closeRental } from '@wuwei-labs/srsly';`,
|
|
198
|
+
instruction: `const instruction = await closeRental({
|
|
199
|
+
payer: (signer || wallet).publicKey?.toBase58(),
|
|
200
|
+
rentalState: "RENTAL_STATE_ADDRESS"
|
|
201
|
+
});`
|
|
202
|
+
};
|
|
191
203
|
//# sourceMappingURL=close.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":";;;AA+NA,kCAKC;AAcD,wEAKC;AAvPD,4CAA+I;AAC/I,kDAA+C;AAE/C,0EAAkK;AAClK,iDAAoF;AACpF,4DAA2D;AAC3D,qCAA8C;AAC9C,sCAAyE;AACzE,4CAAgF;AA6BhF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,YAAY,CACzB,MAAyB,EACzB,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,WAAW,GACZ,GAAG,MAAM,CAAC;IAEX,gFAAgF;IAChF,8DAA8D;IAC9D,MAAM,YAAY,GAAG,IAAA,kBAAS,GAAE,CAAC;IACjC,MAAM,eAAe,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,eAAe,CAAC,CAAC;IAEzE,qCAAqC;IACrC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yGAAyG,CAAC,CAAC;IAC7H,CAAC;IACD,MAAM,GAAG,GAA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AAE,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAC1D,CAAC;IACF,OAAO,IAAA,+CAAuB,EAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,SAAgB,WAAW,CACzB,MAAyB;IAEzB,MAAM,YAAY,GAAG,IAAA,6BAAoB,EAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpF,OAAO,IAAA,uDAA+B,EAAC,YAAY,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,8BAA8B,CAAC,KAAU,EAAE,OAAa;IACtE,OAAO,IAAA,6BAAoB,EAAC,KAAK,IAAI,EAAE;QACrC,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,8BAA8B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qCAAqC;AACxB,QAAA,eAAe,GAAG;IAC7B,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,0BAA0B;IACvC,OAAO,EAAE,kDAAkD;IAC3D,WAAW,EAAE;;;IAGX;CACH,CAAC"}
|
|
@@ -7,6 +7,7 @@ const utils_1 = require("../utils");
|
|
|
7
7
|
const instruction_converter_1 = require("../utils/instruction-converter");
|
|
8
8
|
const accounts_1 = require("../codama/accounts");
|
|
9
9
|
const kit_1 = require("@solana/kit");
|
|
10
|
+
const signer_1 = require("../utils/signer");
|
|
10
11
|
/**
|
|
11
12
|
* Internal function to create a contract reset temp instruction with configuration options.
|
|
12
13
|
*
|
|
@@ -42,9 +43,11 @@ async function _resetContractTemp(params, config) {
|
|
|
42
43
|
// Manually derive ALL game accounts - they all use different program addresses
|
|
43
44
|
const { starbase, starbasePlayer } = await (0, utils_1.deriveGameAccounts)((0, constants_1.toAddress)(ownerProfile), faction, resolvedAddresses.gameId, 0, // starbaseSeqId
|
|
44
45
|
config);
|
|
46
|
+
// Handle signer using smart signer handler for universal compatibility
|
|
47
|
+
const signerTransactionSigner = (0, signer_1.createTransactionSigner)(signer);
|
|
45
48
|
// Create input for the instruction
|
|
46
49
|
const input = {
|
|
47
|
-
signer:
|
|
50
|
+
signer: signerTransactionSigner, // Pass TransactionSigner for proper handling
|
|
48
51
|
contract: (0, constants_1.toAddress)(contract), // Contract to reset
|
|
49
52
|
fleet: (0, constants_1.toAddress)(fleet), // Fleet from contract
|
|
50
53
|
gameId: resolvedAddresses.gameId, // Game ID from config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reset-contract-temp.js","sourceRoot":"","sources":["../../../src/rental/reset-contract-temp.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reset-contract-temp.js","sourceRoot":"","sources":["../../../src/rental/reset-contract-temp.ts"],"names":[],"mappings":";;AAwKA,8CAKC;AA7KD,4CAA+I;AAC/I,kDAA+C;AAC/C,oCAA8C;AAC9C,0EAAkK;AAClK,iDAA6D;AAC7D,qCAA8C;AAC9C,4CAAgF;AAuChF;;;;;;;;GAQG;AACH,KAAK,UAAU,kBAAkB,CAC/B,MAA+B,EAC/B,MAAsB;IAEtB,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,YAAY,GACb,GAAG,MAAM,CAAC;IAEX,gFAAgF;IAChF,MAAM,YAAY,GAAG,IAAA,kBAAS,GAAE,CAAC;IACjC,MAAM,eAAe,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,eAAe,CAAC,CAAC;IAEzE,sDAAsD;IACtD,IAAI,aAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC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cAAc,CAAC,EAAG,0BAA0B;QACtE,WAAW,EAAE,iBAAiB,CAAC,kBAAkB,EAAE,2BAA2B;KAC/E,CAAC;IAEF,gEAAgE;IAChE,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;IACrD,MAAM,EAAE,oCAAoC,EAAE,GAAG,kBAAkB,CAAC;IAEpE,MAAM,cAAc,GAAG,MAAM,oCAAoC,CAC/D,KAAY,EACZ,EAAE,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAC1D,CAAC;IAEF,OAAO,IAAA,+CAAuB,EAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,SAAgB,iBAAiB,CAC/B,MAA+B;IAE/B,MAAM,YAAY,GAAG,IAAA,6BAAoB,EAAC,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1F,OAAO,IAAA,uDAA+B,EAAC,YAAY,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/cjs/rental/reset.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetRentalDemo = void 0;
|
|
3
4
|
exports.resetRental = resetRental;
|
|
4
5
|
exports.getResetRentalInstructionAsync = getResetRentalInstructionAsync;
|
|
5
6
|
const config_1 = require("../utils/config");
|
|
6
7
|
const constants_1 = require("../utils/constants");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const instruction_converter_1 = require("../utils/instruction-converter");
|
|
10
|
+
const fetch_accounts_1 = require("../utils/fetch-accounts");
|
|
11
|
+
const signer_1 = require("../utils/signer");
|
|
8
12
|
/**
|
|
9
13
|
* Internal function to reset a rental instruction with configuration options.
|
|
10
14
|
*
|
|
@@ -19,28 +23,115 @@ const utils_1 = require("../utils");
|
|
|
19
23
|
* @throws Error when account derivation fails or required parameters are missing
|
|
20
24
|
*/
|
|
21
25
|
async function _resetRental(params, config) {
|
|
26
|
+
console.log('🔄 Starting resetRental with params:', {
|
|
27
|
+
hasPayer: !!params.payer,
|
|
28
|
+
hasFleet: !!params.fleet,
|
|
29
|
+
contract: params.contract,
|
|
30
|
+
hasRentalState: !!params.rentalState,
|
|
31
|
+
faction: params.faction,
|
|
32
|
+
hasOwnerProfile: !!params.ownerProfile
|
|
33
|
+
});
|
|
22
34
|
const { payer, fleet, contract, rentalState, faction, ownerProfile, } = params;
|
|
23
35
|
// Get the resolved addresses from config (including network-specific addresses)
|
|
24
|
-
|
|
36
|
+
// Use global config as fallback, same pattern as acceptRental
|
|
37
|
+
const globalConfig = (0, config_1.getConfig)();
|
|
38
|
+
const effectiveConfig = { ...globalConfig, ...config };
|
|
39
|
+
const resolvedAddresses = await (0, config_1.resolveProgramAddresses)(effectiveConfig);
|
|
40
|
+
// Validate contract address before fetching
|
|
41
|
+
if (typeof contract === 'string' && (contract.includes('CONTRACT_ADDRESS') || contract.length < 32)) {
|
|
42
|
+
throw new Error(`Invalid contract address: "${contract}". Please provide a valid Solana address (32-44 characters).`);
|
|
43
|
+
}
|
|
44
|
+
// Fetch fleet, rentalState, and ownerProfile from contract if not provided
|
|
45
|
+
let fleetAddress;
|
|
46
|
+
let rentalStateAddress;
|
|
47
|
+
let ownerProfileAddress;
|
|
48
|
+
// Check if we need to fetch contract state
|
|
49
|
+
const needsContractFetch = !fleet || !rentalState || !ownerProfile;
|
|
50
|
+
if (needsContractFetch) {
|
|
51
|
+
console.log('🔍 Fetching contract state to retrieve missing fields...');
|
|
52
|
+
try {
|
|
53
|
+
const contractState = await (0, fetch_accounts_1.fetchContractState)((0, constants_1.toAddress)(contract));
|
|
54
|
+
// Use provided fleet or fetch from contract
|
|
55
|
+
if (fleet) {
|
|
56
|
+
if (typeof fleet === 'string' && (fleet.includes('FLEET_ADDRESS') || fleet.length < 32)) {
|
|
57
|
+
throw new Error(`Invalid fleet address: "${fleet}". Please provide a valid Solana address (32-44 characters).`);
|
|
58
|
+
}
|
|
59
|
+
fleetAddress = fleet;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
fleetAddress = contractState.data.fleet;
|
|
63
|
+
}
|
|
64
|
+
// Use provided rentalState or fetch from contract
|
|
65
|
+
if (rentalState) {
|
|
66
|
+
if (typeof rentalState === 'string' && (rentalState.includes('RENTAL_STATE_ADDRESS') || rentalState.length < 32)) {
|
|
67
|
+
throw new Error(`Invalid rental state address: "${rentalState}". Please provide a valid Solana address (32-44 characters).`);
|
|
68
|
+
}
|
|
69
|
+
rentalStateAddress = rentalState;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
rentalStateAddress = contractState.data.currentRentalState;
|
|
73
|
+
}
|
|
74
|
+
// Use provided ownerProfile or fetch from contract
|
|
75
|
+
if (ownerProfile) {
|
|
76
|
+
if (typeof ownerProfile === 'string' && (ownerProfile.includes('OWNER_PROFILE_ADDRESS') || ownerProfile.length < 32)) {
|
|
77
|
+
throw new Error(`Invalid owner profile address: "${ownerProfile}". Please provide a valid Solana address (32-44 characters).`);
|
|
78
|
+
}
|
|
79
|
+
ownerProfileAddress = ownerProfile;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
ownerProfileAddress = contractState.data.ownerProfile;
|
|
83
|
+
}
|
|
84
|
+
console.log('✅ Contract state fetched:', {
|
|
85
|
+
fleet: fleetAddress,
|
|
86
|
+
owner: contractState.data.owner,
|
|
87
|
+
currentRentalState: rentalStateAddress,
|
|
88
|
+
ownerProfile: ownerProfileAddress,
|
|
89
|
+
toClose: contractState.data.toClose
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('❌ Failed to fetch contract state:', error);
|
|
94
|
+
throw new Error(`Failed to fetch contract state: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log('🚢 Using all provided addresses');
|
|
99
|
+
// Validate all provided addresses
|
|
100
|
+
if (typeof fleet === 'string' && (fleet.includes('FLEET_ADDRESS') || fleet.length < 32)) {
|
|
101
|
+
throw new Error(`Invalid fleet address: "${fleet}". Please provide a valid Solana address (32-44 characters).`);
|
|
102
|
+
}
|
|
103
|
+
if (typeof rentalState === 'string' && (rentalState.includes('RENTAL_STATE_ADDRESS') || rentalState.length < 32)) {
|
|
104
|
+
throw new Error(`Invalid rental state address: "${rentalState}". Please provide a valid Solana address (32-44 characters).`);
|
|
105
|
+
}
|
|
106
|
+
if (typeof ownerProfile === 'string' && (ownerProfile.includes('OWNER_PROFILE_ADDRESS') || ownerProfile.length < 32)) {
|
|
107
|
+
throw new Error(`Invalid owner profile address: "${ownerProfile}". Please provide a valid Solana address (32-44 characters).`);
|
|
108
|
+
}
|
|
109
|
+
fleetAddress = fleet;
|
|
110
|
+
rentalStateAddress = rentalState;
|
|
111
|
+
ownerProfileAddress = ownerProfile;
|
|
112
|
+
}
|
|
25
113
|
// Derive the three accounts we need
|
|
26
|
-
const { starbase, starbasePlayer } = await (0, utils_1.deriveGameAccounts)((0, constants_1.toAddress)(
|
|
114
|
+
const { starbase, starbasePlayer } = await (0, utils_1.deriveGameAccounts)((0, constants_1.toAddress)(ownerProfileAddress), faction, resolvedAddresses.gameId, 0, // starbaseSeqId
|
|
27
115
|
config);
|
|
28
116
|
// Get network-specific codama functions from centralized config
|
|
29
117
|
const instructionsModule = (0, config_1.getModule)('instructions');
|
|
30
118
|
const programsModule = (0, config_1.getModule)('programs');
|
|
31
119
|
const { getResetRentalInstructionAsync } = instructionsModule;
|
|
32
120
|
const { SRSLY_PROGRAM_ADDRESS } = programsModule;
|
|
33
|
-
//
|
|
121
|
+
// Handle payer using smart signer handler for universal compatibility
|
|
122
|
+
const payerSigner = (0, signer_1.createTransactionSigner)(payer);
|
|
123
|
+
// Let codama derive the rest (rentalAuthority)
|
|
34
124
|
const input = {
|
|
35
|
-
signer:
|
|
36
|
-
fleet: (0, constants_1.toAddress)(
|
|
125
|
+
signer: payerSigner, // Pass TransactionSigner for proper handling
|
|
126
|
+
fleet: (0, constants_1.toAddress)(fleetAddress), // Use resolved fleet address
|
|
37
127
|
contract: (0, constants_1.toAddress)(contract), // Ensure string
|
|
38
|
-
rentalState: (0, constants_1.toAddress)(
|
|
128
|
+
rentalState: (0, constants_1.toAddress)(rentalStateAddress), // Use resolved rental state address
|
|
39
129
|
gameId: resolvedAddresses.gameId, // Already Address from resolveProgramAddresses
|
|
40
130
|
starbase, // Already string from deriveGameAccounts
|
|
41
131
|
starbasePlayer, // Already string from deriveGameAccounts
|
|
42
132
|
};
|
|
43
|
-
|
|
133
|
+
const rawInstruction = await getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
134
|
+
return (0, instruction_converter_1.createFluentInstruction)(rawInstruction);
|
|
44
135
|
}
|
|
45
136
|
/**
|
|
46
137
|
* Creates an instruction to reset a rental contract after cancellation with fluent configuration.
|
|
@@ -84,31 +175,35 @@ async function _resetRental(params, config) {
|
|
|
84
175
|
* ```typescript
|
|
85
176
|
* import { resetRental } from '@srsly/sdk';
|
|
86
177
|
*
|
|
87
|
-
* // Reset a canceled rental
|
|
178
|
+
* // Reset a canceled rental (all addresses auto-fetched from contract)
|
|
88
179
|
* const instruction = await resetRental({
|
|
89
|
-
*
|
|
180
|
+
* payer: wallet, // Transaction payer
|
|
90
181
|
* contract: "ContractAddr...", // Contract to reactivate
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
182
|
+
* faction: 'mud' // Owner's faction
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* // Optionally provide explicit addresses to avoid fetching
|
|
186
|
+
* const instruction = await resetRental({
|
|
187
|
+
* payer: wallet,
|
|
188
|
+
* fleet: "FleetAddress123...", // Optional: will be fetched if omitted
|
|
189
|
+
* contract: "ContractAddr...",
|
|
190
|
+
* rentalState: "RentalStateAddr...", // Optional: will be fetched if omitted
|
|
191
|
+
* faction: 'mud',
|
|
192
|
+
* ownerProfile: "OwnerProfileAddr..." // Optional: will be fetched if omitted
|
|
94
193
|
* });
|
|
95
194
|
*
|
|
96
195
|
* // Configure for mainnet
|
|
97
196
|
* const mainnetInstruction = await resetRental({
|
|
98
|
-
*
|
|
197
|
+
* payer: wallet,
|
|
99
198
|
* contract: "ContractAddr...",
|
|
100
|
-
*
|
|
101
|
-
* faction: 1, // Can use numbers: 1=mud, 2=oni, 3=ustur
|
|
102
|
-
* ownerProfile: "OwnerProfileAddr..."
|
|
199
|
+
* faction: 1 // Can use numbers: 1=mud, 2=oni, 3=ustur
|
|
103
200
|
* }).set({ programs: 'mainnet' });
|
|
104
201
|
*
|
|
105
202
|
* // Override specific game configuration
|
|
106
203
|
* const customInstruction = await resetRental({
|
|
107
|
-
*
|
|
204
|
+
* payer: wallet,
|
|
108
205
|
* contract: "ContractAddr...",
|
|
109
|
-
*
|
|
110
|
-
* faction: 'mud',
|
|
111
|
-
* ownerProfile: "OwnerProfileAddr..."
|
|
206
|
+
* faction: 'mud'
|
|
112
207
|
* }).set({
|
|
113
208
|
* programs: 'mainnet',
|
|
114
209
|
* gameId: 'custom-game-id...'
|
|
@@ -116,11 +211,9 @@ async function _resetRental(params, config) {
|
|
|
116
211
|
*
|
|
117
212
|
* // Convert to @solana/web3.js format
|
|
118
213
|
* const web3jsInstruction = await resetRental({
|
|
119
|
-
*
|
|
214
|
+
* payer: wallet,
|
|
120
215
|
* contract: "ContractAddr...",
|
|
121
|
-
*
|
|
122
|
-
* faction: 'mud',
|
|
123
|
-
* ownerProfile: "OwnerProfileAddr..."
|
|
216
|
+
* faction: 'mud'
|
|
124
217
|
* }).web3js();
|
|
125
218
|
*
|
|
126
219
|
* // Use with your preferred Solana library
|
|
@@ -129,11 +222,12 @@ async function _resetRental(params, config) {
|
|
|
129
222
|
* ```
|
|
130
223
|
*
|
|
131
224
|
* @param params - The rental reset parameters including fleet, contract, rental state, and owner details
|
|
132
|
-
* @returns A
|
|
225
|
+
* @returns A SmartFluentConfigSelector that can be configured with .set() or awaited directly
|
|
133
226
|
* @throws Error when rental is not in canceled state or instruction generation fails
|
|
134
227
|
*/
|
|
135
228
|
function resetRental(params) {
|
|
136
|
-
|
|
229
|
+
const baseSelector = (0, config_1.createConfigSelector)((config) => _resetRental(params, config));
|
|
230
|
+
return (0, instruction_converter_1.createSmartFluentConfigSelector)(baseSelector);
|
|
137
231
|
}
|
|
138
232
|
/**
|
|
139
233
|
* Low-level function to create a rental reset instruction with raw input parameters.
|
|
@@ -153,4 +247,15 @@ function getResetRentalInstructionAsync(input, options) {
|
|
|
153
247
|
return instructionsModule.getResetRentalInstructionAsync(input, options);
|
|
154
248
|
});
|
|
155
249
|
}
|
|
250
|
+
// Demo export for documentation site
|
|
251
|
+
exports.resetRentalDemo = {
|
|
252
|
+
tabName: "reset",
|
|
253
|
+
description: "Reset a canceled rental",
|
|
254
|
+
imports: `import { resetRental } from '@wuwei-labs/srsly';`,
|
|
255
|
+
instruction: `const instruction = await resetRental({
|
|
256
|
+
payer: (signer || wallet).publicKey?.toBase58(),
|
|
257
|
+
contract: "CONTRACT_ADDRESS",
|
|
258
|
+
faction: "oni" // or "mud", "ustur"
|
|
259
|
+
});`
|
|
260
|
+
};
|
|
156
261
|
//# sourceMappingURL=reset.js.map
|