This repo contains AIProtocol Staking contracts, scripts, and tests enabling the staking functionality support for the Artificial Liquid Intelligence Token (ALI ERC20 – AliERC20v2).
The project is built using
- Hardhat, a popular Ethereum development environment,
- Web3.js, a collection of libraries that allows interacting with local or remote Ethereum node using HTTP, IPC or WebSocket, and
- Truffle, a popular development framework for Ethereum.
Smart contracts deployment is configured to use Infura and HD Wallet
What's inside?
- Smart Contract(s):
- StakingImpl – Staking implementation
Following steps were tested to work in macOS Catalina
- Clone the repository
git clone [email protected]:AI-Protocol-Official/ali-staking-contracts.git
- Navigate into the cloned repository
cd ali-staking-contracts
- Install Node Version Manager (nvm) – latest
brew install nvm
- Install Node package manager (npm) and Node.js – version 16.4.0
nvm install v16.4.0
- Activate node version installed
nvm use v16.4.0
- Install project dependencies
npm install
- After executing
nvm use v16.4.0
I getFix:nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local/Cellar/nvm/0.37.2/versions/node/v16.4.0" Run `npm config delete prefix` or `nvm use --delete-prefix v16.4.0` to unset it.
nvm use --delete-prefix v16.4.0 npm config delete prefix npm config set prefix "/usr/local/Cellar/nvm/0.37.2/versions/node/v16.4.0"
- After executing
npm install
I getFix:npm ERR! code 127 npm ERR! path ./ALI-staking/node_modules/utf-8-validate npm ERR! command failed npm ERR! command sh -c node-gyp-build npm ERR! sh: node-gyp-build: command not found npm ERR! A complete log of this run can be found in: npm ERR! ~/.npm/_logs/2021-08-30T07_10_23_362Z-debug.log
npm install -g node-gyp npm install -g node-gyp-build
-
Create or import 12-word mnemonics for
- Mainnet
- Ropsten
- Rinkeby
- Kovan
You can use metamask to create mnemonics: https://metamask.io/
Note: you can use same mnemonic for test networks (ropsten, rinkeby and kovan). Always use a separate one for mainnet, keep it secure.
Note: you can add more configurations to connect to the networks not listed above. Check and add configurations required into the hardhat.config.js.
-
Create an infura access key at https://infura.io/
-
Create etherscan API key at https://etherscan.io/
-
Export mnemonics, infura access key, and etherscan API key as system environment variables (they should be available for hardhat):
Name Value MNEMONIC1 Mainnet mnemonic MNEMONIC3 Ropsten mnemonic MNEMONIC4 Rinkeby mnemonic MNEMONIC42 Kovan mnemonic INFURA_KEY Infura access key ETHERSCAN_KEY Etherscan API key
Note:
Read How do I set an environment variable? article for more info on how to
set up environment variables in Linux, Windows and macOS.
export MNEMONIC1="slush oyster cash hotel choice universe puzzle slot reflect sword intact fat"
export MNEMONIC3="result mom hard lend adapt where result mule address ivory excuse embody"
export MNEMONIC4="result mom hard lend adapt where result mule address ivory excuse embody"
export MNEMONIC42="result mom hard lend adapt where result mule address ivory excuse embody"
export INFURA_KEY="000ba27dfb1b3663aadfc74c3ab092ae"
export ETHERSCAN_KEY="9GEEN6VPKUR7O6ZFBJEKCWSK49YGMPUBBG"
hardhat.config-p_key.js contains an alternative Hardhat configuration using private keys instead of mnemonics
-
Create or import private keys of the accounts for
- Mainnet
- Ropsten
- Rinkeby
- Kovan
You can use metamask to export private keys: https://metamask.io/
Note: you can use the same private key for test networks (ropsten, rinkeby and kovan). Always use a separate one for mainnet, keep it secure.
-
Create an infura access key at https://infura.io/
-
Create etherscan API key at https://etherscan.io/
-
Export private keys, infura access key, and etherscan API key as system environment variables (they should be available for hardhat):
Name Value P_KEY1 Mainnet private key P_KEY3 Ropsten private key P_KEY4 Rinkeby private key P_KEY42 Kovan private key INFURA_KEY Infura access key ETHERSCAN_KEY Etherscan API key
Notes:
- private keys should start with
0x
- use
--config hardhat.config-p_key.js
command line option to run hardhat using an alternative configuration
export P_KEY1="0x5ed21858f273023c7fc0683a1e853ec38636553203e531a79d677cb39b3d85ad"
export P_KEY3="0xfb84b845b8ea672939f5f6c9a43b2ae53b3ee5eb8480a4bfc5ceeefa459bf20c"
export P_KEY4="0xfb84b845b8ea672939f5f6c9a43b2ae53b3ee5eb8480a4bfc5ceeefa459bf20c"
export P_KEY42="0xfb84b845b8ea672939f5f6c9a43b2ae53b3ee5eb8480a4bfc5ceeefa459bf20c"
export INFURA_KEY="000ba27dfb1b3663aadfc74c3ab092ae"
export ETHERSCAN_KEY="9GEEN6VPKUR7O6ZFBJEKCWSK49YGMPUBBG"
Execute npx hardhat compile
command to compile smart contracts.
Compilation settings are defined in hardhat.config.js solidity
section.
Note: Solidity files *.sol use strict compiler version, you need to change all the headers when upgrading the compiler to a newer version
Smart contract tests are built with Truffle – in JavaScript (ES6) and web3.js
The tests are located in test folder. They can be run with built-in Hardhat Network.
Run npx hardhat test
to run all the tests or .npx hardhat test <test_file>
to run individual test file.
Example: npx hardhat test ./test/inft/inft.test.js
Deployments are implemented via hardhat-deploy plugin by Ronan Sandford.
Deployment scripts perform smart contracts deployment itself and their setup configuration. Executing a script may require several transactions to complete, which may fail. To help troubleshoot partially finished deployment, the scripts are designed to be rerunnable and execute only the transactions which were not executed in previous run(s).
Deployment scripts are located under deploy folder. Deployment execution state is saved under deployments folder.
To run fresh deployment (rinkeby):
-
Delete deployments/rinkeby folder contents.
-
Run the deployment of interest with the
npx hardhat deploy
commandnpx hardhat deploy --network rinkeby --tags v1_deploy
where
v1_deploy
specifies the deployment script tag to run, and--network rinkeby
specifies the network to run script for (see hardhat.config.js for network definitions). -
Verify source code on Etherscan with the
npx hardhat etherscan-verify
commandnpx hardhat etherscan-verify --network rinkeby
-
Enable the roles (see Access Control) required by the protocol
npx hardhat deploy --network rinkeby --tags v1_roles
Note: this step can be done via Etherscan UI manually
-
Enable the features (see Access Control) required by the protocol
npx hardhat deploy --network rinkeby --tags v1_features
Note: this step can be done via Etherscan UI manually
To rerun the deployment script and continue partially completed script skip the first step (do not cleanup the deployments folder).
(c) 2021–2024 AI Protocol