From 14877b54894d7a686025f1560f383c3f80df498b Mon Sep 17 00:00:00 2001 From: Philip Diaz Date: Fri, 28 Aug 2020 12:18:15 -0400 Subject: [PATCH] feat: Update server with new NFT contract and config --- bin/originate-fa2-nft-contracts | 72 ------------------------- config/minter.sandbox.json | 6 +-- contracts/bin/fa2_multi_nft_asset.tz | 25 ++++----- server/package.json | 1 + server/src/components/contract_store.ts | 10 ++-- server/src/resolvers/mutations/index.ts | 25 +++++---- 6 files changed, 32 insertions(+), 107 deletions(-) delete mode 100755 bin/originate-fa2-nft-contracts diff --git a/bin/originate-fa2-nft-contracts b/bin/originate-fa2-nft-contracts deleted file mode 100755 index f16e5633..00000000 --- a/bin/originate-fa2-nft-contracts +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -## -# This origination script only works for the development sandbox environment -# TODO: Expand with input arguments that parameterize the public/private keys -# and Tezos RPC address -## - -# Setup - -cd ${BASH_SOURCE%/*}/.. - -docker pull ligolang/ligo:next 2>&1 1>/dev/null - - -# Contract compilation, origination & creation - -compile_contract() { - LIGO_CONTRACT="$1" - LIGO_ENTRY="$2" - docker run \ - -v "$(pwd):/data" --rm \ - -t ligolang/ligo:next \ - compile-contract "/data/$LIGO_CONTRACT" "$LIGO_ENTRY" \ - --brief -} - - -originate_contract() { - PRIVATE_KEY="$1" - STORAGE="$2" - CONFIG_KEY="$3" - docker run \ - -v "$(pwd)/server/config:/usr/src/app/server/config" \ - -i --rm --network="minter-dev-sandbox_default" minter-api-dev \ - yarn exec -s ts-node /usr/src/app/server/scripts/originate_contract.ts "$PRIVATE_KEY" "$STORAGE" "$CONFIG_KEY" -} - - -create_contract() { - CONTRACT="$1" - ENTRY="$2" - PRIVATE_KEY="$3" - STORAGE="$4" - CONFIG_KEY="$5" - compile_contract "$CONTRACT" "$ENTRY" | originate_contract "$PRIVATE_KEY" "$STORAGE" "$CONFIG_KEY" -} - - -# Originator Wallet - -ADMIN_ADDRESS="tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" -ORIGINATOR_PRIVATE_KEY="edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq" - - -# Originate Minter Contract - -MINTER_CONFIG_KEY="minter_contract" -MINTER_CONTRACT="contracts/ligo/src/fa2_nft_minter.mligo" -MINTER_ENTRY="minter_main" -MINTER_STORAGE="(Pair (Pair (Pair (Pair \"$ADMIN_ADDRESS\" False) None) {}) None)" - -MINTER_ADDRESS="$(create_contract "$MINTER_CONTRACT" "$MINTER_ENTRY" "$ORIGINATOR_PRIVATE_KEY" "$MINTER_STORAGE" "$MINTER_CONFIG_KEY")" - -# Originate NFT Contract - -NFT_CONFIG_KEY="nft_contract" -NFT_CONTRACT="contracts/ligo/src/fa2_multi_nft_asset.mligo" -NFT_ENTRY="nft_asset_main" -NFT_STORAGE="(Pair (Pair (Pair \"$MINTER_ADDRESS\" True) None) (Pair (Pair {} 0) (Pair {} {})))" - -create_contract "$NFT_CONTRACT" "$NFT_ENTRY" "$ORIGINATOR_PRIVATE_KEY" "$NFT_STORAGE" "$NFT_CONFIG_KEY" diff --git a/config/minter.sandbox.json b/config/minter.sandbox.json index ec65363b..7cf66db2 100644 --- a/config/minter.sandbox.json +++ b/config/minter.sandbox.json @@ -1,10 +1,10 @@ { "rpc": "http://localhost:20000", "admin": { - "address": "tz1YPSCGWXwBdTncK2aCctSZAXWvGsGwVJqU", - "secret": "edsk3RFgDiCt7tWB2oe96w1eRw72iYiiqZPLu9nnEY23MYRp2d8Kkx" + "address": "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb", + "secret": "edskRpm2mUhvoUjHjXgMoDRxMKhtKfww1ixmWiHCWhHuMEEbGzdnz8Ks4vgarKDtxok7HmrEo1JzkXkdkvyw7Rtw6BNtSd7MJ7" }, "contracts": { - "nft": "KT1HpTpGoktbMf9BFg5kgaCQR7uGw2AVabm5" + "nft": "KT1FVT95brPwbuWb6epuqU95hjzwyz2oqdz1" } } \ No newline at end of file diff --git a/contracts/bin/fa2_multi_nft_asset.tz b/contracts/bin/fa2_multi_nft_asset.tz index 8b6ef950..d55f0bc9 100644 --- a/contracts/bin/fa2_multi_nft_asset.tz +++ b/contracts/bin/fa2_multi_nft_asset.tz @@ -136,29 +136,29 @@ PAIR ; PAIR ; DUP ; - CAR ; CDR ; SWAP ; DUP ; DUG 2 ; + CAR ; CDR ; DIG 2 ; CAR ; CAR ; IF_NONE - { SWAP ; DROP } - { SWAP ; + { DROP } + { DIG 2 ; DUP ; - DUG 2 ; - DIG 3 ; + DUG 3 ; + DIG 2 ; DUP ; - DUG 4 ; + DUG 3 ; GET ; IF_NONE { DROP 3 ; DIG 4 ; DUP ; DUG 5 ; FAILWITH } { COMPARE ; EQ ; - IF { SWAP ; NONE address ; SWAP ; UPDATE } + IF { NONE address ; SWAP ; UPDATE } { DROP 2 ; DIG 4 ; DUP ; DUG 5 ; FAILWITH } } } ; SWAP ; DUP ; @@ -185,12 +185,10 @@ DROP ; DIG 2 ; DROP ; - NIL operation ; - DUG 2 ; DIP { DUP ; CDR ; SWAP ; CAR ; CDR } ; PAIR ; PAIR ; - SWAP ; + NIL operation ; PAIR } ; SWAP ; APPLY ; @@ -637,14 +635,13 @@ CONS ; PAIR } } ; DUP ; - CAR ; - NONE address ; - PAIR ; - SWAP ; CDR ; LAMBDA (pair address (big_map (pair address address) unit)) unit { DROP ; UNIT } ; NIL (pair (option address) (list (pair (pair nat (option address)) nat))) ; DIG 3 ; + CAR ; + NONE address ; + PAIR ; CONS ; PAIR ; PAIR ; diff --git a/server/package.json b/server/package.json index 14c64e49..0e381ef3 100644 --- a/server/package.json +++ b/server/package.json @@ -18,6 +18,7 @@ "apollo-server-express": "^2.9.9", "axios": "^0.19.0", "bcrypt": "^3.0.7", + "bignumber.js": "^9.0.0", "concurrently": "^5.0.0", "configstore": "^5.0.1", "cookie-parser": "^1.4.4", diff --git a/server/src/components/contract_store.ts b/server/src/components/contract_store.ts index 16a80b2e..8a3d8a4b 100644 --- a/server/src/components/contract_store.ts +++ b/server/src/components/contract_store.ts @@ -2,13 +2,13 @@ import Configstore from 'configstore'; import path from 'path'; import { Contract, TezosToolkit } from '@taquito/taquito'; -const CONFIG_NAME = 'contract-config.json'; +const TZ_ENV = process.env.TZ_NETWORK || 'sandbox'; +const CONFIG_NAME = `minter.${TZ_ENV}.json`; const CONFIG_PATH = path.join(__dirname, '../../config/', CONFIG_NAME); const configStore = new Configstore('', {}, { configPath: CONFIG_PATH }); export interface ContractStore { - minterContract(): Promise; nftContract(): Promise; } @@ -16,12 +16,8 @@ export default async function buildContractStore( tzClient: TezosToolkit ): Promise { return { - minterContract() { - const minterContractAddress = configStore.get('minter_contract'); - return tzClient.contract.at(minterContractAddress); - }, nftContract() { - const nftContractAddress = configStore.get('nft_contract'); + const nftContractAddress = configStore.get('contracts.nft'); return tzClient.contract.at(nftContractAddress); } }; diff --git a/server/src/resolvers/mutations/index.ts b/server/src/resolvers/mutations/index.ts index fe82a9dd..8f021872 100644 --- a/server/src/resolvers/mutations/index.ts +++ b/server/src/resolvers/mutations/index.ts @@ -3,6 +3,7 @@ import { MichelsonMap } from '@taquito/taquito'; import PublishedOperation from '../../models/published_operation'; import { TransactionOperation } from '@taquito/taquito/dist/types/operations/transaction-operation'; import { Context } from '../../components/context'; +import { BigNumber } from 'bignumber.js'; async function confirmOperation( { db, pubsub, tzClient }: Context, @@ -20,24 +21,26 @@ const Mutation: MutationResolvers = { async createNonFungibleToken(_parent, args, ctx) { const { db, contractStore } = ctx; const nftContract = await contractStore.nftContract(); - const minterContract = await contractStore.minterContract(); + const nftStorage = await nftContract.storage(); const adminAddress = await ctx.tzClient.signer.publicKeyHash(); const params = [ { - symbol: args.symbol, - name: args.name, - owner: adminAddress, - extras: new MichelsonMap({ - prim: 'map', - args: [{ prim: 'string' }, { prim: 'string' }] - }) + metadata: { + token_id: nftStorage.assets.next_token_id, + symbol: args.symbol, + name: args.name, + decimals: new BigNumber(0), + extras: new MichelsonMap({ + prim: 'map', + args: [{ prim: 'string' }, { prim: 'string' }] + }) + }, + owner: adminAddress } ]; - const operation = await minterContract.methods - .mint(nftContract.address, params) - .send(); + const operation = await nftContract.methods.mint(params).send(); await PublishedOperation.create(db, { hash: operation.hash,