Skip to content

Commit

Permalink
Merge pull request #571 from UnitapApp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ShayanShiravani authored Jul 30, 2024
2 parents f31cbbd + c710a52 commit 2f3f509
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
HasMinimumLensPost,
IsFollowingLensUser,
)
from core.constraints.muon_node import HasMuonNode
from core.constraints.twitter import (
BeFollowedByTwitterUser,
DidQuoteTweet,
Expand Down
1 change: 1 addition & 0 deletions core/constraints/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ConstraintApp(Enum):
GITCOIN_PASSPORT = "gitcoin_passport"
ARB_BRIDGE = "arb_bridge"
TWITTER = "twitter"
MUON = "muon"

@classmethod
def choices(cls):
Expand Down
82 changes: 82 additions & 0 deletions core/constraints/muon_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from django.db.models.functions import Lower

from core.constraints.abstract import ConstraintApp, ConstraintVerification
from core.utils import Web3Utils

MUON_NODE_MANAGER_ABI = [
{
"inputs": [
{"internalType": "address", "name": "stakerAddress", "type": "address"}
],
"name": "stakerAddressInfo",
"outputs": [
{
"components": [
{"internalType": "uint64", "name": "id", "type": "uint64"},
{
"internalType": "address",
"name": "nodeAddress",
"type": "address",
},
{
"internalType": "address",
"name": "stakerAddress",
"type": "address",
},
{"internalType": "string", "name": "peerId", "type": "string"},
{"internalType": "bool", "name": "active", "type": "bool"},
{"internalType": "uint8", "name": "tier", "type": "uint8"},
{"internalType": "uint64[]", "name": "roles", "type": "uint64[]"},
{"internalType": "uint256", "name": "startTime", "type": "uint256"},
{"internalType": "uint256", "name": "endTime", "type": "uint256"},
{
"internalType": "uint256",
"name": "lastEditTime",
"type": "uint256",
},
],
"internalType": "struct IMuonNodeManager.Node",
"name": "node",
"type": "tuple",
}
],
"stateMutability": "view",
"type": "function",
}
]


class HasMuonNode(ConstraintVerification):
app_name = ConstraintApp.MUON.value
CHAIN_ID = 56
CONTRACT_ADDR = "0x6eA3096eB0fAf5c1DEb970DCd29A6b10a48DaD83"

def __init__(self, user_profile) -> None:
from core.models import Chain

super().__init__(user_profile)
self.chain = Chain.objects.get(chain_id=HasMuonNode.CHAIN_ID)
self.web3_utils = Web3Utils(self.chain.rpc_url_private, self.chain.poa)
self.web3_utils.set_contract(HasMuonNode.CONTRACT_ADDR, MUON_NODE_MANAGER_ABI)

def is_observed(self, *args, **kwargs) -> bool:
try:
return self.has_node()
except Exception as e:
print(e)
return False

def has_node(self):
user_wallets = self.user_profile.wallets.values_list(
Lower("address"), flat=True
)

for wallet in user_wallets:
func = self.web3_utils.contract.functions.stakerAddressInfo(
self.web3_utils.to_checksum_address(wallet)
)
node = self.web3_utils.contract_call(func)
if node and node[0] != 0 and node[4]:
return True

return False
2 changes: 2 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
HasMinimumHumanityScore,
HasMinimumLensFollower,
HasMinimumLensPost,
HasMuonNode,
HasNFTVerification,
HasTokenTransferVerification,
HasTokenVerification,
Expand Down Expand Up @@ -137,6 +138,7 @@ class Type(models.TextChoices):
BeFollowedByTwitterUser,
DidRetweetTweet,
DidQuoteTweet,
HasMuonNode,
]

name = models.CharField(
Expand Down
18 changes: 18 additions & 0 deletions prizetap/migrations/0069_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2024-07-30 08:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('prizetap', '0068_alter_constraint_name'),
]

operations = [
migrations.AlterField(
model_name='constraint',
name='name',
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('core.HasTokenVerification', 'HasTokenVerification'), ('core.HasTokenTransferVerification', 'HasTokenTransferVerification'), ('core.AllowListVerification', 'AllowListVerification'), ('core.HasENSVerification', 'HasENSVerification'), ('core.HasLensProfile', 'HasLensProfile'), ('core.IsFollowingLensUser', 'IsFollowingLensUser'), ('core.BeFollowedByLensUser', 'BeFollowedByLensUser'), ('core.DidMirrorOnLensPublication', 'DidMirrorOnLensPublication'), ('core.DidCollectLensPublication', 'DidCollectLensPublication'), ('core.HasMinimumLensPost', 'HasMinimumLensPost'), ('core.HasMinimumLensFollower', 'HasMinimumLensFollower'), ('core.BeFollowedByFarcasterUser', 'BeFollowedByFarcasterUser'), ('core.HasMinimumFarcasterFollower', 'HasMinimumFarcasterFollower'), ('core.DidLikedFarcasterCast', 'DidLikedFarcasterCast'), ('core.DidRecastFarcasterCast', 'DidRecastFarcasterCast'), ('core.IsFollowingFarcasterUser', 'IsFollowingFarcasterUser'), ('core.HasFarcasterProfile', 'HasFarcasterProfile'), ('core.BeAttestedBy', 'BeAttestedBy'), ('core.Attest', 'Attest'), ('core.HasMinimumHumanityScore', 'HasMinimumHumanityScore'), ('core.HasGitcoinPassportProfile', 'HasGitcoinPassportProfile'), ('core.IsFollowingFarcasterChannel', 'IsFollowingFarcasterChannel'), ('core.BridgeEthToArb', 'BridgeEthToArb'), ('core.IsFollowinTwitterUser', 'IsFollowinTwitterUser'), ('core.BeFollowedByTwitterUser', 'BeFollowedByTwitterUser'), ('core.DidRetweetTweet', 'DidRetweetTweet'), ('core.DidQuoteTweet', 'DidQuoteTweet'), ('core.HasMuonNode', 'HasMuonNode'), ('prizetap.HaveUnitapPass', 'HaveUnitapPass'), ('prizetap.NotHaveUnitapPass', 'NotHaveUnitapPass'), ('faucet.OptimismDonationConstraint', 'OptimismDonationConstraint'), ('faucet.OptimismClaimingGasConstraint', 'OptimismClaimingGasConstraint')], max_length=255, unique=True),
),
]
18 changes: 18 additions & 0 deletions tokenTap/migrations/0055_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2024-07-30 09:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tokenTap', '0054_alter_constraint_name'),
]

operations = [
migrations.AlterField(
model_name='constraint',
name='name',
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('core.HasTokenVerification', 'HasTokenVerification'), ('core.HasTokenTransferVerification', 'HasTokenTransferVerification'), ('core.AllowListVerification', 'AllowListVerification'), ('core.HasENSVerification', 'HasENSVerification'), ('core.HasLensProfile', 'HasLensProfile'), ('core.IsFollowingLensUser', 'IsFollowingLensUser'), ('core.BeFollowedByLensUser', 'BeFollowedByLensUser'), ('core.DidMirrorOnLensPublication', 'DidMirrorOnLensPublication'), ('core.DidCollectLensPublication', 'DidCollectLensPublication'), ('core.HasMinimumLensPost', 'HasMinimumLensPost'), ('core.HasMinimumLensFollower', 'HasMinimumLensFollower'), ('core.BeFollowedByFarcasterUser', 'BeFollowedByFarcasterUser'), ('core.HasMinimumFarcasterFollower', 'HasMinimumFarcasterFollower'), ('core.DidLikedFarcasterCast', 'DidLikedFarcasterCast'), ('core.DidRecastFarcasterCast', 'DidRecastFarcasterCast'), ('core.IsFollowingFarcasterUser', 'IsFollowingFarcasterUser'), ('core.HasFarcasterProfile', 'HasFarcasterProfile'), ('core.BeAttestedBy', 'BeAttestedBy'), ('core.Attest', 'Attest'), ('core.HasMinimumHumanityScore', 'HasMinimumHumanityScore'), ('core.HasGitcoinPassportProfile', 'HasGitcoinPassportProfile'), ('core.IsFollowingFarcasterChannel', 'IsFollowingFarcasterChannel'), ('core.BridgeEthToArb', 'BridgeEthToArb'), ('core.IsFollowinTwitterUser', 'IsFollowinTwitterUser'), ('core.BeFollowedByTwitterUser', 'BeFollowedByTwitterUser'), ('core.DidRetweetTweet', 'DidRetweetTweet'), ('core.DidQuoteTweet', 'DidQuoteTweet'), ('core.HasMuonNode', 'HasMuonNode'), ('tokenTap.OncePerMonthVerification', 'OncePerMonthVerification'), ('tokenTap.OnceInALifeTimeVerification', 'OnceInALifeTimeVerification'), ('faucet.OptimismHasClaimedGasConstraint', 'OptimismHasClaimedGasConstraint')], max_length=255, unique=True),
),
]

0 comments on commit 2f3f509

Please sign in to comment.