UNPKG

@wuwei-labs/srsly

Version:

[![npm version](https://img.shields.io/npm/v/ts-sdk-example.svg)](https://www.npmjs.com/package/ts-sdk-example)

48 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCloseContractInstructionAsync = void 0; exports.closeContract = closeContract; const codama_1 = require("../codama"); Object.defineProperty(exports, "getCloseContractInstructionAsync", { enumerable: true, get: function () { return codama_1.getCloseContractInstructionAsync; } }); const utils_1 = require("../utils"); /** * Asynchronously creates an instruction to close a rental contract with minimal required parameters. * Derives rentalAuthority automatically and handles optional parameters. * * @example * ```typescript * // Create the instruction with automatic account derivation * const ix = await closeContract({ * owner: wallet, * fleet: fleetAddress, * contract: contractAddress, * faction: 'mud', // Only needed if starbase and starbasePlayer not provided * // Optional: provide explicit starbase and starbasePlayer if you have them * // Optional: provide rentalState and rentalTokenAccount if active rental exists * }); * * // Add to transaction and sign * const tx = new Transaction().add(ix); * await sendAndConfirmTransaction(connection, tx, [wallet]); * ``` * * @param params The simplified parameters for closing a rental contract * @returns A promise that resolves to the instruction to close a contract */ async function closeContract(params) { const { owner, fleet, contract, faction, gameId = utils_1.DEFAULT_GAME_ID, } = params; const derivedAccounts = await (0, utils_1.deriveGameAccounts)(owner.address, faction, gameId); const starbase = derivedAccounts.starbase; const starbasePlayer = derivedAccounts.starbasePlayer; // Let codama derive the rest (rentalAuthority, ownerTokenAccount, etc.) const input = { owner, fleet, contract, starbase, starbasePlayer, gameId, }; return (0, codama_1.getCloseContractInstructionAsync)(input, { programAddress: codama_1.SRSLY_PROGRAM_ADDRESS }); } //# sourceMappingURL=close.js.map