This repository contains the scripts designed to automate the Velodrome ecosystem using Chainlink oracles.
- GaugeUpkeepManager: This contract is responsible for registering and deregistering scheduled distribute call upkeeps for a gauge. It is registered as an upkeep itself with the following triggers:
- Log triggers (from the
Votercontract)GaugeCreated: Registers a new gauge in the upkeep manager when it is created.GaugeKilled: Deregisters an existing gauge from the upkeep manager when it is killed.GaugeRevived: Registers a gauge in the upkeep manager when it is revived.
- Log triggers (from the
- GaugeUpkeep: This contract is the actual upkeep that calls the
distributefunction on gauges. It iterates over a range of gauge IDs and is triggered on an interval.
- TokenUpkeepManager: This contract is responsible for managing a whitelist of tokens and their corresponding upkeeps. It registers and deregisters upkeeps for token price updates. It is registered as an upkeep itself with the following trigger:
- Log trigger (from the
Votercontract)WhitelistToken: Registers or deregisters a token in the upkeep manager when it is whitelisted or removed from the whitelist.
- Log trigger (from the
- TokenUpkeep: This contract is the actual upkeep that calls the
fetchPricesfunction on tokens. It iterates over a range of token IDs and is triggered on an interval.
- UpkeepBalanceMonitor: This is a utility contract that watches the balances of all active gauge upkeeps and triggers top-up transactions when the balance falls below a certain threshold.
A demo of the environment setup, deployment process, and consuming the outputted data via events, is available here.
This repository uses Hardhat as the development environment.
- Install the dependencies:
pnpm install- Install submodules:
git submodule update --init --recursiveCopy the example configuration and fill in the required environment variables:
cp .env.example .envTests are executed using Hardhat.
- Run the unit tests:
pnpm run test:unit- Run the script tests on a forked network:
pnpm run test:fork
pnpm run test:fork:v2_3- Deploy the
UpkeepBalanceMonitorcontract by running:
npx hardhat run scripts/deploy_balance_monitor.ts --network <network>- Register custom logic trigger for the deployed
UpkeepBalanceMonitorcontract and set the trusted forwarders:
npx hardhat run scripts/<version>/register_monitor_upkeep.ts --network <network>Note: Currently supported Chainlink Automation versions are v2_1 and v2_3.
Note: The account running the script must have enough LINK to pay for the initial upkeep registration funding determined by the BALANCE_MONITOR_UPKEEP_FUND_AMOUNT and BALANCE_MONITOR_UPKEEP_GAS_LIMIT environment variables.
- Transfer LINK tokens to the
UpkeepBalanceMonitorcontract which will be used to top-up the gauge upkeeps.
- Deploy and configure
GaugeUpkeepManagercontract by running:
npx hardhat run scripts/emissions/<version>/deploy_upkeep_manager.ts --network <network>- Register log trigger upkeeps for the deployed
GaugeUpkeepManagercontract and set the trusted forwarders:
npx hardhat run scripts/emissions/<version>/register_log_upkeeps.ts --network <network>Note: Make sure the account running the script has enough LINK to pay for the initial funding of each upkeep registration determined by the LOG_UPKEEP_FUND_AMOUNT and LOG_UPKEEP_GAS_LIMIT environment variables.
- Transfer LINK tokens to the
GaugeUpkeepManagercontract for new gauge upkeep registrations. The amount of LINK required is determined by theNEW_UPKEEP_FUND_AMOUNTenvironment variable.
- Deploy and configure
TokenUpkeepManagercontract by running:
npx hardhat run scripts/prices/deploy_upkeep_manager.ts --network <network>- Register log trigger upkeep for the deployed
TokenUpkeepManagercontract and set the trusted forwarder:
npx hardhat run scripts/prices/register_log_upkeep.ts --network <network>Note: Make sure the account running the script has enough LINK to pay for the initial upkeep registration determined by the LOG_UPKEEP_FUND_AMOUNT and LOG_UPKEEP_GAS_LIMIT environment variables.
-
Transfer LINK tokens to the
TokenUpkeepManagercontract for new token upkeep registrations. The amount of LINK required is determined by theNEW_UPKEEP_FUND_AMOUNTenvironment variable. -
Register tokens in the
TokenUpkeepManagercontract by running:
npx hardhat run scripts/prices/register_tokens.ts --network <network>Note: The script reads the token addresses stored in logs/tokens.json file.
- Add
TokenUpkeepManageras a keeper to thePricescontract, so it can call thestorePricefunction. This is done by calling theaddKeeperfunction on thePricescontract with the address of theTokenUpkeepManagercontract as an argument.