/protocol

Community-led Asset Management. Powered by DeFi.

Primary LanguageSolidityMIT LicenseMIT

Babylon Finance

Community-led Asset Management. Powered by DeFi.

CI

Quick Start

Git clone

git clone https://github.com/babylon-finance/protocol.git

Install dependencies

yarn

Compile contracts

yarn compile

Development

โ›ฝ๏ธ Gas Report

yarn gas-report

๐Ÿ›ก Coverae

yarn coverage

๐Ÿค– Prettier

yarn prettier

๐Ÿ’ช Solhint

yarn lint:contracts

๐Ÿ“ Contract Size

yarn estimate-size

๐Ÿงช Test

To run unit tests

yarn test:unit

To run integartion tests

yarn test:integration

To run fast integration tests (recommended)

yarn test:integration:fast

Or watch test ๐Ÿ‘

yarn test:watch

Deploy

To deploy SCs you need to have .env file configured for the selected network, e.g., mainnet. The file should have the following entries.

  ALCHEMY_KEY=XXXXXXXX
  DEPLOYER_PRIVATE_KEY=XXXXXXXX
  OWNER_PRIVATE_KEY=XXXXXXXX
  BLOCKNATIVE_API_KEY=XXXXXXXX
  ETHERSCAN_KEY=XXXXXXXX
  DEFENDER_API_KEY=XXXXXXXX
  DEFENDER_API_SECRET=XXXXXXXX

For non-upgradeable contracts use named scripts from the deployments/migrations/ folder, e.g., 040-univ2-trade.js would deploy UniswapV2TradeIntegration. To invoke the script use the following command.

  npx hardhat deploy --network mainnet --tags UniV2Trade

tags value can be found inside a deployment script.

To deploy a new implementation for an upgradeable contract use deploy-contract.js script, e.g., to deploy a new implementation for the Strategy contract use the following command:

  npx hardhat deploy-contract --contract StrategyV16 --network mainnet

contract is the name of the new implementation.

To auto-deploy a contract use a simple bash script which will try until it succeeds.

  while ! npx hardhat deploy-contract --contract StrategyV16 --network mainnet; do echo 'Trying to deploy
  again ๐Ÿค–'; done; echo 'Deployed ๐Ÿš€';

deploy-contract command supports passing arguments to the contract constructor. You can use deployments names instead of the addresses. This feature requires using the dx{contractName} notation, e.g.:

  npx hardhat deploy-contract --contract BabylonViewer --network mainnet dxBabControllerProxy
  npx hardhat deploy-contract --contract AddLiquidityOperation --network mainnet lp dxBabControllerProxy

Upgrade

To upgrade Babylon Protocol use upgrade-multisig.js script. It will create a batch tx for Gnosis Multisig to upgrade all the proxies in the protocol. The command bellow upgrades BabController, RewardsDistributor, Strategy, and Garden to the appropriate implementations. The implementations have to be deployed beforehand using deploy-contrat script.

  npx hardhat upgrade-multisig --network mainnet --controller BabControllerV11 --distributor RewardsDistributorV11 --strategy StrategyV14 --garden GardenV15

All the arguments are optional meaning only required proxies should be upgraded.

The list of options for upgrade is the following:

  • controller
  • distributor
  • garden
  • assistant
  • strategy
  • curve
  • oracle
  • buy
  • liquidity
  • deposit
  • lend
  • tradeCurve
  • tradeUniV3
  • tradeSynth
  • tradeUniV2

An example of the command:

npx hardhat upgrade-multisig --network mainnet --curve CurveMetaRegistry --oracle PriceOracle --trade-curve CurveTradeIntegration --liquidity AddLiquidityOperation

This script will create a proposal at Defender Admin. It has to be signed and executed to upgrade the protocol.

scripts

Fuse

npx hardhat fuse --network mainnet

Gets Fuse positions stats of Heart and Heart garden.

AAVE

npx hardhat aave 0x371b23eedb1a5e3822aacff906187111a91fae88 --network mainnet

Gets Aave positions stats of provided accounts. Many accounts can be provided at once.