import * as anchor from "@project-serum/anchor"; import { getAssociatedTokenAddress } from "@solana/spl-token"; import { TOKEN_METADATA_PROGRAM_ID, STRIKR_COLLECTION_MINT, STRIKR_TREASURY, } from "../../constants"; import { getStrikr } from "../../utils"; import { requestComputeUnits } from "../../actions/request-compute-units"; import { Response } from "../../types/types"; /** * Fill the put option request as a seller. * @param provider Anchor provider * @param optionKey Option key representing the option to be filled * @returns Promise resolving to the transaction signature */ export const floorFillPutOption = async ( provider: anchor.AnchorProvider, optionKey: anchor.web3.PublicKey ) : Promise => { 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 sellerPositionNftMintKeypair = new anchor.web3.Keypair(); const sellerPositionNftMint = sellerPositionNftMintKeypair.publicKey; // Signer's position NFT ATA let sellerPositionNftTokenAccount = await getAssociatedTokenAddress( sellerPositionNftMint, provider.wallet.publicKey, true ); transaction.add( await strikr.methods .floorFillPutOption() .accounts({ signer: provider.wallet.publicKey, optionKey: optionKey, sellerPositionNftMint: sellerPositionNftMint, sellerPositionNftTokenAccount: sellerPositionNftTokenAccount, strikrCollectionMint: STRIKR_COLLECTION_MINT, strikrTreasury: STRIKR_TREASURY, tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID, }) .instruction() ); const signature = await provider.sendAndConfirm(transaction, [ sellerPositionNftMintKeypair, ]); return { signature, optionKey: optionKey, }; };