diff --git a/accounts/api.py b/accounts/api.py index 3f2566a..f4f9f5f 100644 --- a/accounts/api.py +++ b/accounts/api.py @@ -199,7 +199,7 @@ def get(self, request: Request, *args, **kwargs): applicant=account, status=PotApplicationStatus.APPROVED ) pot_ids = applications.values_list("pot_id", flat=True) - pots = Pot.objects.filter(id__in=pot_ids) + pots = Pot.objects.filter(account__in=pot_ids) if request.query_params.get("status") == "live": pots = pots.filter( matching_round_start__lte=now, matching_round_end__gte=now diff --git a/donations/admin.py b/donations/admin.py index a9b1769..0103da2 100644 --- a/donations/admin.py +++ b/donations/admin.py @@ -21,7 +21,7 @@ class DonationAdmin(admin.ModelAdmin): "message", "donor__id", ) # Correct field name from 'donor__address' to 'donor__id' if 'id' is used in the model - list_filter = ("donated_at", "donor", "pot", "pot__id") + list_filter = ("donated_at", "donor", "pot", "pot__account") date_hierarchy = "donated_at" ordering = ("-donated_at",) @@ -43,7 +43,7 @@ def recipient_address(self, obj): return obj.recipient.id if obj.recipient else None def token_address(self, obj): - return obj.token.id + return obj.token.account def referrer_address(self, obj): return obj.referrer.id if obj.referrer else None diff --git a/donations/models.py b/donations/models.py index 21e8e1f..824be55 100644 --- a/donations/models.py +++ b/donations/models.py @@ -209,7 +209,7 @@ def fetch_usd_prices(self): price_usd = token.fetch_usd_prices_common(self.donated_at) if not price_usd: logger.info( - f"No USD price found for token {token.name} ({token.id.id}) at {self.donated_at}" + f"No USD price found for token {token.name} ({token.account.id}) at {self.donated_at}" ) return total_amount = token.format_price(self.total_amount) diff --git a/indexer_app/management/commands/populatedata.py b/indexer_app/management/commands/populatedata.py index 7d816e7..4d94246 100644 --- a/indexer_app/management/commands/populatedata.py +++ b/indexer_app/management/commands/populatedata.py @@ -158,7 +158,7 @@ def handle(self, *args, **options): if "decimals" in ft_metadata: token_defaults["decimals"] = ft_metadata["decimals"] ft_token, _ = Token.objects.update_or_create( - id=ft_acct, defaults=token_defaults + account=ft_acct, defaults=token_defaults ) if donation.get("referrer_id"): referrer, _ = Account.objects.get_or_create( @@ -260,7 +260,7 @@ def handle(self, *args, **options): if config.get("chef"): chef, _ = Account.objects.get_or_create(id=config["chef"]) pot_defaults = { - "pot_factory_id": POTFACTORY_ID, + "pot_factory_account": POTFACTORY_ID, "owner_id": config["owner"], "chef_id": config["chef"], "name": config["pot_name"], @@ -311,7 +311,7 @@ def handle(self, *args, **options): "protocol_config_provider": config["protocol_config_provider"], } pot, created = Pot.objects.update_or_create( - id=pot_acct, defaults=pot_defaults + account=pot_acct, defaults=pot_defaults ) print("pot created? ", created) print("adding admins") @@ -427,7 +427,7 @@ def handle(self, *args, **options): # pot donations always NEAR ft_acct, _ = Account.objects.get_or_create(id="near") - ft_token, _ = Token.objects.get_or_create(id=ft_acct) + ft_token, _ = Token.objects.get_or_create(account=ft_acct) donation_defaults = { "donor": donor, "total_amount": donation["total_amount"], @@ -483,7 +483,7 @@ def handle(self, *args, **options): recipient, _ = Account.objects.get_or_create( id=payout["project_id"] ) - near_token, _ = Token.objects.get_or_create(id=near_acct) + near_token, _ = Token.objects.get_or_create(account=near_acct) payout_defaults = { "pot": pot, "recipient": recipient, diff --git a/indexer_app/tasks.py b/indexer_app/tasks.py index dd2175e..c0853c1 100644 --- a/indexer_app/tasks.py +++ b/indexer_app/tasks.py @@ -200,7 +200,7 @@ def update_pot_statistics(): matching_pool_donations = Donation.objects.filter(pot=pot, matching_pool=True) public_donations = Donation.objects.filter(pot=pot, matching_pool=False) try: - print(f"Processing pot: {pot.id}") + print(f"Processing pot: {pot.account}") # total matching pool pot.total_matching_pool = sum( @@ -219,17 +219,17 @@ def update_pot_statistics(): jobs_logger.info(f"Total matching pool USD: {pot.total_matching_pool_usd}") # matching pool balance (get from contract) - url = f"{settings.FASTNEAR_RPC_URL}/account/{pot.id.id}/view/get_config" + url = f"{settings.FASTNEAR_RPC_URL}/account/{pot.account.id}/view/get_config" response = requests.get(url) if response.status_code != 200: jobs_logger.error( - f"Failed to get matching pool balance for pot {pot.id}: {response.text}" + f"Failed to get matching pool balance for pot {pot.account}: {response.text}" ) else: data = response.json() pot.matching_pool_balance = data["matching_pool_balance"] jobs_logger.info( - f"Matching pool balance for pot {pot.id}: {pot.matching_pool_balance}" + f"Matching pool balance for pot {pot.account}: {pot.matching_pool_balance}" ) # matching pool donations count @@ -273,7 +273,7 @@ def update_pot_statistics(): ] ) except Exception as e: - jobs_logger.error(f"Failed to update statistics for pot {pot.id}: {e}") + jobs_logger.error(f"Failed to update statistics for pot {pot.account}: {e}") @shared_task diff --git a/indexer_app/utils.py b/indexer_app/utils.py index 552f1fe..d583bb1 100644 --- a/indexer_app/utils.py +++ b/indexer_app/utils.py @@ -60,7 +60,7 @@ async def handle_new_nadabot_registry( registry, _ = await Account.objects.aget_or_create(id=receiverId) owner, _ = await Account.objects.aget_or_create(id=data["owner"]) nadabot_registry, created = await NadabotRegistry.objects.aupdate_or_create( - id=registry, + account=registry, owner=owner, created_at=created_at, updated_at=created_at, @@ -140,7 +140,7 @@ async def handle_new_pot( # Create Pot object logger.info(f"creating pot with owner {owner_id}....") pot_defaults = { - "pot_factory_id": predecessorId, + "pot_factory_account": predecessorId, "deployer": signer, "deployed_at": created_at, "source_metadata": data["source_metadata"], @@ -186,7 +186,7 @@ async def handle_new_pot( "protocol_config_provider": data["protocol_config_provider"], } pot, created = await Pot.objects.aupdate_or_create( - id=receiver, defaults=pot_defaults + account=receiver, defaults=pot_defaults ) # Add admins to the Pot @@ -264,7 +264,7 @@ async def handle_pot_config_update( } pot, created = await Pot.objects.aupdate_or_create( - id=receiver_id, defaults=pot_config + account=receiver_id, defaults=pot_config ) if data.get("admins"): @@ -304,7 +304,7 @@ async def handle_new_pot_factory(data: dict, receiver_id: str, created_at: datet } # Create Factory object factory, factory_created = await PotFactory.objects.aupdate_or_create( - id=receiver, defaults=defaults + account=receiver, defaults=defaults ) # Add admins to the PotFactory @@ -663,10 +663,10 @@ async def handle_set_payouts(data: dict, receiver_id: str, receipt: Receipt): logger.info(f"set payout data: {data}, {receiver_id}") payouts = data.get("payouts", []) - pot = await Pot.objects.aget(id=receiver_id) + pot = await Pot.objects.aget(account=receiver_id) near_acct, _ = await Account.objects.aget_or_create(id="near") near_token, _ = await Token.objects.aget_or_create( - id=near_acct + account=near_acct ) # Pots only support native NEAR insertion_data = [] @@ -783,7 +783,7 @@ async def handle_list_admin_removal(data, receiver_id, signer_id, receiptId): async def handle_add_nadabot_admin(data, receiverId): logger.info(f"adding admin...: {data}, {receiverId}") try: - obj = await NadabotRegistry.objects.aget(id=receiverId) + obj = await NadabotRegistry.objects.aget(account=receiverId) for acct in data["account_ids"]: user, _ = await Account.objects.aget_or_create(id=acct) @@ -842,6 +842,8 @@ async def handle_new_donation( ) try: + # insert donate contract which is the receiver id(because of activity relationship mainly) + donate_contract, _ = await Account.objects.aget_or_create(id=receiver_id) # Upsert donor account donor, _ = await Account.objects.aget_or_create(id=donation_data["donor_id"]) recipient = None @@ -891,7 +893,7 @@ async def handle_new_donation( if "decimals" in ft_metadata: token_defaults["decimals"] = ft_metadata["decimals"] token, _ = await Token.objects.aupdate_or_create( - id=token_acct, defaults=token_defaults + account=token_acct, defaults=token_defaults ) except Exception as e: @@ -923,7 +925,7 @@ async def handle_new_donation( } if donation_type == "pot": - default_data["pot"] = await Pot.objects.aget(id=receiver_id) + default_data["pot"] = await Pot.objects.aget(account=receiver_id) logger.info(f"default donation data: {default_data}") @@ -1033,7 +1035,7 @@ async def handle_update_default_human_threshold(data: dict, receiverId: str): try: - reg = await NadabotRegistry.objects.filter(id=receiverId).aupdate( + reg = await NadabotRegistry.objects.filter(account=receiverId).aupdate( **{"default_human_threshold": data["default_human_threshold"]} ) logger.info("updated threshold..") diff --git a/nadabot/migrations/0002_rename_id_nadabotregistry_account.py b/nadabot/migrations/0002_rename_id_nadabotregistry_account.py new file mode 100644 index 0000000..eb5beda --- /dev/null +++ b/nadabot/migrations/0002_rename_id_nadabotregistry_account.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.6 on 2024-07-19 22:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("nadabot", "0001_initial"), + ] + + operations = [ + migrations.RenameField( + model_name="nadabotregistry", + old_name="id", + new_name="account", + ), + ] diff --git a/nadabot/models.py b/nadabot/models.py index 971d9da..e0b6cdf 100644 --- a/nadabot/models.py +++ b/nadabot/models.py @@ -20,7 +20,7 @@ class RuleType(models.TextChoices): class NadabotRegistry(models.Model): - id = models.OneToOneField( + account = models.OneToOneField( Account, related_name="registry_id", on_delete=models.CASCADE, diff --git a/pots/admin.py b/pots/admin.py index 54159b4..100d23f 100644 --- a/pots/admin.py +++ b/pots/admin.py @@ -38,8 +38,8 @@ def __init__(self, *args, **kwargs): @admin.register(PotFactory) class PotFactoryAdmin(admin.ModelAdmin): form = PotFactoryForm - list_display = ("id", "owner", "deployed_at") - search_fields = ("id", "owner__id") + list_display = ("account", "owner", "deployed_at") + search_fields = ("account", "owner__id") def get_form(self, request, obj=None, **kwargs): form = super(PotFactoryAdmin, self).get_form(request, obj, **kwargs) @@ -79,8 +79,8 @@ def __init__(self, *args, **kwargs): @admin.register(Pot) class PotAdmin(admin.ModelAdmin): form = PotForm - list_display = ("id", "pot_factory", "deployer", "deployed_at", "name") - search_fields = ("id", "name", "deployer__id") + list_display = ("account", "pot_factory", "deployer", "deployed_at", "name") + search_fields = ("account", "name", "deployer__id") list_filter = ("deployed_at",) def get_form(self, request, obj=None, **kwargs): @@ -118,7 +118,7 @@ def __init__(self, *args, **kwargs): class PotApplicationAdmin(admin.ModelAdmin): form = PotApplicationAdminForm list_display = ("id", "pot", "applicant", "status", "submitted_at") - search_fields = ("pot__id", "applicant__id") + search_fields = ("pot__account", "applicant__id") list_filter = ("status", "submitted_at") autocomplete_fields = ["applicant"] @@ -188,7 +188,7 @@ def application_applicant_id(self, obj): @admin.register(PotPayout) class PotPayoutAdmin(admin.ModelAdmin): list_display = ("id", "pot", "recipient", "amount", "amount_paid_usd", "paid_at") - search_fields = ("pot__id", "recipient__id") + search_fields = ("pot__account", "recipient__id") list_filter = ("paid_at",) def has_add_permission(self, request): @@ -204,7 +204,7 @@ def has_delete_permission(self, request, obj=None): @admin.register(PotPayoutChallenge) class PotPayoutChallengeAdmin(admin.ModelAdmin): list_display = ("id", "challenger", "pot", "message", "created_at") - search_fields = ("challenger__id", "pot__id") + search_fields = ("challenger__id", "pot__account") list_filter = ("created_at",) def has_add_permission(self, request): diff --git a/pots/api.py b/pots/api.py index b7aa8b5..2db837e 100644 --- a/pots/api.py +++ b/pots/api.py @@ -95,7 +95,7 @@ class PotDetailAPI(APIView): def get(self, request: Request, *args, **kwargs): pot_id = kwargs.get("pot_id") try: - pot = Pot.objects.get(id=pot_id) + pot = Pot.objects.get(account=pot_id) except Pot.DoesNotExist: return Response({"message": f"Pot with ID {pot_id} not found."}, status=404) serializer = PotSerializer(pot) @@ -129,7 +129,7 @@ class PotApplicationsAPI(APIView, PageNumberPagination): def get(self, request: Request, *args, **kwargs): pot_id = kwargs.get("pot_id") try: - pot = Pot.objects.get(id=pot_id) + pot = Pot.objects.get(account=pot_id) except Pot.DoesNotExist: return Response({"message": f"Pot with ID {pot_id} not found."}, status=404) @@ -166,7 +166,7 @@ class PotDonationsAPI(APIView, PageNumberPagination): def get(self, request: Request, *args, **kwargs): pot_id = kwargs.get("pot_id") try: - pot = Pot.objects.get(id=pot_id) + pot = Pot.objects.get(account=pot_id) except Pot.DoesNotExist: return Response({"message": f"Pot with ID {pot_id} not found."}, status=404) @@ -203,7 +203,7 @@ class PotSponsorsAPI(APIView, PageNumberPagination): def get(self, request: Request, *args, **kwargs): pot_id = kwargs.get("pot_id") try: - pot = Pot.objects.get(id=pot_id) + pot = Pot.objects.get(account=pot_id) except Pot.DoesNotExist: return Response({"message": f"Pot with ID {pot_id} not found."}, status=404) @@ -245,7 +245,7 @@ class PotPayoutsAPI(APIView, PageNumberPagination): def get(self, request: Request, *args, **kwargs): pot_id = kwargs.get("pot_id") try: - pot = Pot.objects.get(id=pot_id) + pot = Pot.objects.get(account=pot_id) except Pot.DoesNotExist: return Response({"message": f"Pot with ID {pot_id} not found."}, status=404) diff --git a/pots/migrations/0011_rename_id_pot_account_rename_id_potfactory_account.py b/pots/migrations/0011_rename_id_pot_account_rename_id_potfactory_account.py new file mode 100644 index 0000000..7ac40e8 --- /dev/null +++ b/pots/migrations/0011_rename_id_pot_account_rename_id_potfactory_account.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.6 on 2024-07-19 22:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("pots", "0010_alter_potpayout_paid_at"), + ] + + operations = [ + migrations.RenameField( + model_name="pot", + old_name="id", + new_name="account", + ), + migrations.RenameField( + model_name="potfactory", + old_name="id", + new_name="account", + ), + ] diff --git a/pots/models.py b/pots/models.py index ba326ae..2cb8e82 100644 --- a/pots/models.py +++ b/pots/models.py @@ -13,7 +13,7 @@ class PotFactory(models.Model): - id = models.OneToOneField( + account = models.OneToOneField( Account, primary_key=True, related_name="pot_factory", @@ -70,7 +70,7 @@ class Meta: class Pot(models.Model): - id = models.OneToOneField( + account = models.OneToOneField( Account, primary_key=True, related_name="pot", @@ -460,7 +460,7 @@ def fetch_usd_prices(self): return self.amount_paid_usd = token.format_price(self.amount) * price_usd self.save() - logger.info(f"Saved USD prices for pot payout for pot id: {self.pot.id}") + logger.info(f"Saved USD prices for pot payout for pot id: {self.pot.account}") except Exception as e: logger.error(f"Failed to calculate and save USD prices: {e}") diff --git a/pots/serializers.py b/pots/serializers.py index 901affd..0ad1d3f 100644 --- a/pots/serializers.py +++ b/pots/serializers.py @@ -15,7 +15,7 @@ class PotSerializer(ModelSerializer): class Meta: model = Pot fields = [ - "id", + "account", "pot_factory", "deployer", "deployed_at", @@ -99,7 +99,7 @@ class Meta: EXAMPLE_POT_ID = "some-pot.v1.potfactory.potlock.near" SIMPLE_POT_EXAMPLE = { - "id": "some-pot.v1.potfactory.potlock.near", + "account": "some-pot.v1.potfactory.potlock.near", "deployed_at": "2024-02-16T17:45:03.600845Z", "source_metadata": { "link": "https://github.com/PotLock/core", diff --git a/tokens/admin.py b/tokens/admin.py index b949d2b..6caa086 100644 --- a/tokens/admin.py +++ b/tokens/admin.py @@ -6,7 +6,7 @@ @admin.register(Token) class TokenAdmin(admin.ModelAdmin): list_display = ( - "id", + "account", "name", "symbol", "coingecko_id", @@ -14,7 +14,7 @@ class TokenAdmin(admin.ModelAdmin): "decimals", "get_most_recent_price", ) - search_fields = ("id",) + search_fields = ("account",) def get_most_recent_price(self, obj): price = obj.get_most_recent_price() @@ -35,7 +35,7 @@ def get_most_recent_price(self, obj): @admin.register(TokenHistoricalPrice) class TokenHistoricalPriceAdmin(admin.ModelAdmin): list_display = ("token", "timestamp", "price_usd") - search_fields = ("token__id",) + search_fields = ("token__account",) list_filter = ("timestamp",) # def has_add_permission(self, request): diff --git a/tokens/migrations/0006_rename_id_token_account.py b/tokens/migrations/0006_rename_id_token_account.py new file mode 100644 index 0000000..a485351 --- /dev/null +++ b/tokens/migrations/0006_rename_id_token_account.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.6 on 2024-07-19 22:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("tokens", "0005_alter_token_coingecko_id_alter_token_icon_and_more"), + ] + + operations = [ + migrations.RenameField( + model_name="token", + old_name="id", + new_name="account", + ), + ] diff --git a/tokens/models.py b/tokens/models.py index 5ff50dc..c32e742 100644 --- a/tokens/models.py +++ b/tokens/models.py @@ -14,7 +14,7 @@ class Token(models.Model): - id = models.OneToOneField( + account = models.OneToOneField( Account, on_delete=models.CASCADE, primary_key=True,