---
name: thyme-migrate-chainlink
description: Move Chainlink Automation upkeeps (custom logic, time-based and log trigger) to Thyme Flow. Use when a repository has contracts implementing `checkUpkeep`/`performUpkeep`, `AutomationCompatibleInterface`, `KeeperCompatibleInterface`, `ILogAutomation` or `CronUpkeep`, scripts that register upkeeps, or when the user asks to replace Chainlink Automation or Keepers. Covers finding the upkeeps, writing a Flow task that calls them, testing locally and handing over to the thyme-flow skill for upload and scheduling.
---

# Migrate Chainlink Automation to Thyme Flow

Chainlink deprecated Automation v1.x on June 30, 2026 and v2.1 on July 31,
2026. Upkeeps on those registries are no longer performed. Thyme Flow can call
the same contracts: a TypeScript task reads `checkUpkeep` on every run and
returns a `performUpkeep` call when it says so. Flow sends that call from a
Safe the user owns, through a role limited to the contracts and functions they
allow. The contract usually does not change.

This skill covers the translation. For the `thyme` CLI itself (deployment,
login, upload, executables, profiles, secrets) read the **thyme-flow** skill:
`https://flow.thymelabs.io/docs/skills/thyme-flow/SKILL.md`. Its rules apply
here too: never print credentials, a person approves logins and signs profile
changes, and ask before anything that sends transactions.

## 1. Inventory before you change anything

```bash
grep -rln --include='*.sol' -e 'checkUpkeep' -e 'AutomationCompatible' -e 'KeeperCompatible' -e 'ILogAutomation' -e 'CronUpkeep' .
grep -rn --include='*.sol' -e 'forwarder' -e 'Forwarder' -e 'cannotExecute' -e 'StreamsLookup' -e 'checkCallback' .
grep -rn --exclude-dir=node_modules -e 'registerUpkeep' -e 'AutomationRegistrar' -e 'checkData' .
```

For each upkeep, list:

| Item | Where to find it |
|---|---|
| Upkeep contract | The deployed address, from deployment files or the user. |
| Type | Custom logic (`checkUpkeep`), time-based (cron job spec) or log trigger (`checkLog`). |
| `checkData` | Registration scripts, or ask the user. Often `0x`. |
| Chain | The network the upkeep was registered on. |
| Check frequency needed | How quickly the upkeep must react. Automation checked every block. |
| Sender checks | Whether `performUpkeep` requires the Automation forwarder or registry as `msg.sender`. |

Tell the user the plan before porting: which upkeeps port directly, which need
a decision (see section 5), and which one you will move first.

## 2. Custom logic upkeeps

One task works for any contract with the Automation interface:

```ts
import { defineTask, z } from '@thyme-labs/sdk'
import { encodeFunctionData, parseAbi, type Hex } from 'viem'

const abi = parseAbi([
  'function checkUpkeep(bytes) view returns (bool, bytes)',
  'function performUpkeep(bytes)',
])

export default defineTask({
  schema: z.object({
    upkeep: z.address(),
    checkData: z.string().regex(/^0x([0-9a-fA-F]{2})*$/).default('0x'),
  }),
  async run(ctx) {
    const [upkeepNeeded, performData] = await ctx.client.readContract({
      address: ctx.args.upkeep,
      abi,
      functionName: 'checkUpkeep',
      args: [ctx.args.checkData as Hex],
    })
    if (!upkeepNeeded) {
      return { canExec: false, message: 'checkUpkeep returned false' }
    }
    return {
      canExec: true,
      calls: [{
        to: ctx.args.upkeep,
        data: encodeFunctionData({ abi, functionName: 'performUpkeep', args: [performData] }),
      }],
    }
  },
})
```

```json
{ "calls": [{ "target": { "arg": "upkeep" }, "function": "performUpkeep(bytes)" }] }
```

- Declare `checkUpkeep` as `view` in the ABI even when the contract does not.
  `readContract` is an `eth_call`, so state changes in the check are discarded.
- Do not pass `account` to `readContract`. With no sender, the call's origin
  is the zero address, which the `cannotExecute` modifier requires.
- `performUpkeep` should re-check its condition, as Chainlink recommends.
  Flow may run the check and the transaction a few seconds apart.
- To serve several upkeeps from one project, use one executable per upkeep
  with different args.

## 3. Time-based and log trigger upkeeps

**Time-based (cron) upkeeps** called a target function on a schedule through a
`CronUpkeep` contract. Skip the intermediate contract: create a task that
returns the target call directly, with a cron trigger
`{ "type": "cron", "cronspec": "<expression>" }`. Add a guard in the task (for
example, a last-run timestamp read from the target) if a double run would hurt.

**Log trigger upkeeps** (`checkLog(Log, bytes)`) have no direct trigger in
Flow. Use an interval trigger:

1. Keep the last processed block in `ctx.storage` (as a decimal string).
2. Fetch the matching logs with `ctx.client.getLogs` from the cursor to the
   current block, capped to a small range per run.
3. For each log, build the `Log` struct the contract expects (`index`,
   `timestamp`, `txHash`, `blockNumber`, `blockHash`, `source`, `topics`,
   `data`), call `checkLog` with `readContract`, and collect the
   `performUpkeep` calls it asks for.
4. Return at most a few calls per run. A Roles profile sends them as one
   atomic batch, so one revert undoes them all.
5. Advance the cursor in `onSuccess`, and when nothing matched, before
   returning `canExec: false`.

Keep each run bounded: a cloud run has about 30 seconds.

## 4. Test and ship

1. Put the upkeep address and `checkData` in `args.json`, set `RPC_URL` and
   `SIMULATE_ACCOUNT` in `.env`, and run `thyme run <name>`, then
   `thyme run <name> --simulate`. Use the user's Safe address as
   `SIMULATE_ACCOUNT` when `performUpkeep` checks the sender.
2. Hand over to thyme-flow for login, `thyme upload`, the profile and the
   executable. The user must allow `performUpkeep(bytes)` on the upkeep
   contract in their Safe profile in the Console; tell them the address.
3. Choose an interval that matches how quickly the upkeep must react (30
   seconds to one day), or a cron expression. Run
   `thyme executables simulate` before asking the user whether to resume or
   run it for real.
4. Once Flow runs cleanly, the user can cancel the old upkeep and withdraw any
   remaining LINK in the Chainlink Automation app, if their registry still
   allows it.

## 5. Things that need the user's decision

Stop and explain these instead of guessing:

- **Sender checks.** If `performUpkeep` only accepts the Automation forwarder
  or registry, the Safe's calls revert. The owner must allow the Safe address,
  through an existing setter or a contract upgrade.
- **Data Streams lookups.** `checkUpkeep` that reverts with `StreamsLookup` and
  expects `checkCallback` relies on Chainlink Data Streams. Flow cannot answer
  that lookup. The task can fetch the data itself only if the user has another
  source.
- **Consensus requirements.** Flow is a hosted keeper, not a decentralized
  network. If the protocol needs decentralized execution or consensus on
  results, Chainlink's replacement, CRE, is the better fit. Say so.
- **Unsupported chains.** Run `thyme chains list` to see what the deployment
  enables, and tell the user if their chain is missing.

## 6. Report back

For every upkeep, tell the user: the task and args you used, the trigger and
interval, the `permissions.json` entry, the local run result, and what they
must still do (approve login, allow `performUpkeep` on the Safe profile, update
sender allowlists, top up dBank credit for mainnet gas, cancel the old upkeep).
