Skip to content

Commit

Permalink
revenue and fee dashboard v0 finalized bug resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
naik-ai committed Oct 9, 2024
1 parent 2224e1f commit d3cae8b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/integrations/all_bridge_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from requests.exceptions import HTTPError, RequestException, Timeout

from src.integrations.models.all_bridge_explorer import (
AllBridgeExplorerTokenInfo,
AllBridgeExplorerTransfer,
)
AllBridgeExplorerTokenInfo, AllBridgeExplorerTransfer)
from src.integrations.utilities import get_raw_from_bq, pydantic_schema_to_list

# Base URL for the API
Expand Down Expand Up @@ -111,7 +109,9 @@ def get_all_bridge_explorer_latest_transfers(
logging.error(f"Bad request error for URL: {url}. Error: {str(e)}")
raise # Don't retry on 400 errors
if attempt < max_retries - 1:
delay = (base_delay * 2**attempt) + (random.randint(0, 1000) / 1000)
delay = (base_delay * 2**attempt) + (
random.randint(0, 1000) / 1000
)
logging.warning(
f"Request failed. Retrying in {delay:.2f} seconds..."
)
Expand Down
25 changes: 11 additions & 14 deletions src/streamlit_everclear/pages/2_Revenue_&_fees.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import logging
import pandas as pd
from datetime import datetime, timedelta

import pandas as pd
import pytz
import streamlit as st
from setup import (
get_raw_data_from_postgres_by_sql,
get_chain_id_to_chain_name_data_from_bq,
get_raw_data_from_bq_df,
get_db_url,
get_raw_data_from_bq_df,
get_raw_data_from_postgres_by_sql,
)

# TODO:

# [ ] Adding Revenue
# [ ] Adding Fees - gas fee paid - by Everclear for message (Relay)
# [ ] Adding Message Cost - by Everclear for message Cost
# [ ] Add Date: Lasty X days

# calculations steps for each
# 1. Revenue -> 1 bps fo orgin amount
# 2. Discount applied to invoice if any - per intent
# 3. pricing rate per intent by different timestamps
st.set_page_config(layout="wide")


def apply_sidebar_filters(
Expand Down Expand Up @@ -222,6 +213,11 @@ def calculate_revenue_fees_metrics(cdf):
inplace=True,
)
df["revenue_usd"] = df["origin_amount_usd"] * 0.0001
# when status is not settled_and_completed revenue and hub status is dispatched_and_unsupported is 0
df.loc[
(df["hub_status"] == "DISPATCHED_UNSUPPORTED"),
"revenue_usd",
] = 0
# total cost
df["total_cost_usd"] = (
df["intent_message_cost_usd"]
Expand All @@ -239,6 +235,7 @@ def calculate_revenue_fees_metrics(cdf):
cols_to_keep = [
"id",
"status",
"hub_status",
"origin_timestamp",
"settlement_timestamp",
# chain and token
Expand Down
1 change: 1 addition & 0 deletions src/streamlit_everclear/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Adding the streamlit pages to the sidebar
import logging
import os

import pandas as pd
import pandas_gbq as gbq
import streamlit as st
Expand Down
41 changes: 0 additions & 41 deletions src/streamlit_everclear/sql/revenue_fee_gas_per_intent.sql
Original file line number Diff line number Diff line change
Expand Up @@ -204,44 +204,3 @@ FROM
SELECT
*
FROM semi s







WITH raw AS (

SELECT
m.id AS message_id,
m.message_status,
m.type,
unnest(m.intent_ids) AS intent_ids,
origin_domain,
destination_domain,
array_length(m.intent_ids, 1) AS intent_count,
(m.gas_price::float * m.gas_limit::float) / array_length(m.intent_ids, 1) AS gas_amount_per_intent,
m.quote::float / array_length(m.intent_ids, 1) AS quote_per_intent
FROM
public.messages m

)


SELECT
*
FROM raw r
WHERE intent_ids= '0xf99092486cb398504e688b19adb536e208f85fa709f8d901863b769e1b5455bc'



SELECT
*
FROM public.messages m
WHERE m.id = '0xb50dda0adf08d1328ce8530527f8d8069910ff90e7a141c05c72483775b6cf61'





0 comments on commit d3cae8b

Please sign in to comment.