@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
49 lines • 1.9 kB
JavaScript
import { getAcceptRentalInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama';
import { deriveGameAccounts, DEFAULT_GAME_ID, } from '../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
*/
export async function acceptRental(params) {
const { borrower, borrowerProfile, borrowerFaction, fleet, contract, gameId = DEFAULT_GAME_ID, amount, duration, } = params;
// Derive the three accounts we need
const { profileFaction, starbase, starbasePlayer } = await 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 getAcceptRentalInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS });
}
export { getAcceptRentalInstructionAsync };
//# sourceMappingURL=accept.js.map