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, getStrikrAuthority } from "../../utils"; import { requestComputeUnits } from "../../actions/request-compute-units"; import { Response } from "../../types/types"; /** * Create a put option request as an option buyer * @param provider Anchor provider * @param collectionIdentifierKey CollectionIdentifier key of the NFT collection which underlies the option * @returns Promise resolving to the transaction signature */ export const floorCreatePutOption = async ( provider: anchor.AnchorProvider, collectionIdentifierKey: anchor.web3.PublicKey, strikePrice: anchor.BN, duration: anchor.BN, premium: anchor.BN ): Promise => { const strikr = getStrikr(provider); const transaction = new anchor.web3.Transaction(); const optionKeypair = new anchor.web3.Keypair(); const buyerPositionNftMintKeypair = new anchor.web3.Keypair(); const buyerPositionNftMint = buyerPositionNftMintKeypair.publicKey; // Request additional compute units and attach the instruction const computeUnitsIx = requestComputeUnits(provider, 400_000, 0); transaction.add(computeUnitsIx); // Signer's position NFT ATA let buyerPositionNftTokenAccount = await getAssociatedTokenAddress( buyerPositionNftMint, provider.wallet.publicKey, true ); const strikrAuthority = await getStrikrAuthority(); transaction.add( await strikr.methods .floorCreatePutOption(strikePrice, duration, premium) .accounts({ signer: provider.wallet.publicKey, strikrTreasury: STRIKR_TREASURY, optionKey: optionKeypair.publicKey, collectionIdentifierKey: collectionIdentifierKey, buyerPositionNftMint: buyerPositionNftMint, buyerPositionNftTokenAccount: buyerPositionNftTokenAccount, strikrCollectionMint: STRIKR_COLLECTION_MINT, tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID, }) .instruction() ); const signature = await provider.sendAndConfirm(transaction, [ buyerPositionNftMintKeypair, ]); return { signature, optionKey: optionKeypair.publicKey, }; };