Skip to content

Commit

Permalink
Initial commit to integrate latest version of hypersdk as of oct 2 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Oct 3, 2024
1 parent 4e6ba82 commit 0d0a8d7
Show file tree
Hide file tree
Showing 75 changed files with 14,693 additions and 365 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
web_wallet/node_modules
tests/e2e/e2e.test
build
.nuklai-cli/
**.coverage.**
42 changes: 42 additions & 0 deletions Dockerfile.devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#####
# Source of precompiled avalanchego
#####
ARG INSTALL_AVALANCHEGO_VERSION_SHORT=d366a137
FROM avaplatform/avalanchego:${INSTALL_AVALANCHEGO_VERSION_SHORT} AS avalanchego

#####
# Base layer with hypersdk
#####
FROM golang:1.22-bookworm AS hypersdk-downloader

RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl && apt clean && rm -rf /var/lib/apt/lists/*


ARG INSTALL_AVALANCHEGO_VERSION=v1.11.12-rc.2
COPY --from=avalanchego /avalanchego/build/avalanchego /root/.hypersdk/avalanchego-${INSTALL_AVALANCHEGO_VERSION}/avalanchego


ENV GOMODCACHE /go/pkg/mod

WORKDIR /app

RUN go install github.com/onsi/ginkgo/v2/ginkgo@v2.13.1

COPY ./go.mod ./go.sum ./

COPY ./actions ./actions
COPY ./chain ./chain
COPY ./cmd/nuklaivm ./cmd/nuklaivm
COPY ./consts ./consts
COPY ./emission ./emission
COPY ./genesis ./genesis
COPY ./marketplace ./marketplace
COPY ./scripts ./scripts
COPY ./storage ./storage
COPY ./tests ./tests
COPY ./vm ./vm

WORKDIR /app


ENTRYPOINT ["/bin/bash", "-c", "./scripts/stop.sh; ./scripts/run.sh && echo 'Devnet started' && tail -f /dev/null"]
28 changes: 28 additions & 0 deletions Dockerfile.faucet
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#####
# Build the faucet
#####

FROM golang:1.22-bookworm AS faucet-builder

WORKDIR /build
COPY ./go.mod ./go.sum ./

COPY ./ ./

ENV GOMODCACHE /go/pkg/mod
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -o build/faucet ./cmd/faucet

#####
# Final layer with faucet, VM and avalanchego
#####
FROM debian:bookworm-slim

RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl && apt clean && rm -rf /var/lib/apt/lists/*

COPY --from=faucet-builder /build/build/faucet /faucet



ENTRYPOINT ["/faucet"]
12 changes: 12 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Build stage
FROM node:22-bookworm AS build
WORKDIR /app
COPY web_wallet/package.json web_wallet/package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm install
COPY web_wallet/ ./web_wallet/
WORKDIR /app/web_wallet
RUN npm run build-no-check

# # Production stage
FROM nginx:latest
COPY --from=build /app/web_wallet/dist /usr/share/nginx/html
6 changes: 1 addition & 5 deletions actions/burn_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ func (*BurnAssetFT) GetTypeID() uint8 {
return nconsts.BurnAssetFTID
}

func (b *BurnAssetFT) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (b *BurnAssetFT) StateKeys(actor codec.Address) state.Keys {
return state.Keys{
string(storage.AssetKey(b.AssetID)): state.Read | state.Write,
string(storage.BalanceKey(actor, b.AssetID)): state.Read | state.Write,
}
}

func (*BurnAssetFT) StateKeysMaxChunks() []uint16 {
return []uint16{storage.AssetChunks, storage.BalanceChunks}
}

func (b *BurnAssetFT) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down
6 changes: 1 addition & 5 deletions actions/burn_asset_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (*BurnAssetNFT) GetTypeID() uint8 {
return nconsts.BurnAssetNFTID
}

func (b *BurnAssetNFT) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (b *BurnAssetNFT) StateKeys(actor codec.Address) state.Keys {
return state.Keys{
string(storage.AssetKey(b.AssetID)): state.Read | state.Write,
string(storage.AssetNFTKey(b.NftID)): state.Read | state.Write,
Expand All @@ -45,10 +45,6 @@ func (b *BurnAssetNFT) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
}
}

func (*BurnAssetNFT) StateKeysMaxChunks() []uint16 {
return []uint16{storage.AssetChunks, storage.AssetNFTChunks, storage.BalanceChunks, storage.BalanceChunks}
}

func (b *BurnAssetNFT) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down
6 changes: 3 additions & 3 deletions actions/burn_asset_nft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/nuklai/nuklaivm/storage"
"github.com/nuklai/nuklaivm/utils"
"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/chain/chaintest"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/codec/codectest"
"github.com/ava-labs/hypersdk/state"

nchain "github.com/nuklai/nuklaivm/chain"
nconsts "github.com/nuklai/nuklaivm/consts"
)

func TestBurnAssetNFTAction(t *testing.T) {
addr := codectest.NewRandomAddress()
assetID := ids.GenerateTestID()
nftID := nchain.GenerateIDWithIndex(assetID, 0)
nftID := utils.GenerateIDWithIndex(assetID, 0)

tests := []chaintest.ActionTest{
{
Expand Down Expand Up @@ -121,7 +121,7 @@ func BenchmarkBurnAssetNFT(b *testing.B) {
require := require.New(b)
actor := codec.CreateAddress(0, ids.GenerateTestID())
assetID := ids.GenerateTestID()
nftID := nchain.GenerateIDWithIndex(assetID, 0)
nftID := utils.GenerateIDWithIndex(assetID, 0)

burnAssetNFTActionBenchmark := &chaintest.ActionBenchmark{
Name: "BurnAssetNFTBenchmark",
Expand Down
6 changes: 1 addition & 5 deletions actions/claim_delegation_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ func (*ClaimDelegationStakeRewards) GetTypeID() uint8 {
return nconsts.ClaimDelegationStakeRewardsID
}

func (c *ClaimDelegationStakeRewards) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (c *ClaimDelegationStakeRewards) StateKeys(actor codec.Address) state.Keys {
return state.Keys{
string(storage.BalanceKey(actor, ids.Empty)): state.All,
string(storage.DelegateUserStakeKey(actor, c.NodeID)): state.Read,
}
}

func (*ClaimDelegationStakeRewards) StateKeysMaxChunks() []uint16 {
return []uint16{storage.BalanceChunks, storage.DelegateUserStakeChunks}
}

func (*ClaimDelegationStakeRewards) OutputsWarpMessage() bool {
return false
}
Expand Down
13 changes: 4 additions & 9 deletions actions/claim_marketplace_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/nuklai/nuklaivm/emission"
"github.com/nuklai/nuklaivm/storage"
"github.com/nuklai/nuklaivm/utils"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/state"

hutils "github.com/ava-labs/hypersdk/utils"
nchain "github.com/nuklai/nuklaivm/chain"
nconsts "github.com/nuklai/nuklaivm/consts"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func (*ClaimMarketplacePayment) GetTypeID() uint8 {
return nconsts.ClaimMarketplacePaymentID
}

func (c *ClaimMarketplacePayment) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (c *ClaimMarketplacePayment) StateKeys(actor codec.Address) state.Keys {
return state.Keys{
string(storage.DatasetKey(c.DatasetID)): state.Read,
string(storage.AssetKey(c.MarketplaceAssetID)): state.Read | state.Write,
Expand All @@ -57,10 +56,6 @@ func (c *ClaimMarketplacePayment) StateKeys(actor codec.Address, _ ids.ID) state
}
}

func (*ClaimMarketplacePayment) StateKeysMaxChunks() []uint16 {
return []uint16{storage.DatasetChunks, storage.AssetChunks, storage.AssetChunks, storage.BalanceChunks}
}

func (c *ClaimMarketplacePayment) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down Expand Up @@ -102,7 +97,7 @@ func (c *ClaimMarketplacePayment) Execute(
}

// Unmarshal the metadata JSON into a map
metadataMap, err := nchain.BytesToMap(metadata)
metadataMap, err := utils.BytesToMap(metadata)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -137,7 +132,7 @@ func (c *ClaimMarketplacePayment) Execute(
}
decimalsToUse = decimals
}
baseValueOfOneUnit, _ := hutils.ParseBalance("1", decimalsToUse)
baseValueOfOneUnit, _ := utils.ParseBalance("1", decimalsToUse)
// Get the current block height
currentBlockHeight := emission.GetEmission().GetLastAcceptedBlockHeight()
// Calculate the number of blocks the subscription has been active
Expand Down
6 changes: 1 addition & 5 deletions actions/claim_validator_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ func (*ClaimValidatorStakeRewards) GetTypeID() uint8 {
return nconsts.ClaimValidatorStakeRewardsID
}

func (c *ClaimValidatorStakeRewards) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (c *ClaimValidatorStakeRewards) StateKeys(actor codec.Address) state.Keys {
return state.Keys{
string(storage.BalanceKey(actor, ids.Empty)): state.All,
string(storage.RegisterValidatorStakeKey(c.NodeID)): state.Read,
}
}

func (*ClaimValidatorStakeRewards) StateKeysMaxChunks() []uint16 {
return []uint16{storage.BalanceChunks, storage.RegisterValidatorStakeChunks}
}

func (c *ClaimValidatorStakeRewards) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down
14 changes: 5 additions & 9 deletions actions/complete_contribute_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/nuklai/nuklaivm/marketplace"
"github.com/nuklai/nuklaivm/storage"
"github.com/nuklai/nuklaivm/utils"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/state"

smath "github.com/ava-labs/avalanchego/utils/math"
nchain "github.com/nuklai/nuklaivm/chain"
nconsts "github.com/nuklai/nuklaivm/consts"
)

Expand All @@ -41,8 +41,8 @@ func (*CompleteContributeDataset) GetTypeID() uint8 {
return nconsts.CompleteContributeDatasetID
}

func (d *CompleteContributeDataset) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
nftID := nchain.GenerateIDWithIndex(d.DatasetID, d.UniqueNFTIDForContributor)
func (d *CompleteContributeDataset) StateKeys(_ codec.Address) state.Keys {
nftID := utils.GenerateIDWithIndex(d.DatasetID, d.UniqueNFTIDForContributor)
return state.Keys{
string(storage.AssetKey(d.DatasetID)): state.Read | state.Write,
string(storage.AssetNFTKey(nftID)): state.Allocate | state.Write,
Expand All @@ -53,10 +53,6 @@ func (d *CompleteContributeDataset) StateKeys(_ codec.Address, _ ids.ID) state.K
}
}

func (*CompleteContributeDataset) StateKeysMaxChunks() []uint16 {
return []uint16{storage.AssetChunks, storage.AssetNFTChunks, storage.DatasetChunks, storage.BalanceChunks, storage.BalanceChunks, storage.BalanceChunks}
}

func (d *CompleteContributeDataset) Execute(
ctx context.Context,
_ chain.Rules,
Expand All @@ -83,7 +79,7 @@ func (d *CompleteContributeDataset) Execute(
}

// Check if the nftID already exists
nftID := nchain.GenerateIDWithIndex(d.DatasetID, d.UniqueNFTIDForContributor)
nftID := utils.GenerateIDWithIndex(d.DatasetID, d.UniqueNFTIDForContributor)
exists, _, _, _, _, _, _ = storage.GetAssetNFT(ctx, mu, nftID)
if exists {
return nil, ErrOutputNFTAlreadyExists
Expand Down Expand Up @@ -123,7 +119,7 @@ func (d *CompleteContributeDataset) Execute(
metadataNFTMap := make(map[string]string, 0)
metadataNFTMap["dataLocation"] = string(dataContribution.DataLocation)
metadataNFTMap["dataIdentifier"] = string(dataContribution.DataIdentifier)
metadataNFT, err := nchain.MapToBytes(metadataNFTMap)
metadataNFT, err := utils.MapToBytes(metadataNFTMap)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions actions/complete_contribute_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/nuklai/nuklaivm/marketplace"
"github.com/nuklai/nuklaivm/storage"
"github.com/nuklai/nuklaivm/utils"
"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/chain/chaintest"
"github.com/ava-labs/hypersdk/codec/codectest"
"github.com/ava-labs/hypersdk/state"

nchain "github.com/nuklai/nuklaivm/chain"
nconsts "github.com/nuklai/nuklaivm/consts"
)

Expand Down Expand Up @@ -92,7 +92,7 @@ func TestCompleteContributeDatasetAction(t *testing.T) {
// Set valid dataset
require.NoError(t, storage.SetDataset(context.Background(), store, datasetID, []byte("Dataset Name"), []byte("Description"), []byte("Science"), []byte("MIT"), []byte("MIT"), []byte("http://license-url.com"), []byte("Metadata"), true, ids.Empty, ids.Empty, 0, 100, 0, 100, 100, addr))
// Create existing NFT
nftID := nchain.GenerateIDWithIndex(datasetID, uniqueNFTID)
nftID := utils.GenerateIDWithIndex(datasetID, uniqueNFTID)
require.NoError(t, storage.SetAssetNFT(context.Background(), store, datasetID, uniqueNFTID, nftID, []byte("Dataset NFT"), []byte("Metadata"), addr))
return store
}(),
Expand All @@ -119,7 +119,7 @@ func TestCompleteContributeDatasetAction(t *testing.T) {
}(),
Assertion: func(ctx context.Context, t *testing.T, store state.Mutable) {
config := marketplace.GetDatasetConfig()
nftID := nchain.GenerateIDWithIndex(datasetID, uniqueNFTID)
nftID := utils.GenerateIDWithIndex(datasetID, uniqueNFTID)

// Check if the balance is correctly updated
balance, err := storage.GetBalance(ctx, store, addr, config.CollateralAssetIDForDataContribution)
Expand All @@ -141,7 +141,7 @@ func TestCompleteContributeDatasetAction(t *testing.T) {
CollateralAssetID: marketplace.GetDatasetConfig().CollateralAssetIDForDataContribution,
CollateralAmountRefunded: marketplace.GetDatasetConfig().CollateralAmountForDataContribution,
DatasetID: datasetID,
DatasetChildNftID: nchain.GenerateIDWithIndex(datasetID, uniqueNFTID),
DatasetChildNftID: utils.GenerateIDWithIndex(datasetID, uniqueNFTID),
To: addr,
DataLocation: dataLocation,
DataIdentifier: dataIdentifier,
Expand Down
10 changes: 1 addition & 9 deletions actions/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,14 @@ func (*ContractCall) GetTypeID() uint8 {
return mconsts.ContractCallID
}

func (t *ContractCall) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
func (t *ContractCall) StateKeys(_ codec.Address) state.Keys {
result := state.Keys{}
for _, stateKeyPermission := range t.SpecifiedStateKeys {
result.Add(stateKeyPermission.Key, stateKeyPermission.Permission)
}
return result
}

func (t *ContractCall) StateKeysMaxChunks() []uint16 {
result := make([]uint16, 0, len(t.SpecifiedStateKeys))
for range t.SpecifiedStateKeys {
result = append(result, 1)
}
return result
}

func (t *ContractCall) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down
6 changes: 1 addition & 5 deletions actions/contract_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (*ContractDeploy) GetTypeID() uint8 {
return mconsts.ContractDeployID
}

func (d *ContractDeploy) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
func (d *ContractDeploy) StateKeys(_ codec.Address) state.Keys {
if d.address == codec.EmptyAddress {
d.address = storage.GetAddressForDeploy(0, d.CreationInfo)
}
Expand All @@ -43,10 +43,6 @@ func (d *ContractDeploy) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
}
}

func (*ContractDeploy) StateKeysMaxChunks() []uint16 {
return []uint16{storage.BalanceChunks}
}

func (d *ContractDeploy) Execute(
ctx context.Context,
_ chain.Rules,
Expand Down
Loading

0 comments on commit 0d0a8d7

Please sign in to comment.