Skip to content

Earn rewards for helping secure the Chainlink Network. Chainlink Staking is a security mechanism in which stakers commit LINK in smart contracts to back certain performance guarantees around oracle services.

License

Notifications You must be signed in to change notification settings

smartcontractkit/staking-v0.1

Repository files navigation

Chainlink Staking

Learning Resources

To learn more about Staking and the technical design, please check out the following resources:

Developer Guide

Setup

$ 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.

Compile

Make sure you have VIA_IR=true in your .env

Compile the smart contracts with Hardhat:

$ pnpm compile

TypeChain

Compile the smart contracts and generate TypeChain artifacts:

$ pnpm typechain

Lint Solidity

Lint the Solidity code with Solhint:

$ pnpm lint:sol

Lint TypeScript

Lint the TypeScript code:

$ pnpm lint:ts

Format files

$ pnpm format

Test

Run unit tests:

$ pnpm test

Run a single test:

$ pnpm test test/MyContract.test.ts

Coverage

Note: coverage must be run with VIA_IR=false

Generate a test coverage report:

$ pnpm coverage

Unit test coverage is at 100%.

Clean

Delete the smart contract artifacts, the coverage reports and the Hardhat cache:

$ pnpm clean

Slither static analysis

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.*()) in Staking.sol before running Slither.

On older Slither versions you will need to replace all library errors (revert RewardLib.*(), revert StakingPoolLib.*()) with plain revert() 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

Foundry fuzz and invariant tests

Make sure you have foundry / forge installed.

We use foundry for fuzz and invariant testing.

forge test

Gas snapshot

You can find a .gas-snapshot file for several key flows. You may find it helpful during gas golfing.

forge snapshot

Tooling

  • 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

Verification

Contracts can be verified using the @nomiclabs/hardhat-etherscan package.

  1. Set the ETHERSCAN_API_KEY environment variable.
  2. 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',
  },
];
  1. Verify the contract
npx hardhat verify --network $NETWORK --constructor-args args.js $STAKING_CONTRACT_ADDRESS

About

Earn rewards for helping secure the Chainlink Network. Chainlink Staking is a security mechanism in which stakers commit LINK in smart contracts to back certain performance guarantees around oracle services.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published