Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokentap contribution hub #262

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,8 @@ def to_checksum_address(address: str):
return Web3.to_checksum_address(address.lower())

@staticmethod
def hash_message(address, token, amount, nonce):
message_hash = Web3().solidity_keccak(
["address", "address", "uint256", "uint32"],
[
Web3.to_checksum_address(address),
Web3.to_checksum_address(token),
amount,
nonce,
],
)
def hash_message(abi_types, values):
message_hash = Web3.solidity_keccak(abi_types, values)
hashed_message = encode_defunct(hexstr=message_hash.hex())

return hashed_message
Expand Down
10 changes: 9 additions & 1 deletion tokenTap/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ def create_uint32_random_nonce():


def hash_message(address, token, amount, nonce):
hashed_message = Web3Utils.hash_message(address, token, amount, nonce)
hashed_message = Web3Utils.hash_message(
["address", "address", "uint256", "uint32"],
[
Web3Utils.to_checksum_address(address),
Web3Utils.to_checksum_address(token),
int(amount),
nonce,
],
)
return hashed_message


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 4.0.4 on 2024-01-13 08:45

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tokenTap', '0030_tokendistribution_distributor_address_and_more'),
]

operations = [
migrations.AddField(
model_name='tokendistribution',
name='constraint_params',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='tokendistribution',
name='reversed_constraints',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='constraint',
name='name',
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('tokenTap.OncePerMonthVerification', 'OncePerMonthVerification'), ('tokenTap.OnceInALifeTimeVerification', 'OnceInALifeTimeVerification'), ('faucet.OptimismHasClaimedGasInThisRound', 'OptimismHasClaimedGasInThisRound')], max_length=255, unique=True),
),
migrations.AlterField(
model_name='tokendistribution',
name='amount',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='tokendistribution',
name='constraints',
field=models.ManyToManyField(blank=True, related_name='token_distributions', to='tokenTap.constraint'),
),
migrations.AlterField(
model_name='tokendistribution',
name='distributor',
field=models.CharField(max_length=255, null=True),
),
migrations.AlterField(
model_name='tokendistribution',
name='max_number_of_claims',
field=models.PositiveIntegerField(null=True, validators=[django.core.validators.MinValueValidator(1)]),
),
migrations.AlterField(
model_name='tokendistribution',
name='name',
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name='tokendistribution',
name='notes',
field=models.TextField(default=''),
preserve_default=False,
),
]
19 changes: 13 additions & 6 deletions tokenTap/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.cache import cache
from django.core.validators import MinValueValidator
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -30,9 +31,9 @@ class Status(models.TextChoices):
REJECTED = "REJECTED", _("Rejected")
VERIFIED = "VERIFIED", _("Verified")

name = models.CharField(max_length=100)
name = models.CharField(max_length=255)

distributor = models.CharField(max_length=100, null=True, blank=True)
distributor = models.CharField(max_length=255, null=True)
distributor_profile = models.ForeignKey(
UserProfile, on_delete=models.DO_NOTHING, related_name="token_distributions"
)
Expand All @@ -47,21 +48,27 @@ class Status(models.TextChoices):

token = models.CharField(max_length=100)
token_address = models.CharField(max_length=255)
amount = models.BigIntegerField()
amount = models.CharField(max_length=100)
chain = models.ForeignKey(
Chain, on_delete=models.CASCADE, related_name="token_distribution"
)
contract = models.CharField(max_length=255, null=True, blank=True)

constraints = models.ManyToManyField(Constraint, blank=True)
constraints = models.ManyToManyField(
Constraint, blank=True, related_name="token_distributions"
)
constraint_params = models.TextField(null=True, blank=True)
reversed_constraints = models.TextField(null=True, blank=True)

created_at = models.DateTimeField(auto_now_add=True)
start_at = models.DateTimeField(default=timezone.now)
deadline = models.DateTimeField()

max_number_of_claims = models.IntegerField(null=True, blank=True)
max_number_of_claims = models.PositiveIntegerField(
null=True, validators=[MinValueValidator(1)]
)

notes = models.TextField(null=True, blank=True)
notes = models.TextField()
necessary_information = models.TextField(null=True, blank=True)

status = models.CharField(
Expand Down
4 changes: 1 addition & 3 deletions tokenTap/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ def validate(self, data):
chain_id = data["chain"].chain_id
if chain_id not in valid_chains:
raise serializers.ValidationError({"chain": "Invalid value"})
valid_contracts = list(CONTRACT_ADDRESSES[chain_id].values())
if data["contract"] not in valid_contracts:
raise serializers.ValidationError({"contract": "Invalid value"})
data["contract"] = CONTRACT_ADDRESSES[chain_id]
data["distributor_profile"] = self.context["user_profile"]
return data
6 changes: 6 additions & 0 deletions tokenTap/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path

from tokenTap.views import (
CreateTokenDistribution,
GetTokenDistributionConstraintsView,
TokenDistributionClaimListView,
TokenDistributionClaimRetrieveView,
Expand Down Expand Up @@ -42,4 +43,9 @@
ValidChainsView.as_view(),
name="get-valid-chains",
),
path(
"create-token-distribution/",
CreateTokenDistribution.as_view(),
name="create-token-distribution",
),
]