UNPKG

@wuwei-labs/srsly

Version:
48 lines 1.92 kB
/** * @purpose Simplified closeBorrower instruction wrapper * * Thin convenience wrapper around Codama-generated closeBorrower instruction. * Closes a borrower's managed token account and BorrowerState. * Borrower-only — only the borrower may authorize the close (and pays * the transaction fee). */ import { address } from '@solana/kit'; import { getCloseBorrowerInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; import { fetchConfig } from '../accounts/config'; /** * Close a borrower's managed ATA + BorrowerState PDA, refunding rent to * the borrower wallet. Borrower-only — call `claimBorrower` first to * sweep any remaining ATLAS. * * @param params - Close borrower parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * const ix = await closeBorrower({ borrower: borrowerWallet }); * ``` */ export async function closeBorrower(params, config) { const finalConfig = mergeConfig(config); if (!params.borrower) { throw new Error('borrower is required'); } const borrowerSigner = toTransactionSigner(params.borrower); const configAccount = await fetchConfig(finalConfig.rpcUrl); const atlasMint = configAccount.data.atlasMint; const addresses = getAddresses(config); const programAddress = address(addresses.srsly); const kitInstruction = await getCloseBorrowerInstructionAsync({ borrower: borrowerSigner, mint: atlasMint, }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=closeBorrower.js.map