Skip to content

0x2me/vaults

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contracts for Vaults & Strategies

Prerequisites

  • Nodejs LTS (v14). It is recommended to use nvm to support multiple versions of nodejs locally.
  • Solidity compiler v0.8.9
  • It uses hardhat, no need to install anything, just run npm install .

Build

npx hardhat compile
npm run build

Test

Unit Tests

Run:

npm run test/unit

Integration Tests

Prerequisites:

  • ALCHEMY_API_KEY env configured in the .env file or exported before executing the integration tests

Run:

npm run test/integration

Print contracts logs

To print the contract logs to the console during the test execution you have to add the --logs flag like this:

npm run test/unit -- --logs

or using the hardhat cli directly:

npx hardhat test --logs

Run Tests in VSCode

To run the tests in VSCode, install the Mocha Test Explorer extension, and then update this VSCode option mochaExplorer.files to test/**/*.{j,t}s.

Static Analysis

Static analysis is used to test contracts for possible issues and optimizations. This should be done in development and as part of PR review process.

Slither

crytic/slither the Solidity source analyzer You will need to install it locally:

pip3 install slither-analyzer

If you dont have solidity installed locally - i.e. solc command is throwing command not found then you will need to install it with the following:

brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity

Testing

Run slither on all contracts: slither .

Run slither on a single file: slither contracts/vaults/BaseVault.sol --solc-remaps @openzeppelin=/$(pwd)/node_modules/@openzeppelin

You can use Slither printers to quickly report crucial contract information. crytic/slither#printers e.g.

❯ slither contracts/vaults/BaseVault.sol --solc-remaps @openzeppelin=/$(pwd)/node_modules/@openzeppelin --print human-summary

Compiled with solc
Number of lines: 2987 (+ 0 in dependencies, + 0 in tests)
Number of assembly lines: 0
Number of contracts: 27 (+ 0 in dependencies, + 0 tests)

Number of optimization issues: 16
Number of informational issues: 142
Number of low issues: 16
Number of medium issues: 2
Number of high issues: 0

ERCs: ERC20

+------------------------+-------------+-------+--------------------+--------------+--------------------+
|          Name          | # functions |  ERCS |     ERC20 info     | Complex code |      Features      |
+------------------------+-------------+-------+--------------------+--------------+--------------------+
|        Ownable         |      7      |       |                    |      No      |                    |
|        Pausable        |      6      |       |                    |      No      |                    |
|       SafeERC20        |      6      |       |                    |      No      |      Send ETH      |
|                        |             |       |                    |              | Tokens interaction |
|        Address         |      11     |       |                    |      No      |      Send ETH      |
|                        |             |       |                    |              |    Delegatecall    |
|                        |             |       |                    |              |      Assembly      |
|        Counters        |      4      |       |                    |      No      |                    |
|         ECDSA          |      9      |       |                    |      No      |     Ecrecover      |
|                        |             |       |                    |              |      Assembly      |
|        SafeMath        |      13     |       |                    |      No      |                    |
|     EnumerableSet      |      24     |       |                    |      No      |      Assembly      |
|  AccessControlManager  |      5      |       |                    |      No      |                    |
| AllowlistAccessControl |      9      |       |                    |      No      |                    |
|       IStrategy        |      22     |       |                    |      No      |                    |
|       BaseVault        |     113     | ERC20 |     No Minting     |     Yes      | Tokens interaction |
|                        |             |       | Approve Race Cond. |              |                    |
|                        |             |       |                    |              |                    |
+------------------------+-------------+-------+--------------------+--------------+--------------------+
contracts/vaults/BaseVault.sol analyzed (27 contracts)

Deploy

Before you can deploy you need to have a populated .env file in the root of this project using .env.example as an example.

Local Mainnet Fork

Prerequisites:

Start a fork of the mainnet locally with hardhat:

The default forked block is configured in the hardhat.config.ts config file and can be manually changed by setting the FORK_BLOCK_NUMBER env.

Learn more about Mainnet forking here: https://hardhat.org/hardhat-network/guides/mainnet-forking.html

npm run start-fork

In a new terminal window/tab copy the network configuration files:

If you don't copy the mainnet-production.json file all contracts will be deployed as new contracts and not as upgrades of the existing ones in the fork network.

cp ./deployments/mainnet-production.json ./deployments/dev.json
cp ./.openzeppelin/mainnet.json ./.openzeppelin/unknown-31337.json

Deploy the contracts:

The deploy-by-config.ts script with the --deploy true flag will deploy all contracts with the configuration specified from the ./deployment-config/mainnet-production.yaml config file to the localhost forked network and will use the ./deployments/dev.json file to determinate contract by contract if it has to be deployed, or it is already up-to-date and will then update the ./deployments/dev.json file to match the new status of the contracts.

HARDHAT_NETWORK=localhost ./node_modules/.bin/ts-node --files ./scripts/deploy-by-config.ts --config ./deployment-config/mainnet-production.yaml --deploy true --update false --dryrun false --env dev

Update the contracts configuration:

Part of the configuration defined in the mainnet-production.yaml config file is set in this step and can be changed by executing this step again

HARDHAT_NETWORK=localhost ./node_modules/.bin/ts-node --files ./scripts/deploy-by-config.ts --config ./deployment-config/mainnet-production.yaml --deploy false --update true --dryrun false --env dev

The fork network is now ready to be tested.

Reset Local Mainnet Fork

npm run reset-fork

Get ETH, DAI, USDC, YOP, ... tokens

To be able to test deposit, withdraw, boost and staking you need funds in different tokens. And because you may not have an account in the mainnet with a lot of funds you can add them to the forked mainnet with the npm run populate-fork command.

To start you need to set the DEVELOPMENT_WALLET env to your development account address which will receive the funds.

Then run the following cmd to add ETH, DAI, USDC, YOP, ... to your development account.

npm run populate-fork

Note: Tokens are not minted but tranfered from existing accounts defined in accounts.ts file, therfore depending on status of the mainnet and the forked block number one or more accounts may not have the required funds and the populate-fork cmd could fail.

Deploy To Mainnet Fork

See deployment by config.

More Coming Soon

Upgrade

See upgrade instructions.

Other available commands

npx hardhat accounts
npx hardhat clean
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
npx hardhat run scripts/deploy-all.ts
npx hardhat size-contracts
TS_NODE_FILES=true npx ts-node scripts/deploy-all.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix

For more information, please checkout Hardhat docs.

Environment Variables

Many cmds can be tweaked using environment variables, they can be set in the .env file in the project root, and for starting you can the .env.example file.

cp .env.example .env
Name Description Default Value
ALCHEMY_API_KEY The Alchemy API key is personal and can be optained by creating an account at https://alchemyapi.io
FORK_BLOCK_NUMBER The block number from which the mainnet will be forked. Check https://etherscan.io to pick your preferred block number.
DEVELOPMENT_WALLET The public address of your development account/wallet.

Deployed Contract Addresses

Rinkeby Testnet

Mocks

Access Control

Rewards

Staking

Vaults

About

No description, website, or topics provided.

Resources

Stars

Watchers