Skip to content

Join two series ​

Sample the share rate and the pooled ether on the same grid, and put them side by side on each block.

cql
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;

from stETH at 25_800_000..26_000_000 every 7200 as a
| extend ethPerShare = format(a.getPooledEthByShares(1e18), 18)
| join (
    from stETH at 25_800_000..26_000_000 every 7200 as b
    | extend pooledEther = format(b.getTotalPooledEther(), 18)
  ) on $block
| project { block: $block, ethPerShare, pooledEther }
| order by block asc

Open in workbench →

The query returns 29 rows, oldest first. These are the first six:

blockethPerSharepooledEther
258048001.242190142783145759577513.744139325389714808
258120001.2422710907264860539577726.064524543518701572
258192001.2423464406452301739578787.206360787975638105
258264001.2424241817093757619583377.950886032964272514
258336001.242501079439676829621710.894523357280615501
258408001.2425759764014953919624902.757062597687619272
ethPerShare by blockA step line of ethPerShare over block, from all 29 rows the query returned.1.24251.24301.24351.2440ethPerShare25850000259000002595000026000000block25804800 ethPerShare 1.2421901427831457525812000 ethPerShare 1.24227109072648605325819200 ethPerShare 1.24234644064523017325826400 ethPerShare 1.24242418170937576125833600 ethPerShare 1.2425010794396768225840800 ethPerShare 1.24257597640149539125848000 ethPerShare 1.2426506520846679125855200 ethPerShare 1.24272623822670456125862400 ethPerShare 1.24280144431176669225869600 ethPerShare 1.24287653428011665225876800 ethPerShare 1.24295362601336701825884000 ethPerShare 1.24302892625581253625891200 ethPerShare 1.24310321188183654425898400 ethPerShare 1.24317779040800536725905600 ethPerShare 1.24325420610236652125912800 ethPerShare 1.24332996843206419525920000 ethPerShare 1.24340600138434362925927200 ethPerShare 1.24348239751034256325934400 ethPerShare 1.24355861068948000725941600 ethPerShare 1.24363798825853603725948800 ethPerShare 1.24371450605248061525956000 ethPerShare 1.24379049583633124625963200 ethPerShare 1.24386939110987725525970400 ethPerShare 1.24394552895779880225977600 ethPerShare 1.24402131289398821825984800 ethPerShare 1.24409960849842156325992000 ethPerShare 1.24417638420736858125999200 ethPerShare 1.24425303053124970226000000 ethPerShare 1.244253030531249702
ethPerShare by blockA step line of ethPerShare over block, from all 29 rows the query returned.1.24251.24301.24351.2440ethPerShare2590000026000000block25804800 ethPerShare 1.2421901427831457525812000 ethPerShare 1.24227109072648605325819200 ethPerShare 1.24234644064523017325826400 ethPerShare 1.24242418170937576125833600 ethPerShare 1.2425010794396768225840800 ethPerShare 1.24257597640149539125848000 ethPerShare 1.2426506520846679125855200 ethPerShare 1.24272623822670456125862400 ethPerShare 1.24280144431176669225869600 ethPerShare 1.24287653428011665225876800 ethPerShare 1.24295362601336701825884000 ethPerShare 1.24302892625581253625891200 ethPerShare 1.24310321188183654425898400 ethPerShare 1.24317779040800536725905600 ethPerShare 1.24325420610236652125912800 ethPerShare 1.24332996843206419525920000 ethPerShare 1.24340600138434362925927200 ethPerShare 1.24348239751034256325934400 ethPerShare 1.24355861068948000725941600 ethPerShare 1.24363798825853603725948800 ethPerShare 1.24371450605248061525956000 ethPerShare 1.24379049583633124625963200 ethPerShare 1.24386939110987725525970400 ethPerShare 1.24394552895779880225977600 ethPerShare 1.24402131289398821825984800 ethPerShare 1.24409960849842156325992000 ethPerShare 1.24417638420736858125999200 ethPerShare 1.24425303053124970226000000 ethPerShare 1.244253030531249702
pooledEther by blockA line of pooledEther over block, from all 29 rows the query returned.960000096500009700000pooledEther25850000259000002595000026000000block25804800 pooledEther 9577513.74413932538971480825812000 pooledEther 9577726.06452454351870157225819200 pooledEther 9578787.20636078797563810525826400 pooledEther 9583377.95088603296427251425833600 pooledEther 9621710.89452335728061550125840800 pooledEther 9624902.75706259768761927225848000 pooledEther 9626003.92947492706571898325855200 pooledEther 9626612.8436787151746331925862400 pooledEther 9615950.85493020929141081825869600 pooledEther 9614703.73305493833618254825876800 pooledEther 9645709.48803030927664095425884000 pooledEther 9659720.85448586936824106425891200 pooledEther 9659717.2529022072522093325898400 pooledEther 9664389.75004932245782430825905600 pooledEther 9666281.39449674648120762225912800 pooledEther 9661959.97906199930354783225920000 pooledEther 9657454.66644778501191342825927200 pooledEther 9658254.09827846811694761225934400 pooledEther 9658937.20975066148566047225941600 pooledEther 9658441.97424946039413072525948800 pooledEther 9660650.42205440573119190925956000 pooledEther 9663581.0193447384746061525963200 pooledEther 9666771.7386255306957227225970400 pooledEther 9654732.77621078105801955325977600 pooledEther 9672773.60803459447611609525984800 pooledEther 9681483.24568419209934178325992000 pooledEther 9696026.21453945668507110825999200 pooledEther 9718661.08588752288764237326000000 pooledEther 9719445.089671689740474249
pooledEther by blockA line of pooledEther over block, from all 29 rows the query returned.960000096500009700000pooledEther2590000026000000block25804800 pooledEther 9577513.74413932538971480825812000 pooledEther 9577726.06452454351870157225819200 pooledEther 9578787.20636078797563810525826400 pooledEther 9583377.95088603296427251425833600 pooledEther 9621710.89452335728061550125840800 pooledEther 9624902.75706259768761927225848000 pooledEther 9626003.92947492706571898325855200 pooledEther 9626612.8436787151746331925862400 pooledEther 9615950.85493020929141081825869600 pooledEther 9614703.73305493833618254825876800 pooledEther 9645709.48803030927664095425884000 pooledEther 9659720.85448586936824106425891200 pooledEther 9659717.2529022072522093325898400 pooledEther 9664389.75004932245782430825905600 pooledEther 9666281.39449674648120762225912800 pooledEther 9661959.97906199930354783225920000 pooledEther 9657454.66644778501191342825927200 pooledEther 9658254.09827846811694761225934400 pooledEther 9658937.20975066148566047225941600 pooledEther 9658441.97424946039413072525948800 pooledEther 9660650.42205440573119190925956000 pooledEther 9663581.0193447384746061525963200 pooledEther 9666771.7386255306957227225970400 pooledEther 9654732.77621078105801955325977600 pooledEther 9672773.60803459447611609525984800 pooledEther 9681483.24568419209934178325992000 pooledEther 9696026.21453945668507110825999200 pooledEther 9718661.08588752288764237326000000 pooledEther 9719445.089671689740474249

One row per sampled block, with the share rate and the pooled ether at that block. The ethPerShare column is Sample a long range's, block for block. The two columns move differently. The share rate steps up once a day, when stETH rebases. The last two rows, 25 999 200 and 26 000 000, are 800 blocks apart and share one rate. The pooled ether moves at every sample, and falls as well as rises. Deposits and withdrawals change it between rebases. Across those same two rows it grows by about 784.

How it reads ​

The two sources use the same range and the same step, so they land on the same blocks. That is what makes $block a usable key. An inner join keeps a row only where both sides have that block. Here that is every block: 29 on each side, 29 joined.

A key written as one name appears once in the output, so $block is one column, not two. The join keeps the other columns both sides have from both sides. It renames the right one with a number — $timestamp1, $address1 — and the project leaves them out.

The two sides read the same contract, which keeps the example small. The same shape joins two contracts — stETH on one side and wstETH's stEthPerToken() on the other — as long as their grids agree. That is when join earns its place. Two calls on one contract at one block fit in one project with no join at all, as Read the share rate now does.

Variations ​

  • Everything on either side. join kind=fullouter, then where isnull(pooledEther) or where isnull(ethPerShare) to see the blocks one side lacks.
  • A ratio. Read totalShares = format(b.getTotalShares(), 18) on the right-hand side beside pooledEther, then | extend computed = pooledEther / totalShares after the join: the share rate, computed from its two parts.
  • Across chains. $block is no key between chains, and CQL refuses on $block across two (CQL3007). Sample both sides by time … every 1h. Give each a column t = bin($sampleAt, 1h) with extend. Then join on t, as Compare a contract across chains does. End both ranges on the hour. CQL also samples an end between two hours, and that sample repeats the last hour.

In the workbench ​

Both series can share one chart. In Visualize:

  1. Choose Line.
  2. Choose block for x. The tab asks for its decimals. Choose 0.
  3. Choose ethPerShare for y.
  4. Choose pooledEther in the + y picker beside it.

The two series differ by far more than 100 times, so the tab warns that one axis flattens the smaller. The two charts above show that it does. Chart them one at a time.

See also ​