hackbg / chainlink-makerdao-automation

Chainlink Automation contracts for MakerDAO cron jobs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 git@github.com: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

About

Chainlink Automation contracts for MakerDAO cron jobs


Languages

Language:TypeScript 69.5%Language:Solidity 29.4%Language:JavaScript 1.2%