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)

53 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAcceptRentalInstructionAsync = void 0; exports.acceptRental = acceptRental; const codama_1 = require("../codama"); Object.defineProperty(exports, "getAcceptRentalInstructionAsync", { enumerable: true, get: function () { return codama_1.getAcceptRentalInstructionAsync; } }); const utils_1 = require("../utils"); /** * Asynchronously creates an instruction to accept a rental with minimal required parameters. * Derives borrowerProfileFaction, starbase, and starbasePlayer automatically. * * @example * ```typescript * // Create the instruction with automatic account derivation * const ix = await acceptRental({ * borrower: wallet, * borrowerProfile: profileAddress, * borrowerFaction: 1, // 1 = mud, 2 = oni, 3 = ustur * fleet: fleetAddress, * contract: contractAddress, * amount: 1000, * duration: 86400 // 1 day in seconds * // gameId is optional and will default to the standard game ID * }); * * // Add to transaction and sign * const tx = new Transaction().add(ix); * await sendAndConfirmTransaction(connection, tx, [wallet]); * ``` * * @param params The simplified parameters for accepting a rental * @returns A promise that resolves to the instruction to accept a rental */ async function acceptRental(params) { const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId = utils_1.DEFAULT_GAME_ID, amount, duration, } = params; // Derive the three accounts we need const { profileFaction, starbase, starbasePlayer } = await (0, utils_1.deriveGameAccounts)(borrowerProfile, borrowerFaction, gameId); // Let codama derive the rest (rentalThread, rentalState, rentalAuthority, etc.) const input = { borrower, borrowerProfile, borrowerProfileFaction: profileFaction, fleet, contract, gameId, starbase, starbasePlayer, amount, duration, }; return (0, codama_1.getAcceptRentalInstructionAsync)(input, { programAddress: codama_1.SRSLY_PROGRAM_ADDRESS }); } //# sourceMappingURL=accept.js.map