Spaces:
Running
Running
gauravlochab
commited on
Commit
·
c744bf3
1
Parent(s):
ff271a0
refactor: Update API and graph layout
Browse files- app.py +60 -4
- daily_value_locked.csv +4 -0
app.py
CHANGED
@@ -8,7 +8,6 @@ import json
|
|
8 |
from web3 import Web3
|
9 |
import os
|
10 |
from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
11 |
-
from app_value_locked import fetch_daily_value_locked
|
12 |
# Load environment variables from .env file
|
13 |
# RPC URLs
|
14 |
OPTIMISM_RPC_URL = os.getenv('OPTIMISM_RPC_URL')
|
@@ -139,6 +138,61 @@ def create_visualizations():
|
|
139 |
transactions_data = fetch_and_aggregate_transactions()
|
140 |
df_transactions, df_agents, df_agents_weekly = process_transactions_and_agents(transactions_data)
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
chain_name_map = {
|
143 |
10: "Optimism",
|
144 |
8453: "Base",
|
@@ -155,7 +209,6 @@ def create_visualizations():
|
|
155 |
df_transactions["is_swap"] = df_transactions.apply(lambda x: x["sending_chain"] == x["receiving_chain"], axis=1)
|
156 |
|
157 |
swaps_per_chain = df_transactions[df_transactions["is_swap"]].groupby(["date", "sending_chain"]).size().reset_index(name="swap_count")
|
158 |
-
|
159 |
fig_swaps_chain = px.bar(
|
160 |
swaps_per_chain,
|
161 |
x="date",
|
@@ -292,7 +345,7 @@ def create_visualizations():
|
|
292 |
template='plotly_white'
|
293 |
)
|
294 |
|
295 |
-
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered
|
296 |
|
297 |
# Gradio interface
|
298 |
def dashboard():
|
@@ -302,7 +355,7 @@ def dashboard():
|
|
302 |
fig_tx_chain = create_transcation_visualizations()
|
303 |
gr.Plot(fig_tx_chain)
|
304 |
|
305 |
-
fig_swaps_chain, fig_bridges_chain, fig_agents_registered = create_visualizations()
|
306 |
with gr.Tab("Swaps Daily"):
|
307 |
gr.Plot(fig_swaps_chain)
|
308 |
|
@@ -315,6 +368,9 @@ def dashboard():
|
|
315 |
with gr.Tab("DAA"):
|
316 |
fig_agents_with_transactions_daily = create_active_agents_visualizations()
|
317 |
gr.Plot(fig_agents_with_transactions_daily)
|
|
|
|
|
|
|
318 |
|
319 |
return demo
|
320 |
|
|
|
8 |
from web3 import Web3
|
9 |
import os
|
10 |
from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
|
|
11 |
# Load environment variables from .env file
|
12 |
# RPC URLs
|
13 |
OPTIMISM_RPC_URL = os.getenv('OPTIMISM_RPC_URL')
|
|
|
138 |
transactions_data = fetch_and_aggregate_transactions()
|
139 |
df_transactions, df_agents, df_agents_weekly = process_transactions_and_agents(transactions_data)
|
140 |
|
141 |
+
# Fetch daily value locked data
|
142 |
+
df_tvl = pd.read_csv('daily_value_locked.csv')
|
143 |
+
|
144 |
+
# Calculate total value locked per chain per day
|
145 |
+
df_tvl["total_value_locked_usd"] = df_tvl["amount0_usd"] + df_tvl["amount1_usd"]
|
146 |
+
df_tvl_daily = df_tvl.groupby(["date", "chain_name"])["total_value_locked_usd"].sum().reset_index()
|
147 |
+
df_tvl_daily['date'] = pd.to_datetime(df_tvl_daily['date'])
|
148 |
+
|
149 |
+
# Filter out dates with zero total value locked
|
150 |
+
df_tvl_daily = df_tvl_daily[df_tvl_daily["total_value_locked_usd"] > 0]
|
151 |
+
|
152 |
+
chain_name_map = {
|
153 |
+
"mode": "Mode",
|
154 |
+
"base": "Base",
|
155 |
+
"ethereum": "Ethereum",
|
156 |
+
"optimism": "Optimism"
|
157 |
+
}
|
158 |
+
df_tvl_daily["chain_name"] = df_tvl_daily["chain_name"].map(chain_name_map)
|
159 |
+
|
160 |
+
# Plot total value locked
|
161 |
+
fig_tvl = px.bar(
|
162 |
+
df_tvl_daily,
|
163 |
+
x="date",
|
164 |
+
y="total_value_locked_usd",
|
165 |
+
color="chain_name",
|
166 |
+
opacity=0.7,
|
167 |
+
title="Total Volume Invested in Pools in Different Chains Daily",
|
168 |
+
labels={"date": "Date","chain_name": "Transaction Chain", "total_value_locked_usd": "Total Volume Invested (USD)"},
|
169 |
+
barmode='stack',
|
170 |
+
color_discrete_map={
|
171 |
+
"Mode": "orange",
|
172 |
+
"Base": "purple",
|
173 |
+
"Ethereum": "darkgreen",
|
174 |
+
"Optimism": "blue"
|
175 |
+
}
|
176 |
+
)
|
177 |
+
fig_tvl.update_layout(
|
178 |
+
xaxis_title="Date",
|
179 |
+
|
180 |
+
yaxis=dict(tickmode='linear', tick0=0, dtick=4),
|
181 |
+
xaxis=dict(
|
182 |
+
tickmode='array',
|
183 |
+
tickvals=df_tvl_daily['date'],
|
184 |
+
ticktext=df_tvl_daily['date'].dt.strftime('%b %d'),
|
185 |
+
tickangle=-45,
|
186 |
+
),
|
187 |
+
bargap=0.6, # Increase gap between bar groups (0-1)
|
188 |
+
bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
189 |
+
height=600,
|
190 |
+
width=1200, # Specify width to prevent bars from being too wide
|
191 |
+
showlegend=True,
|
192 |
+
template='plotly_white'
|
193 |
+
)
|
194 |
+
fig_tvl.update_xaxes(tickformat="%b %d")
|
195 |
+
|
196 |
chain_name_map = {
|
197 |
10: "Optimism",
|
198 |
8453: "Base",
|
|
|
209 |
df_transactions["is_swap"] = df_transactions.apply(lambda x: x["sending_chain"] == x["receiving_chain"], axis=1)
|
210 |
|
211 |
swaps_per_chain = df_transactions[df_transactions["is_swap"]].groupby(["date", "sending_chain"]).size().reset_index(name="swap_count")
|
|
|
212 |
fig_swaps_chain = px.bar(
|
213 |
swaps_per_chain,
|
214 |
x="date",
|
|
|
345 |
template='plotly_white'
|
346 |
)
|
347 |
|
348 |
+
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered,fig_tvl
|
349 |
|
350 |
# Gradio interface
|
351 |
def dashboard():
|
|
|
355 |
fig_tx_chain = create_transcation_visualizations()
|
356 |
gr.Plot(fig_tx_chain)
|
357 |
|
358 |
+
fig_swaps_chain, fig_bridges_chain, fig_agents_registered,fig_tvl = create_visualizations()
|
359 |
with gr.Tab("Swaps Daily"):
|
360 |
gr.Plot(fig_swaps_chain)
|
361 |
|
|
|
368 |
with gr.Tab("DAA"):
|
369 |
fig_agents_with_transactions_daily = create_active_agents_visualizations()
|
370 |
gr.Plot(fig_agents_with_transactions_daily)
|
371 |
+
|
372 |
+
with gr.Tab("Total Value Locked"):
|
373 |
+
gr.Plot(fig_tvl)
|
374 |
|
375 |
return demo
|
376 |
|
daily_value_locked.csv
CHANGED
@@ -2,3 +2,7 @@ chain_name,date,event,topic_0,from,to,token_id,token0,token1,liquidity,amount0,a
|
|
2 |
optimism,2024-10-07,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0x5f0c4273ff97ae91fc8d2fc8621b5e37a741d1b1,826974,0x2218a117083f5B482B0bB821d27056Ba9c04b1D3,0xdFA46478F9e5EA86d57387849598dbFB2e964b02,13516644515555081265,8.98929230571145,20.324144854406946,9.97811445933971,10.184307041674192
|
3 |
base,2024-09-19,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xa13dfc6ddcff0b5b637e721ee83d6cf7e0676e73,963863,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1210264887099988865,359.58545796548844,0.0040734158306472,9.341785679831974,10.270669941235578
|
4 |
base,2024-09-26,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,12.205037194519935,12.469864740059744
|
|
|
|
|
|
|
|
|
|
2 |
optimism,2024-10-07,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0x5f0c4273ff97ae91fc8d2fc8621b5e37a741d1b1,826974,0x2218a117083f5B482B0bB821d27056Ba9c04b1D3,0xdFA46478F9e5EA86d57387849598dbFB2e964b02,13516644515555081265,8.98929230571145,20.324144854406946,9.97811445933971,10.184307041674192
|
3 |
base,2024-09-19,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xa13dfc6ddcff0b5b637e721ee83d6cf7e0676e73,963863,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1210264887099988865,359.58545796548844,0.0040734158306472,9.341785679831974,10.270669941235578
|
4 |
base,2024-09-26,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,12.205037194519935,12.469864740059744
|
5 |
+
optimism,2024-09-14,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,12.0644,12.3921
|
6 |
+
optimism,2024-09-04,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,14.9849,14.9849
|
7 |
+
mode,2024-11-07,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,18.2495,18.3223
|
8 |
+
mode,2024-11-19,Transfer,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000000000000000000000,0xac55eeb3fdacfdfae78c62caa58934900ad54ed2,978001,0x01CCF4941298a0b5AC4714c0E1799a2dF8387048,0x4200000000000000000000000000000000000006,1524286215726092055,469.7981777244338,0.004945631076533,16.9373,16.9373
|