Skip to content

Commit 805e120

Browse files
authored
add pyoso guide to 4337 docs
1 parent bbabc4b commit 805e120

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

l2s/how-to-create-your-own-4337-metrics.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,102 @@ The resulting data shows which Paymaster application has the biggest volume of c
9393

9494
![](how-to-create-your-own-4337-metrics-image-8.png)
9595

96+
## Using OSO's pyoso library for 4337 data analysis
97+
98+
For a more streamlined approach to analyzing Account Abstraction data, you can use OSO's pyoso library which provides direct access to curated 4337 datasets across all Superchain networks. This approach eliminates the need for BigQuery setup -- and lets you connect 4337 data with 100s of other public data models.
99+
100+
### Getting Started with pyoso
101+
102+
First, you'll need to [get an API key](https://docs.opensource.observer/docs/get-started/python) to access the data.
103+
104+
<img width="2492" height="1124" alt="image" src="https://github.com/user-attachments/assets/cbfeed2a-991f-4eeb-8215-f22a87cad8e7" />
105+
106+
Then, install the pyoso library and set up your environment:
107+
108+
```bash
109+
pip install pyoso
110+
```
111+
112+
Initialize the client:
113+
114+
```python
115+
import pandas as pd
116+
from pyoso import Client
117+
118+
# Set up the OSO client
119+
OSO_API_KEY = "YOUR_API_KEY"
120+
client = Client(api_key=OSO_API_KEY)
121+
```
122+
123+
### Available 4337 Data Models
124+
125+
OSO hosts lighter weight "staging" versions of the same tables shared above:
126+
127+
- Enriched EntryPoint Traces (`stg_superchain__4337_traces`)
128+
- User Operation Logs (`stg_superchain__4337_userop_logs`)
129+
- OLI Address Labels (`stg_openlabelsinitiative__labels_decoded`)
130+
131+
### Example: Analyzing Paymaster Usage
132+
133+
Here's how to analyze paymaster usage across all Superchain networks:
134+
135+
```python
136+
# Get daily paymaster usage by project and chain
137+
df_paymaster_usage = client.to_pandas("""
138+
WITH paymasters AS (
139+
SELECT address
140+
FROM stg_openlabelsinitiative__labels_decoded
141+
WHERE tag_id = 'is_paymaster'
142+
),
143+
labeled_paymasters AS (
144+
SELECT
145+
address,
146+
MIN(tag_value) AS owner_project
147+
FROM stg_openlabelsinitiative__labels_decoded
148+
WHERE
149+
tag_id = 'owner_project'
150+
AND address IN (SELECT address FROM paymasters)
151+
GROUP BY 1
152+
)
153+
154+
SELECT
155+
DATE_TRUNC('DAY', block_timestamp) AS bucket_day,
156+
COALESCE(p.owner_project, 'unknown') AS owner_project,
157+
chain,
158+
COUNT(*) AS userops_count
159+
FROM stg_superchain__4337_userop_logs AS logs
160+
LEFT JOIN labeled_paymasters AS p ON logs.paymaster_address = p.address
161+
GROUP BY 1,2,3
162+
ORDER BY bucket_day DESC, userops_count DESC
163+
""")
164+
```
165+
166+
### Example: Chain-by-Chain Activity Analysis
167+
168+
Analyze Account Abstraction activity across different Superchain networks:
169+
170+
```python
171+
# Get total activity by chain
172+
df_chain_totals = client.to_pandas("""
173+
SELECT
174+
chain,
175+
COUNT(*) AS total_userops,
176+
COUNT(DISTINCT sender_address) AS unique_users,
177+
COUNT(DISTINCT paymaster_address) AS unique_paymasters,
178+
AVG(userop_gas_used) AS avg_gas_used,
179+
SUM(userop_gas_used * userop_gas_price) / 1e18 AS total_gas_cost_eth
180+
FROM stg_superchain__4337_userop_logs
181+
WHERE paymaster_address != '0x0000000000000000000000000000000000000000'
182+
GROUP BY chain
183+
ORDER BY total_userops DESC
184+
""")
185+
```
186+
187+
<img width="1601" height="798" alt="image" src="https://github.com/user-attachments/assets/8fe0b494-bf4f-4ff2-8f07-ad4bf6d47393" />
188+
189+
---
190+
191+
For a longer tutorial on Account Abstraction analysis using pyoso, check out the [Monitor Account Abstraction Adoption tutorial](https://docs.opensource.observer/docs/tutorials/account-abstraction/) which covers user operations, paymaster analysis, and cross-chain activity patterns.
192+
193+
96194
Thanks for reading and feel free to outreach to Superchain 4337 Team in case any questions or ideas arise!

0 commit comments

Comments
 (0)