@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
49 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCreateContractInstructionAsync = void 0;
exports.createContract = createContract;
const codama_1 = require("../codama");
Object.defineProperty(exports, "getCreateContractInstructionAsync", { enumerable: true, get: function () { return codama_1.getCreateContractInstructionAsync; } });
const utils_1 = require("../utils");
/**
* Asynchronously creates an instruction to create a rental contract with minimal required parameters.
* Derives ownerTokenAccount, contract, and rentalAuthority automatically if not provided.
*
* @example
* ```typescript
* // Create the instruction with minimal parameters
* const ix = await createContract({
* owner: wallet,
* fleet: fleetAddress,
* ownerProfile: profileAddress,
* rate: 100, // 100 ATLAS per second
* durationMin: 3600, // 1 hour in seconds
* durationMax: 604800, // 1 week in seconds
* paymentsFreq: "daily"
* });
*
* // Add to transaction and sign
* const tx = new Transaction().add(ix);
* await sendAndConfirmTransaction(connection, tx, [wallet]);
* ```
*
* @param params The simplified parameters for creating a rental contract
* @returns A promise that resolves to the instruction to create a contract
*/
async function createContract(params) {
const { owner, fleet, ownerProfile, rate, durationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, gameId = utils_1.DEFAULT_GAME_ID, } = params;
// Let codama derive the rest (contract, rentalAuthority, ownerTokenAccount, etc.)
const input = {
owner,
fleet,
ownerProfile,
gameId,
rate,
durationMin,
durationMax,
paymentsFeq: paymentsFreq,
ownerKeyIndex,
};
return (0, codama_1.getCreateContractInstructionAsync)(input, { programAddress: codama_1.SRSLY_PROGRAM_ADDRESS });
}
//# sourceMappingURL=create.js.map