Skip to content

Chainlink Keepers contracts for automating MakerDAO cron jobs

Notifications You must be signed in to change notification settings

brianmcmichael/chainlink-makerdao-keepers

 
 

Repository files navigation

Chainlink Keepers Contracts for MakerDAO

Chainlink Keepers implementation for MIP63: Maker Keeper Network.

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

Main Contracts

  • DssCronKeeper.sol
    • Executes pending jobs from MakerDAO Sequencer
    • Triggers upkeep refunding when needed by calling the topup contract
    • Chainlink Keepers Compatible
  • DssVestTopUp.sol
    • Checks whether upkeep refund is viable
    • Refunds upkeep by
      • Withdrawing accrued tokens from MakerDAO Vest
      • Using transferred tokens in case of emergency
      • Swapping tokens for LINK

Architecture Overview

graph TD
 A(Chainlink Keepers Network) -->|calls upkeeps| B(KeeperRegistry)
 B -->|check and perform| C(DssCronKeeper)
 C -->|trigger refund| D(DssVestTopUp)
 C -->|run jobs| E(DssCron)
 D -->|withdraw tokens| F(DssVest)
 D -->|return excess tokens| G(DaiJoin)
 D -->|check balance / add funds| B
 D -->|swap tokens for LINK| H(Uniswap)
Loading

Setup

Clone the repo and install all dependencies:

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

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 related
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. Production environment
Name Description
SEQUENCER Address of Sequencer
NETWORK_NAME Short name from the Sequencer network registry
DSS_VEST Address of DssVest
DAI_JOIN Address of DaiJoin
VOW Address of Vow
PAYMENT_TOKEN Address of ERC-20 token used for payment in DssVest, like DAI
KEEPER_REGISTRY Address of KeeperRegistry
SWAP_ROUTER Address of Uniswap V3 Router
LINK_TOKEN Address of ERC-20 token used for payment in KeeperRegistry
PAYMENT_USD_PRICE_FEED Chainlink price feed for the DAI / USD pair or the associated PAYMENT_TOKEN and USD
LINK_USD_PRICE_FEED Chainlink price feed for the LINK / USD pair
MIN_WITHDRAW_AMOUNT Minimum amount of PAYMENT_TOKOEN required to trigger top up
MAX_DEPOSIT_AMOUNT Maximum amount of PAYMENT_TOKOEN allowed to fund an upkeep. The excess amount is returned to the Surplus Buffer.
BALANCE_THRESHOLD Upkeep LINK balance threshold
  1. Staging environment
Name Description
STAGING_SWAP_ROUTER Address of Uniswap V3 Router on testnet
STAGING_LINK_TOKEN Address of ERC-20 token like LINK on testnet
STAGING_PAYMENT_USD_PRICE_FEED Chainlink price feed for the DAI / USD pair on testnet
STAGING_LINK_USD_PRICE_FEED Chainlink price feed for the LINK / USD pair on testnet
STAGING_UNISWAP_V3_FACTORY Uniswap V3 Factory address
NONFUNGIBLE_POSITION_MANAGER NonFungible Position Manager

Note: All example values are the actual values for Ethereum Mainnet and the staging ones for Goerli testnet.

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>
  1. Then deploy DssVestTopUp.sol:
npx hardhat run scripts/deploy_topup.ts --network <network>
  • The deployed contract must be initialized with vestId and upkeepId by calling the respective setter functions
    • To acquire vestId, a new application must be submitted to MakerDAO
    • The upkeepId is available after registering a new Upkeep
  1. Finally, to enable auto refunding of the DssCronKeeper upkeep, call setUpkeepRefunder(address) and pass the address of the deployed DssVestTopUp

Note: all setter functions must be called from the contract owner account, which is the deployer account if not changed afterwards.

References

About

Chainlink Keepers contracts for automating MakerDAO cron jobs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 66.9%
  • Solidity 30.0%
  • Shell 2.1%
  • JavaScript 1.0%