diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 423dc86..1c9163d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: - name: Set up Python environment uses: actions/setup-python@v1 with: - python-version: "3.8" + python-version: "3.9" - name: flake8 Lint uses: py-actions/flake8@v1 with: diff --git a/src/constants.py b/src/constants.py index 66aef77..7bd1d4a 100755 --- a/src/constants.py +++ b/src/constants.py @@ -69,11 +69,9 @@ if os.environ.get('ENV') == 'production': KLIMA_PROTOCOL_SUBGRAPH = GRAPH_BASE_URL + PROTOCOL_SUBGRAPH_ID - KLIMA_CARBON_SUBGRAPH = GRAPH_BASE_URL + CARBON_SUBGRAPH_ID KLIMA_BONDS_SUBGRAPH = GRAPH_BASE_URL + BONDS_SUBGRAPH_ID POLYGON_DIGITAL_CARBON_SUBGRAPH = GRAPH_BASE_URL + POLYGON_DIGITAL_CARBON_ID else: KLIMA_PROTOCOL_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-klimadao-protocol-metrics' + GRAPH_VERSION_SUFFIX - KLIMA_CARBON_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-polygon-bridged-carbon' + GRAPH_VERSION_SUFFIX KLIMA_BONDS_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-klimadao-bonds' + GRAPH_VERSION_SUFFIX POLYGON_DIGITAL_CARBON_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-polygon-digital-carbon' + GRAPH_VERSION_SUFFIX diff --git a/src/retirement_fee_info/main.py b/src/retirement_fee_info/main.py index 7a8d30b..afc9cba 100644 --- a/src/retirement_fee_info/main.py +++ b/src/retirement_fee_info/main.py @@ -1,11 +1,14 @@ import os from discord.ext import tasks +from web3 import Web3 from subgrounds.subgrounds import Subgrounds from ..time_utils import get_days_ago_timestamp -from ..constants import KLIMA_CARBON_SUBGRAPH +from ..constants import POLYGON_DIGITAL_CARBON_SUBGRAPH, \ + BCT_ADDRESS, UBO_ADDRESS, NBO_ADDRESS, MCO2_ADDRESS, NCT_ADDRESS + from ..utils import get_discord_client, \ update_nickname, update_presence, \ prettify_number @@ -17,59 +20,71 @@ sg = Subgrounds() -offsets = ["BCT", "MCO2", "UBO", "NBO", "NCT"] +pool_names = ["BCT", "MCO2", "UBO", "NBO", "NCT"] +pool_addresses = { + 'BCT': BCT_ADDRESS, + 'NBO': NBO_ADDRESS, + 'UBO': UBO_ADDRESS, + 'NCT': NCT_ADDRESS, + 'MCO2': MCO2_ADDRESS +} counter = 0 def get_info(): global counter - currentOffset = offsets[counter] + current_pool = pool_names[counter] ts = get_days_ago_timestamp(7) - w_offset_amount = get_retirement_fees(sg, - ts, - currentOffset) + w_retired_amount = get_retirement_fees(sg, ts, current_pool) counter += 1 - if counter == len(offsets): + if counter == len(pool_names): counter = 0 - return w_offset_amount, currentOffset + return w_retired_amount, current_pool -def get_retirement_fees(sg, timestamp, offset): +def get_retirement_fees(sg, timestamp, pool): ''' param `sg`: Initialized subgrounds object param `timestamp`: Timestamp used for cutoff date (data created after the provided date will be fetched) - param `offset`: Specific Offset for which amount and fee will be retrieved + param `pool`: Specific pool for which amount and fee will be retrieved returns: - `w_offset_amount`: Total amount provided from retirements + `w_pool_amount`: Total amount provided from retirements ''' try: - kbm = sg.load_subgraph(KLIMA_CARBON_SUBGRAPH) + pdc = sg.load_subgraph(POLYGON_DIGITAL_CARBON_SUBGRAPH) - retirement_df = kbm.Query.dailyKlimaRetirements( - where=[kbm.DailyKlimaRetirement.timestamp > timestamp] + retirement_df = pdc.Query.dailyKlimaRetireSnapshots( + where=[pdc.Query.dailyKlimaRetireSnapshots.timestamp > timestamp] ) retirement_df = sg.query_df( [retirement_df.amount, retirement_df.feeAmount, - retirement_df.token]) + retirement_df.pool]) if retirement_df.size == 0: return 0, 0, 0 - w_offset_amount = retirement_df.loc[ - retirement_df['dailyKlimaRetirements_token'] == offset, - 'dailyKlimaRetirements_amount'].sum() + retirement_df['dailyKlimaRetireSnapshots_pool'] = retirement_df.dailyKlimaRetireSnapshots_pool.apply( + lambda x: Web3.to_checksum_address(x) + ) + + w_pool_amount = retirement_df.loc[ + retirement_df['dailyKlimaRetireSnapshots_pool'] == pool_addresses[pool], + 'dailyKlimaRetireSnapshots_amount' + ].sum() - return w_offset_amount + return w_pool_amount - except Exception: + # TODO: clean up this bad practice and add better monitoring for bots going down + except Exception as e: + print(e) return None @@ -83,12 +98,14 @@ async def on_ready(): # Loop time set to 2mins @tasks.loop(seconds=120) async def update_info(): - offset_amount, offset = get_info() + pool_amount, pool = get_info() + + print(pool_amount, pool) - if offset_amount and offset is not None: + if pool_amount and pool is not None: - offset_text = f'Retired {offset}: {prettify_number(offset_amount)}t' - success = await update_nickname(client, offset_text) + pool_text = f'Retired {pool}: {prettify_number(pool_amount)}t' + success = await update_nickname(client, pool_text) if not success: return