Spaces:
Running
Running
gauravlochab
commited on
Commit
·
39b4e26
1
Parent(s):
36a3394
feat: Update API endpoint in get_transfers function
Browse files
app.py
CHANGED
@@ -6,12 +6,17 @@ import plotly.express as px
|
|
6 |
from datetime import datetime, timedelta
|
7 |
import json
|
8 |
from web3 import Web3
|
9 |
-
from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
10 |
-
from app_value_locked import fetch_daily_value_locked
|
11 |
import os
|
12 |
|
13 |
-
|
|
|
|
|
|
|
14 |
|
|
|
|
|
15 |
# Initialize a Web3 instance
|
16 |
web3 = Web3(Web3.HTTPProvider(OPTIMISM_RPC_URL))
|
17 |
|
@@ -30,7 +35,7 @@ with open('./contracts/service_registry_abi.json', 'r') as abi_file:
|
|
30 |
service_registry = web3.eth.contract(address=contract_address, abi=contract_abi)
|
31 |
|
32 |
def get_transfers(integrator: str, wallet: str) -> str:
|
33 |
-
url = f"https://li.quest/v1/analytics/transfers?&wallet={wallet}"
|
34 |
headers = {"accept": "application/json"}
|
35 |
response = requests.get(url, headers=headers)
|
36 |
return response.json()
|
@@ -154,6 +159,7 @@ def process_transactions_and_agents(data):
|
|
154 |
})
|
155 |
|
156 |
df_transactions = pd.DataFrame(rows)
|
|
|
157 |
df_agents = pd.DataFrame(list(daily_agent_counts.items()), columns=['date', 'agent_count'])
|
158 |
df_agents_with_transactions = pd.DataFrame(list(daily_agents_with_transactions.items()), columns=['date', 'agent_count_with_transactions'])
|
159 |
|
@@ -177,62 +183,63 @@ def create_visualizations():
|
|
177 |
df_transactions, df_agents_weekly, df_agents_with_transactions_weekly, df_agents_with_transactions = process_transactions_and_agents(transactions_data)
|
178 |
# Map chain IDs to chain names
|
179 |
|
180 |
-
|
181 |
-
df_tvl = fetch_daily_value_locked()
|
182 |
-
|
183 |
-
# Calculate total value locked per chain per day
|
184 |
-
df_tvl["total_value_locked_usd"] = df_tvl["amount0_usd"] + df_tvl["amount1_usd"]
|
185 |
-
df_tvl_daily = df_tvl.groupby(["date", "chain_name"])["total_value_locked_usd"].sum().reset_index()
|
186 |
-
df_tvl_daily['date'] = pd.to_datetime(df_tvl_daily['date'])
|
187 |
-
|
188 |
-
# Filter out dates with zero total value locked
|
189 |
-
df_tvl_daily = df_tvl_daily[df_tvl_daily["total_value_locked_usd"] > 0]
|
190 |
-
chain_name_map = {
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
}
|
195 |
-
df_tvl_daily["chain_name"] = df_tvl_daily["chain_name"].map(chain_name_map)
|
196 |
|
197 |
-
# Plot total value locked
|
198 |
-
fig_tvl = px.bar(
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
)
|
213 |
-
fig_tvl.update_layout(
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
)
|
229 |
-
fig_tvl.update_xaxes(tickformat="%b %d")
|
230 |
|
231 |
|
232 |
chain_name_map = {
|
233 |
10: "Optimism",
|
234 |
8453: "Base",
|
235 |
-
1: "Ethereum"
|
|
|
236 |
}
|
237 |
df_transactions["sending_chain"] = df_transactions["sending_chain"].map(chain_name_map)
|
238 |
df_transactions["receiving_chain"] = df_transactions["receiving_chain"].map(chain_name_map)
|
@@ -428,17 +435,17 @@ def create_visualizations():
|
|
428 |
)
|
429 |
)
|
430 |
|
431 |
-
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_agents_with_transactions_daily
|
432 |
|
433 |
# Gradio interface
|
434 |
def dashboard():
|
435 |
with gr.Blocks() as demo:
|
436 |
gr.Markdown("# Valory Transactions Dashboard")
|
437 |
-
with gr.Tab("Chain Daily activity"):
|
438 |
-
|
439 |
-
|
440 |
|
441 |
-
fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_agents_with_transactions_daily
|
442 |
#Fetch and display visualizations
|
443 |
with gr.Tab("Swaps Daily"):
|
444 |
gr.Plot(fig_swaps_chain)
|
@@ -451,14 +458,14 @@ def dashboard():
|
|
451 |
#fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily,fig_tvl = create_visualizations()
|
452 |
gr.Plot(fig_agents_registered)
|
453 |
|
454 |
-
with gr.Tab("DAA"):
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
with gr.Tab("Total Value Locked"):
|
460 |
-
|
461 |
-
|
462 |
|
463 |
return demo
|
464 |
|
|
|
6 |
from datetime import datetime, timedelta
|
7 |
import json
|
8 |
from web3 import Web3
|
9 |
+
# from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
10 |
+
# from app_value_locked import fetch_daily_value_locked
|
11 |
import os
|
12 |
|
13 |
+
from dotenv import load_dotenv
|
14 |
+
|
15 |
+
# Load environment variables from .env file
|
16 |
+
load_dotenv()
|
17 |
|
18 |
+
OPTIMISM_RPC_URL = os.getenv('OPTIMISM_RPC_URL')
|
19 |
+
print('OPTIMISM_RPC_URL',OPTIMISM_RPC_URL)
|
20 |
# Initialize a Web3 instance
|
21 |
web3 = Web3(Web3.HTTPProvider(OPTIMISM_RPC_URL))
|
22 |
|
|
|
35 |
service_registry = web3.eth.contract(address=contract_address, abi=contract_abi)
|
36 |
|
37 |
def get_transfers(integrator: str, wallet: str) -> str:
|
38 |
+
url = f"https://li.quest/v1/analytics/transfers?&wallet={wallet}&fromTimestamp=1726165800"
|
39 |
headers = {"accept": "application/json"}
|
40 |
response = requests.get(url, headers=headers)
|
41 |
return response.json()
|
|
|
159 |
})
|
160 |
|
161 |
df_transactions = pd.DataFrame(rows)
|
162 |
+
breakpoint()
|
163 |
df_agents = pd.DataFrame(list(daily_agent_counts.items()), columns=['date', 'agent_count'])
|
164 |
df_agents_with_transactions = pd.DataFrame(list(daily_agents_with_transactions.items()), columns=['date', 'agent_count_with_transactions'])
|
165 |
|
|
|
183 |
df_transactions, df_agents_weekly, df_agents_with_transactions_weekly, df_agents_with_transactions = process_transactions_and_agents(transactions_data)
|
184 |
# Map chain IDs to chain names
|
185 |
|
186 |
+
# # Fetch daily value locked data
|
187 |
+
# df_tvl = fetch_daily_value_locked()
|
188 |
+
|
189 |
+
# # Calculate total value locked per chain per day
|
190 |
+
# df_tvl["total_value_locked_usd"] = df_tvl["amount0_usd"] + df_tvl["amount1_usd"]
|
191 |
+
# df_tvl_daily = df_tvl.groupby(["date", "chain_name"])["total_value_locked_usd"].sum().reset_index()
|
192 |
+
# df_tvl_daily['date'] = pd.to_datetime(df_tvl_daily['date'])
|
193 |
+
|
194 |
+
# # Filter out dates with zero total value locked
|
195 |
+
# df_tvl_daily = df_tvl_daily[df_tvl_daily["total_value_locked_usd"] > 0]
|
196 |
+
# chain_name_map = {
|
197 |
+
# "optimism": "Optimism",
|
198 |
+
# "base": "Base",
|
199 |
+
# "ethereum": "Ethereum"
|
200 |
+
# }
|
201 |
+
# df_tvl_daily["chain_name"] = df_tvl_daily["chain_name"].map(chain_name_map)
|
202 |
|
203 |
+
# # Plot total value locked
|
204 |
+
# fig_tvl = px.bar(
|
205 |
+
# df_tvl_daily,
|
206 |
+
# x="date",
|
207 |
+
# y="total_value_locked_usd",
|
208 |
+
# color="chain_name",
|
209 |
+
# opacity=0.7,
|
210 |
+
# title="Total Volume Invested in Pools in Different Chains Daily",
|
211 |
+
# labels={"date": "Date","chain_name": "Transaction Chain", "total_value_locked_usd": "Total Volume Invested (USD)"},
|
212 |
+
# barmode='stack',
|
213 |
+
# color_discrete_map={
|
214 |
+
# "Optimism": "blue",
|
215 |
+
# "Base": "purple",
|
216 |
+
# "Ethereum": "darkgreen"
|
217 |
+
# }
|
218 |
+
# )
|
219 |
+
# fig_tvl.update_layout(
|
220 |
+
# xaxis_title=None,
|
221 |
+
# yaxis=dict(tickmode='linear', tick0=0, dtick=1),
|
222 |
+
# xaxis=dict(
|
223 |
+
# tickmode='array',
|
224 |
+
# tickvals=df_tvl_daily['date'],
|
225 |
+
# ticktext=df_tvl_daily['date'].dt.strftime('%b %d'),
|
226 |
+
# tickangle=-45,
|
227 |
+
# ),
|
228 |
+
# bargap=0.6, # Increase gap between bar groups (0-1)
|
229 |
+
# bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
230 |
+
# height=600, # Specify width to prevent bars from being too wide
|
231 |
+
# margin=dict(l=50, r=50, t=50, b=50), # Add margins
|
232 |
+
# showlegend=True,
|
233 |
+
# template='plotly_white'
|
234 |
+
# )
|
235 |
+
# fig_tvl.update_xaxes(tickformat="%b %d")
|
236 |
|
237 |
|
238 |
chain_name_map = {
|
239 |
10: "Optimism",
|
240 |
8453: "Base",
|
241 |
+
1: "Ethereum",
|
242 |
+
34443: "Mode"
|
243 |
}
|
244 |
df_transactions["sending_chain"] = df_transactions["sending_chain"].map(chain_name_map)
|
245 |
df_transactions["receiving_chain"] = df_transactions["receiving_chain"].map(chain_name_map)
|
|
|
435 |
)
|
436 |
)
|
437 |
|
438 |
+
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_agents_with_transactions_daily
|
439 |
|
440 |
# Gradio interface
|
441 |
def dashboard():
|
442 |
with gr.Blocks() as demo:
|
443 |
gr.Markdown("# Valory Transactions Dashboard")
|
444 |
+
# with gr.Tab("Chain Daily activity"):
|
445 |
+
# fig_tx_chain = create_transcation_visualizations()
|
446 |
+
# gr.Plot(fig_tx_chain)
|
447 |
|
448 |
+
fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_agents_with_transactions_daily = create_visualizations()
|
449 |
#Fetch and display visualizations
|
450 |
with gr.Tab("Swaps Daily"):
|
451 |
gr.Plot(fig_swaps_chain)
|
|
|
458 |
#fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily,fig_tvl = create_visualizations()
|
459 |
gr.Plot(fig_agents_registered)
|
460 |
|
461 |
+
# with gr.Tab("DAA"):
|
462 |
+
# fig_agents_with_transactions_daily = create_active_agents_visualizations()
|
463 |
+
# #fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily,fig_tvl = create_visualizations()
|
464 |
+
# gr.Plot(fig_agents_with_transactions_daily)
|
465 |
+
|
466 |
+
# with gr.Tab("Total Value Locked"):
|
467 |
+
# #fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily, fig_tvl,fig_tvl = create_visualizations()
|
468 |
+
# gr.Plot(fig_tvl)
|
469 |
|
470 |
return demo
|
471 |
|