UNPKG

@wuwei-labs/srsly

Version:
70 lines 2.71 kB
/** * @purpose Simplified deleteRental instruction wrapper * * Thin convenience wrapper around Codama-generated deleteRental instruction. * Admin-only instruction to delete corrupted rental state for schema migrations. * Returns lamports to the borrower. Use release_rental after to clean up thread and SAGE fleet. */ import { address } from '@solana/kit'; import { getDeleteRentalInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; /** * Admin escape hatch to delete a corrupted RentalState (used during * schema migrations). Returns rent to the borrower; follow with * `releaseRental` to free the fleet. * * @param params - Delete rental parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // Admin deletes corrupted rental state * const ix = await deleteRental({ * admin: adminWallet, * borrower: "BORROWER_WALLET_ADDRESS", * rentalState: "RENTAL_STATE_ADDRESS" * }); * * // After deletion, call releaseRental to clean up thread and SAGE fleet * const releaseIx = await releaseRental({ * signer: anyWallet, * fleet: "FLEET_ADDRESS", * borrower: "BORROWER_ADDRESS", * borrowerProfile: "BORROWER_PROFILE_ADDRESS", * faction: "mud" * }); * ``` */ export async function deleteRental(params, config) { // Merge config const finalConfig = mergeConfig(config); // Validate required params if (!params.admin) { throw new Error('admin is required'); } if (!params.rentalState) { throw new Error('rentalState is required'); } // Convert admin to transaction signer const adminSigner = toTransactionSigner(params.admin); // Get network-specific addresses const addresses = getAddresses(config); const programAddress = address(addresses.srsly); // Call Codama-generated instruction const kitInstruction = await getDeleteRentalInstructionAsync({ admin: adminSigner, // System Program can't be marked writable, so fall back to admin (lamports go to admin anyway) borrower: address((!params.borrower || params.borrower === '11111111111111111111111111111111' ? adminSigner.address : params.borrower)), rentalState: address(params.rentalState), }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=deleteRental.js.map