@wuwei-labs/srsly 2.0.0-beta.4 → 2.0.0-beta.5
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 +214 -68
- package/dist/cjs/codama/devnet/constants.js +32 -0
- package/dist/cjs/codama/devnet/constants.js.map +1 -0
- package/dist/cjs/codama/mainnet/constants.js +32 -0
- package/dist/cjs/codama/mainnet/constants.js.map +1 -0
- package/dist/cjs/contract/close.js +51 -19
- package/dist/cjs/contract/close.js.map +1 -1
- package/dist/cjs/contract/create.js +31 -19
- package/dist/cjs/contract/create.js.map +1 -1
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/rental/accept.js +46 -33
- package/dist/cjs/rental/accept.js.map +1 -1
- package/dist/cjs/rental/cancel.js +30 -24
- package/dist/cjs/rental/cancel.js.map +1 -1
- package/dist/cjs/rental/close.js +31 -25
- package/dist/cjs/rental/close.js.map +1 -1
- package/dist/cjs/rental/reset.js +40 -38
- package/dist/cjs/rental/reset.js.map +1 -1
- package/dist/cjs/utils/config.js +204 -0
- package/dist/cjs/utils/config.js.map +1 -0
- package/dist/cjs/utils/constants.js +66 -13
- package/dist/cjs/utils/constants.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/profiles.js +38 -18
- package/dist/cjs/utils/profiles.js.map +1 -1
- package/dist/esm/codama/devnet/constants.js +29 -0
- package/dist/esm/codama/devnet/constants.js.map +1 -0
- package/dist/esm/codama/mainnet/constants.js +29 -0
- package/dist/esm/codama/mainnet/constants.js.map +1 -0
- package/dist/esm/contract/close.js +52 -20
- package/dist/esm/contract/close.js.map +1 -1
- package/dist/esm/contract/create.js +31 -19
- package/dist/esm/contract/create.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/rental/accept.js +47 -34
- package/dist/esm/rental/accept.js.map +1 -1
- package/dist/esm/rental/cancel.js +30 -24
- package/dist/esm/rental/cancel.js.map +1 -1
- package/dist/esm/rental/close.js +31 -25
- package/dist/esm/rental/close.js.map +1 -1
- package/dist/esm/rental/reset.js +41 -39
- package/dist/esm/rental/reset.js.map +1 -1
- package/dist/esm/utils/config.js +161 -0
- package/dist/esm/utils/config.js.map +1 -0
- package/dist/esm/utils/constants.js +60 -10
- package/dist/esm/utils/constants.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/profiles.js +39 -19
- package/dist/esm/utils/profiles.js.map +1 -1
- package/dist/types/codama/devnet/constants.d.ts +33 -0
- package/dist/types/codama/devnet/constants.d.ts.map +1 -0
- package/dist/types/codama/mainnet/constants.d.ts +33 -0
- package/dist/types/codama/mainnet/constants.d.ts.map +1 -0
- package/dist/types/contract/close.d.ts +20 -5
- package/dist/types/contract/close.d.ts.map +1 -1
- package/dist/types/contract/create.d.ts +23 -13
- package/dist/types/contract/create.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rental/accept.d.ts +35 -6
- package/dist/types/rental/accept.d.ts.map +1 -1
- package/dist/types/rental/cancel.d.ts +27 -3
- package/dist/types/rental/cancel.d.ts.map +1 -1
- package/dist/types/rental/close.d.ts +28 -3
- package/dist/types/rental/close.d.ts.map +1 -1
- package/dist/types/rental/reset.d.ts +32 -4
- package/dist/types/rental/reset.d.ts.map +1 -1
- package/dist/types/utils/config.d.ts +112 -0
- package/dist/types/utils/config.d.ts.map +1 -0
- package/dist/types/utils/constants.d.ts +9 -7
- package/dist/types/utils/constants.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/profiles.d.ts +14 -8
- package/dist/types/utils/profiles.d.ts.map +1 -1
- package/package.json +4 -2
- package/dist/cjs/network.js +0 -107
- package/dist/cjs/network.js.map +0 -1
- package/dist/esm/network.js +0 -67
- package/dist/esm/network.js.map +0 -1
- package/dist/types/network.d.ts +0 -58
- package/dist/types/network.d.ts.map +0 -1
|
@@ -1,39 +1,56 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
2
|
-
import {
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
|
+
import { getSageGameId } from '../utils/constants';
|
|
3
|
+
import { deriveGameAccounts, } from '../utils';
|
|
3
4
|
/**
|
|
4
5
|
* Asynchronously creates an instruction to close a rental contract with minimal required parameters.
|
|
5
6
|
* Derives rentalAuthority automatically and handles optional parameters.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
|
-
* // Create the instruction with
|
|
10
|
+
* // Create the instruction with default devnet settings
|
|
10
11
|
* const ix = await closeContract({
|
|
11
12
|
* owner: wallet,
|
|
12
13
|
* fleet: fleetAddress,
|
|
13
14
|
* contract: contractAddress,
|
|
14
|
-
* faction: 'mud',
|
|
15
|
-
* // Optional: provide explicit starbase and starbasePlayer if you have them
|
|
16
|
-
* // Optional: provide rentalState and rentalTokenAccount if active rental exists
|
|
15
|
+
* faction: 'mud',
|
|
17
16
|
* });
|
|
18
17
|
*
|
|
19
|
-
* //
|
|
20
|
-
* const
|
|
21
|
-
*
|
|
18
|
+
* // Use mainnet configuration
|
|
19
|
+
* const ix = await closeContract({
|
|
20
|
+
* owner: wallet,
|
|
21
|
+
* fleet: fleetAddress,
|
|
22
|
+
* contract: contractAddress,
|
|
23
|
+
* faction: 'mud',
|
|
24
|
+
* }).set({ network: 'mainnet' });
|
|
25
|
+
*
|
|
26
|
+
* // Override specific constants
|
|
27
|
+
* const ix = await closeContract({
|
|
28
|
+
* owner: wallet,
|
|
29
|
+
* fleet: fleetAddress,
|
|
30
|
+
* contract: contractAddress,
|
|
31
|
+
* faction: 'mud',
|
|
32
|
+
* }).set({
|
|
33
|
+
* network: 'mainnet',
|
|
34
|
+
* gameId: 'custom-game-id...'
|
|
35
|
+
* });
|
|
22
36
|
* ```
|
|
23
37
|
*
|
|
24
38
|
* @param params The simplified parameters for closing a rental contract
|
|
25
39
|
* @returns A promise that resolves to the instruction to close a contract
|
|
26
40
|
*/
|
|
27
41
|
/**
|
|
28
|
-
* Internal function to close a contract instruction
|
|
42
|
+
* Internal function to close a contract instruction with configuration options
|
|
29
43
|
*/
|
|
30
|
-
async function _closeContract(params,
|
|
31
|
-
const { owner, fleet, contract, faction, gameId
|
|
32
|
-
|
|
44
|
+
async function _closeContract(params, config) {
|
|
45
|
+
const { owner, fleet, contract, faction, gameId, } = params;
|
|
46
|
+
// Get the actual game ID to use (param override, config override, or network default)
|
|
47
|
+
const actualGameId = gameId || await getSageGameId(config);
|
|
48
|
+
const derivedAccounts = await deriveGameAccounts(owner.address, faction, actualGameId, 0, // starbaseSeqId
|
|
49
|
+
config);
|
|
33
50
|
const starbase = derivedAccounts.starbase;
|
|
34
51
|
const starbasePlayer = derivedAccounts.starbasePlayer;
|
|
35
52
|
// Dynamically import network-specific codama functions
|
|
36
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
53
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
37
54
|
const { getCloseContractInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
38
55
|
// Let codama derive the rest (rentalAuthority, ownerTokenAccount, etc.)
|
|
39
56
|
const input = {
|
|
@@ -42,20 +59,35 @@ async function _closeContract(params, network) {
|
|
|
42
59
|
contract,
|
|
43
60
|
starbase,
|
|
44
61
|
starbasePlayer,
|
|
45
|
-
gameId,
|
|
62
|
+
gameId: actualGameId,
|
|
46
63
|
};
|
|
47
64
|
return getCloseContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
48
65
|
}
|
|
49
66
|
/**
|
|
50
|
-
* Creates an instruction to close a rental contract with fluent
|
|
67
|
+
* Creates an instruction to close a rental contract with fluent configuration.
|
|
68
|
+
*
|
|
69
|
+
* @param params The contract closing parameters
|
|
70
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Use devnet defaults
|
|
75
|
+
* await closeContract(params);
|
|
76
|
+
*
|
|
77
|
+
* // Use mainnet
|
|
78
|
+
* await closeContract(params).set({ network: 'mainnet' });
|
|
79
|
+
*
|
|
80
|
+
* // Override game ID
|
|
81
|
+
* await closeContract(params).set({ gameId: 'custom...' });
|
|
82
|
+
* ```
|
|
51
83
|
*/
|
|
52
84
|
export function closeContract(params) {
|
|
53
|
-
return
|
|
85
|
+
return createConfigSelector((config) => _closeContract(params, config));
|
|
54
86
|
}
|
|
55
|
-
// Export
|
|
87
|
+
// Export config selector for getCloseContractInstructionAsync
|
|
56
88
|
export function getCloseContractInstructionAsync(input, options) {
|
|
57
|
-
return
|
|
58
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
89
|
+
return createConfigSelector(async (config) => {
|
|
90
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
59
91
|
return codamaModule.getCloseContractInstructionAsync(input, options);
|
|
60
92
|
});
|
|
61
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/contract/close.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,OAAO,EACL,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAkClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH;;GAEG;AACH,KAAK,UAAU,cAAc,CAC3B,MAA2B,EAC3B,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,GACP,GAAG,MAAM,CAAC;IAEX,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3D,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAC9C,KAAK,CAAC,OAAO,EACb,OAAQ,EACR,YAA+B,EAC/B,CAAC,EAAE,gBAAgB;IACnB,MAAM,CACP,CAAC;IAEF,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IAC1C,MAAM,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;IAEtD,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,gCAAgC,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAEjF,wEAAwE;IACxE,MAAM,KAAK,GAAG;QACZ,KAAK;QACL,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,cAAc;QACd,MAAM,EAAE,YAAY;KACrB,CAAC;IAEF,OAAO,gCAAgC,CACrC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA2B;IAE3B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gCAAgC,CAAC,KAAU,EAAE,OAAa;IACxE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,gCAAgC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
2
|
-
import {
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
|
+
import { getSageGameId } from '../utils/constants';
|
|
3
3
|
/**
|
|
4
|
-
* Internal function to create a contract instruction
|
|
4
|
+
* Internal function to create a contract instruction with configuration options
|
|
5
5
|
*/
|
|
6
|
-
async function _createContract(params,
|
|
7
|
-
const { owner, fleet, ownerProfile, rate, durationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, gameId
|
|
6
|
+
async function _createContract(params, config) {
|
|
7
|
+
const { owner, fleet, ownerProfile, rate, durationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, gameId, } = params;
|
|
8
|
+
// Get the actual game ID to use (param override, config override, or network default)
|
|
9
|
+
const actualGameId = gameId || await getSageGameId(config);
|
|
8
10
|
// Dynamically import network-specific codama functions
|
|
9
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
11
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
10
12
|
const { getCreateContractInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
11
13
|
// Let codama derive the rest (contract, rentalAuthority, ownerTokenAccount, etc.)
|
|
12
14
|
const input = {
|
|
13
15
|
owner,
|
|
14
16
|
fleet,
|
|
15
17
|
ownerProfile,
|
|
16
|
-
gameId,
|
|
18
|
+
gameId: actualGameId,
|
|
17
19
|
rate,
|
|
18
20
|
durationMin,
|
|
19
21
|
durationMax,
|
|
@@ -23,31 +25,41 @@ async function _createContract(params, network) {
|
|
|
23
25
|
return getCreateContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
|
-
* Creates an instruction to create a rental contract with fluent
|
|
28
|
+
* Creates an instruction to create a rental contract with fluent configuration.
|
|
27
29
|
*
|
|
28
30
|
* @example
|
|
29
31
|
* ```typescript
|
|
30
|
-
* // Use
|
|
31
|
-
* const ix = await createContract(params)
|
|
32
|
+
* // Use devnet defaults
|
|
33
|
+
* const ix = await createContract(params);
|
|
32
34
|
*
|
|
33
|
-
* // Use
|
|
34
|
-
* const ix = await createContract(params).mainnet
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* // Use mainnet configuration
|
|
36
|
+
* const ix = await createContract(params).set({ network: 'mainnet' });
|
|
37
|
+
*
|
|
38
|
+
* // Override specific constants
|
|
39
|
+
* const ix = await createContract(params).set({
|
|
40
|
+
* network: 'mainnet',
|
|
41
|
+
* gameId: 'custom-game-id...',
|
|
42
|
+
* sageProgramAddress: 'custom-sage...'
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Chain configurations
|
|
46
|
+
* const ix = await createContract(params)
|
|
47
|
+
* .set({ network: 'devnet' })
|
|
48
|
+
* .set({ gameId: 'override-game...' });
|
|
37
49
|
* ```
|
|
38
50
|
*
|
|
39
51
|
* @param params The simplified parameters for creating a rental contract
|
|
40
|
-
* @returns A
|
|
52
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
41
53
|
*/
|
|
42
54
|
export function createContract(params) {
|
|
43
|
-
return
|
|
55
|
+
return createConfigSelector((config) => _createContract(params, config));
|
|
44
56
|
}
|
|
45
57
|
/**
|
|
46
|
-
* Export
|
|
58
|
+
* Export config selector for getCreateContractInstructionAsync
|
|
47
59
|
*/
|
|
48
60
|
export function getCreateContractInstructionAsync(input, options) {
|
|
49
|
-
return
|
|
50
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
61
|
+
return createConfigSelector(async (config) => {
|
|
62
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
51
63
|
return codamaModule.getCreateContractInstructionAsync(input, options);
|
|
52
64
|
});
|
|
53
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAyDnD;;GAEG;AACH,KAAK,UAAU,eAAe,CAC5B,MAA4B,EAC5B,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,GAAG,CAAC,EACjB,MAAM,GACP,GAAG,MAAM,CAAC;IAEX,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3D,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAElF,kFAAkF;IAClF,MAAM,KAAK,GAAG;QACZ,KAAK;QACL,KAAK;QACL,YAAY;QACZ,MAAM,EAAE,YAAY;QACpB,IAAI;QACJ,WAAW;QACX,WAAW;QACX,WAAW,EAAE,YAAY;QACzB,aAAa;KACd,CAAC;IAEF,OAAO,iCAAiC,CACtC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAC5B,MAA4B;IAE5B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iCAAiC,CAAC,KAAU,EAAE,OAAa;IACzE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,iCAAiC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
2
|
-
import {
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
|
+
import { getSageGameId, ATLAS_TO_STARDUST } from '../utils/constants';
|
|
3
|
+
import { deriveGameAccounts, } from '../utils';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Derives borrowerProfileFaction, starbase, and starbasePlayer automatically.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Create the instruction with automatic account derivation
|
|
10
|
-
* const ix = await acceptRental({
|
|
11
|
-
* borrower: wallet,
|
|
12
|
-
* borrowerProfile: profileAddress,
|
|
13
|
-
* borrowerFaction: 1, // 1 = mud, 2 = oni, 3 = ustur
|
|
14
|
-
* fleet: fleetAddress,
|
|
15
|
-
* contract: contractAddress,
|
|
16
|
-
* amount: 1000,
|
|
17
|
-
* duration: 86400 // 1 day in seconds
|
|
18
|
-
* // gameId is optional and will default to the standard game ID
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // Add to transaction and sign
|
|
22
|
-
* const tx = new Transaction().add(ix);
|
|
23
|
-
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @param params The simplified parameters for accepting a rental
|
|
27
|
-
* @returns A promise that resolves to the instruction to accept a rental
|
|
5
|
+
* Internal function to accept a rental instruction with configuration options
|
|
28
6
|
*/
|
|
29
|
-
async function _acceptRental(params,
|
|
30
|
-
const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId
|
|
7
|
+
async function _acceptRental(params, config) {
|
|
8
|
+
const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId, rate, duration, } = params;
|
|
9
|
+
// Get the actual game ID to use (param override, config override, or network default)
|
|
10
|
+
const actualGameId = gameId || await getSageGameId(config);
|
|
11
|
+
// Calculate the total amount from rate and duration
|
|
12
|
+
// Convert ATLAS to stardust (smallest unit): 1 ATLAS = 100,000,000 stardust
|
|
13
|
+
const amount = BigInt(rate) * BigInt(duration) * BigInt(ATLAS_TO_STARDUST);
|
|
31
14
|
// Derive the three accounts we need
|
|
32
|
-
const { profileFaction, starbase, starbasePlayer } = await deriveGameAccounts(borrowerProfile, borrowerFaction,
|
|
15
|
+
const { profileFaction, starbase, starbasePlayer } = await deriveGameAccounts(borrowerProfile, borrowerFaction, actualGameId, 0, // starbaseSeqId
|
|
16
|
+
config);
|
|
33
17
|
// Let codama derive the rest (rentalThread, rentalState, rentalAuthority, etc.)
|
|
34
18
|
const input = {
|
|
35
19
|
borrower,
|
|
@@ -37,23 +21,52 @@ async function _acceptRental(params, network) {
|
|
|
37
21
|
borrowerProfileFaction: profileFaction,
|
|
38
22
|
fleet,
|
|
39
23
|
contract,
|
|
40
|
-
gameId,
|
|
24
|
+
gameId: actualGameId,
|
|
41
25
|
starbase,
|
|
42
26
|
starbasePlayer,
|
|
43
27
|
amount,
|
|
44
28
|
duration,
|
|
45
29
|
};
|
|
46
30
|
// Dynamically import network-specific codama functions
|
|
47
|
-
const codamaModule = await getCachedNetworkModule('instructions');
|
|
31
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
48
32
|
const { getAcceptRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
49
33
|
return getAcceptRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
50
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instruction to accept a rental with fluent configuration.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Use devnet defaults
|
|
41
|
+
* const ix = await acceptRental({
|
|
42
|
+
* borrower: wallet,
|
|
43
|
+
* borrowerProfile: profileAddress,
|
|
44
|
+
* borrowerFaction: 1, // 1 = mud, 2 = oni, 3 = ustur
|
|
45
|
+
* fleet: fleetAddress,
|
|
46
|
+
* contract: contractAddress,
|
|
47
|
+
* rate: 1000, // ATLAS tokens
|
|
48
|
+
* duration: 86400 // 1 day in seconds (total: 1000 * 86400 * 100M stardust)
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Use mainnet configuration
|
|
52
|
+
* const ix = await acceptRental(params).set({ network: 'mainnet' });
|
|
53
|
+
*
|
|
54
|
+
* // Override specific constants
|
|
55
|
+
* const ix = await acceptRental(params).set({
|
|
56
|
+
* network: 'mainnet',
|
|
57
|
+
* gameId: 'custom-game-id...'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param params The simplified parameters for accepting a rental
|
|
62
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
63
|
+
*/
|
|
51
64
|
export function acceptRental(params) {
|
|
52
|
-
return
|
|
65
|
+
return createConfigSelector((config) => _acceptRental(params, config));
|
|
53
66
|
}
|
|
54
67
|
export function getAcceptRentalInstructionAsync(input, options) {
|
|
55
|
-
return
|
|
56
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
68
|
+
return createConfigSelector(async (config) => {
|
|
69
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
57
70
|
return codamaModule.getAcceptRentalInstructionAsync(input, options);
|
|
58
71
|
});
|
|
59
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/rental/accept.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAMtE,OAAO,EACL,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAiDlB;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA0B,EAC1B,MAAsB;IAEtB,MAAM,EACJ,QAAQ,EACR,eAAe,EACf,eAAe,EACf,KAAK,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3D,oDAAoD;IACpD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAE3E,oCAAoC;IACpC,MAAM,EACJ,cAAc,EACd,QAAQ,EACR,cAAc,EACf,GAAG,MAAM,kBAAkB,CAC1B,eAAe,EACf,eAAe,EACf,YAA+B,EAC/B,CAAC,EAAE,gBAAgB;IACnB,MAAM,CACP,CAAC;IAEF,gFAAgF;IAChF,MAAM,KAAK,GAAoC;QAC7C,QAAQ;QACR,eAAe;QACf,sBAAsB,EAAE,cAAc;QACtC,KAAK;QACL,QAAQ;QACR,MAAM,EAAE,YAAY;QACpB,QAAQ;QACR,cAAc;QACd,MAAM;QACN,QAAQ;KACT,CAAC;IAEF,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAEhF,OAAO,+BAA+B,CACpC,KAAY,EACZ,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA0B;IAE1B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,43 +1,49 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* Internal function to cancel a rental instruction with configuration options
|
|
4
|
+
*/
|
|
5
|
+
async function _cancelRental(params, config) {
|
|
6
|
+
const { borrower, contract, } = params;
|
|
7
|
+
// Let codama derive all the optional accounts
|
|
8
|
+
const input = {
|
|
9
|
+
borrower,
|
|
10
|
+
contract,
|
|
11
|
+
};
|
|
12
|
+
// Dynamically import network-specific codama functions
|
|
13
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
14
|
+
const { getCancelRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
15
|
+
return getCancelRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instruction to cancel a rental with fluent configuration.
|
|
6
19
|
*
|
|
7
20
|
* @example
|
|
8
21
|
* ```typescript
|
|
9
|
-
* //
|
|
22
|
+
* // Use devnet defaults
|
|
10
23
|
* const ix = await cancelRental({
|
|
11
24
|
* borrower: wallet,
|
|
12
25
|
* contract: contractAddress
|
|
13
26
|
* });
|
|
14
27
|
*
|
|
15
|
-
* //
|
|
16
|
-
* const
|
|
17
|
-
*
|
|
28
|
+
* // Use mainnet configuration
|
|
29
|
+
* const ix = await cancelRental(params).set({ network: 'mainnet' });
|
|
30
|
+
*
|
|
31
|
+
* // Override specific constants
|
|
32
|
+
* const ix = await cancelRental(params).set({
|
|
33
|
+
* network: 'mainnet',
|
|
34
|
+
* sageProgramAddress: 'custom...'
|
|
35
|
+
* });
|
|
18
36
|
* ```
|
|
19
37
|
*
|
|
20
38
|
* @param params The simplified parameters for canceling a rental
|
|
21
|
-
* @returns A
|
|
39
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
22
40
|
*/
|
|
23
|
-
async function _cancelRental(params, network) {
|
|
24
|
-
const { borrower, contract, } = params;
|
|
25
|
-
// Let codama derive all the optional accounts
|
|
26
|
-
const input = {
|
|
27
|
-
borrower,
|
|
28
|
-
contract,
|
|
29
|
-
};
|
|
30
|
-
// Dynamically import network-specific codama functions
|
|
31
|
-
const codamaModule = await getCachedNetworkModule('instructions');
|
|
32
|
-
const { getCancelRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
33
|
-
return getCancelRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
34
|
-
}
|
|
35
41
|
export function cancelRental(params) {
|
|
36
|
-
return
|
|
42
|
+
return createConfigSelector((config) => _cancelRental(params, config));
|
|
37
43
|
}
|
|
38
44
|
export function getCancelRentalInstructionAsync(input, options) {
|
|
39
|
-
return
|
|
40
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
45
|
+
return createConfigSelector(async (config) => {
|
|
46
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
41
47
|
return codamaModule.getCancelRentalInstructionAsync(input, options);
|
|
42
48
|
});
|
|
43
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/rental/cancel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AAoBxH;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA0B,EAC1B,MAAsB;IAEtB,MAAM,EACJ,QAAQ,EACR,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,8CAA8C;IAC9C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,QAAQ;KACT,CAAC;IAEF,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAEhF,OAAO,+BAA+B,CACpC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA0B;IAE1B,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAU,EAAE,OAAa;IACvE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,+BAA+B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/rental/close.js
CHANGED
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* Internal function to close a rental instruction with configuration options
|
|
4
|
+
*/
|
|
5
|
+
async function _closeRental(params, config) {
|
|
6
|
+
const { borrower, ownerTokenAccount, contract, } = params;
|
|
7
|
+
// Let codama derive the optional accounts
|
|
8
|
+
const input = {
|
|
9
|
+
borrower,
|
|
10
|
+
ownerTokenAccount,
|
|
11
|
+
contract,
|
|
12
|
+
};
|
|
13
|
+
// Dynamically import network-specific codama functions
|
|
14
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
15
|
+
const { getCloseRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
16
|
+
return getCloseRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instruction to close a rental with fluent configuration.
|
|
6
20
|
*
|
|
7
21
|
* @example
|
|
8
22
|
* ```typescript
|
|
9
|
-
* //
|
|
23
|
+
* // Use devnet defaults
|
|
10
24
|
* const ix = await closeRental({
|
|
11
25
|
* borrower: borrowerAddress,
|
|
12
26
|
* ownerTokenAccount: ownerTokenAccountAddress,
|
|
13
27
|
* contract: contractAddress
|
|
14
28
|
* });
|
|
15
29
|
*
|
|
16
|
-
* //
|
|
17
|
-
* const
|
|
18
|
-
*
|
|
30
|
+
* // Use mainnet configuration
|
|
31
|
+
* const ix = await closeRental(params).set({ network: 'mainnet' });
|
|
32
|
+
*
|
|
33
|
+
* // Override specific constants
|
|
34
|
+
* const ix = await closeRental(params).set({
|
|
35
|
+
* network: 'mainnet',
|
|
36
|
+
* sageProgramAddress: 'custom...'
|
|
37
|
+
* });
|
|
19
38
|
* ```
|
|
20
39
|
*
|
|
21
40
|
* @param params The simplified parameters for closing a rental
|
|
22
|
-
* @returns A
|
|
41
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
23
42
|
*/
|
|
24
|
-
async function _closeRental(params, network) {
|
|
25
|
-
const { borrower, ownerTokenAccount, contract, } = params;
|
|
26
|
-
// Let codama derive the optional accounts
|
|
27
|
-
const input = {
|
|
28
|
-
borrower,
|
|
29
|
-
ownerTokenAccount,
|
|
30
|
-
contract,
|
|
31
|
-
};
|
|
32
|
-
// Dynamically import network-specific codama functions
|
|
33
|
-
const codamaModule = await getCachedNetworkModule('instructions');
|
|
34
|
-
const { getCloseRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
35
|
-
return getCloseRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
36
|
-
}
|
|
37
43
|
export function closeRental(params) {
|
|
38
|
-
return
|
|
44
|
+
return createConfigSelector((config) => _closeRental(params, config));
|
|
39
45
|
}
|
|
40
46
|
export function getCloseRentalInstructionAsync(input, options) {
|
|
41
|
-
return
|
|
42
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
47
|
+
return createConfigSelector(async (config) => {
|
|
48
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
43
49
|
return codamaModule.getCloseRentalInstructionAsync(input, options);
|
|
44
50
|
});
|
|
45
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"close.js","sourceRoot":"","sources":["../../../src/rental/close.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AAyBxH;;GAEG;AACH,KAAK,UAAU,YAAY,CACzB,MAAyB,EACzB,MAAsB;IAEtB,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,QAAQ,GACT,GAAG,MAAM,CAAC;IAEX,0CAA0C;IAC1C,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,iBAAiB;QACjB,QAAQ;KACT,CAAC;IAEF,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAE/E,OAAO,8BAA8B,CACnC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,WAAW,CACzB,MAAyB;IAEzB,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAU,EAAE,OAAa;IACtE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,8BAA8B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/rental/reset.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import { getCachedNetworkModule,
|
|
2
|
-
import {
|
|
1
|
+
import { getCachedNetworkModule, createConfigSelector } from '../utils/config';
|
|
2
|
+
import { getSageGameId } from '../utils/constants';
|
|
3
|
+
import { deriveGameAccounts, } from '../utils';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
* Internal function to reset a rental instruction with configuration options
|
|
6
|
+
*/
|
|
7
|
+
async function _resetRental(params, config) {
|
|
8
|
+
const { fleet, contract, rentalState, gameId, faction, ownerProfile, } = params;
|
|
9
|
+
// Get the actual game ID to use (param override, config override, or network default)
|
|
10
|
+
const actualGameId = gameId || await getSageGameId(config);
|
|
11
|
+
// Derive the three accounts we need
|
|
12
|
+
const { starbase, starbasePlayer } = await deriveGameAccounts(ownerProfile, faction, actualGameId, 0, // starbaseSeqId
|
|
13
|
+
config);
|
|
14
|
+
// Dynamically import network-specific codama functions
|
|
15
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
16
|
+
const { getResetRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
17
|
+
// Let codama derive the rest (rentalAuthority)
|
|
18
|
+
const input = {
|
|
19
|
+
fleet,
|
|
20
|
+
contract,
|
|
21
|
+
rentalState,
|
|
22
|
+
gameId: actualGameId,
|
|
23
|
+
starbase,
|
|
24
|
+
starbasePlayer,
|
|
25
|
+
};
|
|
26
|
+
return getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instruction to reset a rental with fluent configuration.
|
|
7
30
|
*
|
|
8
31
|
* @example
|
|
9
32
|
* ```typescript
|
|
10
|
-
* //
|
|
33
|
+
* // Use devnet defaults
|
|
11
34
|
* const ix = await resetRental({
|
|
12
35
|
* fleet: fleetAddress,
|
|
13
36
|
* contract: contractAddress,
|
|
@@ -16,47 +39,26 @@ import { DEFAULT_GAME_ID, deriveGameAccounts, } from '../utils';
|
|
|
16
39
|
* ownerProfile: ownerProfileAddress
|
|
17
40
|
* });
|
|
18
41
|
*
|
|
19
|
-
* //
|
|
20
|
-
* const ix = await resetRental({
|
|
21
|
-
* fleet: fleetAddress,
|
|
22
|
-
* contract: contractAddress,
|
|
23
|
-
* rentalState: rentalStateAddress,
|
|
24
|
-
* starbase: starbaseAddress,
|
|
25
|
-
* starbasePlayer: starbasePlayerAddress
|
|
26
|
-
* });
|
|
42
|
+
* // Use mainnet configuration
|
|
43
|
+
* const ix = await resetRental(params).set({ network: 'mainnet' });
|
|
27
44
|
*
|
|
28
|
-
* //
|
|
29
|
-
* const
|
|
30
|
-
*
|
|
45
|
+
* // Override specific constants
|
|
46
|
+
* const ix = await resetRental(params).set({
|
|
47
|
+
* network: 'mainnet',
|
|
48
|
+
* gameId: 'custom-game-id...',
|
|
49
|
+
* sageProgramAddress: 'custom...'
|
|
50
|
+
* });
|
|
31
51
|
* ```
|
|
32
52
|
*
|
|
33
53
|
* @param params The simplified parameters for resetting a rental
|
|
34
|
-
* @returns A
|
|
54
|
+
* @returns A ConfigSelector that can be configured with .set() or awaited directly
|
|
35
55
|
*/
|
|
36
|
-
async function _resetRental(params, network) {
|
|
37
|
-
const { fleet, contract, rentalState, gameId = DEFAULT_GAME_ID, faction, ownerProfile, } = params;
|
|
38
|
-
// Derive the three accounts we need
|
|
39
|
-
const { starbase, starbasePlayer } = await deriveGameAccounts(ownerProfile, faction, gameId);
|
|
40
|
-
// Dynamically import network-specific codama functions
|
|
41
|
-
const codamaModule = await getCachedNetworkModule('instructions');
|
|
42
|
-
const { getResetRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS } = codamaModule;
|
|
43
|
-
// Let codama derive the rest (rentalAuthority)
|
|
44
|
-
const input = {
|
|
45
|
-
fleet,
|
|
46
|
-
contract,
|
|
47
|
-
rentalState,
|
|
48
|
-
gameId,
|
|
49
|
-
starbase,
|
|
50
|
-
starbasePlayer,
|
|
51
|
-
};
|
|
52
|
-
return getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
|
|
53
|
-
}
|
|
54
56
|
export function resetRental(params) {
|
|
55
|
-
return
|
|
57
|
+
return createConfigSelector((config) => _resetRental(params, config));
|
|
56
58
|
}
|
|
57
59
|
export function getResetRentalInstructionAsync(input, options) {
|
|
58
|
-
return
|
|
59
|
-
const codamaModule = await getCachedNetworkModule('instructions', network);
|
|
60
|
+
return createConfigSelector(async (config) => {
|
|
61
|
+
const codamaModule = await getCachedNetworkModule('instructions', config?.network);
|
|
60
62
|
return codamaModule.getResetRentalInstructionAsync(input, options);
|
|
61
63
|
});
|
|
62
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reset.js","sourceRoot":"","sources":["../../../src/rental/reset.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"reset.js","sourceRoot":"","sources":["../../../src/rental/reset.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAA2C,MAAM,iBAAiB,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,OAAO,EACL,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAyClB;;GAEG;AACH,KAAK,UAAU,YAAY,CACzB,MAAyB,EACzB,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,WAAW,EACX,MAAM,EACN,OAAO,EACP,YAAY,GACb,GAAG,MAAM,CAAC;IAEX,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3D,oCAAoC;IACpC,MAAM,EACJ,QAAQ,EACR,cAAc,EACf,GAAG,MAAM,kBAAkB,CAC1B,YAAY,EACZ,OAAO,EACP,YAA+B,EAC/B,CAAC,EAAE,gBAAgB;IACnB,MAAM,CACP,CAAC;IAEF,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,GAAG,YAAY,CAAC;IAE/E,+CAA+C;IAC/C,MAAM,KAAK,GAAG;QACZ,KAAK;QACL,QAAQ;QACR,WAAW;QACX,MAAM,EAAE,YAAY;QACpB,QAAQ;QACR,cAAc;KACf,CAAC;IAEF,OAAO,8BAA8B,CACnC,KAAK,EACL,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,WAAW,CACzB,MAAyB;IAEzB,OAAO,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAU,EAAE,OAAa;IACtE,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnF,OAAO,YAAY,CAAC,8BAA8B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC"}
|