UNPKG

@wuwei-labs/srsly

Version:
84 lines 3.23 kB
/** * @purpose Simplified invalidateRental instruction wrapper * * Thin convenience wrapper around Codama-generated invalidateRental instruction. * Emergency function to invalidate a fleet's rental status when contract doesn't exist. */ import { address } from '@solana/kit'; import { getInvalidateRentalInstructionAsync } 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'; /** * Emergency clear of a fleet's SAGE rental flag when no SRSLY contract * exists. Use `releaseRental` instead when a contract still exists. * * @param params - Invalidate rental parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // Emergency invalidation of a stuck fleet (contract doesn't exist) * const ix = await invalidateRental({ * fleet: "FLEET_ADDRESS", * signer: wallet, * ownerProfile: "OWNER_PROFILE_ADDRESS", * faction: "mud" * }); * * // With compute budget * const ix2 = await invalidateRental({ * fleet: fleetAddress, * signer: adminWallet, * ownerProfile: ownerProfileAddress, * faction: 1, * computeUnits: 200_000 * }); * ``` */ export async function invalidateRental(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 const kitInstruction = await getInvalidateRentalInstructionAsync({ 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=invalidateRental.js.map