id: evm-contract-upgrade-watchdog
namespace: company.team
description: |
Watch the smart contracts your product depends on (stablecoins, oracles,
bridges, your own proxies) for upgrades and changes of control: a new
implementation, proxy admin, beacon, or owner. Each change is compared
with an approved baseline and reported once. On-call either approves it
as the new baseline, with a note kept in an audit log, or pauses your own
protocol through a guardian signer.
triggers:
- id: contract_event
type: io.kestra.plugin.core.trigger.Webhook
description: Point an on-chain alert (Alchemy Notify, QuickNode Streams,
Tenderly) for Upgraded, AdminChanged, BeaconUpgraded or
OwnershipTransferred events of the watched contracts at this webhook, so a
change is checked within seconds.
key: upgrade-watchdog-change-me
- id: periodic_check
type: io.kestra.plugin.core.trigger.Schedule
description: Catches every change, including ones that emit no event.
cron: "*/10 * * * *"
inputs:
- id: contracts
type: ARRAY
itemType: STRING
defaults:
- USDC=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
- Chainlink ETH/USD=0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
description: Contracts to watch, as `Label=0xaddress`. The defaults are Ethereum
mainnet contracts.
- id: remind_minutes
type: INT
defaults: 60
description: Ask again after this long while a change is still not approved.
- id: pause_target
type: STRING
required: false
description: Your contract with a `pause()` function, for the "Pause the
protocol" answer. Leave empty to disable that answer.
- id: guardian
type: STRING
required: false
description: Address allowed to call `pause()` on `pause_target`. The signer
behind EVM_SIGNER_URL signs for it.
- id: explorer_url
type: STRING
defaults: https://etherscan.io
description: Block explorer for links in Slack.
- id: kestra_url
type: STRING
defaults: http://localhost:8080
description: Base URL of your Kestra UI, used for the approval link.
variables:
# Storage slots defined by EIP-1967, and the ones older OpenZeppelin proxies (such as USDC's) use.
slots:
implementation: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
admin: "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103"
beacon: "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeeee59ff6cb3582b35133d50"
legacy_implementation: "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"
legacy_admin: "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"
# One JSON-RPC batch reading the code, the five slots and owner() of every contract.
read_batch: >-
[{"jsonrpc": "2.0", "id": "chain", "method": "eth_chainId", "params": []},
{"jsonrpc": "2.0", "id": "head", "method": "eth_blockNumber", "params":
[]}{% for c in inputs.contracts %}{% set a = c | split('=') | last | trim |
lower %}, {"jsonrpc": "2.0", "id": "code/{{ a }}", "method": "eth_getCode",
"params": ["{{ a }}", "latest"]},{% for s in vars.slots %} {"jsonrpc":
"2.0", "id": "{{ s.key }}/{{ a }}", "method": "eth_getStorageAt", "params":
["{{ a }}", "{{ s.value }}", "latest"]},{% endfor %} {"jsonrpc": "2.0",
"id": "owner/{{ a }}", "method": "eth_call", "params": [{"to": "{{ a }}",
"data": "0x8da5cb5b"}, "latest"]}{% endfor %}]
tasks:
- id: validate_contracts
type: io.kestra.plugin.core.flow.If
description: Entries must be `Label=0xaddress`; labels cannot contain commas.
condition: "{{ inputs.contracts | jq('[.[] | select(test(\"^[^=,]+=
*0x[0-9a-fA-F]{40} *$\") | not)] | length') | first > 0 }}"
then:
- id: invalid_contracts
type: io.kestra.plugin.core.execution.Fail
errorMessage: "These entries are not in the form Label=0xaddress: {{
inputs.contracts | jq('[.[] | select(test(\"^[^=,]+=
*0x[0-9a-fA-F]{40} *$\") | not)] | join(\", \")') | first }}"
- id: read_contracts
type: io.kestra.plugin.core.http.Request
uri: "{{ secret('EVM_RPC_URL') }}"
method: POST
contentType: application/json
body: "{{ render(vars.read_batch) }}"
retry:
type: exponential
interval: PT2S
maxInterval: PT30S
maxAttempts: 3
- id: ensure_tables
type: io.kestra.plugin.jdbc.postgresql.Queries
url: "{{ secret('POSTGRES_URL') }}"
username: "{{ secret('POSTGRES_USER') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
sql: |
CREATE TABLE IF NOT EXISTS contract_watch (
chain_id BIGINT NOT NULL,
address TEXT NOT NULL,
label TEXT NOT NULL,
approved JSONB NOT NULL,
observed JSONB NOT NULL,
changed_at TIMESTAMPTZ,
asked_at TIMESTAMPTZ,
approved_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (chain_id, address)
);
CREATE TABLE IF NOT EXISTS contract_watch_log (
id BIGSERIAL PRIMARY KEY,
at TIMESTAMPTZ NOT NULL DEFAULT now(),
chain_id BIGINT NOT NULL,
address TEXT NOT NULL,
label TEXT NOT NULL,
event TEXT NOT NULL,
before_state JSONB,
after_state JSONB,
note TEXT,
execution_id TEXT
);
- id: resolve
type: io.kestra.plugin.jdbc.postgresql.Query
description: Decode the batch into one row per contract, find what kind of proxy
it is, and prepare the second batch (implementation code, beacon
implementation).
url: "{{ secret('POSTGRES_URL') }}"
username: "{{ secret('POSTGRES_USER') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
fetchType: FETCH
parameters:
batch: "{{ outputs.read_contracts.body }}"
contracts: "{{ inputs.contracts | toJson }}"
sql: |
WITH r AS (
SELECT e->>'id' AS id, e->>'result' AS result, e->'error'->>'message' AS err
FROM jsonb_array_elements(CAST(:batch AS jsonb)) e
), c AS (
SELECT DISTINCT ON (lower(trim(split_part(x, '=', 2))))
trim(split_part(x, '=', 1)) AS label, lower(trim(split_part(x, '=', 2))) AS address
FROM jsonb_array_elements_text(CAST(:contracts AS jsonb)) x
), raw AS (
SELECT c.label, c.address,
max(r.result) FILTER (WHERE r.id = 'code/' || c.address) AS code,
max(r.result) FILTER (WHERE r.id = 'implementation/' || c.address) AS impl,
max(r.result) FILTER (WHERE r.id = 'admin/' || c.address) AS admin,
max(r.result) FILTER (WHERE r.id = 'beacon/' || c.address) AS beacon,
max(r.result) FILTER (WHERE r.id = 'legacy_implementation/' || c.address) AS legacy_impl,
max(r.result) FILTER (WHERE r.id = 'legacy_admin/' || c.address) AS legacy_admin,
max(r.result) FILTER (WHERE r.id = 'owner/' || c.address AND r.err IS NULL) AS owner,
string_agg(r.id || ': ' || r.err, '; ') FILTER (WHERE r.err IS NOT NULL AND r.id <> 'owner/' || c.address) AS rpc_error
FROM c LEFT JOIN r ON r.id LIKE '%/' || c.address
GROUP BY c.label, c.address
), addr AS (
-- A 32-byte word holds an address in its last 20 bytes; an empty slot means "not set".
SELECT label, address, code, rpc_error,
CASE WHEN impl ~ '^0x0*$' OR impl IS NULL THEN NULL ELSE '0x' || right(impl, 40) END AS impl,
CASE WHEN admin ~ '^0x0*$' OR admin IS NULL THEN NULL ELSE '0x' || right(admin, 40) END AS admin,
CASE WHEN beacon ~ '^0x0*$' OR beacon IS NULL THEN NULL ELSE '0x' || right(beacon, 40) END AS beacon,
CASE WHEN legacy_impl ~ '^0x0*$' OR legacy_impl IS NULL THEN NULL ELSE '0x' || right(legacy_impl, 40) END AS legacy_impl,
CASE WHEN legacy_admin ~ '^0x0*$' OR legacy_admin IS NULL THEN NULL ELSE '0x' || right(legacy_admin, 40) END AS legacy_admin,
CASE WHEN length(owner) <> 66 THEN NULL ELSE '0x' || right(owner, 40) END AS owner
FROM raw
)
SELECT label, address, owner, beacon,
coalesce(impl, legacy_impl) AS implementation,
coalesce(admin, legacy_admin) AS admin,
CASE WHEN impl IS NOT NULL THEN 'EIP-1967 proxy'
WHEN beacon IS NOT NULL THEN 'beacon proxy'
WHEN legacy_impl IS NOT NULL THEN 'proxy (legacy OpenZeppelin slots)'
ELSE 'contract' END AS kind,
CASE WHEN rpc_error IS NOT NULL THEN 'the RPC call failed: ' || rpc_error
WHEN code IS NULL OR code = '0x' THEN 'there is no contract at this address on this chain'
END AS problem,
CAST(CASE
WHEN coalesce(impl, legacy_impl) IS NOT NULL THEN jsonb_build_array(jsonb_build_object('jsonrpc', '2.0', 'id', 'code/' || address, 'method', 'eth_getCode', 'params', jsonb_build_array(coalesce(impl, legacy_impl), 'latest')))
WHEN beacon IS NOT NULL THEN jsonb_build_array(jsonb_build_object('jsonrpc', '2.0', 'id', 'beacon/' || address, 'method', 'eth_call', 'params', jsonb_build_array(jsonb_build_object('to', beacon, 'data', '0x5c60da1b'), 'latest')))
ELSE '[]' END AS TEXT) AS calls
FROM addr
ORDER BY label
- id: contracts_ok
type: io.kestra.plugin.core.flow.If
description: A typo or the wrong chain shows up as a missing contract; failing
is safer than taking an empty baseline.
condition: "{{ outputs.resolve.rows | jq('[.[] | select(.problem != null)] |
length') | first > 0 }}"
then:
- id: bad_contracts
type: io.kestra.plugin.core.execution.Fail
errorMessage: "{{ outputs.resolve.rows | jq('[.[] | select(.problem != null) |
\"\\(.label) (\\(.address)): \\(.problem)\"] | join(\"; \")') | first
}}"
- id: read_implementations
type: io.kestra.plugin.core.http.Request
description: Code of each proxy's implementation, and the implementation each
beacon points to.
uri: "{{ secret('EVM_RPC_URL') }}"
method: POST
contentType: application/json
body: "{{ outputs.resolve.rows | jq('[.[] | .calls | fromjson | .[]] +
[{\"jsonrpc\": \"2.0\", \"id\": \"head\", \"method\": \"eth_blockNumber\",
\"params\": []}]') | first | toJson }}"
retry:
type: exponential
interval: PT2S
maxInterval: PT30S
maxAttempts: 3
- id: analyze
type: io.kestra.plugin.jdbc.postgresql.Query
description: |
Compare each contract with its approved baseline. The first sighting becomes the baseline.
A change is reported once (the conditional UPDATE also keeps two concurrent runs from both reporting it),
proposed again every remind_minutes, and reported again when the contract returns to its approved state.
url: "{{ secret('POSTGRES_URL') }}"
username: "{{ secret('POSTGRES_USER') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
fetchType: FETCH
parameters:
rows: "{{ outputs.resolve.rows | toJson }}"
batch: "{{ outputs.read_implementations.body }}"
chain: "{{ outputs.read_contracts.body | jq('.[] | select(.id == \"chain\") |
.result') | first }}"
remind: "{{ inputs.remind_minutes }}"
execution: "{{ execution.id }}"
sql: |
WITH r AS (
SELECT e->>'id' AS id, e->>'result' AS result, e->'error'->>'message' AS err
FROM jsonb_array_elements(CAST(:batch AS jsonb)) e
), meta AS (
SELECT CAST(CAST('x' || lpad(substr(:chain, 3), 16, '0') AS BIT(64)) AS BIGINT) AS chain_id,
(SELECT CAST(CAST('x' || lpad(substr(result, 3), 16, '0') AS BIT(64)) AS BIGINT) FROM r WHERE id = 'head') AS block
), obs AS (
SELECT x->>'label' AS label, x->>'address' AS address, x->>'kind' AS kind,
jsonb_strip_nulls(jsonb_build_object(
'implementation', coalesce(x->>'implementation',
(SELECT CASE WHEN length(result) = 66 THEN '0x' || right(result, 40) END FROM r WHERE id = 'beacon/' || (x->>'address'))),
'admin', x->>'admin',
'beacon', x->>'beacon',
'owner', x->>'owner',
'code', (SELECT CASE WHEN result = '0x' THEN 'none'
ELSE 'sha256 ' || left(encode(sha256(decode(substr(result, 3), 'hex')), 'hex'), 12) END
FROM r WHERE id = 'code/' || (x->>'address')))) AS state
FROM jsonb_array_elements(CAST(:rows AS jsonb)) x
), prev AS (
SELECT w.* FROM contract_watch w, meta WHERE w.chain_id = meta.chain_id
), ins AS (
INSERT INTO contract_watch (chain_id, address, label, approved, observed)
SELECT meta.chain_id, o.address, o.label, o.state, o.state FROM obs o, meta
ON CONFLICT (chain_id, address) DO NOTHING
RETURNING address
), upd AS (
UPDATE contract_watch w
SET observed = o.state, label = o.label,
changed_at = CASE WHEN w.observed IS DISTINCT FROM o.state THEN now() ELSE w.changed_at END,
asked_at = CASE WHEN o.state <> w.approved
AND (w.observed IS DISTINCT FROM o.state OR w.asked_at IS NULL
OR w.asked_at < now() - make_interval(mins => CAST(:remind AS INT)))
THEN now() ELSE w.asked_at END
FROM obs o, meta
WHERE w.chain_id = meta.chain_id AND w.address = o.address
AND (w.observed IS DISTINCT FROM o.state OR w.label <> o.label
OR (o.state <> w.approved AND (w.asked_at IS NULL
OR w.asked_at < now() - make_interval(mins => CAST(:remind AS INT)))))
RETURNING w.address, w.changed_at = now() AND w.observed <> w.approved AS newly_changed,
w.changed_at = now() AND w.observed = w.approved AS restored,
w.asked_at = now() AS propose
), cur AS (
SELECT o.label, o.address, o.kind, o.state,
coalesce(p.approved, o.state) AS approved,
p.address IS NULL AND i.address IS NOT NULL AS first_seen,
coalesce(u.newly_changed, false) AS newly_changed,
coalesce(u.restored, false) AS restored,
coalesce(u.propose, false) AS propose
FROM obs o
LEFT JOIN prev p USING (address)
LEFT JOIN ins i USING (address)
LEFT JOIN upd u USING (address)
), log AS (
INSERT INTO contract_watch_log (chain_id, address, label, event, before_state, after_state, execution_id)
SELECT meta.chain_id, address, label,
CASE WHEN first_seen THEN 'baseline' WHEN restored THEN 'restored' ELSE 'changed' END,
CASE WHEN first_seen THEN NULL ELSE approved END, state, :execution
FROM cur, meta
WHERE first_seen OR newly_changed OR restored
)
SELECT c.label, c.address, c.kind, meta.block, c.first_seen, c.newly_changed, c.restored, c.propose,
c.state <> c.approved AS unapproved,
left(md5(CAST(c.state AS TEXT)), 10) AS change_id,
CAST(c.state AS TEXT) AS state,
-- control changes and an implementation without code are critical; a plain upgrade is high
CASE WHEN c.state->>'owner' IS DISTINCT FROM c.approved->>'owner'
OR c.state->>'admin' IS DISTINCT FROM c.approved->>'admin'
OR c.state->>'beacon' IS DISTINCT FROM c.approved->>'beacon'
OR c.state->>'code' = 'none' THEN 'CRITICAL'
WHEN c.state <> c.approved THEN 'UPGRADE' END AS severity,
(SELECT string_agg(format('- %s: %s → %s', k, coalesce(c.approved->>k, 'none'), coalesce(c.state->>k, 'none')), E'\n' ORDER BY k)
FROM (SELECT jsonb_object_keys(c.state || c.approved) AS k) keys
WHERE c.state->>k IS DISTINCT FROM c.approved->>k
-- the code fingerprint follows the implementation; show it alone only when it moved by itself or vanished
AND NOT (k = 'code' AND c.state->>'code' <> 'none'
AND c.state->>'implementation' IS DISTINCT FROM c.approved->>'implementation')) AS diff,
(SELECT string_agg(format('%s %s', k, c.state->>k), ', ' ORDER BY k)
FROM jsonb_object_keys(c.state) k) AS summary
FROM cur c, meta
ORDER BY c.label
- id: report
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.analyze.rows | jq('[.[] | select(.first_seen or
.newly_changed or .restored)] | length') | first > 0 }}"
then:
- id: notify_changes
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
{% for x in outputs.analyze.rows %}{% if x.newly_changed %}{{ x.severity }}: {{ x.label }} ({{ x.address }}) changed, seen at block {{ x.block }}:
{{ x.diff }}
{{ inputs.explorer_url }}/address/{{ x.address }}
{% elseif x.restored %}{{ x.label }} ({{ x.address }}) is back to its approved state.
{% elseif x.first_seen %}Now watching {{ x.label }} ({{ x.address }}), {{ x.kind }}: {{ x.summary }}
{% endif %}{% endfor %}
- id: propose
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.analyze.rows | jq('[.[] | select(.propose)] | length') |
first > 0 }}"
then:
- id: ask_on_call
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
Unapproved contract changes:
{% for x in outputs.analyze.rows %}{% if x.propose %}- {{ x.severity }} {{ x.label }} ({{ x.address }})
{% endif %}{% endfor %}Decide within 4 hours: {{ inputs.kestra_url }}/ui/main/executions/{{ flow.namespace }}/{{ flow.id }}/{{ execution.id }}
- Approve as new baseline: you checked the change (audit, announcement, governance vote); a note is kept in contract_watch_log
- Pause the protocol: {% if (inputs.pause_target ?? '') != '' %}call pause() on {{ inputs.pause_target }} from the guardian {{ inputs.guardian }}{% else %}not configured (set pause_target and guardian){% endif %}
- Not yet: keep it unapproved; you will be asked again in {{ inputs.remind_minutes }} min
- id: wait_for_decision
type: io.kestra.plugin.core.flow.Pause
description: No answer within 4 hours leaves the change unapproved; it is
proposed again later.
pauseDuration: PT4H
behavior: RESUME
onResume:
- id: decision
type: SELECT
values:
- Approve as new baseline
- Pause the protocol
- Not yet
defaults: Not yet
- id: only_contracts
type: STRING
required: false
description: Optional comma-separated labels or addresses to approve. Empty
means every proposed contract.
- id: note
type: STRING
required: false
description: Why the change is expected, for example a link to the announcement.
Stored in the audit log.
- id: approve
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.wait_for_decision.onResume.decision == 'Approve as new
baseline' }}"
then:
- id: approve_changes
type: io.kestra.plugin.jdbc.postgresql.Query
description: Approve exactly the state that was shown. A contract that changed
again after the proposal is not approved.
url: "{{ secret('POSTGRES_URL') }}"
username: "{{ secret('POSTGRES_USER') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
fetchType: FETCH
parameters:
proposed: "{{ outputs.analyze.rows | jq('[.[] | select(.propose) |
\"\\(.address)/\\(.change_id)\"] | join(\",\")') | first }}"
only: "{{ outputs.wait_for_decision.onResume.only_contracts ?? '' }}"
note: "{{ outputs.wait_for_decision.onResume.note ?? '' }}"
chain: "{{ outputs.read_contracts.body | jq('.[] | select(.id == \"chain\") |
.result') | first }}"
execution: "{{ execution.id }}"
sql: |
WITH meta AS (
SELECT CAST(CAST('x' || lpad(substr(:chain, 3), 16, '0') AS BIT(64)) AS BIGINT) AS chain_id
), only_list AS (
SELECT trim(t) AS name, lower(trim(t)) AS key FROM unnest(string_to_array(:only, ',')) t WHERE trim(t) <> ''
), sel AS (
SELECT w.chain_id, w.address, w.label, split_part(p, '/', 2) AS change_id
FROM unnest(string_to_array(:proposed, ',')) p
JOIN meta ON true
JOIN contract_watch w ON w.chain_id = meta.chain_id AND w.address = split_part(p, '/', 1)
WHERE NOT EXISTS (SELECT 1 FROM only_list)
OR EXISTS (SELECT 1 FROM only_list WHERE key IN (w.address, lower(w.label)))
), upd AS (
UPDATE contract_watch w
SET approved = w.observed, approved_at = now(), asked_at = NULL
FROM sel
WHERE w.chain_id = sel.chain_id AND w.address = sel.address
AND left(md5(CAST(w.observed AS TEXT)), 10) = sel.change_id
AND w.observed <> w.approved
RETURNING w.chain_id, w.address, w.label, w.observed
), log AS (
INSERT INTO contract_watch_log (chain_id, address, label, event, after_state, note, execution_id)
SELECT chain_id, address, label, 'approved', observed, NULLIF(:note, ''), :execution FROM upd
)
SELECT sel.label, sel.address,
CASE WHEN upd.address IS NOT NULL THEN 'approved as the new baseline'
ELSE 'NOT approved: it changed again after the proposal, or was already handled' END AS result
FROM sel LEFT JOIN upd USING (address)
UNION ALL
SELECT name, NULL, 'NOT approved: not part of this proposal'
FROM only_list
WHERE NOT EXISTS (SELECT 1 FROM sel WHERE only_list.key IN (sel.address, lower(sel.label)))
- id: notify_approved
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
Contract changes reviewed{% if (outputs.wait_for_decision.onResume.note ?? '') != '' %} ("{{ outputs.wait_for_decision.onResume.note }}"){% endif %}:
{% for x in outputs.approve_changes.rows %}- {{ x.label }}: {{ x.result }}
{% endfor %}
- id: pause_protocol
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.wait_for_decision.onResume.decision == 'Pause the
protocol' }}"
then:
- id: pause_configured
type: io.kestra.plugin.core.flow.If
condition: "{{ [inputs.pause_target ?? '', inputs.guardian ?? ''] | jq('[.[] |
select(test(\"^0x[0-9a-fA-F]{40}$\"))] | length') | first < 2 }}"
then:
- id: not_configured
type: io.kestra.plugin.core.execution.Fail
errorMessage: Pause was requested, but pause_target and guardian are not both
set to addresses. Nothing was sent; pause manually
- id: send_pause
type: io.kestra.plugin.core.http.Request
uri: "{{ secret('EVM_SIGNER_URL') }}"
method: POST
contentType: application/json
options:
allowFailed: true
body: "{{ {'jsonrpc': '2.0', 'id': 1, 'method': 'eth_sendTransaction', 'params':
[{'from': inputs.guardian, 'to': inputs.pause_target, 'data':
'0x8456cb59'}]} | toJson }}"
- id: pause_sent
type: io.kestra.plugin.core.flow.If
condition: "{{ (outputs.send_pause.body | jq('.error.message // \"\"') | first)
!= '' }}"
then:
- id: pause_refused
type: io.kestra.plugin.core.execution.Fail
errorMessage: "The signer refused the pause transaction: {{
outputs.send_pause.body | jq('.error.message') | first }}. The
protocol is NOT paused"
- id: wait_for_receipt
type: io.kestra.plugin.core.flow.LoopUntil
condition: "{{ (outputs.pause_receipt.body | jq('.result != null') | first) }}"
checkFrequency:
interval: PT3S
maxIterations: 100
failOnMaxReached: true
tasks:
- id: pause_receipt
type: io.kestra.plugin.core.http.Request
uri: "{{ secret('EVM_RPC_URL') }}"
method: POST
contentType: application/json
body: "{{ {'jsonrpc': '2.0', 'id': 1, 'method': 'eth_getTransactionReceipt',
'params': [outputs.send_pause.body | jq('.result') | first]} |
toJson }}"
- id: check_paused
type: io.kestra.plugin.core.http.Request
description: Read paused() so the result comes from the contract, not from the
transaction alone.
uri: "{{ secret('EVM_RPC_URL') }}"
method: POST
contentType: application/json
body: "{{ {'jsonrpc': '2.0', 'id': 1, 'method': 'eth_call', 'params': [{'to':
inputs.pause_target, 'data': '0x5c975abb'}, 'latest']} | toJson
}}"
- id: pause_worked
type: io.kestra.plugin.core.flow.If
condition: "{{ (outputs.pause_receipt.body | jq('.result.status') | first) !=
'0x1' or not (outputs.check_paused.body | jq('.result // \"\" |
test(\"^0x0*1$\")') | first) }}"
then:
- id: pause_failed
type: io.kestra.plugin.core.execution.Fail
errorMessage: "Pause transaction {{ outputs.send_pause.body | jq('.result') |
first }} {{ (outputs.pause_receipt.body | jq('.result.status')
| first) == '0x1' ? 'was mined but paused() is not true' :
'reverted: check that the guardian may call pause()' }}. The
protocol is NOT paused"
- id: notify_paused
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
PAUSED: {{ inputs.pause_target }} is paused (paused() = true) by transaction {{ inputs.explorer_url }}/tx/{{ outputs.send_pause.body | jq('.result') | first }}
The contract changes stay unapproved until someone approves them.
errors:
- id: alert_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: >-
Contract upgrade watchdog failed in execution {{ execution.id }} {% if
errorLogs() | length > 0 %}at `{{ errorLogs()[0]['taskId'] }}`: {{
errorLogs()[0]['message'] | split(' \[\[') | first }}{% else %}without an
error message{% endif %}. {{ inputs.kestra_url }}/ui/main/executions/{{
flow.namespace }}/{{ flow.id }}/{{ execution.id }}
outputs:
- id: contracts
type: JSON
description: Every watched contract with its current state, whether it differs
from the approved baseline, and what changed.
value: "{{ outputs.analyze.rows ?? [] }}"