UNPKG

@wuwei-labs/srsly

Version:
62 lines 2.9 kB
"use strict"; /** * @purpose Simplified deleteContractThread instruction wrapper * * Thin convenience wrapper around Codama-generated deleteContractThread instruction. * Admin-only instruction to delete a contract's thread for schema migrations. * Unlike closeContractThread, does not require the contract account. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteContractThread = deleteContractThread; 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 thread_1 = require("../accounts/thread"); const thread_2 = require("../pda/thread"); const srsly_1 = require("../pda/srsly"); /** * Admin variant of `closeContractThread` that doesn't require the * contract account on-chain — used when the contract is already deleted * or unparseable. * * @param params - Thread deletion parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) */ async function deleteContractThread(params, config) { const finalConfig = (0, config_1.mergeConfig)(config); if (!params.admin) { throw new Error('admin is required'); } if (!params.contract) { throw new Error('contract is required'); } const adminSigner = (0, signer_1.toTransactionSigner)(params.admin); const addresses = (0, config_1.getAddresses)(config); const programAddress = (0, kit_1.address)(addresses.srsly); const contractAddress = (0, kit_1.address)(params.contract); // Derive thread PDA const rentalAuthority = await (0, srsly_1.deriveRentalAuthority)(); const contractThread = await (0, thread_2.deriveContractThread)(contractAddress, rentalAuthority); // Fetch thread account to read actual fiber_ids const threadAccount = await (0, thread_1.fetchThreadByAddress)(contractThread, finalConfig.rpcUrl); const fiberIds = Array.from(threadAccount.data.fiberIds); // Derive fiber PDAs only for fibers that actually exist on the thread const fiberAccounts = await Promise.all(fiberIds.map(async (id) => ({ address: await (0, thread_2.deriveFiber)(contractThread, id), role: kit_1.AccountRole.WRITABLE, }))); const kitInstruction = await (0, instructions_1.getDeleteContractThreadInstructionAsync)({ admin: adminSigner, thread: contractThread, }, { programAddress }); // Add fiber PDAs as remaining accounts (writable, non-signer) kitInstruction.accounts.push(...fiberAccounts); return (0, instructions_2.prepareInstructions)(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=deleteContractThread.js.map