diff --git a/dkg/constants.py b/dkg/constants.py index 170d0dd..c2c9659 100644 --- a/dkg/constants.py +++ b/dkg/constants.py @@ -21,11 +21,11 @@ BLOCKCHAINS = { "development": { - "hardhat1:31337": { + "hardhat1:31337": { "hub": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "rpc": "http://localhost:8545", }, - "hardhat2:31337": { + "hardhat2:31337": { "hub": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "rpc": "http://localhost:9545", }, @@ -43,7 +43,7 @@ "base:84532": { "hub": "0x6C861Cb69300C34DfeF674F7C00E734e840C29C0", "rpc": "https://sepolia.base.org", - } + }, }, "testnet": { "otp:20430": { @@ -58,7 +58,7 @@ "base:84532": { "hub": "0x144eDa5cbf8926327cb2cceef168A121F0E4A299", "rpc": "https://sepolia.base.org", - } + }, }, "mainnet": { "otp:2043": { @@ -88,11 +88,7 @@ DEFAULT_HASH_FUNCTION_ID = 1 DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = { - "development": { - "hardhat1:31337": 2, - "hardhat2:31337": 2, - "otp:2043": 2 - }, + "development": {"hardhat1:31337": 2, "hardhat2:31337": 2, "otp:2043": 2}, "devnet": { "otp:2160": 2, "gnosis:10200": 2, @@ -112,3 +108,6 @@ PRIVATE_HISTORICAL_REPOSITORY = "privateHistory" PRIVATE_CURRENT_REPOSITORY = "privateCurrent" + +NEUROWEB_BLOCKCHAIN_PREFIX = "otp" +INCENTIVE_POOL_NAME = "ParanetNeurowebIncentivesPool" diff --git a/dkg/data/interfaces/ParanetIncentivesPoolFactory.json b/dkg/data/interfaces/ParanetIncentivesPoolFactory.json index c276757..ef433ce 100644 --- a/dkg/data/interfaces/ParanetIncentivesPoolFactory.json +++ b/dkg/data/interfaces/ParanetIncentivesPoolFactory.json @@ -75,6 +75,11 @@ }, { "inputs": [ + { + "internalType": "bool", + "name": "isNativeReward", + "type": "bool" + }, { "internalType": "address", "name": "paranetKAStorageContract", diff --git a/dkg/data/interfaces/ParanetNeurowebIncentivesPool.json b/dkg/data/interfaces/ParanetNeurowebIncentivesPool.json index 288bf3e..8f9dfa6 100644 --- a/dkg/data/interfaces/ParanetNeurowebIncentivesPool.json +++ b/dkg/data/interfaces/ParanetNeurowebIncentivesPool.json @@ -6,6 +6,11 @@ "name": "hubAddress", "type": "address" }, + { + "internalType": "address", + "name": "rewardTokenAddress", + "type": "address" + }, { "internalType": "address", "name": "paranetsRegistryAddress", @@ -81,19 +86,19 @@ "anonymous": false, "inputs": [ { - "indexed": false, - "internalType": "uint256", - "name": "oldMultiplier", - "type": "uint256" + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" }, { "indexed": false, "internalType": "uint256", - "name": "newMultiplier", + "name": "amount", "type": "uint256" } ], - "name": "NeuroEmissionMultiplierUpdateFinalized", + "name": "NativeNeuroRewardDeposit", "type": "event" }, { @@ -110,34 +115,34 @@ "internalType": "uint256", "name": "newMultiplier", "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" } ], - "name": "NeuroEmissionMultiplierUpdateInitiated", + "name": "NeuroEmissionMultiplierUpdateFinalized", "type": "event" }, { "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" + "indexed": false, + "internalType": "uint256", + "name": "oldMultiplier", + "type": "uint256" }, { "indexed": false, "internalType": "uint256", - "name": "amount", + "name": "newMultiplier", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", "type": "uint256" } ], - "name": "NeuroRewardDeposit", + "name": "NeuroEmissionMultiplierUpdateInitiated", "type": "event" }, { @@ -213,7 +218,7 @@ } ], "internalType": "struct ParanetStructs.ParanetIncentivizationProposalVoterInput[]", - "name": "voters_", + "name": "newVoters", "type": "tuple[]" } ], @@ -715,6 +720,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "isNativeNeuro", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -924,6 +942,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "token", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "totalMinersClaimedNeuro", diff --git a/dkg/dataclasses.py b/dkg/dataclasses.py index 7b49ee3..cabc160 100644 --- a/dkg/dataclasses.py +++ b/dkg/dataclasses.py @@ -55,8 +55,9 @@ class KnowledgeAssetContentVisibility(AutoStrEnumUpperCase): PRIVATE = auto() -class ParanetIncentivizationType(AutoStrEnumCapitalize): - NEUROWEB = auto() +class ParanetIncentivizationType(Enum): + NEUROWEB = "Neuroweb" + NEUROWEB_ERC20 = "NeurowebERC20" @dataclass diff --git a/dkg/paranet.py b/dkg/paranet.py index 474f255..9fd6e1e 100644 --- a/dkg/paranet.py +++ b/dkg/paranet.py @@ -28,6 +28,7 @@ from dkg.types import Address, UAL, HexStr from dkg.utils.blockchain_request import BlockchainRequest from dkg.utils.ual import parse_ual +from dkg.constants import NEUROWEB_BLOCKCHAIN_PREFIX, INCENTIVE_POOL_NAME class Paranet(Module): @@ -37,10 +38,15 @@ class NeuroWebIncentivesPoolParams(BaseIncentivesPoolParams): operator_percentage: float voters_percentage: float - def to_contract_args(self) -> dict: + def to_contract_args(self, incentive_type: ParanetIncentivizationType) -> dict: return { "tracToNeuroEmissionMultiplier": int( - self.neuro_emission_multiplier * (10**12) + self.neuro_emission_multiplier + * ( + 10**12 + if incentive_type == ParanetIncentivizationType.NEUROWEB + else 10**18 + ) ), "paranetOperatorRewardPercentage": int(self.operator_percentage * 100), "paranetIncentivizationProposalVotersRewardPercentage": int( @@ -52,6 +58,7 @@ def __init__(self, manager: DefaultRequestManager): self.manager = manager self.incentives_pools_deployment_functions = { ParanetIncentivizationType.NEUROWEB: self._deploy_neuro_incentives_pool, + ParanetIncentivizationType.NEUROWEB_ERC20: self._deploy_neuro_incentives_pool, } _register_paranet = Method(BlockchainRequest.register_paranet) @@ -91,7 +98,7 @@ def deploy_incentives_contract( self, ual: UAL, incentives_pool_parameters: NeuroWebIncentivesPoolParams, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType, ) -> dict[str, str | HexStr | TxReceipt]: deploy_incentives_pool_fn = self.incentives_pools_deployment_functions.get( incentives_type, @@ -111,9 +118,10 @@ def deploy_incentives_contract( ) receipt: TxReceipt = deploy_incentives_pool_fn( + incentives_type == ParanetIncentivizationType.NEUROWEB, knowledge_asset_storage, knowledge_asset_token_id, - **incentives_pool_parameters.to_contract_args(), + **incentives_pool_parameters.to_contract_args(incentives_type), ) events = self.manager.blockchain_provider.decode_logs_event( @@ -137,9 +145,7 @@ def deploy_incentives_contract( _get_incentives_pool_address = Method(BlockchainRequest.get_incentives_pool_address) def get_incentives_pool_address( - self, - ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + self, ual: UAL, incentives_type: ParanetIncentivizationType ) -> Address: parsed_ual = parse_ual(ual) knowledge_asset_storage, knowledge_asset_token_id = ( @@ -259,8 +265,14 @@ def is_voter( self, ual: UAL, address: Address | None = None, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType = None, ) -> bool: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._is_proposal_voter( contract=self._get_incentives_pool_contract(ual, incentives_type), addr=address or self.manager.blockchain_provider.account.address, @@ -273,8 +285,14 @@ def is_voter( def calculate_claimable_miner_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType = None, ) -> int: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._get_claimable_knowledge_miner_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -286,8 +304,14 @@ def calculate_claimable_miner_reward_amount( def calculate_all_claimable_miner_rewards_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType = None, ) -> int: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._get_claimable_all_knowledge_miners_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -299,8 +323,14 @@ def calculate_all_claimable_miner_rewards_amount( def claim_miner_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: None, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + receipt: TxReceipt = self._claim_knowledge_miner_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -329,8 +359,14 @@ def claim_miner_reward( def calculate_claimable_operator_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType = None, ) -> int: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._get_claimable_paranet_operator_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -342,8 +378,14 @@ def calculate_claimable_operator_reward_amount( def claim_operator_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType = None, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + receipt: TxReceipt = self._claim_paranet_operator_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -372,8 +414,14 @@ def claim_operator_reward( def calculate_claimable_voter_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._get_claimable_proposal_voter_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -385,8 +433,14 @@ def calculate_claimable_voter_reward_amount( def calculate_all_claimable_voters_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + return self._get_claimable_all_proposal_voters_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -398,8 +452,14 @@ def calculate_all_claimable_voters_reward_amount( def claim_voter_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + incentives_type: ParanetIncentivizationType | None = None, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = incentives_type or ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.NEUROWEB_ERC20.value + ) + receipt: TxReceipt = self._claim_incentivization_proposal_voter_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -457,11 +517,9 @@ def update_claimable_rewards(self, ual: UAL) -> dict[str, str | HexStr | TxRecei } def _get_incentives_pool_contract( - self, - ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, + self, ual: UAL, incentives_type: ParanetIncentivizationType ) -> str | dict[str, str]: - incentives_pool_name = f"Paranet{str(incentives_type)}IncentivesPool" + incentives_pool_name = INCENTIVE_POOL_NAME is_incentives_pool_cached = ( incentives_pool_name in self.manager.blockchain_provider.contracts.keys() ) diff --git a/dkg/utils/blockchain_request.py b/dkg/utils/blockchain_request.py index b684b9b..35464fd 100644 --- a/dkg/utils/blockchain_request.py +++ b/dkg/utils/blockchain_request.py @@ -70,7 +70,7 @@ class BlockchainRequest: allowance = ContractCall( contract="Token", function="allowance", - args={"owner": Address, "spender": Address} + args={"owner": Address, "spender": Address}, ) increase_allowance = ContractTransaction( contract="Token", @@ -225,6 +225,7 @@ class BlockchainRequest: contract="ParanetIncentivesPoolFactory", function="deployNeuroIncentivesPool", args={ + "isNativeReward": bool, "paranetKAStorageContract": Address, "paranetKATokenId": int, "tracToNeuroEmissionMultiplier": float, diff --git a/examples/paranets_demo.py b/examples/paranets_demo.py index 6f79faf..8cf5a6a 100644 --- a/examples/paranets_demo.py +++ b/examples/paranets_demo.py @@ -22,6 +22,7 @@ from dkg import DKG from dkg.providers import BlockchainProvider, NodeHTTPProvider +from dkg.dataclasses import ParanetIncentivizationType node_provider = NodeHTTPProvider("http://localhost:8900") blockchain_provider = BlockchainProvider( @@ -128,7 +129,7 @@ def convert_hexbytes(data): voters_percentage=5.5, ) deploy_incentives_contract_result = dkg.paranet.deploy_incentives_contract( - paranet_ual, incentives_pool_params + paranet_ual, incentives_pool_params, ParanetIncentivizationType.ERC20 ) print("======================== PARANET NEURO INCENTIVES POOL DEPLOYED") @@ -324,7 +325,7 @@ def print_reward_stats(is_voter: bool = False): ], }, }, - 100000000000000000000 + 100000000000000000000, ) print("======================== KA1 UPDATED")