UNPKG

@wuwei-labs/srsly

Version:
73 lines 2.89 kB
"use strict"; /** * @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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteRental = deleteRental; const kit_1 = require("@solana/kit"); const instructions_1 = require("../generated/codama/instructions"); const config_1 = require("../utils/config"); const signer_1 = require("../utils/signer"); const instructions_2 = require("../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" * }); * ``` */ async function deleteRental(params, config) { // Merge config const finalConfig = (0, config_1.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 = (0, signer_1.toTransactionSigner)(params.admin); // Get network-specific addresses const addresses = (0, config_1.getAddresses)(config); const programAddress = (0, kit_1.address)(addresses.srsly); // Call Codama-generated instruction const kitInstruction = await (0, instructions_1.getDeleteRentalInstructionAsync)({ admin: adminSigner, // System Program can't be marked writable, so fall back to admin (lamports go to admin anyway) borrower: (0, kit_1.address)((!params.borrower || params.borrower === '11111111111111111111111111111111' ? adminSigner.address : params.borrower)), rentalState: (0, kit_1.address)(params.rentalState), }, { programAddress }); return (0, instructions_2.prepareInstructions)(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=deleteRental.js.map