diff --git a/src/dfktools/void_hunt/__init__.py b/src/dfktools/void_hunt/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/dfktools/void_hunt/hunts_diamond.py b/src/dfktools/void_hunt/hunts_diamond.py new file mode 100644 index 0000000..7e7a64d --- /dev/null +++ b/src/dfktools/void_hunt/hunts_diamond.py @@ -0,0 +1,91 @@ +from web3 import Web3 + +CRYSTALVALE_CONTRACT_ADDRESS = "0xEaC69796Cff468ED1694A6FfAc4cbC23bbe33aFa" + + +ABI = """ + [ + {"anonymous": false, "inputs": [{"components": [{"internalType": "address", "name": "facetAddress", "type": "address"}, {"internalType": "enum IDiamondCut.FacetCutAction", "name": "action", "type": "uint8"}, {"internalType": "bytes4[]", "name": "functionSelectors", "type": "bytes4[]"}], "indexed": false, "internalType": "struct IDiamondCut.FacetCut[]", "name": "_diamondCut", "type": "tuple[]"}, {"indexed": false, "internalType": "address", "name": "_init", "type": "address"}, {"indexed": false, "internalType": "bytes", "name": "_calldata", "type": "bytes"}], "name": "DiamondCut", "type": "event"}, + {"inputs": [{"components": [{"internalType": "address", "name": "facetAddress", "type": "address"}, {"internalType": "enum IDiamondCut.FacetCutAction", "name": "action", "type": "uint8"}, {"internalType": "bytes4[]", "name": "functionSelectors", "type": "bytes4[]"}], "internalType": "struct IDiamondCut.FacetCut[]", "name": "_diamondCut", "type": "tuple[]"}, {"internalType": "address", "name": "_init", "type": "address"}, {"internalType": "bytes", "name": "_calldata", "type": "bytes"}], "name": "diamondCut", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "bytes4", "name": "_functionSelector", "type": "bytes4"}], "name": "facetAddress", "outputs": [{"internalType": "address", "name": "facetAddress_", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "facetAddresses", "outputs": [{"internalType": "address[]", "name": "facetAddresses_", "type": "address[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_facet", "type": "address"}], "name": "facetFunctionSelectors", "outputs": [{"internalType": "bytes4[]", "name": "facetFunctionSelectors_", "type": "bytes4[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "facets", "outputs": [{"components": [{"internalType": "address", "name": "facetAddress", "type": "address"}, {"internalType": "bytes4[]", "name": "functionSelectors", "type": "bytes4[]"}], "internalType": "struct IDiamondLoupe.Facet[]", "name": "facets_", "type": "tuple[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "bytes4", "name": "_interfaceId", "type": "bytes4"}], "name": "supportsInterface", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "stateMutability": "view", "type": "function"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "previousOwner", "type": "address"}, {"indexed": true, "internalType": "address", "name": "newOwner", "type": "address"}], "name": "OwnershipTransferred", "type": "event"}, + {"inputs": [], "name": "owner", "outputs": [{"internalType": "address", "name": "owner_", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_newOwner", "type": "address"}], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [], "name": "UintUtils__InsufficientHexLength", "type": "error"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "feeAddress", "type": "address"}, {"indexed": true, "internalType": "uint256", "name": "feePercent", "type": "uint256"}], "name": "FeeAddressAdded", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "source", "type": "address"}, {"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "address", "name": "token", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256"}, {"indexed": false, "internalType": "uint64", "name": "timestamp", "type": "uint64"}], "name": "FeeDeferred", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "source", "type": "address"}, {"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "address", "name": "token", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256"}, {"indexed": false, "internalType": "uint64", "name": "timestamp", "type": "uint64"}], "name": "FeeDisbursed", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "source", "type": "address"}, {"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "address", "name": "token", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256"}, {"indexed": false, "internalType": "uint64", "name": "timestamp", "type": "uint64"}], "name": "FeeLockedBurned", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "huntId", "type": "uint256"}], "name": "HuntCanceled", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "huntId", "type": "uint256"}, {"components": [{"internalType": "uint256", "name": "id", "type": "uint256"}, {"internalType": "uint256", "name": "huntDataId", "type": "uint256"}, {"internalType": "uint256", "name": "startBlock", "type": "uint256"}, {"internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}, {"internalType": "address", "name": "player", "type": "address"}, {"internalType": "enum HuntStatus", "name": "status", "type": "uint8"}, {"internalType": "uint256", "name": "resultSubmittedTimestamp", "type": "uint256"}, {"internalType": "uint256[]", "name": "petXpBonuses", "type": "uint256[]"}, {"internalType": "uint256", "name": "startAtTime", "type": "uint256"}, {"internalType": "uint256", "name": "retries", "type": "uint256"}], "indexed": false, "internalType": "struct Hunt", "name": "hunt", "type": "tuple"}, {"indexed": false, "internalType": "bool", "name": "huntWon", "type": "bool"}, {"indexed": false, "internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}], "name": "HuntCompleted", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "uint256", "name": "huntId", "type": "uint256"}, {"indexed": true, "internalType": "address", "name": "item", "type": "address"}, {"indexed": true, "internalType": "address", "name": "player", "type": "address"}, {"indexed": false, "internalType": "uint8", "name": "equipmentType", "type": "uint8"}, {"indexed": false, "internalType": "uint16", "name": "displayId", "type": "uint16"}, {"indexed": false, "internalType": "uint8", "name": "rarity", "type": "uint8"}, {"indexed": false, "internalType": "uint256", "name": "nftId", "type": "uint256"}], "name": "HuntEquipmentMinted", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "uint256", "name": "questId", "type": "uint256"}, {"indexed": true, "internalType": "address", "name": "player", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "heroId", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "petId", "type": "uint256"}], "name": "HuntPetBonusReceived", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "huntId", "type": "uint256"}, {"indexed": false, "internalType": "bool", "name": "result", "type": "bool"}], "name": "HuntResultSubmitted", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "huntId", "type": "uint256"}], "name": "HuntRetried", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "uint256", "name": "huntId", "type": "uint256"}, {"indexed": true, "internalType": "address", "name": "player", "type": "address"}, {"indexed": true, "internalType": "address", "name": "item", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "data", "type": "uint256"}], "name": "HuntRewardMinted", "type": "event"}, + {"anonymous": false, "inputs": [{"components": [{"internalType": "uint256", "name": "id", "type": "uint256"}, {"internalType": "uint256", "name": "huntDataId", "type": "uint256"}, {"internalType": "uint256", "name": "startBlock", "type": "uint256"}, {"internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}, {"internalType": "address", "name": "player", "type": "address"}, {"internalType": "enum HuntStatus", "name": "status", "type": "uint8"}, {"internalType": "uint256", "name": "resultSubmittedTimestamp", "type": "uint256"}, {"internalType": "uint256[]", "name": "petXpBonuses", "type": "uint256[]"}, {"internalType": "uint256", "name": "startAtTime", "type": "uint256"}, {"internalType": "uint256", "name": "retries", "type": "uint256"}], "indexed": false, "internalType": "struct Hunt", "name": "hunt", "type": "tuple"}], "name": "HuntStarted", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "uint256", "name": "huntId", "type": "uint256"}, {"indexed": true, "internalType": "address", "name": "player", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "heroId", "type": "uint256"}, {"indexed": false, "internalType": "uint64", "name": "xpEarned", "type": "uint64"}], "name": "HuntXP", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32"}, {"indexed": true, "internalType": "bytes32", "name": "previousAdminRole", "type": "bytes32"}, {"indexed": true, "internalType": "bytes32", "name": "newAdminRole", "type": "bytes32"}], "name": "RoleAdminChanged", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32"}, {"indexed": true, "internalType": "address", "name": "account", "type": "address"}, {"indexed": true, "internalType": "address", "name": "sender", "type": "address"}], "name": "RoleGranted", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32"}, {"indexed": true, "internalType": "address", "name": "account", "type": "address"}, {"indexed": true, "internalType": "address", "name": "sender", "type": "address"}], "name": "RoleRevoked", "type": "event"}, + {"inputs": [], "name": "cleanupExecutorTest", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}], "name": "completeHunt", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_data", "type": "uint256"}], "name": "executorTest", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "bytes32", "name": "role", "type": "bytes32"}], "name": "getRoleAdmin", "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "bytes32", "name": "role", "type": "bytes32"}, {"internalType": "address", "name": "account", "type": "address"}], "name": "grantRole", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "bytes32", "name": "role", "type": "bytes32"}, {"internalType": "address", "name": "account", "type": "address"}], "name": "hasRole", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "bytes32", "name": "role", "type": "bytes32"}], "name": "renounceRole", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "bytes32", "name": "role", "type": "bytes32"}, {"internalType": "address", "name": "account", "type": "address"}], "name": "revokeRole", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}, {"internalType": "bool", "name": "_huntWon", "type": "bool"}], "name": "submitHuntResult", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [], "name": "getActiveHunts", "outputs": [{"internalType": "uint256[]", "name": "", "type": "uint256[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getHeroCore", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_heroId", "type": "uint256"}], "name": "getHeroHunt", "outputs": [{"components": [{"internalType": "uint256", "name": "id", "type": "uint256"}, {"internalType": "uint256", "name": "huntDataId", "type": "uint256"}, {"internalType": "uint256", "name": "startBlock", "type": "uint256"}, {"internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}, {"internalType": "address", "name": "player", "type": "address"}, {"internalType": "enum HuntStatus", "name": "status", "type": "uint8"}, {"internalType": "uint256", "name": "resultSubmittedTimestamp", "type": "uint256"}, {"internalType": "uint256[]", "name": "petXpBonuses", "type": "uint256[]"}, {"internalType": "uint256", "name": "startAtTime", "type": "uint256"}, {"internalType": "uint256", "name": "retries", "type": "uint256"}], "internalType": "struct Hunt", "name": "", "type": "tuple"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntDataId", "type": "uint256"}, {"internalType": "uint256[]", "name": "_heroIds", "type": "uint256[]"}], "name": "getHeroHuntAvailableAtTimestamps", "outputs": [{"internalType": "uint256[]", "name": "", "type": "uint256[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}], "name": "getHunt", "outputs": [{"components": [{"internalType": "uint256", "name": "id", "type": "uint256"}, {"internalType": "uint256", "name": "huntDataId", "type": "uint256"}, {"internalType": "uint256", "name": "startBlock", "type": "uint256"}, {"internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}, {"internalType": "address", "name": "player", "type": "address"}, {"internalType": "enum HuntStatus", "name": "status", "type": "uint8"}, {"internalType": "uint256", "name": "resultSubmittedTimestamp", "type": "uint256"}, {"internalType": "uint256[]", "name": "petXpBonuses", "type": "uint256[]"}, {"internalType": "uint256", "name": "startAtTime", "type": "uint256"}, {"internalType": "uint256", "name": "retries", "type": "uint256"}], "internalType": "struct Hunt", "name": "", "type": "tuple"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getHuntCooldown", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getHuntCounter", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getItemMinter", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getPetCore", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getPowerUpManager", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getQuests", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "getRandomGenerator", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_address", "type": "address"}], "name": "getUserHuntIds", "outputs": [{"internalType": "uint256[]", "name": "", "type": "uint256[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_address", "type": "address"}], "name": "getUserHunts", "outputs": [{"components": [{"internalType": "uint256", "name": "id", "type": "uint256"}, {"internalType": "uint256", "name": "huntDataId", "type": "uint256"}, {"internalType": "uint256", "name": "startBlock", "type": "uint256"}, {"internalType": "uint256[]", "name": "heroIds", "type": "uint256[]"}, {"internalType": "address", "name": "player", "type": "address"}, {"internalType": "enum HuntStatus", "name": "status", "type": "uint8"}, {"internalType": "uint256", "name": "resultSubmittedTimestamp", "type": "uint256"}, {"internalType": "uint256[]", "name": "petXpBonuses", "type": "uint256[]"}, {"internalType": "uint256", "name": "startAtTime", "type": "uint256"}, {"internalType": "uint256", "name": "retries", "type": "uint256"}], "internalType": "struct Hunt[]", "name": "", "type": "tuple[]"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_id", "type": "uint256"}], "name": "huntAtIndex", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function"}, + {"inputs": [], "name": "MODERATOR_ROLE", "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], "stateMutability": "view", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntDataId", "type": "uint256"}], "name": "addActiveHuntDataId", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_account", "type": "address"}], "name": "clearUserHunts", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntDataId", "type": "uint256"}], "name": "removeActiveHuntDataId", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address[]", "name": "_feeAddresses", "type": "address[]"}, {"internalType": "uint256[]", "name": "_feePercents", "type": "uint256[]"}], "name": "setFees", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_flagStorage", "type": "address"}], "name": "setFlagStorage", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_heroCore", "type": "address"}], "name": "setHeroCore", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}, {"internalType": "uint256", "name": "_heroId", "type": "uint256"}, {"internalType": "uint256", "name": "_value", "type": "uint256"}], "name": "setHeroHuntAvailableAt", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntCooldown", "type": "uint256"}], "name": "setHuntCooldown", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_itemMinter", "type": "address"}], "name": "setItemMinter", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_petCore", "type": "address"}], "name": "setPetCore", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_token", "type": "address"}], "name": "setPowerToken", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_powerUpManager", "type": "address"}], "name": "setPowerUpManager", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_quests", "type": "address"}], "name": "setQuests", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "address", "name": "_randomGenerator", "type": "address"}], "name": "setRandomGenerator", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}], "name": "cancelHunt", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntId", "type": "uint256"}], "name": "retryHunt", "outputs": [], "stateMutability": "nonpayable", "type": "function"}, + {"inputs": [{"internalType": "uint256", "name": "_huntDataId", "type": "uint256"}, {"internalType": "uint256[]", "name": "_heroIds", "type": "uint256[]"}], "name": "startHunt", "outputs": [], "stateMutability": "nonpayable", "type": "function"} + ] +""" + + +def getHeroHuntAvailableAtTimestamps(contract_address, huntId, heroIds, rpc_address): + w3 = Web3(Web3.HTTPProvider(rpc_address)) + + contract = w3.eth.contract(Web3.to_checksum_address(contract_address), abi=ABI) + + raw = contract.functions.getHeroHuntAvailableAtTimestamps(huntId, heroIds).call() + + heroes_ready = [] + for i, r in enumerate(raw): + heroes_ready.append({"heroId": heroIds[i], "ready": r}) + return heroes_ready diff --git a/src/dfktools/void_hunt_example.py b/src/dfktools/void_hunt_example.py new file mode 100644 index 0000000..7612b39 --- /dev/null +++ b/src/dfktools/void_hunt_example.py @@ -0,0 +1,35 @@ +import logging +import sys +import void_hunt.hunts_diamond as hunts +import time +from web3 import Web3 +from datetime import datetime + +if __name__ == "__main__": + log_format = "%(asctime)s|%(name)s|%(levelname)s: %(message)s" + + logger = logging.getLogger("DFK-hunts") + logger.setLevel(logging.DEBUG) + logging.basicConfig(level=logging.INFO, format=log_format, stream=sys.stdout) + + rpc_server = "https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc" + logger.info("Using RPC server " + rpc_server) + + # View Hero Hunt Ready Time (Crystalvale) + hunt_id = 1 # Boar hunt + hero_ids = [1000000139507, 700] + heroes_timers = hunts.getHeroHuntAvailableAtTimestamps( + hunts.CRYSTALVALE_CONTRACT_ADDRESS, hunt_id, hero_ids, rpc_server + ) + + sorted_heroes_timers = sorted(heroes_timers, key=lambda x: x["ready"]) + + logger.info("Heroes boar hunt ready:") + + for hero in sorted_heroes_timers: + ready = ( + "Now" + if hero["ready"] < time.time() + else datetime.fromtimestamp(hero["ready"]) + ) + logger.info(f"{hero['heroId']} -- {ready}")