import * as anchor from "@project-serum/anchor"; import { getAssociatedTokenAddress } from "@solana/spl-token"; import { TOKEN_METADATA_PROGRAM_ID, STRIKR_COLLECTION_MINT, } from "../../constants"; import { getStrikr, getStrikrAuthority } from "../../utils"; import { getFloorOption } from "./get-floor-option"; import { requestComputeUnits } from "../../actions/request-compute-units"; import { Response } from "../../types/types"; /** * Close the put option buyer position. * @param provider Anchor provider * @param optionKey Option key representing a unique option * @returns Promise resolving to the transaction signature */ export const floorClosePutOptionBuyer = async ( provider: anchor.AnchorProvider, optionKey: anchor.web3.PublicKey ): Promise => { const strikr = getStrikr(provider); const transaction = new anchor.web3.Transaction(); const optionState = await getFloorOption(provider.connection, optionKey); // Request additional compute units and attach the instruction const computeUnitsIx = requestComputeUnits(provider, 400_000, 0); transaction.add(computeUnitsIx); const buyerPositionNftTokenAccount = await getAssociatedTokenAddress( optionState.buyerPositionNftMint, provider.wallet.publicKey, true ); transaction.add( await strikr.methods .floorClosePutOptionBuyer() .accounts({ signer: provider.wallet.publicKey, optionKey: optionKey, strikrCollectionMint: STRIKR_COLLECTION_MINT, buyerPositionNftMint: optionState.buyerPositionNftMint, buyerPositionNftTokenAccount: buyerPositionNftTokenAccount, tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID, }) .instruction() ); const signature = await provider.sendAndConfirm(transaction); return { signature, optionKey: optionState.optionKey, }; };