This repository contains Solidity smart contracts to be used with the Topos Protocol in the Topos ecosystem. The contract compilation/deployment and testing methods are taken care by the Hardhat development framework.
To install the project along with all the dependencies run:
$ npm install
This project contains some smart contracts which inherit from OpenZeppelin contracts. This should be installed automatically.
To build:
$ npm run build
To run the tests:
$ npm run test
To see the test coverage:
npm run coverage
For formatting this project uses prettier
with the prettier-plugin-solidity
plugin. For general style guide and security checks this project uses Solhint
.
To run linter:
$ npm run lint
To fix the format:
$ npm run lint:fix
A NodeJS script is made available to deploy contracts with CREATE2
, i.e., with constant addresses. The script is to be used with a deployed instance of ConstAddressDeployer
. See an example below:
$ npm run deploy http://myChainRPCEndpoint myCompiledContract.json MySecretSalt ACustomGasLimit|null MyConstructorArg AnotherConstructorArg
E.g.
$ npm run deploy http://127.0.0.1:8545 artifacts/contracts/topos-core/ToposCore.sol/ToposCore.json $TOPOS_CORE_SALT 2000000 0xF121424e3F7d73fCD79DcBCA67E8F10BeBE67b00 0x3100000000000000000000000000000000000000000000000000000000000000
To deploy the full Topos Messaging Protocol, another deploy:topos-msg-protocol
npm script is available. This scripts deploys the following contracts:
TokenDeployer
with constant addressToposCore
with constant addressToposCoreProxy
with constant addressToposMessaging
with constant address
$ npm run deploy:topos-msg-protocol http://myChainRPCEndpoint pathToSequencerPrivateKey
E.g.
$ npm run deploy:topos-msg-protocol http://127.0.0.1:8545 /data/node-1/consensus/validator.key
This script requires a few environment variables to be set:
- TOKEN_DEPLOYER_SALT: salt for the
TokenDeployer
contract - TOPOS_CORE_SALT: salt for the
ToposCore
contract - TOPOS_CORE_PROXY_SALT: salt for the
ToposCoreProxy
contract - TOPOS_MESSAGING_SALT: salt for the
ToposMessaging
contract - PRIVATE_KEY: the private key of the account to be used to deploy contracts
To deploy the full Topos Messaging Protocol on dynamic contract addresses (could be any Ethereum compatible network, not just Polygon Edge network with predeployed const address deployer contract), deploy:topos-msg-protocol-dynamic
npm script is available. This script is intended for usage primarily during development. It deploys the following contracts:
TokenDeployer
ToposCore
ToposCoreProxy
ToposMessaging
$ npm run deploy:topos-msg-protocol-dynamic http://myChainRPCEndpoint sequencerPrivateKey
E.g.
$ npm run deploy:topos-msg-protocol-dynamic http://127.0.0.1:8545 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
This script requires a few environment variables to be set:
- PRIVATE_KEY: the private key of the account to be used to deploy contracts
Some of the above commands can be run in docker.
$ docker build . --t target [build|test|lint]
This project is released under the terms of the MIT license.