Skip to content

Commit

Permalink
support minting new nfts online
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanda committed Jan 19, 2022
1 parent 0e68464 commit 710b8e8
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 80 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ You can create an image for your contract too and publish it to https://nftoptio

![sample](./docs/contract.png)

## 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:

```javascript
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"])
})
```

## Motivation

### What are options?
Expand Down
23 changes: 22 additions & 1 deletion src/client/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,25 @@ You can create an image for your contract too and publish it to https://nftoptio

`example.png`

![sample](https://raw.githubusercontent.com/dbanda/solana-nft-options/master/docs/contract.png)
![sample](https://raw.githubusercontent.com/dbanda/solana-nft-options/master/docs/contract.png)


## 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:

```javascript
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"])
})
```
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.14",
"version": "1.0.15",
"description": "Minting of options contract NFTs on the Solana blockchain",
"main": "build/index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions src/client/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ async function get_token_map(): Promise<Map<string,string>>{
* @returns
*/
export async function create_call(connection: Connection, strike: number, expiry: number, multiple: number, creator_account: Signer,
instrument: PublicKey | string, strike_instrument: PublicKey | string, creator_instrument_acc: PublicKey,
creator_strike_instrument_acc: PublicKey) : Promise<[string, Contract]>{
instrument: PublicKey | string | null, strike_instrument: PublicKey | string | null, creator_instrument_acc: PublicKey | null,
creator_strike_instrument_acc: PublicKey | null) : Promise<[string, Contract]>{
console.log("creating call contract")

return create_option(connection, strike, expiry, multiple, creator_account, instrument,
Expand All @@ -94,15 +94,15 @@ export async function create_call(connection: Connection, strike: number, expiry
* @returns
*/
export async function create_put(connection: Connection, strike: number, expiry: number, multiple: number, creator_account: Keypair,
instrument: PublicKey, strike_instrument: PublicKey, creator_instrument_acc: PublicKey,
creator_strike_instrument_acc: PublicKey) : Promise<[string, Contract]>{
instrument: PublicKey | string | null, strike_instrument: PublicKey| string | null, creator_instrument_acc: PublicKey | null,
creator_strike_instrument_acc: PublicKey | null) : Promise<[string, Contract]>{
console.log("creating put contract")

return create_option(connection, strike, expiry, multiple, creator_account, instrument,
strike_instrument, creator_instrument_acc, creator_strike_instrument_acc, OptionType.put)
}

async function create_new_nft_mint(connection: Connection, multiple: number, creator_account: Signer) {
export async function create_new_nft_mint(connection: Connection, multiple: number, creator_account: Signer) {
const instrument_mint_acc = new Keypair();
console.log("instrument mint account key: ", instrument_mint_acc.publicKey.toString())
const mint_rent = await connection.getMinimumBalanceForRentExemption(MintLayout.span, 'confirmed')
Expand Down Expand Up @@ -178,7 +178,7 @@ async function create_new_nft_mint(connection: Connection, multiple: number, cre
}

export async function create_option(connection: Connection, strike: number, expiry: number, multiple: number, creator_account: Signer,
instrument: PublicKey | string, strike_instrument: PublicKey | string, creator_instrument_acc: PublicKey, creator_strike_instrument_acc: PublicKey, kind: OptionType) : Promise<[string, Contract]>{
instrument: PublicKey | string | null, strike_instrument: PublicKey | string | null, creator_instrument_acc: PublicKey | null, creator_strike_instrument_acc: PublicKey, kind: OptionType) : Promise<[string, Contract]>{

// check if the either instrument or strike_instrument is a symbol or address(public); assume symbol if string
if (typeof instrument == "string" || typeof strike_instrument == "string"){
Expand Down
Loading

0 comments on commit 710b8e8

Please sign in to comment.