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

dkg-evm-module

v8.0.1-alpha.1

Published

Smart contracts for OriginTrail V6

Downloads

1,414

Readme

DKG EVM Module

License GitHub Actions Status solidity - v0.8.16 NPM Package

This repository contains the smart contracts for OriginTrail V6, which serves as the core module for the Decentralized Knowledge Graph (DKG). The module handles various aspects, such as DKG Node profile management, Knowledge Asset ownership, consensus mechanisms, and others, in order to ensure the secure and efficient operation of the network. The contracts are written in Solidity and can be deployed on Ethereum and compatible networks.

Repository Structure

This repository contains the following main components:

  • abi: Stores the generated ABI files for the smart contracts.
  • contracts: Contains the Solidity source files for the smart contracts.
  • deploy: Contains deployment scripts for all contracts with additional helpers for automatic deployment on OriginTrail Parachain.
  • deployments: Contains JSON files with addresses of the latest deployed contracts on OTP (Alphanet / Devnet / Testnet / Mainnet)
  • scripts: Includes Hardhat scripts that can be run using the Hardhat CLI for specific purposes, such as deploying contracts, generating accounts, or interacting with the blockchain.
  • tasks: Contains Hardhat tasks that can be executed through the Hardhat CLI to automate various actions and processes related to the project. These tasks can be helpful for interacting with smart contracts, managing deployments, or running custom scripts as needed.
  • test: Includes the test files for the smart contracts.
  • utils: Includes utility functions and files used throughout the repository.

Prerequisites and Setup

Before running the commands, make sure you have the following prerequisites installed:

  • Node.js (version 14.x or higher)
  • npm
  • slither (Optional, needed for static Solidity code analysis)

Clone the repository and install the dependencies:

git clone https://github.com/OriginTrail/dkg-evm-module.git

cd dkg-evm-module

npm install

NPM Scripts

This project utilizes a variety of NPM scripts to run various tasks and processes. The scripts are defined in the package.json file and are designed to be used with the Hardhat CLI, leveraging Hardhat plugins for additional functionality. Here's a brief description of the scripts:

  • clean: Removes the cache and artifacts folders generated by Hardhat.
  • compile:size: Compiles the smart contracts and analyzes the size of the compiled contracts using the hardhat-contract-sizer plugin.
  • compile: Compiles the smart contracts with specific configuration using hardhat.node.config.ts.
  • coverage: Generates a code coverage report for the smart contracts with specific network and coverage settings.
  • deploy:v1:gnosis_chiado_test, deploy:v1:gnosis_mainnet, deploy:v1:localhost, deploy:v1:otp_mainnet, deploy:v1:otp_testnet, and deploy:v1: Deploy version 1 of the smart contracts to various networks including Gnosis Chiado, Hardhat, OriginTrail Parachain Alphanet, OriginTrail Parachain Devnet, OriginTrail Parachain Testnet, and OriginTrail Parachain Mainnet.
  • deploy:v2:gnosis_chiado_test, deploy:v2:gnosis_mainnet, deploy:v2:localhost, deploy:v2:otp_mainnet, deploy:v2:otp_testnet, and deploy:v2: Similar to the v1 deploy scripts, these deploy version 2 of the smart contracts to the respective networks.
  • dev:v1, dev:v2, and dev: Run local development nodes with Hardhat for different versions of contracts.
  • export-abi: Updates ABI files according to the current state of the smart contracts.
  • format:fix: Automatically fixes code formatting issues for JSON, JavaScript, TypeScript, and Solidity files using Prettier.
  • format: Checks code formatting for the same file types.
  • generate-evm-account and generate-otp-account: Generate new Ethereum and OriginTrail accounts, respectively.
  • lint:fix, lint:sol:fix, lint:ts:fix, lint:sol, lint:ts, and lint: Provide various linting functionalities for Solidity and TypeScript files, including fixing issues.
  • mint-test-tokens: Mints test tokens on the local development network.
  • prepare: Sets up Husky Git hooks and generates TypeChain typings for the smart contracts.
  • slither:reentrancy and slither: Run Slither static analysis with a focus on reentrancy vulnerabilities, and a general analysis, respectively.
  • test:fulltrace, test:gas:fulltrace, test:gas:trace, test:gas, test:integration, test:trace, test:unit, test:v1:integration, test:v1:unit, test:v1, test:v2:integration, test:v2:unit, test:v2, and test: A comprehensive suite of test scripts for different scenarios, including full trace, gas usage, integration, and unit tests for different versions.
  • typechain: Generates TypeChain typings for the smart contracts.

These scripts can be run using the npm run <script-name> command. For example, to compile the smart contracts, you can run:

npm run compile

Additional Hardhat tasks

Hardhat has plenty of other useful commands, extended by the installed plugins. Here's a brief description of the most useful tasks:

  • decode: Decodes encoded ABI data (e.g. input data of transaction).
  • encode_selector: Calculates EVM function/event/error selector (sighash).
  • encode_data: Encodes data needed for low-level contract calls.
  • clear_sharding_table: Removes nodes from sharding table based on Node IDs from the given CSV file (example usage: npx hardhat clear_sharding_table --file-path ./peers.csv --network otp_testnet).

These tasks can be run using the npx hardhat <task-name> command. For example, to decode input data, you can run:

npx hardhat decode --data <bytes-data>

Usage example of encode_data task. Here we want to call ProofManagerV1 function called setReq, and this function can be called only through forwardCall in HubController and encoding arguments for this function can be done by using this task:

npx hardhat encode_data --contract-name ProofManagerV1 --function-name setReq 1 true

Alternatively, encoded data can be produced from Remix by copying prepared calldata from ProofManagerV1 setReq call.

Contracts deployment on parachains

Update environment use OTP_DEVNET/OTP_TESTNET/OTP_MAINNET

RPC_OTP_DEVNET='<https_endpoint>'
EVM_PRIVATE_KEY_OTP_DEVNET='<0x_ethereum_private_key>'
ACCOUNT_WITH_OTP_URI_OTP_DEVNET='<substrate_account_uri>'

OriginTrail Parachain Devnet (v1 contracts)

npm run deploy:v1:otp_devnet

or (v2 contracts)

npm run deploy:v2:otp_devnet

OriginTrail Parachain Testnet (v1 contracts)

npm run deploy:v1:otp_testnet

or (v2 contracts)

npm run deploy:v2:otp_testnet

OriginTrail Parachain Mainnet (v1 contracts)

npm run deploy:v1:otp_mainnet

or (v2 contracts)

npm run deploy:v2:otp_mainnet

Gnosis Chiado Dev (v1 contracts)

npm run deploy:v1:gnosis_chiado_dev

or (v2 contracts)

npm run deploy:v2:gnosis_chiado_dev

Gnosis Chiado Test (v1 contracts)

npm run deploy:v1:gnosis_chiado_test

or (v2 contracts)

npm run deploy:v2:gnosis_chiado_test

Gnosis Mainnet (v1 contracts)

npm run deploy:v1:gnosis_mainnet

or (v2 contracts)

npm run deploy:v2:gnosis_mainnet

Redeploy contract

In order to redeploy desired contract, set deployed to false in deployments/<network>_contracts.json.