npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solana-options

v1.1.0

Published

Minting of options contract NFTs on the Solana blockchain

Downloads

89

Readme

Installation

npm install solana-options

See code and docs here: https://github.com/dbanda/solana-nft-options

Examples

The webapp https://nftoptions.app (source code) is a great working example of how you can use this package with the phantom wallet.

Let's show how you can create a call contract to sell 420 units of SOL token for 69 USDC expiring 10 minutes from now

var sol = require("@solana/web3.js");
var sol_options = require("solana-options")

// included for example purposes only.
// In practice this would come securely from a wallet such as Phantom e.t.c
const your_private_key = [45,142,52,139,158,173,187,83,102,42,19,164,139,139,205,
 206,230,214,180,206,143,85,173,181,255,225,10,156,247,8,71,177,181,140,215,
 137,129,185,26,79,119,184,240,246,7,123,174,112,154,172,151,52,204,95,75,118,
 145,69,121,55,243,232,216,63]

// connect to your cluster e.g localhost or devnet
const connection = new sol.Connection("https://api.devnet.solana.com", 'singleGossip');
// create a call contract contract

// your account
let creator_acc = sol.Keypair.fromSecretKey(new Uint8Array(your_private_key))

// set strikes and expiry
let strike = 69
let expiry = Date.now()/1000 + 600 //expire in 10 mins
let multiple = 420

// the address or symbol you are selling on this call
let instrument = "SOL"
// alternatively you can use the address of the token
// e.g let instrument = new PublicKey("SOL1111111111111111111111111111111")

// the token address or symbol of the token you recieve if the call is exercised
let strike_instrument = "USDC"


// the address of your accounts that you will send and receive these instruments. 
// for this example your instrument account must hold 420 SOL that will be used as collateral
let creator_instrument_acc = new sol.PublicKey("45AFNwW71KwdSPXGgEJVhKGMHjEDnH4ECVSd59SFJ7R3")
let creator_strike_instrument_acc = new sol.PublicKey('9H39mHQDLNN1crrQFwRu5w8Euje5k3pfzKxkHaD51gXw')

// create the call
create_call(
    connection,strike, expiry, multiple, creator_acc, instrument, strike_instrument, 
    creator_instrument_acc, creator_strike_instrument_acc
).then(([sig, contract])=>{
    console.log(sol_options.print_contract(contract))
})
{
    "strike": 69,
    "expiry": 1640148885.292,
    "multiple": 420,
    "instrument": "SOL1111111111111111111111111111111",
    "strike_instrument": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "nft_id": "9dpDMmB9pZk1zvRg8eTkvTrY7krwhG59WJ6UNgUKBYgz",
    "nft_account": "FyMJLrW3jBr4EqSaGuFfX3SWAEM5ZcEjD4xiwF7LqJY8",
    "account_id": "Db7AumhkBYaNkh4QZMPFiGGW8gGFJ4WvTDm8DRPVWFJy",
    "collateral_acc": "5cNgbTSQAdmyJRJLr9bqFTLMSQV1FRKTJoJXMViVr1uR",
    "writer_recv_acc": "9H39mHQDLNN1crrQFwRu5w8Euje5k3pfzKxkHaD51gXw",
    "writer": "DDhMZx3tJLat2Vhx7NEKxRWFT7hg82h8yMeJbSPL3fe6",
    "kind": "call"
}

Publish

You can create an image for your contract too and publish it to https://nftoptions.app

    create_call(
        connection,strike, expiry, multiple, creator_acc, instrument, strike_instrument, 
        creator_instrument_acc, creator_strike_instrument_acc
    ).then(([sig, contract])=>{
        console.log(printed_contract(contract))
        sol_options.create_doc_img(contract).then(async img=>{
            img.write("example.png");
            await sol_options.publish_doc(contract)
        })
    })

example.png

sample

Contracts on minted NFTs

You can also issue contracts on newly minted NFTs by setting the instrument to null. The will mint a new token and use it as the instrument token. For example, to create a call contract giving the buyer the right to by your one-of-a-kind NFT for 420 USDC you can do:

    let strike = 420
    let multiple = 1
    let expiry = Date.now()/1000 + 600 //expire in 10 mins
    let strike_instrument = "USDC"
    // your account holding the strike instrument
    let creator_strike_instrument_acc = new sol.PublicKey('9H39mHQDLNN1crrQFwRu5w8Euje5k3pfzKxkHaD51gXw')

    create_call(
        connection,strike, expiry, multiple, creator_acc, null, strike_instrument, 
        null, creator_strike_instrument_acc
    ).then(([sig, contract])=>{
        console.log("Your newly minted NFT id" , printed_contract(contract)["instrument"])
    })