- About
- Frameworks and Tooling
- Repository Description
- Installation
- Configuration
- Alternative Configuration: Using Private Keys instead of Mnemonics, and Alchemy instead of Infura
- Using Custom JSON-RPC Endpoint URL
- Testing
- Test Coverage
- Deployment
- Address List
Click here to read project description.
The project is built using
- Hardhat, a popular Ethereum development environment
- Why not standalone Truffle?
- Truffle runs the tests several times slower than Hardhat
- Truffle + ganache fails to run big test suites, presumably it fails to close socket connections gracefully and causes open sockets overflow
- Why not Foundry?
- Foundry forces the tests to be written in Solidity, which complicates
- porting the existing tests from myriad of projects using JavaScript for tests,
- getting help from the vast community of Node.js developers in writing tests
- Foundry forces the tests to be written in Solidity, which complicates
- Why not standalone Truffle?
- Web3.js, a collection of libraries that allows interacting with local or remote Ethereum node using HTTP, IPC or WebSocket
- Truffle as a Hardhat module (plugin)
Smart contracts deployment is configured to use Infura or Alchemy and HD Wallet
Following steps were tested to work in macOS Catalina
- Install Node Version Manager (nvm) – latest
brew install nvm
- Install Node package manager (npm) and Node.js – version 16.20.0+
nvm install 16
- Activate node version installed
nvm use 16
- Install project dependencies
npm install
-
Create or import 12-word mnemonics for
- Mainnet
- Mantle
- Linea
- Unichain
- Zircuit
- Morph
You can use MetaMask to create mnemonics: https://metamask.io/
Note: you can use same mnemonic for test networks. 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.
Note: you can use private keys instead of mnemonics (see Alternative Configuration section below)
-
Create an infura access key at https://infura.io/
Note: you can use alchemy API key instead of infura access key (see Alternative Configuration section below)
-
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 MNEMONIC5003 Mantle testnet mnemonic MNEMONIC59141 Linea testnet mnemonic MNEMONIC1301 Unichain testnet mnemonic MNEMONIC48899 Zircuit testnet mnemonic MNEMONIC2810 Morph testnet mnemonic INFURA_KEY Infura access key ETHERSCAN_KEY Etherscan API key ARBISCAN_KEY arbiscan 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="witch collapse practice feed shame open despair creek road again ice least"
export MNEMONIC5003="someone relief rubber remove donkey jazz segment nose spray century put beach"
export MNEMONIC59141="slush oyster cash hotel choice universe puzzle slot reflect sword intact fat"
export MNEMONIC1301="result mom hard lend adapt where result mule address ivory excuse embody"
export INFURA_KEY="000ba27dfb1b3663aadfc74c3ab092ae"
export ETHERSCAN_KEY="9GEEN6VPKUR7O6ZFBJEKCWSK49YGMPUBBG"
export ARBISCAN_KEY="VF9IZLVDRA03VE3K5S46EADMW6VNV0V73U"
Alternatively to using mnemonics, private keys can be used instead. When both mnemonics and private keys are set in the environment variables, private keys are used.
Similarly, alchemy can be used instead of infura. If both infura and alchemy keys are set, alchemy is used.
-
Create or import private keys of the accounts for
- Mainnet
- Mantle
- Linea
- Unichain
- Zircuit
- Morph
You can use MetaMask to export private keys: https://metamask.io/
-
Create an alchemy API key at https://alchemy.com/
-
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_KEY5003 Mantle testnet private key P_KEY59141 Linea testnet private key P_KEY1301 Unichain testnet private key P_KEY48899 Zircuit testnet private key P_KEY2810 Morph testnet private key ALCHEMY_KEY Alchemy API key ETHERSCAN_KEY Etherscan API key ARBISCAN_KEY arbiscan API key
Note: private keys should start with
0x
export P_KEY1="0x5ed21858f273023c7fc0683a1e853ec38636553203e531a79d677cb39b3d85ad"
export P_KEY5003="0xfb84b845b8ea672939f5f6c9a43b2ae53b3ee5eb8480a4bfc5ceeefa459bf20c"
export P_KEY59141="0x5ed21858f273023c7fc0683a1e853ec38636553203e531a79d677cb39b3d85ad"
export P_KEY1301="0xfb84b845b8ea672939f5f6c9a43b2ae53b3ee5eb8480a4bfc5ceeefa459bf20c"
export ALCHEMY_KEY="hLe1XqWAUlvmlW42Ka5fdgbpb97ENsMJ"
export ETHERSCAN_KEY="9GEEN6VPKUR7O6ZFBJEKCWSK49YGMPUBBG"
export ARBISCAN_KEY="VF9IZLVDRA03VE3K5S46EADMW6VNV0V73U"
To use custom JSON-RPC endpoint instead of infura/alchemy public endpoints, set the corresponding RPC URL as an environment variable:
Name | Value |
---|---|
MAINNET_RPC_URL | Mainnet JSON-RPC endpoint URL |
MANTLE_RPC_URL | Mantle testnet JSON-RPC endpoint URL |
LINEA_RPC_URL | Linea testnet JSON-RPC endpoint URL |
UNICHAIN_RPC_URL | Unichain testnet JSON-RPC endpoint URL |
ZIRCUIT_RPC_URL | Zircuit testnet JSON-RPC endpoint URL |
MORPH_RPC_URL | Morph testnet JSON-RPC endpoint URL |
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 another 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.
Smart contracts test coverage is powered by [solidity-coverage] plugin.
Run npx hardhat coverage
to run test coverage and generate the report.
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 (<NETWORK_NAME>):
-
Delete deployments/<NETWORK_NAME> folder contents.
-
Run the deployment of interest with the
npx hardhat <TAG>
commandnpx hardhat deploy --network <NETWORK_NAME> --tags <TAG>
where
<TAG>
specifies the deployment script(s) tag to run, and--network <NETWORK_NAME>
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 <network_name> --api-key $ETHERSCAN_KEY
To rerun the deployment script and continue partially completed script skip the first step (do not cleanup the deployments folder).
The RWA smart contracts has been deployed to following testnets:
-
Mantle Sepolia
- RWA Vault: 0x9004AFffF01e0c812BbCd062344D6d858b799B35
- RWA Leverage: 0x0467D7C3c14E076D4bC412863A1edD3525D60015
-
Linea Sepolia
- RWA Vault: 0x0467D7C3c14E076D4bC412863A1edD3525D60015
- RWA Leverage: 0x3Ab503f2f8b9Cf3181fAddCBF79ad9B108D2947c
-
Unichain Sepolia
- RWA Vault: 0x9004AFffF01e0c812BbCd062344D6d858b799B35
- RWA Leverage: 0x0467D7C3c14E076D4bC412863A1edD3525D60015
-
Zircuit Testnet
- RWA Vault: 0x9004AFffF01e0c812BbCd062344D6d858b799B35
- RWA Leverage: 0x0467D7C3c14E076D4bC412863A1edD3525D60015
-
Morph Holesky
- RWA Vault: 0x9004AFffF01e0c812BbCd062344D6d858b799B35
- RWA Leverage: 0x0467D7C3c14E076D4bC412863A1edD3525D60015