Skip to content

Commit

Permalink
list improvement and stellar token price
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Sep 26, 2024
1 parent 44ff64e commit 0dc2907
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 57 deletions.
26 changes: 26 additions & 0 deletions grantpicks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from django.utils.translation import gettext_lazy as _

from datetime import datetime

from base.logging import logger

from accounts.models import Account
from pots.models import PotApplication
from tokens.models import Token
Expand Down Expand Up @@ -313,6 +317,28 @@ class Round(models.Model):
)




def update_vault_usd_equivalent(self):
# first, see if there is a TokenHistoricalPrice within 1 day (or HISTORICAL_PRICE_QUERY_HOURS) of self.paid_at
try:
token = Token.objects.get(account_id="stellar")
price_usd = token.fetch_usd_prices_common(datetime.now())
if not price_usd:
logger.info(
f"No USD price found for token {token.symbol} at {datetime.now()}"
)
return
self.vault_total_deposits_usd = token.format_price(self.vault_total_deposits) * price_usd
self.current_vault_balance_usd = token.format_price(self.current_vault_balance) * price_usd
self.save()
logger.info(
f"Saved USD prices for round vault for round id: {self.id}"
)
except Exception as e:
logger.error(f"Failed to calculate and stellar vault USD prices: {e}")


class RoundDeposit(models.Model):
id = models.AutoField(
_("deposit id"),
Expand Down
16 changes: 14 additions & 2 deletions indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
handle_add_nadabot_admin, # handle_batch_donations,
handle_add_stamp,
handle_default_list_status_change,
handle_delete_list,
handle_list_admin_removal,
handle_list_registration_update,
handle_list_upvote,
handle_new_donation,
handle_new_group,
handle_new_list,
handle_new_list_and_reg,
handle_new_list_registration,
handle_new_nadabot_registry,
handle_new_pot,
Expand Down Expand Up @@ -133,6 +135,10 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
await handle_registry_unblacklist_action(
parsed_log.get("data")[0], receiver_id, now_datetime
)
if event_name == "delete_list":
await handle_delete_list(
parsed_log.get("data")[0]
)
except json.JSONDecodeError:
logger.warning(
f"Receipt ID: `{receipt_execution_outcome.receipt.receipt_id}`\nError during parsing logs from JSON string to dict"
Expand Down Expand Up @@ -411,15 +417,15 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
logger.info(f"creating list... {args_dict}, {action}")
if receiver_id != LISTS_CONTRACT:
break
await handle_new_list(signer_id, receiver_id, status_obj)
await handle_new_list(signer_id, receiver_id, status_obj, None)
break

case "upvote":
logger.info(f"up voting... {args_dict}")
if receiver_id != LISTS_CONTRACT:
break
await handle_list_upvote(
args_dict, receiver_id, signer_id, receipt.receipt_id
args_dict, receiver_id, signer_id, receipt.receipt_id, now_datetime
)
break
case "owner_add_admins":
Expand All @@ -444,6 +450,12 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
logger.info(f"updating configs.. {args_dict}")
await handle_set_factory_configs(args_dict, receiver_id)
break
case "create_list_with_registrations":
logger.info(f"creating list... {args_dict}, {action}")
if receiver_id != LISTS_CONTRACT:
break
await handle_new_list_and_reg(signer_id, receiver_id, status_obj, receipt)
break
# TODO: handle remove upvote

except Exception as e:
Expand Down
44 changes: 21 additions & 23 deletions indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pots.models import Pot, PotApplication, PotApplicationStatus, PotPayout

from .logging import logger
from .utils import create_or_update_round, create_round_application, get_block_height, get_ledger_sequence, process_application_to_round, process_project_event, process_rounds_deposit_event, process_vote_event, save_block_height, update_application, update_approved_projects, update_ledger_sequence
from .utils import create_or_update_round, create_round_application, create_round_payout, get_block_height, get_ledger_sequence, process_application_to_round, process_project_event, process_rounds_deposit_event, process_vote_event, save_block_height, update_application, update_approved_projects, update_ledger_sequence, update_round_payout

CURRENT_BLOCK_HEIGHT_KEY = "current_block_height"

Expand Down Expand Up @@ -403,43 +403,41 @@ def process_stellar_events():
event_name = event.event_type

if event_name == 'c_project':
process_project_event(event_data)
event.processed = True
event.processed = process_project_event(event_data)

elif event_name == 'c_round' or event_name == 'u_round':
create_or_update_round(event_data, event.contract_id, event.ingested_at)

# Mark event as processed
event.processed = True
event.processed = create_or_update_round(event_data, event.contract_id, event.ingested_at)

elif event_name == 'apply_to_round':
process_application_to_round(event_data, event.transaction_hash)

# Mark event as processed
event.processed = True
event.processed = process_application_to_round(event_data, event.transaction_hash)

elif event_name == 'c_app':
create_round_application(event_data, event.transaction_hash)
event.processed = True

event.processed = create_round_application(event_data, event.transaction_hash)


elif event_name == 'u_app': # application review and aproval
jobs_logger.info(f"eventulating data for event, {event_data}")
update_application(event_data, event.transaction_hash)
event.processed = True
elif event_name == 'u_app': # application review and aproval
event.processed = update_application(event_data, event.transaction_hash)

elif event_name == 'u_ap':
jobs_logger.info(f"eventulating data for approved project event, {event_data}")
update_approved_projects(event_data)
event.processed = True
elif event_name == 'u_ap':
event.processed = update_approved_projects(event_data)

elif event_name == 'c_depo':
process_rounds_deposit_event(event_data, event.transaction_hash)
# Mark event as processed
event.processed = True

event.processed = process_rounds_deposit_event(event_data, event.transaction_hash)

elif event_name == 'c_vote':
process_vote_event(event_data, event.transaction_hash)
# Mark event as processed
event.processed = True

event.processed = process_vote_event(event_data, event.transaction_hash)
elif event_name == "c_pay":
event.processed = create_round_payout(event_data, event.transaction_hash)
elif event_name == "u_pay":

event.processed = update_round_payout(event_data, event.transaction_hash)
event.save()

except Exception as e:
Expand Down
Loading

0 comments on commit 0dc2907

Please sign in to comment.