Liquid Restaking (LRT) — Track flows like a pro
A brief history of LRTs and AVSes
Liquid Restaking Tokens (LRTs) are a mechanism that repurposes staked ether (ETH) to support external systems such as rollups and oracles, providing an economic security layer.
The approach enhances Ethereum’s core security stability by lowering the risk of a liquidation cascade and positioning withdrawals from the Ethereum Beacon Chain as a backup defence.
Unlike traditional liquid staking protocols (LSTs) that validate the consensus chain, LRTs use funds to validate Actively Validated Services (AVSes), which include various systems like rollups, oracles, and bridges.
How to monitor ETH flows like a pro
To get the net as well as individual flows from in and out of an LRT protocol address, we need to have access to Ethereum traces
or eth_transfers
as well as Beacon withdrawals
. Whilst this tutorial is specific to LRTs, the same steps would apply to an LST protocol, with the only difference being that LST protocols usually have massive arrays of addresses associated with them.
Deposit Monitoring
Within Ethereum traces
we can narrow our search down to the flows directed into the Beacon Deposit Contract from the address (LRT) we are interested in monitoring. The function signature we are following here is:
deposit(bytes pubkey, bytes withdrawal_credentials, bytes signature, bytes32 deposit_data_root)
SELECT
date_trunc('hour', block_time) as dt,
SUM(value/POW(10,18)) as amount
FROM ethereum_mainnet.traces as t
WHERE t.from_address = '{your_address_here}' -- Address of interest
AND t.to_address = '0x00000000219ab540356cbb839cbe05303d7705fa' -- beacon deposit address
AND substr(t.input, 1,10) = '0x22895118' -- Function signature of interest deposit(bytes pubkey, bytes withdrawal_credentials, bytes signature, bytes32 deposit_data_root)
GROUP BY 1
ORDER BY 1 ASC
The above will provide us with all of the Deposits (inflows) of ETH inside the staking contract, associated with that address.
When selecting your address of interest, please ensure that it is the final address in the call
stack that is interacting with the Beacon Deposit address, as this will be the same one as the withdrawal address.
Withdrawal Monitoring
Next, we need to monitor the Withdrawal flows out of the Beacon chain. To do that we need to look at the withdrawals
table generated when a set of withdrawals are executed.
SELECT
date_trunc('hour', block_time) as dt,
SUM(amount/POW(10,9)) as amount
FROM beacon_mainnet.withdrawals
WHERE address = '{your_address_here}' -- Address of interest
GROUP BY 2
ORDER BY 1 ASC
The above will provide us with all of the Withdrawals (outflows) of ETH from the staking contract to the (LRT) address of interest.
Net Flows (TVL) Monitoring
Now with all of the above information, we can put the final query together, which will provide us with Net Flows (or TVL) and flow deltas for that address aggregated over daily, hourly or minutely. For the above example, I am aggregating the data hourly.
Here is how to put all that together in SQL to get the expected results:
WITH deposit_value as (
SELECT
date_trunc('hour', block_time) as dt
SUM(value/POW(10,18)) as amount
FROM ethereum_mainnet.traces as t
WHERE t.from_address = '{your_address_here}' -- Address of interest
AND t.to_address = '0x00000000219ab540356cbb839cbe05303d7705fa' -- beacon deposit address
AND substr(t.input, 1,10) = '0x22895118' -- Function signature of interest deposit(bytes pubkey, bytes withdrawal_credentials, bytes signature, bytes32 deposit_data_root)
GROUP By 1
),
withdraw_value as (
SELECT
date_trunc('hour', block_time) as dt,
SUM(amount/POW(10,9)) as amount
from beacon_mainnet.withdrawals
WHERE address = '{your_address_here}' -- Address of interest
GROUP BY 1
),
agg_by_date as (
SELECT
dt,
-amount as amount
FROM withdraw_value
UNION ALL
SELECT
dt,
amount
FROM deposit_value
)
SELECT
DISTINCT
agg.dt as dt,
agg.amount,
SUM(agg.amount) OVER (ORDER BY agg.dt) as net_flow,
CASE WHEN agg.amount < 0 then 'outflow' ELSE 'inflow' END as flow_type
FROM agg_by_date as agg
ORDER BY 1;
The above will give us a table that contains the following information:
Now you can also visualize your results, see for example daily flows into an LRT of interest.
You could also unclick the inflow
label and get only the outflows of the following address:
You can also look at the TVL associated with that address. In other words, the Net flows over time in-out of this address.
Next steps
If you are interested in monitoring these flows in real-time, you could now create an API out of this query using https://app.zettablock.com/ and even generate webhooks on top of that API, so you can be alerted for any new incoming flows in or out of the Beacon Deposit contract, associated with you address(es) of interest.
Summary
It is quite tedious to be doing contract calls, or crawling 2 chains locally, just to be able to calculate these Net TVL and flow values for your dApp or personal interest. In the above tutorial, we’ve looked at how to utilize a Data Provider service to get the Net TVL and ETH flows over time, from an LRT or LST address(es) of interest.