-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #571 from UnitapApp/develop
Develop
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |