@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
52 lines • 1.9 kB
JavaScript
import { getResetRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
import { DEFAULT_GAME_ID, deriveGameAccounts, } from '../utils';
/**
* Asynchronously creates an instruction to reset a rental with minimal required parameters.
* This is used to reset a fleet's rental state after a rental has ended.
* Can derive starbase, starbasePlayer, and rentalAuthority automatically.
*
* @example
* ```typescript
* // Create the instruction with minimum required parameters and faction
* const ix = await resetRental({
* fleet: fleetAddress,
* contract: contractAddress,
* rentalState: rentalStateAddress,
* faction: 'mud',
* ownerProfile: ownerProfileAddress
* });
*
* // Or with explicit starbase and starbasePlayer
* const ix = await resetRental({
* fleet: fleetAddress,
* contract: contractAddress,
* rentalState: rentalStateAddress,
* starbase: starbaseAddress,
* starbasePlayer: starbasePlayerAddress
* });
*
* // Add to transaction and sign
* const tx = new Transaction().add(ix);
* await sendAndConfirmTransaction(connection, tx, [owner]);
* ```
*
* @param params The simplified parameters for resetting a rental
* @returns A promise that resolves to the instruction to reset a rental
*/
export async function resetRental(params) {
const { fleet, contract, rentalState, gameId = DEFAULT_GAME_ID, faction, ownerProfile, } = params;
// Derive the three accounts we need
const { starbase, starbasePlayer } = await deriveGameAccounts(ownerProfile, faction, gameId);
// Let codama derive the rest (rentalAuthority)
const input = {
fleet,
contract,
rentalState,
gameId,
starbase,
starbasePlayer,
};
return getResetRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
}
export { getResetRentalInstructionAsync };
//# sourceMappingURL=reset.js.map