Back to QuickStarts

Automation Station

Use FlashLiquidity's Automation Station to manage your upkeeps.

Overview

This tutorial shows how to create, manage, fund, and batch migrate Chainlink Automation upkeeps using FlashLiquidity's Automation Station.

Objective

In this tutorial, you will deploy the AutomationStation contract and register it as an upkeep. This main station upkeep monitors the balances for all your other upkeeps and funds them when the balances are too low. The repository includes Hardhat tasks to help you run each AutomationStation function from the command line.

Before you begin

Before you start this tutorial, complete the following items:

Steps to implement

1 Install the dependencies

Clone the source and install the required packages:

  1. Install Foundry, or update it to the latest version by running foundryup -v in your terminal.

  2. Clone the flashliquidity-automation repository:

    git clone https://github.com/flashliquidity/flashliquidity-automation.git && \
    cd flashliquidity-automation
    
  3. Install the dependencies:

    yarn setup
    
  4. Copy the .env.example file to .env at the root of the directory:

    cp .env.example .env
    
  5. In the .env file, set your private key and the RPC URL for the network you're using.

2 Deploy the AutomationStation contract

Deploy the AutomationStation contract to an Automation-supported network by setting parameters within a deployment script and then running the deployment script.

  1. Navigate to the deploy/deployStation.ts file to find the deployment script.

  2. Edit the deployment script, filling in the required parameters for the AutomationStation constructor. Make sure to format each value as a string.

    At a minimum, you need to fill in these two parameters:

    • linkToken: The address of the ERC-677 compatible LINK token. For this example, you can use the address for Sepolia (0x779877A7B0D9E8603169DdbD7836e478b4624789) or see all the LINK token addresses for other networks. Note: If you're using bridged LINK for certain networks, the LINK may not be ERC-677 compatible. Use the Chainlink Pegswap service to convert Chainlink tokens to be ERC-677 compatible before funding the station.
    • registrar: The address of the Chainlink Automation registrar for the selected network. For Sepolia, the registrar address is 0xb0E49c5D0d05cbc241d68c05BC5BA1d1B7B72976.

    The following parameters have default values in the script. Check that the settings related to refueling upkeeps and minimum balances make sense for your usage, and update them if necessary:

    • registerUpkeepSelector: The Chainlink Automation Registrar 4-byte function selector of registerUpkeep, which stays the same across different networks. Leave this at its default value: 0x3f678e11.
    • refuelAmount: The amount of LINK tokens that the AutomationStation adds to an underfunded upkeep's balance. (Default value: 1000000000000000000 or 1 LINK)
    • stationUpkeepMinBalance: The minimum balance of LINK tokens for the main station upkeep. If the balance falls below this threshold, the main station upkeep is considered underfunded. (Default value: 1000000000000000000 or 1 LINK)
    • minDelayNextRefuel: The minimum delay time in seconds between consecutive refuels of the same upkeep (main station upkeep excluded). (Default value: 600 or 10 minutes)
    • approveAmountLINK: The initial allowance of LINK tokens to the Chainlink Automation Registrar. (Default value: 100000000000000000000 or 100 LINK)
  3. Save your changes to the deploy/deployStation.ts file.

  4. Run the deployment script:

    npx hardhat deploy --network sepolia
    

You can view the supported networks for the deployment scripts inside the Hardhat configuration file (hardhat.config.ts) and add any required network if it is missing.

After you've run the deployment script successfully, the output shows the address of your AutomationStation contract:

Compiled 15 Solidity files successfully (evm target: paris).
deploying "AutomationStation" (tx: 0x16fa37c6bdba69ccd8ab585e89d8b5e99045a2b5e97daa2beddc3a7c6859ba31)...: deployed at 0x084E1fc7411B95a0A5b5833495c4b73E8D7ed3F4 with 2691939 gas
3 Fund and initialize the AutomationStation

After deploying the AutomationStation contract, you need to fund the station contract before initializing it as an upkeep. During the initialization process, the main station upkeep is registered. This upkeep monitors all your other registered upkeeps to ensure they are not underfunded; if they are, it adds funds to their balance.

  1. Send LINK to the contract address for your deployed AutomationStation. To test this example, you can fund your AutomationStation contract initially with 10 LINK. Get testnet LINK if needed, and see how to fund your contract in MetaMask.

  2. When you run the initialize task, it registers your deployed AutomationStation contract as an upkeep on Chainlink Automation. You can pass in the following optional parameters:

    • registry: The address of the Chainlink Automation Registry for the selected network. If you set this parameter now, the station's Automation forwarder will be automatically set during initialization. Otherwise, you must set the forwarder before registering other upkeeps. The registry address for Sepolia is 0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad.
    • amount: The amount of LINK tokens to fund the main station upkeep. (Default value: 10000000000000000000 or 10 LINK tokens)
    • gasLimit: The maximum gas limit that the station upkeep will use for transactions. (Default value: 750000)

    If you need to change any other default values for your station upkeep, edit registrationParams in tasks/initializeStation.ts and refer to the registration parameters. By default, the station's contract address is used intentionally for both the adminAddress and upkeepContract fields.

  3. Run the initialize task, passing in the Automation registry address for Sepolia, funding the main upkeep with 5 LINK, and setting a gas limit of 500000:

    npx hardhat initialize --registry 0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad --amount 5000000000000000000 --gas-limit 500000 --network sepolia
    

After you've run the initialization script successfully, the output shows your AutomationStation upkeep ID:

Transaction Hash: 0x3e58940174da3f1474461618ffe1246c2433e0cacd9a80d00eb75297ae7c7226
AutomationStation initialized with upkeep ID:  84877182316128104585193271963895268683397687270564021275663287366641771569317

To view your upkeep in the Chainlink Automation App, copy the ID and append it to the URL. For example: https://automation.chain.link/sepolia/84877182316128104585193271963895268683397687270564021275663287366641771569317

Note: If your wallet is connected to the Chainlink Automation App, your AutomationStation upkeep will not appear in the dashboard for the connected wallet, because the owner of the station's upkeep is the address for the deployed AutomationStation contract.

4 Register new upkeeps

After the station is initialized, you can use its registerUpkeep function to register a new Chainlink Automation upkeep. The station monitors the newly registered upkeep to ensure that the upkeep meets the minimum LINK token balance required for execution. If the balance falls below this threshold, the station uses its own LINK token balance to increase the upkeep balance until it meets the required minimum.

To register a new upkeep, run the registerUpkeep Hardhat task.

  1. You can pass the following arguments to set the registration parameters for your new upkeep:

    Basic configurations

    • name: The name of the upkeep displayed in the Chainlink Automation App
    • contract: The address of your Automation-compatible contract. If you don't have a deployed Automation-compatible contract on Sepolia, you can use this verified contract: 0x00b68EBB9a12C5bc21ef8E937a3D6E4E963d028D. (View the source code here.)
    • gasLimit: The maximum gas limit that the station upkeep will use for transactions
    • amount: The LINK token amount to fund the upkeep. (Default value: 5000000000000000000 or 5 LINK)
      • The station's LINK token balance must be greater than or equal to the amount you set in the amount parameter.
      • The allowance of LINK tokens to the Chainlink Automation Registrar must also be greater than or equal to the amount.

    Advanced configurations

    • checkData: Used to specify static data to pass to your checkUpkeep or checkLog functions in order to execute different code paths. (Default value: 0x)
    • triggerType: Used to indicate whether an upkeep is a log trigger upkeep. 0 is Conditional upkeep, 1 is Log trigger upkeep. (Default value: 0)
    • triggerConfig: The configuration for your log trigger upkeep. Leave this at 0x for conditional upkeeps. (Default value: 0x)
    • offchainConfig: Used to set an optional gas price threshold for your upkeep. Leave this at 0x otherwise. (Default value: 0x)

    The default adminAddress is the station's contract address so that the station has permission to manage your new upkeep.

  2. Fill in the contract address for your upkeep and run the upkeep registration task:

    npx hardhat registerUpkeep --name test --contract 0x00b68ebb9a12c5bc21ef8e937a3d6e4e963d028d --gas-limit 1000000 --network sepolia
    

After you've run the upkeep registration script successfully, the output shows your newly registered upkeep ID:

Transaction Hash: 0x56281ea33f37875216e5bd2b473271759945e2b3ec87b7ef2fc7a4899a5e5e10
New upkeep ID:  64045242553038992080465745424964370653102938021228808437683191013349716918956
5 Add existing upkeeps for balance monitoring

Use the addUpkeeps task to add a list of existing upkeeps for your AutomationStation to monitor. This function does not directly modify any of your upkeeps in Chainlink Automation; instead, it adds upkeep IDs to the AutomationStation's s_upkeepIds watchlist, which is then used for balance monitoring.

  1. Prepare the list of upkeep IDs for all the upkeeps that you want to add to the station's watchlist.

  2. Run the task:

    npx hardhat addUpkeeps --network sepolia <upkeepID1> <upkeepID2> <upkeepID3> ... <upkeepID_N>
    

This script outputs a transaction hash:

Transaction Hash: 0x8e8841d6a8dbb0909965e9bd5599308c5120632345211110ef2cc196428a1a14

You can verify that your upkeep IDs were added by checking the value of s_upkeepIds, or by viewing your deployed station contract in the block explorer to confirm that the addUpkeeps function ran successfully.

6 Manage batches of upkeeps

Unlike the addUpkeeps function, which simply updates the AutomationStation's internal list of upkeeps for balance monitoring, these functions modify batches of upkeeps on Chainlink Automation:

  • pauseUpkeeps - Pauses a specified list of upkeeps
  • unpauseUpkeeps - Unpauses a specified list of upkeeps
  • withdrawUpkeeps - Withdraws LINK from a specified list of canceled upkeeps
  • migrateUpkeeps - Migrates a specified list of upkeeps to a newer registry

To use these functions:

  1. Prepare the list of upkeep IDs for all the upkeeps that you want to manage.

  2. Run the corresponding Hardhat task for the batch function you want to execute on your list of upkeeps. For example, to run pauseUpkeeps.ts:

    npx hardhat pauseUpkeeps --network sepolia <upkeepID1> <upkeepID2> <upkeepID3> ... <upkeepID_N>
    

The script outputs a transaction hash:

Transaction Hash: 0x1504119fd7ac19a87aad8a2100145b3bc95cc57a0f56855e28ccdb2984c9e6ab

You can verify that your upkeeps were updated by checking them in the Chainlink Automation App, or by viewing your deployed station contract in the block explorer to confirm that the function ran successfully.

7 Dismantle the Automation Station
  1. Remove upkeeps that the Automation Station upkeep is monitoring by using the removeUpkeep function. This function removes one upkeep at a time from the station's watchlist. Use the index of the upkeep within the station's watchlist:

    npx hardhat removeUpkeep --index 1 --network sepolia
    

    Alternatively, you can run the unregisterUpkeep task to remove individual upkeeps from the station's watchlist and cancel them in Chainlink Automation:

    npx hardhat unregisterUpkeep --index 1 --network sepolia 
    
  2. After all upkeeps are removed from the station's watchlist, you can dismantle the station by calling the dismantle function:

    npx hardhat dismantle --network sepolia
    

Get the latest Chainlink content straight to your inbox.