UNPKG

@wuwei-labs/srsly

Version:
84 lines 3.19 kB
/** * @purpose Simplified releaseRental instruction wrapper * * Thin convenience wrapper around Codama-generated releaseRental instruction. * Release a fleet from SRSLY rental control when contract exists but rental is inactive. */ import { address } from '@solana/kit'; import { getReleaseRentalInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; import { deriveGameAccounts } from '../pda/sage'; import { fetchFleet } from '../accounts/fleet'; /** * Free a fleet from SRSLY's rental hold once the rental has been closed. * Use `invalidateRental` instead when no contract exists. * * @param params - Release rental parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // Release a stuck fleet (contract must exist) * const ix = await releaseRental({ * fleet: "FLEET_ADDRESS", * signer: wallet, * ownerProfile: "OWNER_PROFILE_ADDRESS", * faction: "mud" * }); * * // With compute budget * const ix2 = await releaseRental({ * fleet: fleetAddress, * signer: adminWallet, * ownerProfile: ownerProfileAddress, * faction: 1, * computeUnits: 200_000 * }); * ``` */ export async function releaseRental(params, config) { // Merge config const finalConfig = mergeConfig(config); // Validate required params if (!params.fleet) { throw new Error('fleet is required'); } if (!params.signer) { throw new Error('signer is required'); } // Convert signer to transaction signer const signerAccount = toTransactionSigner(params.signer); // Get network-specific addresses (including gameId) const addresses = getAddresses(config); const gameId = address(addresses.gameId); const sageProgram = address(addresses.sage); const programAddress = address(addresses.srsly); // Auto-fetch ownerProfile and faction from fleet when not provided let ownerProfile = params.ownerProfile; let faction = params.faction; if (!ownerProfile || !faction) { const fleetState = await fetchFleet(params.fleet, finalConfig.rpcUrl); ownerProfile = ownerProfile ?? fleetState.ownerProfile; faction = faction ?? fleetState.faction; } // Derive owner's SAGE accounts (NOT borrower's) const gameAccounts = await deriveGameAccounts(ownerProfile, faction, gameId); // Call Codama-generated instruction // Contract and rentalAuthority are auto-derived by Codama from seeds const kitInstruction = await getReleaseRentalInstructionAsync({ signer: signerAccount, fleet: address(params.fleet), gameId: gameId, starbase: gameAccounts.starbase, starbasePlayer: gameAccounts.starbasePlayer, sageProgram, }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=releaseRental.js.map