Skip to main content

Javascript

Getting Started#

yarn add @mithraic-labs/psyoptions

More docs will be coming soon on how to use the following instructions.

Functions#

Functions#


initializeAccountsForMarket#

initializeAccountsForMarket(object: { connection: Connection ; payer: Account ; programId: string | PublicKey }): Promise<{ optionMarketKey: PublicKey ; optionMintKey: PublicKey ; quoteAssetPoolKey: PublicKey ; signers: Account[] ; transaction: Transaction ; underlyingAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey }>

Generate and initialize the Accounts to be used for the new option market.

Parameters:#

NameTypeDescription
objectobject-
object.connectionConnection
object.payerAccountAccount to pay for the creation of these new accounts
object.programIdstring | PublicKeythe public key for the PsyOptions program

Returns: Promise<{ optionMarketKey: PublicKey ; optionMintKey: PublicKey ; quoteAssetPoolKey: PublicKey ; signers: Account[] ; transaction: Transaction ; underlyingAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey }>

initializeMarketInstruction#

initializeMarketInstruction(object: { expirationUnixTimestamp: number ; fundingAccountKey: PublicKey ; optionMarketKey: PublicKey ; optionMintKey: PublicKey ; programId: PublicKey ; quoteAmountPerContract: number ; quoteAssetMintKey: PublicKey ; quoteAssetPoolKey: PublicKey ; underlyingAmountPerContract: number ; underlyingAssetMintKey: PublicKey ; underlyingAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for InitializeMarket

Instruction to initialize a new option market. Strike price is determined by quote amount per contract / underlying amount per contract

Parameters:#

NameTypeDescription
objectobject-
object.expirationUnixTimestampnumberunix timestamp when the option market expires
object.fundingAccountKeyPublicKeyThe payer account that is funding the SOL for the TX
object.optionMarketKeyPublicKeykey for a new Account that will store the data for the options market
object.optionMintKeyPublicKeyuninitialized SPL Token mint to be used as the Option Token mint for the new option market
object.programIdPublicKeythe public key for the PsyOptions program
object.quoteAmountPerContractnumberamount of quote needed to exercise the option
object.quoteAssetMintKeyPublicKeySPL Token mint of the quote asset
object.quoteAssetPoolKeyPublicKeyunintitialized SPL Token account to store locked quote asset
object.underlyingAmountPerContractnumberamount of underlying asset needed to mint an Option Token
object.underlyingAssetMintKeyPublicKeySPL Token mint of the underlying asset
object.underlyingAssetPoolKeyPublicKeyunintitialized SPL Token account to store locked underlying asset
object.writerTokenMintKeyPublicKeyuninitialized SPL Token mint to be used as the Writer Token mint for the new option market

Returns: Promise<TransactionInstruction>


mintCoveredCallInstruction#

mintCoveredCallInstruction(object: { authorityPubkey: PublicKey ; fundingAccountKey: PublicKey ; mintedOptionDestKey: PublicKey ; optionMarketKey: PublicKey ; optionMintKey: PublicKey ; programId: PublicKey ; underlyingAssetPoolKey: PublicKey ; underlyingAssetSrcKey: PublicKey ; underlyingMintKey: PublicKey ; writerTokenDestKey: PublicKey ; writerTokenMintKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for MintCoveredCall

Mints an Option Token and Writer Token after successfully transfering underlying asset to the option market's pool.

Parameters:#

NameTypeDescription
objectobject-
object.authorityPubkeyPublicKeyonwer of the underlyingAssetSrcKey, likely the wallet making the transaction
object.fundingAccountKeyPublicKeyThe payer account that is funding the SOL for the TX
object.mintedOptionDestKeyPublicKeypublic key where the option will be minted to
object.optionMarketKeyPublicKeypublic key for the opton market
object.optionMintKeyPublicKeypublic key of the option token mint for the option market
object.programIdPublicKeythe public key for the PsyOptions program
object.underlyingAssetPoolKeyPublicKeypublic key of the underlying asset pool for the market, where the asset will be transfered to
object.underlyingAssetSrcKeyPublicKeyaccount the underlying asset will be transfered from
object.underlyingMintKeyPublicKeypublic key of the underlying asset mint
object.writerTokenDestKeyPublicKeypublic key where the Writer Token will be minted to
object.writerTokenMintKeyPublicKeypublic key of the Writer Token mint for the option market

Returns: Promise<TransactionInstruction>


exerciseCoveredCallInstruction#

exerciseCoveredCallInstruction(object: { exerciserQuoteAssetAuthorityKey: PublicKey ; exerciserQuoteAssetKey: PublicKey ; exerciserUnderlyingAssetKey: PublicKey ; fundingAccountKey: PublicKey ; optionMarketKey: PublicKey ; optionMintKey: PublicKey ; optionTokenAuthorityKey: PublicKey ; optionTokenKey: PublicKey ; programId: PublicKey ; quoteAssetMintKey: PublicKey ; quoteAssetPoolKey: PublicKey ; underlyingAssetPoolKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for ExerciseCoveredCall.

This instruction will burn an Option Token, transfer quote asset to the quote asset pool, and transfer underlying asset from the underlying asset pool to the specified account. The amount of underlying asset transfered depends on the underlying amount per contract, aka contract size. The amount of quote asset transfered depends on the quote amount per contract, aka contract size * price.

Note this instruction may only be called prior to the option market expiration

Parameters:#

NameTypeDescription
objectobject-
object.exerciserQuoteAssetAuthorityKeyPublicKeyowner of the exerciserQuoteAssetKey, likely the wallet
object.exerciserQuoteAssetKeyPublicKeypublic key where the quote asset will be transfered from
object.exerciserUnderlyingAssetKeyPublicKeypublic key where the underlying asset will be transfered to
object.fundingAccountKeyPublicKeyThe payer account that is funding the SOL for the TX making the transaction
object.optionMarketKeyPublicKeypublic key for the opton market
object.optionMintKeyPublicKeypublic key of the option token mint for the option market
object.optionTokenAuthorityKeyPublicKeyonwer of the optionTokenKey, likely the wallet
object.optionTokenKeyPublicKeypublic key of the account where the Option Token will be burned from
object.programIdPublicKeythe public key for the PsyOptions program
object.quoteAssetMintKeyPublicKeypublic key for the quote asset mint
object.quoteAssetPoolKeyPublicKeypublic key of the quote asset pool for the market, where the asset will be transfered to
object.underlyingAssetPoolKeyPublicKeypublic key of the underlying asset pool for the market, where the asset will be transfered from

Returns: Promise<TransactionInstruction>


closePositionInstruction#

closePositionInstruction(object: { optionMarketKey: PublicKey ; optionMintKey: PublicKey ; optionTokenSrcAuthKey: PublicKey ; optionTokenSrcKey: PublicKey ; programId: PublicKey ; underlyingAssetDestKey: PublicKey ; underlyingAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey ; writerTokenSourceAuthorityKey: PublicKey ; writerTokenSourceKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for ClosePosition.

This instruction will burn a Writer Token and an Option Token. Upon burning these tokens, the program will transfer the locked underlying asset to the specified public key. The amount of underlying asset transfered depends on the underlying amount per contract, aka contract size.

Parameters:#

NameTypeDescription
objectobject-
object.optionMarketKeyPublicKeypublic key for the opton market
object.optionMintKeyPublicKeypublic key of the option token mint for the option market
object.optionTokenSrcAuthKeyPublicKeyOnwer of the optionTokenSrcKey, likely the wallet that owns the account
object.optionTokenSrcKeyPublicKeypublic key of the account where the Option Token will be burned from
object.programIdPublicKeythe public key for the PsyOptions program
object.underlyingAssetDestKeyPublicKeypublic key of the account to send the underlying asset to
object.underlyingAssetPoolKeyPublicKeypublic key of the underlying asset pool for the market, where the asset will be transfered from
object.writerTokenMintKeyPublicKeypublic key of the writer token mint for the option market
object.writerTokenSourceAuthorityKeyPublicKeyowner of the writerTokenSourceKey, likely the wallet making the transaction
object.writerTokenSourceKeyPublicKeypublic key of the account where the Writer Token will be burned from

Returns: Promise<TransactionInstruction>


exchangeWriterTokenForQuoteInstruction#

exchangeWriterTokenForQuoteInstruction(object: { optionMarketKey: PublicKey ; programId: PublicKey ; quoteAssetDestKey: PublicKey ; quoteAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey ; writerTokenSourceAuthorityKey: PublicKey ; writerTokenSourceKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for ExchangeWriterTokenForQuote

This instruction will burn a Writer Token and transfer quote asset to the specified account. The amount of quote asset transfered depends on the quote amount per contract, aka contract size * price.

Note this instruction can only be called after an option has been exercised

Parameters:#

NameTypeDescription
objectobject-
object.optionMarketKeyPublicKeypublic key for the opton market
object.programIdPublicKeythe public key for the PsyOptions program
object.quoteAssetDestKeyPublicKeypublic key of the account to send the quote asset to
object.quoteAssetPoolKeyPublicKeypublic key of the quote asset pool for the market, where the asset will be transfered from
object.writerTokenMintKeyPublicKeypublic key of the writer token mint for the option market
object.writerTokenSourceAuthorityKeyPublicKeyowner of the writerTokenSourceKey, likely the wallet making the transaction
object.writerTokenSourceKeyPublicKeypublic key of the account where the Writer Token will be burned from

Returns: Promise<TransactionInstruction>


closePostExpirationCoveredCallInstruction#

closePostExpirationCoveredCallInstruction(object: { optionMarketKey: PublicKey ; programId: PublicKey ; underlyingAssetDestKey: PublicKey ; underlyingAssetPoolKey: PublicKey ; writerTokenMintKey: PublicKey ; writerTokenSourceAuthorityKey: PublicKey ; writerTokenSourceKey: PublicKey }): Promise<TransactionInstruction>

Generate the instruction for ClosePostExpiration

This instruction will burn a Writer Token and transfer underlying asset back to the specified account. The amount of underlying asset transfered depends on the underlying amount per contract, aka contract size.

Note this instruction can only be called after the option market has expired

Parameters:#

NameTypeDescription
objectobject-
object.optionMarketKeyPublicKeypublic key for the opton market
object.programIdPublicKeythe public key for the PsyOptions program
object.underlyingAssetDestKeyPublicKeypublic key of the account to send the underlying asset to
object.underlyingAssetPoolKeyPublicKeypublic key of the underlying asset pool for the market, where the asset will be transfered from
object.writerTokenMintKeyPublicKeypublic key of the writer token mint for the option market
object.writerTokenSourceAuthorityKeyPublicKeyowner of the writerTokenSourceKey, likely the wallet making the transaction
object.writerTokenSourceKeyPublicKeypublic key of the account where the Writer Token will be burned from

Returns: Promise<TransactionInstruction>