Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@nayms/contracts

1.0.0-507 • Public • Published

CircleCI Coverage Status

Nayms Smart contracts.

How to use

Install the package:

npm install @nayms/contracts

The package exposes the following properties:

  • contracts - the key contracts (see below)
  • rawContracts - ABIs of all Solidity contracts in the repo
  • addresses - on-chain addresses of contracts in rawContracts
  • events - ABIs for events to listen for
  • buildConfig - the contents of buildConfig.json, this is used to keep track of the build number in VersionInfo.sol, for upgradeable contracts.
  • extractEventsFromAbis() - given an array of contract ABIs, this will extract the event ABIs within.
  • keccak256() - keccak256 hash function
  • ROLES - role constants
  • ROLEGROUPS - rolegroup constants

The key contracts are:

  • ACL (IACL.sol) - Interface for our access control system. We have a single global ACL for our platform.
  • AccessControl (AccessControl.sol) - Interface for obtaining ACL context info from deployed contracts.
  • EntityDeployer (IEntityDeployer.sol) - Interface for the entity deployer. We have a single global deployer for our platform.
  • Entity (IEntity.sol) - Interface for interacting with entities.
  • ERC20 (IERC20.sol) - Interface for interacting with ERC-20 contracts.
  • EtherToken (IEtherToken.sol) - Interface for interacting with wrapped ETH token contract. We have a single global instance for our platform.
  • Market (IMarket.sol) - Interface for interacting with our MakerOTC matching market. We have a single global instance for our platform.
  • Policy (IPolicy.sol) - Interface for interacting with policies.
  • Settings (ISettings.sol) - Interface for global settings. We have a single global settings instance for our platform.

We automatically deploy the first Entity via the EntityDeployer. This is the Nayms company entity and its address can be obtained via Settings.getAddress(SETTINGS.NAYMS_ENTITY) as well as by calling EntityDeployer.getEntity(0).

Example usage

const ethers = require('ethers')
const { parseLog } = require('ethereum-event-logs')
const { contracts, addresses, events } = require('@nayms/contracts')
 
const mnemonic = '<mnemonic pass phrase>'
 
const init = async () => {
  const provider = new ethers.providers.InfuraProvider('rinkeby', '<infura token>')
 
  const wallet = ethers.Wallet.fromMnemonic(mnemonic).connect(provider)
 
  const deployer = new ethers.Contract(
    // '4' is Rinkeby (see https://chainid.network/chains/)
    addresses.EntityDeployer['4'].address,
    contracts.EntityDeployer.abi,
    wallet
  )
 
  // deploy a new Entity
  const tx = await deployer.deploy({
    gasPrice: '0x3B9ACA00', // 1,000,000,000
    gasLimit: '0x2DC6C0', // 1,500,000
  })
 
  console.log(`Tx hash: ${tx.hash}`)
 
  const receipt = await provider.waitForTransaction(tx.hash)
 
  const [ newEntityEvent ] = parseLog(receipt.logs, [ events.NewEntity ])
  const { args: { entity } } = newEntityEvent
 
  console.log(`New entity deployed at: ${entity}`)
}
 
init().catch(err => {
  console.error(err)
  process.exit(-1)
})

To deploy and use the contracts on your local chain please clone this repository and run the following deployment commands:

yarn compile
yarn deploy:local
# The addresses at which the contract are deployed will be output in the terminal. 

Development

Note: Requires Node 12+

Install dependencies:

yarn

Initialize git submodules (for maker-otc trading engine):

git submodule init
git submodule update

First, run the dev network in a separate terminal:

yarn devnet

Compile the contracts:

yarn compile

Now deploy the contracts to it:

yarn deploy:local

Now you can run the tests:

yarn test

Deployments

Set up the env vars:

export MNEMONI="..."
export INFURA_KEY="..."

To deploy a fresh set of contracts and update deployedAddresses.json, do:

FRESH=true yarn deploy:rinkeby

To just upgrade existing contracts:

yarn deploy:rinkeby

For mainnet it's the same process, but using the deploy:mainnet command instead.

Note: when deploying to public networks, if deployment fails with a "transaction underpriced" error then it means there are pending transactions for the deployment account - you need to wait for these to complete before trying again.

Notes

Keywords

none

Install

npm i @nayms/contracts

DownloadsWeekly Downloads

36

Version

1.0.0-507

License

ISC

Unpacked Size

20.6 MB

Total Files

131

Last publish

Collaborators

  • avatar
  • avatar
  • avatar