Nori marketplace smart contracts
This package can be used in your project by installing it the package:
yarn add -D @nori-dot-com/contracts
Then, in your solidity code, you can import the contracts you need:
import '@nori-dot-com/contracts/dist/solidity/Market.sol';
forge install nori-dot-eco/contracts
Note You may also need to configure path remapping if you are using foundry.
yarn add -D @nori-dot-com/contracts @openzeppelin/contracts-upgradeable@4.8.2 erc721a-upgradeable@4.2.2
Then, in your solidity code, you can import the contracts you need:
import '@nori-dot-com/contracts/dist/solidity/Market.sol';
Refer to the contracts README for detailed documentation about how each smart contract works.
Make sure to initialize submodules
git submodule update --init --recursive
Then install dependencies
yarn install && foundryup
Finally, make sure you set the necessary environment variables (refer to the default dotenv file for a list of supported variables)
You can run the following command to start a hardhat node:
hardhat node
This command will do the following:
- Start a local node with a new instance of a locally running chain.
- Seed test wallets with funds.
- Run the deployment scripts which seed the test contracts.
Note that you will need to have SOLC_PROFILE
environment variable configured as production
or the deployment will be prevented.
The following command will deploy new implementations and upgrade the existing proxies if they exist.
hardhat deploy --network [networkName] --tags market
TODO: documentation around how to deploy and force the deployment of fresh proxies as well.
To serially run the hardhat test suite followed by the forge test suite, run the following:
yarn test
To run just the typescript test suite using hardhat, run the following command:
yarn test:hardhat
To run just the solidity test suite using forge, run the following command:
yarn test:forge
To generate gas reports, run the following command:
yarn snapshot
The resulting snapshot file should be checked-in with every PR.
You can also run yarn snapshot:production
to generate a snapshot using production compiler settings or yarn snapshot:test
to use the fastest compiler settings.
Custom hardhat tasks have been implemented that allow for calling functions on deployed contracts.
hardhat [contract name] --func [function name] [arguments] --network [network name]
Example: Mint 1 NORI on goerli
hardhat NORI \
--func mint \
"0x321af43416f670ce8b4ba214dfb87c4199e2a77f" \
1000000000000000000 \
"0x" \
"0x" \
--network goerli
Example: Deposit 100 bpNORI on amoy
hardhat BridgedPolygonNORI \
--func deposit \
0x6dc772f80495f47d8000530a59ee975b67b7c646 \
"0x0000000000000000000000000000000000000000000000056bc75e2d63100000" \
--network amoy
ℹ️ Note that the final argument (
0x0000000000000000000000000000000000000000000000056bc75e2d63100000
) is auint256
bytes-encoded representation of 100 bpNORI.
Generate documentation for contracts using the following command:
yarn docgen # runs hardhat docgen
Running this command will re-generate the contract documentation in the docs folder. Note that the template used to generate the documentation is located in the sub-folder called templates.
Print the named accounts used for development and testing
hardhat accounts
You can connect to your local node from MetaMask by adding giving it a custom RPC configuration. For example, if you are using the default hardhat network configuration (e.g., if your node was started via hardhat node
), then you can connect to it by adding a custom RPC configuration with the following values:
RPC URL | Chain ID |
---|---|
http://localhost:8545 |
9001 |
For more, refer to the official MetaMask documentation on this topic.
Ethernal is an etherscan-style interface for your local hardhat node. Sign up for a free account and run your local node with the following extra variables to have contract ABIs and transactions synced there for viewing / interacting with.
ETHERNAL=true \
ETHERNAL_EMAIL="you@nori.com" \
ETHERNAL_PASSWORD="xxxxxx_yyyyyyyy" \
hardhat node
For more, refer to the official hardhat-ethernal documentation.
Foundry offers the ability to write scripts in solidity that foundry can then run (via forge script
) to create and send real transactions to a specified network.
For an overview, checkout the official tutorial here.
Setup
For these scripts to work, the following environment variables must be set in your environment:
AMOY_RPC_URL # The RPC URL for the amoy network
MNEMONIC # The mnemonic you want to use to sign your transaction with
ℹ️ The first index of the
$MNEMONIC
HD path needs to be funded with MATIC, have the correct permissions to make the contract calls, etc.
ℹ️ Our on-chain market on amoy was deployed with a fireblocks signer, so we have been using the fireblocks signer from the command line with hardhat tasks to grant necessary permissions to other addresses that we may want to use.
Here is the hardhat command for granting the CONSIGNOR_ROLE
to an address (hardhat is currently required to use a fireblocks signer):
hardhat \
--network amoy \
Removal \
--func grantRole \
`cast call 0xa051E9EeaC803d2fCA1DbF415b78AD9BfEB723b0 "CONSIGNOR_ROLE()" --rpc-url amoy` `# The bytes32 representation of the CONSIGNOR_ROLE` \
0x465d5a3fFeA4CD109043499Fa576c3E16f918463
See forge script --help
for many more command line options to the scripting.
A description of how to run some example scripts can be found in the examples below this section.
Example: Minting and listing new removals on amoy
forge script \
script/MintAndListRemovals.s.sol:MintAndListRemovals \
--rpc-url amoy \
--mnemonics=$MNEMONIC \
--broadcast \
-vvvvv
ℹ️ Transactions for minting removals have at times seemed really slow on amoy (taking almost 15 minutes to get included).
Example: Minting bpNORI
forge script \
script/MintBPNori.s.sol:MintBPNori.sol \
--rpc-url amoy \
--mnemonics=$MNEMONIC \
--broadcast \
-vvvv
You can use cast send
to send transactions and interact with deployed contracts.
Example: Deposit/mint bpNORI
The following deposits 100 bpNORI to $TO_ADDRESS
on amoy (the first account of the $MNEMONIC
must have the DEPOSITOR_ROLE
role).
cast send \
--mnemonic=$MNEMONIC
--rpc-url amoy \
$TO_ADDRESS \
"deposit(address,bytes)" \
$BP_NORI_ADDRESS \
`cast --to-uint256 100000000000000000000`
To set up autocomplete for the foundry CLI tools, follow the instructions here.
To set up autocomplete for hardhat follow the instructions in the docs.
ZSH setup
- For ZSH (omz), add the following to your zsh config file (requires zsh-completions)
# https://github.com/zsh-users/zsh-completions
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src \
autoload -U compinit && compinit