To learn more about Staking and the technical design, please check out the following resources:
- Technical Specification: Learn about the internals of the Staking contracts. Includes a Glossary.
- API Docs: Autogenerated docs based on inline documentation.
- Developer Guide: Learn how to compile the code and run tests.
$ pnpm install
$ pnpm prepare
Create a .env
following the .env.example
:
NODE_URL=optional, only for mainnet / testnet deployment
ETHERSCAN_API_KEY=optional, only for verification
MNEMONIC=here is where your twelve words mnemonic should be put my friend
VIA_IR=true
Install and setup direnv
to load and unload environment variables depending on the current directory.
Make sure you have
VIA_IR=true
in your.env
Compile the smart contracts with Hardhat:
$ pnpm compile
Compile the smart contracts and generate TypeChain artifacts:
$ pnpm typechain
Lint the Solidity code with Solhint:
$ pnpm lint:sol
Lint the TypeScript code:
$ pnpm lint:ts
$ pnpm format
Run unit tests:
$ pnpm test
Run a single test:
$ pnpm test test/MyContract.test.ts
Note: coverage must be run with VIA_IR=false
Generate a test coverage report:
$ pnpm coverage
Unit test coverage is at 100%.
Delete the smart contract artifacts, the coverage reports and the Hardhat cache:
$ pnpm clean
Slither does not currently work due to an issue with library events. You can temporarily work around it by commenting out all library events (
emit RewardLib.*()
,emit StakingPoolLib.*()
) inStaking.sol
before running Slither.On older Slither versions you will need to replace all library errors (
revert RewardLib.*()
,revert StakingPoolLib.*()
) with plainrevert()
because of an issue with library errors.
Make sure you are on the latest >=0.9.0
version of Slither.
pnpm slither
Make sure you have python and slither installed. You can install it by running
asdf install
pip3 install -r tools/requirements.txt
asdf reshim python
Make sure you have foundry / forge installed.
We use foundry for fuzz and invariant testing.
forge test
You can find a .gas-snapshot
file for several key flows. You may find it helpful during gas golfing.
forge snapshot
- Hardhat: compile and run the smart contracts on a local development network
- Foundry: a smart contract development toolchain
- TypeChain: generate TypeScript types for smart contracts
- Ethers: renowned Ethereum library and wallet implementation
- Waffle: tooling for writing comprehensive smart contract tests
- Solhint: linter
- Solcover: code coverage
- Prettier Plugin Solidity: code formatter
- Slither: static code analyzer
Contracts can be verified using the @nomiclabs/hardhat-etherscan
package.
- Set the
ETHERSCAN_API_KEY
environment variable. - Create a file to fill in the constructor arguments. Name this
args.js
.
Sample
module.exports = [
{
LINKAddress: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
monitoredFeed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419',
initialMaxPoolSize: '25000000000000000000000000',
initialMaxCommunityStakeAmount: '7000000000000000000000',
initialMaxOperatorStakeAmount: '50000000000000000000000',
minCommunityStakeAmount: '1000000000000000000',
minOperatorStakeAmount: '1000000000000000000000',
priorityPeriodThreshold: '10800',
regularPeriodThreshold: '12000',
maxAlertingRewardAmount: '3500000000000000000000',
minInitialOperatorCount: '55',
minRewardDuration: '2592000',
slashableDuration: '7776000',
delegationRateDenominator: '20',
},
];
- Verify the contract
npx hardhat verify --network $NETWORK --constructor-args args.js $STAKING_CONTRACT_ADDRESS