UNPKG

@wuwei-labs/srsly

Version:
76 lines 2.91 kB
"use strict"; /** * @purpose Simplified deleteContract instruction wrapper * * Thin convenience wrapper around Codama-generated deleteContract instruction. * Admin-only instruction to delete contract state for schema migrations. * Returns lamports to the contract owner. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteContract = deleteContract; 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"); const contract_1 = require("../accounts/contract"); /** * Admin escape hatch to delete a corrupted ContractState (used during * schema migrations). Returns rent to the contract owner. * * @param params - Delete contract parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // Admin deletes corrupted contract state * const ix = await deleteContract({ * admin: adminWallet, * owner: "OWNER_WALLET_ADDRESS", * contract: "CONTRACT_STATE_ADDRESS" * }); * ``` */ async function deleteContract(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.contract) { throw new Error('contract is required'); } // Auto-fetch owner from contract if not provided let ownerAddress; if (params.owner) { ownerAddress = (0, kit_1.address)(params.owner); } else { try { const rpcUrl = (0, config_1.getRpcUrl)(); const contractData = await (0, contract_1.fetchContract)(params.contract, rpcUrl); ownerAddress = contractData.data.owner; } catch (error) { throw new Error(`Could not fetch owner from contract. If contract state is corrupted, provide --owner manually. Error: ${error.message}`); } } // 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 (config PDA auto-derived) const kitInstruction = await (0, instructions_1.getDeleteContractInstructionAsync)({ admin: adminSigner, owner: ownerAddress, contract: (0, kit_1.address)(params.contract), }, { programAddress }); return (0, instructions_2.prepareInstructions)(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=deleteContract.js.map