Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanda committed Dec 22, 2021
1 parent 7f83e16 commit 6617e19
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
73 changes: 36 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,69 @@ See https://nftoptions.app

## Examples

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

```Javascript
import { AccountInfo, Keypair } from "@solana/web3.js";
import { Connection, PublicKey} from "@solana/web3.js";
import { create_call, create_put, exercise_call, OptionType } from ".";
import { create_doc_img } from "./doc";
var sol = require("@solana/web3.js");
var sol_options = require("solana-options")

const your_private_key = [58,61,83,12,252,164,114,167,16,61,196,241,213,62,111,76,253,145,3,249,205,251,23,52,
237,158,140,188,84,202,116,216,78,242,2,9,33,177,53,200,7,221,76,53,149,13,243,125,153,187,239,178,76,
197,203,88,218,186,174,108,71,19,254,203]
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 Connection("https://api.devnet.solana.com", 'singleGossip');
const connection = new sol.Connection("https://api.devnet.solana.com", 'singleGossip');

```

```Javascript
// create a call contract contract to sell 420 SOL at a price of 69 USDC each
// create a call contract contract

// your account
let creator_acc = Keypair.fromSecretKey(new Uint8Array(your_private_key))
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 (600s)
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("So11111111111111111111111111111111111111112")
// 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 1000000000 SOL that will be used as collateral
let creator_instrument_acc = new PublicKey("GsnpfUQTFnQBuokhttUajopkEeg4YNgwf7j2SSKhRigJ")
let creator_strike_instrument_acc = new PublicKey('8Tv1h2eNjhfQJXyNR3Ey8WwoHAF1qZW7s7aNH49oCMBP')
// 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
connection,strike, expiry, multiple, creator_acc, instrument, strike_instrument,
creator_instrument_acc, creator_strike_instrument_acc
).then(([sig, contract])=>{
console.log(printed_contract(contract))
console.log(sol_options.print_contract(contract))
})
```

```json
{
"strike": 69,
"expiry": 1639040144.763,
"expiry": 1640148885.292,
"multiple": 420,
"instrument": "D3KCKMTY8rgWtVmxKdCeugKEFbJMjSHk7iWiLMAKrrMf",
"strike_instrument": "6Uhbk6FwCLLQfsKJ8kn8uCsiF5iZNVQDw5QxMNJh9XiJ",
"nft_id": "4q3E9ZxG6VFhQUL45AC3qmVpv1aEzr5dXRUo1h9Ceqaj",
"nft_account": "HyhK3xraTRGXPbwow5PY7Z7yhMTQuPDme13rdngYFQfU",
"account_id": "7dsBkXTW1cdmN6bFENampDLkQsk63TZimsduUwCB8aWr",
"collateral_acc": "GGDmFyQbHRSxpL8AikpLSArQc9EA5CJNvwkALohCJ5An",
"writer_recv_acc": "GsnpfUQTFnQBuokhttUajopkEeg4YNgwf7j2SSKhRigJ",
"writer": "6KAqLqtYj5d31Am1pQDYqPSUWyKFkqh3q7iayNvmUMox",
"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"
}
```
Expand All @@ -90,16 +89,16 @@ create_call(
You can create an image for your contract too and publish it to http://nftoptions.app

```Javascript
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))
create_doc_img(contract, (err, img, cb)=>{
img.write("example.png");
await publish_doc(contract)
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`
Expand Down
2 changes: 1 addition & 1 deletion src/client/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solana-options",
"version": "1.0.5",
"version": "1.0.6",
"description": "Minting of options contract NFT on the Solana blockchain",
"main": "build/index.js",
"scripts": {
Expand Down

0 comments on commit 6617e19

Please sign in to comment.