import * as anchor from "@project-serum/anchor"; import { getAssociatedTokenAddress } from "@solana/spl-token"; import { getStrikr } from "../utils"; import { TOKEN_METADATA_PROGRAM_ID, STRIKR_COLLECTION_MINT, } from "../constants"; import { requestComputeUnits } from "../actions/request-compute-units"; /** * Exercise the put option * @param provider Anchor provider * @param assetNftMint Asset NFT which underlies the option * @param buyerPositionNftMint Position NFT representing option buyer position * @returns Promise resolving to the transaction signature */ export const exercisePutOption = async ( provider: anchor.AnchorProvider, assetNftMint: anchor.web3.PublicKey, buyerPositionNftMint: anchor.web3.PublicKey ) => { const strikr = getStrikr(provider); const transaction = new anchor.web3.Transaction(); // Request additional compute units and attach the instruction const computeUnitsIx = requestComputeUnits(provider, 400_000, 0); transaction.add(computeUnitsIx); const buyerPositionNftTokenAccount = await getAssociatedTokenAddress( buyerPositionNftMint, provider.wallet.publicKey, true ); transaction.add( await strikr.methods .exercisePutOption() .accounts({ signer: provider.wallet.publicKey, assetNftMint, strikrCollectionMint: STRIKR_COLLECTION_MINT, buyerPositionNftMint, buyerPositionNftTokenAccount, tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID, }) .instruction() ); return await provider.sendAndConfirm(transaction); };