Skip to content

The ethereum smart contracts that power nori.com

License

Notifications You must be signed in to change notification settings

nori-dot-eco/contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nori Symbol - full_color

Nori marketplace smart contracts

🏗️ Integrations

JavaScript/TypeScript

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';

Solidity

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/[email protected] [email protected]

Then, in your solidity code, you can import the contracts you need:

import '@nori-dot-com/contracts/dist/solidity/Market.sol';

📔 Documentation

Refer to the contracts README for detailed documentation about how each smart contract works.

👩‍💻 Development

Setup

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)

Deploying contracts locally

You can run the following command to start a hardhat node:

hardhat node

This command will do the following:

  1. Start a local node with a new instance of a locally running chain.
  2. Seed test wallets with funds.
  3. Run the deployment scripts which seed the test contracts.

Deploying the market contracts on a live network

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.

Testing

To serially run the hardhat test suite followed by the forge test suite, run the following:

yarn test

Hardhat

To run just the typescript test suite using hardhat, run the following command:

yarn test:hardhat

Forge

To run just the solidity test suite using forge, run the following command:

yarn test:forge

Gas reports

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.

👷 Hardhat Tasks

Interact with contracts

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 a uint256 bytes-encoded representation of 100 bpNORI.

Generate contract documentation

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.

Accounts

Print the named accounts used for development and testing

hardhat accounts

🥷 Tips and tricks

Connecting to your local node from MetaMask

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

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="[email protected]" \
ETHERNAL_PASSWORD="xxxxxx_yyyyyyyy" \
hardhat node

For more, refer to the official hardhat-ethernal documentation.

Foundry

Forge

Solidity Scripting

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

Cast

Sending transactions

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`

Autocomplete

To set up autocomplete for the foundry CLI tools, follow the instructions here.

Hardhat

Autocomplete

To set up autocomplete for hardhat follow the instructions in the docs.

Autocomplete

ZSH setup
  1. 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

About

The ethereum smart contracts that power nori.com

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published