UNPKG

@wuwei-labs/srsly

Version:
53 lines 2.28 kB
/** * @purpose Simplified updateContractThread instruction wrapper * * Thin convenience wrapper around Codama-generated updateContractThread instruction. * Funds additional lamports and/or updates the payment frequency for a contract thread. */ import { address } from '@solana/kit'; import { getUpdateContractThreadInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; import { deriveContractThread } from '../pda/thread'; import { deriveRentalAuthority } from '../pda/srsly'; import { normalizeSchedule } from '../params/schedule'; import { convertSol } from '../params/sol'; /** * Top up a contract thread's lamports balance and (optionally) * reschedule its payment frequency. * * @param params - Thread update parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) */ export async function updateContractThread(params, config) { const finalConfig = mergeConfig(config); if (!params.owner) { throw new Error('owner is required'); } if (!params.contract) { throw new Error('contract is required'); } const ownerSigner = toTransactionSigner(params.owner); const addresses = getAddresses(config); const programAddress = address(addresses.srsly); const contractAddress = address(params.contract); // Derive thread PDA const rentalAuthority = await deriveRentalAuthority(); const contractThread = await deriveContractThread(contractAddress, rentalAuthority); // Normalize optional schedule const paymentsFreq = params.paymentsFreq ? normalizeSchedule(params.paymentsFreq) : null; const kitInstruction = await getUpdateContractThreadInstructionAsync({ payer: ownerSigner, contract: contractAddress, contractThread, lamports: convertSol(params.lamports ?? 0), paymentsFreq, }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=updateContractThread.js.map