import { Program, Provider, Wallet } from "@project-serum/anchor"; import { SendTxRequest } from "@project-serum/anchor/dist/provider"; import { PublicKey, Signer } from "@solana/web3.js"; import { CleanupOpts, Construction, ConstructionCompiled } from "../index"; import { newCleanupError } from "../error"; import { getActionIdlDummyProgram } from "../utils/idls"; import { closeConstructionAccount } from "./construciton"; /** * Close the ephemeral accounts such that the caller reclaims more rent then * is spent on the transaction of closing the account. * * As a note: this may mean that result accounts are not closed as they have next to * no rent */ export const cleanup = async ( provider: Provider, mallocProgram: Program, construction: Construction, constructionSigner: Signer, authority: Wallet | Signer, options?: CleanupOpts ): Promise => { const recipient = options?.solRecipient ?? provider.wallet.publicKey; const deleteConstructionTx = closeConstructionAccount( mallocProgram, constructionSigner.publicKey, recipient, authority ); return [deleteConstructionTx]; };