Code Monkey home page Code Monkey logo

chainlink-makerdao-automation's Introduction

Chainlink Automation Contracts for MakerDAO

MIP63: Maker Keeper Network implementation for the Chainlink Automation Network.

Maintains Maker protocol by poking oracles, liquidating vaults, managing the autoline, managing D3Ms, etc.

Main Contracts

  • DssCronKeeper.sol
    • Executes pending jobs from the Sequencer
    • Triggers upkeep refunding when needed by calling DssVestTopUp
    • Registered as upkeep
  • DssVestTopUp.sol
    • Withdraws accumulated DAI from the Vest
    • Swaps DAI for LINK via Uniswap
    • Transfers swapped LINK to the upkeep balance

Architecture Overview

graph TD
 A(Chainlink Automation Network) -->|calls upkeep| B(KeeperRegistry)
 B -->|checks and performs upkeep| C(DssCronKeeper)
 C -->|triggers refund| D(DssVestTopUp)
 C -->|runs jobs| E(DssCron)
 D -->|withdraws DAI| F(NetworkPaymentAdapter)
 D -->|checks upkeep balance / add funds| B
 D -->|swaps DAI for LINK| H(Uniswap Router)
 D -->|checks price for swap|I(Chainlink Price Feeds)

Setup

Clone the repo and install all dependencies.

git clone [email protected]:hackbg/chainlink-makerdao-automation.git
cd chainlink-makerdao-automation

git submodule init
git submodule update

npm install

Configuration

Copy the .env.example to .env file and make sure you've set all of the following.

  1. Hardhat development environment
Name Description
RPC_URL URL of a node
PRIVATE_KEY Controls which account Hardhat uses
ETHERSCAN_API_KEY Required to verify contract code on Etherscan
  1. DssCronKeeper contract
Name Description
SEQUENCER Address of Sequencer
NETWORK_NAME Short name from the Sequencer network registry
  1. DssVestTopUp contract
Name Description
UPKEEP_ID Unique identifier of the registered upkeep for DssCronKeeper
KEEPER_REGISTRY_V2_1 Address of KeeperRegistry V2.1
DAI_TOKEN Address of DAI token
LINK_TOKEN Address of LINK token
NETWORK_PAYMENT_ADAPTER Address of NetworkPaymentAdapter for the keeper network
DAI_USD_PRICE_FEED Chainlink price feed for the DAI / USD pair
LINK_USD_PRICE_FEED Chainlink price feed for the LINK / USD pair
SWAP_ROUTER_V3 Address of Uniswap V3 Router
SLIPPAGE_TOLERANCE_BPS Price slippage tolerance in basis points. Learn more here.
UNISWAP_PATH Uniswap V3 path for swapping DAI for LINK. Example: DAI, 500, WETH, 3000, LINK. Learn more here.
  1. End-to-end test environment (optional)
Name Description
AUTOMATION_REGISTRAR_V2_1 Address of Automation Registrar V2.1 contract
EOA_WITH_LINK Address of the Externally Owned Account (EOA) with at least 50 LINK balance before the block specified when running the tests on a fork.
UNISWAP_V3_FACTORY Uniswap V3 Factory address
NONFUNGIBLE_POSITION_MANAGER Uniswap V3 Nonfungible Position Manager address
VOW Address of Vow

Note: Example contract addresses are for Ethereum mainnet.

Test

Run unit tests on the local Hardhat network.

npm test

For end-to-end testing.

npm run test:e2e

Deploy

  1. Run the following to deploy DssVestCronKeeper.sol to a network configured in Hardhat config.
npx hardhat run scripts/deploy_keeper.ts --network <network>

Note: After successful deployment, the contract must be registered as new upkeep to start performing pending jobs.

  1. Then deploy DssVestTopUp.sol by running the following.
npx hardhat run scripts/deploy_topup.ts --network <network>
  1. Finally, to enable auto refunding of the DssCronKeeper upkeep, call setUpkeepRefunder(address) and pass the address of the deployed DssVestTopUp contract.

References

chainlink-makerdao-automation's People

Contributors

imollov avatar ivaylonikolov7 avatar mradkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chainlink-makerdao-automation's Issues

Add readme

Include:

  • Overview
  • Architecture diagram
  • Setup instructions

Update test for vesting accrued tokens

SwapRouterMock contract should be able to take tokens from the vest and use Vest event as we are currently relying on that vested tokens are left in the contract which shouldn't be the case.

Reuse deployments

AC:

  • use hardhat-deploy plugin
  • flows for hardhat/local, testnet/staging and mainnet/prod
  • reuse fixtures in tests

Split deploy script

Must be possible to deploy the contracts independently.

Todo:

  • Split deploy script into two separate
  • Update docs with instructions which functions need be called to link the contracts

Run E2E tests on mainnet fork

Background:

  • Currently end-to-end tests are running on a fork of Goerli testnet until the mainnet deployment of KeeperRegistry v2

Todo:

  • Switch to mainnet and drop the additional staging env variables

Automate E2E tests

AC:

  • check that jobs are executed and upkeep is getting refunded
  • run on forked mainnet
  • simulate upkeep calls via the registry

KeeperRegistry mock contract

implement functions from contract:

  • getUpkeep
  • getMinBalanceForUpkeep
  • addFunds

helper functions:

  • setBalance
  • setMinBalance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.