From de5652e509d7a97bb8857f125211ad2773de4781 Mon Sep 17 00:00:00 2001 From: brkagithub Date: Fri, 15 Nov 2024 11:26:52 +0100 Subject: [PATCH 1/5] Make http service use v0 routes by default --- dkg/providers/node_http.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dkg/providers/node_http.py b/dkg/providers/node_http.py index 1286655..7c3c0ae 100644 --- a/dkg/providers/node_http.py +++ b/dkg/providers/node_http.py @@ -25,9 +25,18 @@ class NodeHTTPProvider: - def __init__(self, endpoint_uri: URI | str, auth_token: str | None = None): + def __init__( + self, + endpoint_uri: URI | str, + auth_token: str | None = None, + api_version: str = "v0", + ): self.endpoint_uri = URI(endpoint_uri) self.auth_token = auth_token + self.api_version = api_version + + def get_full_url(self, path: str) -> str: + return f"{self.endpoint_uri}/{self.api_version}/{path}" def make_request( self, @@ -36,7 +45,7 @@ def make_request( params: dict[str, Any] = {}, data: dict[str, Any] = {}, ) -> NodeResponseDict: - url = f"{self.endpoint_uri}/{path}" + url = self.get_full_url(path) headers = ( {"Authorization": f"Bearer {self.auth_token}"} if self.auth_token else {} ) From 2b71ba9d425a50e0c70d5cbb166a26faeab06427 Mon Sep 17 00:00:00 2001 From: brkagithub Date: Mon, 18 Nov 2024 16:25:44 +0100 Subject: [PATCH 2/5] Add ERC20 incentive type, improve multiplier --- dkg/constants.py | 16 ++-- .../ParanetIncentivesPoolFactory.json | 5 ++ .../ParanetNeurowebIncentivesPool.json | 71 ++++++++++----- dkg/dataclasses.py | 5 +- dkg/paranet.py | 89 ++++++++++++++----- dkg/utils/blockchain_request.py | 3 +- examples/paranets_demo.py | 5 +- 7 files changed, 140 insertions(+), 54 deletions(-) diff --git a/dkg/constants.py b/dkg/constants.py index 170d0dd..54dfac4 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,5 @@ PRIVATE_HISTORICAL_REPOSITORY = "privateHistory" PRIVATE_CURRENT_REPOSITORY = "privateCurrent" + +NEUROWEB_BLOCKCHAIN_PREFIX = "otp" 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..21993de 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" + ERC20 = "NeurowebERC20" @dataclass diff --git a/dkg/paranet.py b/dkg/paranet.py index 474f255..c528c83 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 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.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,13 @@ def is_voter( self, ual: UAL, address: Address | None = None, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> bool: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.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 +284,13 @@ def is_voter( def calculate_claimable_miner_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> int: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + return self._get_claimable_knowledge_miner_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -286,8 +302,13 @@ def calculate_claimable_miner_reward_amount( def calculate_all_claimable_miner_rewards_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> int: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + return self._get_claimable_all_knowledge_miners_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -299,8 +320,13 @@ def calculate_all_claimable_miner_rewards_amount( def claim_miner_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + receipt: TxReceipt = self._claim_knowledge_miner_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -329,8 +355,13 @@ def claim_miner_reward( def calculate_claimable_operator_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> int: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + return self._get_claimable_paranet_operator_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -342,8 +373,13 @@ def calculate_claimable_operator_reward_amount( def claim_operator_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + receipt: TxReceipt = self._claim_paranet_operator_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -372,8 +408,13 @@ def claim_operator_reward( def calculate_claimable_voter_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> int: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + return self._get_claimable_proposal_voter_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -385,8 +426,13 @@ def calculate_claimable_voter_reward_amount( def calculate_all_claimable_voters_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> int: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + return self._get_claimable_all_proposal_voters_reward_amount( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -398,8 +444,13 @@ def calculate_all_claimable_voters_reward_amount( def claim_voter_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = ParanetIncentivizationType.NEUROWEB, ) -> dict[str, str | HexStr | TxReceipt]: + incentives_type = ( + ParanetIncentivizationType.NEUROWEB.value + if NEUROWEB_BLOCKCHAIN_PREFIX in ual + else ParanetIncentivizationType.ERC20.value + ) + receipt: TxReceipt = self._claim_incentivization_proposal_voter_reward( contract=self._get_incentives_pool_contract(ual, incentives_type) ) @@ -457,11 +508,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 = f"ParanetNeurowebIncentivesPool" 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") From df7b905885816cbcadde3945c1cb120db21eb398 Mon Sep 17 00:00:00 2001 From: brkagithub Date: Wed, 20 Nov 2024 11:00:34 +0100 Subject: [PATCH 3/5] Bring back incentive_type param, minor feedback --- dkg/constants.py | 1 + dkg/dataclasses.py | 2 +- dkg/paranet.py | 51 +++++++++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/dkg/constants.py b/dkg/constants.py index 54dfac4..c2c9659 100644 --- a/dkg/constants.py +++ b/dkg/constants.py @@ -110,3 +110,4 @@ PRIVATE_CURRENT_REPOSITORY = "privateCurrent" NEUROWEB_BLOCKCHAIN_PREFIX = "otp" +INCENTIVE_POOL_NAME = "ParanetNeurowebIncentivesPool" diff --git a/dkg/dataclasses.py b/dkg/dataclasses.py index 21993de..cabc160 100644 --- a/dkg/dataclasses.py +++ b/dkg/dataclasses.py @@ -57,7 +57,7 @@ class KnowledgeAssetContentVisibility(AutoStrEnumUpperCase): class ParanetIncentivizationType(Enum): NEUROWEB = "Neuroweb" - ERC20 = "NeurowebERC20" + NEUROWEB_ERC20 = "NeurowebERC20" @dataclass diff --git a/dkg/paranet.py b/dkg/paranet.py index c528c83..9fd6e1e 100644 --- a/dkg/paranet.py +++ b/dkg/paranet.py @@ -28,7 +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 +from dkg.constants import NEUROWEB_BLOCKCHAIN_PREFIX, INCENTIVE_POOL_NAME class Paranet(Module): @@ -58,7 +58,7 @@ def __init__(self, manager: DefaultRequestManager): self.manager = manager self.incentives_pools_deployment_functions = { ParanetIncentivizationType.NEUROWEB: self._deploy_neuro_incentives_pool, - ParanetIncentivizationType.ERC20: self._deploy_neuro_incentives_pool, + ParanetIncentivizationType.NEUROWEB_ERC20: self._deploy_neuro_incentives_pool, } _register_paranet = Method(BlockchainRequest.register_paranet) @@ -265,11 +265,12 @@ def is_voter( self, ual: UAL, address: Address | None = None, + incentives_type: ParanetIncentivizationType = None, ) -> bool: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._is_proposal_voter( @@ -284,11 +285,12 @@ def is_voter( def calculate_claimable_miner_reward_amount( self, ual: UAL, + incentives_type: ParanetIncentivizationType = None, ) -> int: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._get_claimable_knowledge_miner_reward_amount( @@ -302,11 +304,12 @@ def calculate_claimable_miner_reward_amount( def calculate_all_claimable_miner_rewards_amount( self, ual: UAL, + incentives_type: ParanetIncentivizationType = None, ) -> int: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._get_claimable_all_knowledge_miners_reward_amount( @@ -320,11 +323,12 @@ def calculate_all_claimable_miner_rewards_amount( def claim_miner_reward( self, ual: UAL, + incentives_type: None, ) -> dict[str, str | HexStr | TxReceipt]: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) receipt: TxReceipt = self._claim_knowledge_miner_reward( @@ -355,11 +359,12 @@ def claim_miner_reward( def calculate_claimable_operator_reward_amount( self, ual: UAL, + incentives_type: ParanetIncentivizationType = None, ) -> int: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._get_claimable_paranet_operator_reward_amount( @@ -373,11 +378,12 @@ def calculate_claimable_operator_reward_amount( def claim_operator_reward( self, ual: UAL, + incentives_type: ParanetIncentivizationType = None, ) -> dict[str, str | HexStr | TxReceipt]: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) receipt: TxReceipt = self._claim_paranet_operator_reward( @@ -408,11 +414,12 @@ def claim_operator_reward( def calculate_claimable_voter_reward_amount( self, ual: UAL, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._get_claimable_proposal_voter_reward_amount( @@ -426,11 +433,12 @@ def calculate_claimable_voter_reward_amount( def calculate_all_claimable_voters_reward_amount( self, ual: UAL, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) return self._get_claimable_all_proposal_voters_reward_amount( @@ -444,11 +452,12 @@ def calculate_all_claimable_voters_reward_amount( def claim_voter_reward( self, ual: UAL, + incentives_type: ParanetIncentivizationType | None = None, ) -> dict[str, str | HexStr | TxReceipt]: - incentives_type = ( + incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value if NEUROWEB_BLOCKCHAIN_PREFIX in ual - else ParanetIncentivizationType.ERC20.value + else ParanetIncentivizationType.NEUROWEB_ERC20.value ) receipt: TxReceipt = self._claim_incentivization_proposal_voter_reward( @@ -510,7 +519,7 @@ def update_claimable_rewards(self, ual: UAL) -> dict[str, str | HexStr | TxRecei def _get_incentives_pool_contract( self, ual: UAL, incentives_type: ParanetIncentivizationType ) -> str | dict[str, str]: - incentives_pool_name = f"ParanetNeurowebIncentivesPool" + incentives_pool_name = INCENTIVE_POOL_NAME is_incentives_pool_cached = ( incentives_pool_name in self.manager.blockchain_provider.contracts.keys() ) From f1706bc3231fbd4343539a138af3d98608b45d14 Mon Sep 17 00:00:00 2001 From: brkagithub Date: Thu, 5 Dec 2024 11:27:47 +0100 Subject: [PATCH 4/5] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c5ca5c2..f8faeb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dkg" -version = "1.1.1" +version = "1.1.2" description = "Python library for interacting with the OriginTrail Decentralized Knowledge Graph" authors = ["Uladzislau Hubar "] license = "Apache-2.0" From 5cbb2e9dba07de7ab2bed8ade42806aefe31e67a Mon Sep 17 00:00:00 2001 From: brkagithub Date: Thu, 5 Dec 2024 12:12:16 +0100 Subject: [PATCH 5/5] Fix incentives type param to be optionally none --- dkg/paranet.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dkg/paranet.py b/dkg/paranet.py index 9fd6e1e..446a488 100644 --- a/dkg/paranet.py +++ b/dkg/paranet.py @@ -38,7 +38,7 @@ class NeuroWebIncentivesPoolParams(BaseIncentivesPoolParams): operator_percentage: float voters_percentage: float - def to_contract_args(self, incentive_type: ParanetIncentivizationType) -> dict: + def to_contract_args(self, incentive_type: ParanetIncentivizationType | None) -> dict: return { "tracToNeuroEmissionMultiplier": int( self.neuro_emission_multiplier @@ -98,7 +98,7 @@ def deploy_incentives_contract( self, ual: UAL, incentives_pool_parameters: NeuroWebIncentivesPoolParams, - incentives_type: ParanetIncentivizationType, + incentives_type: ParanetIncentivizationType | None = None, ) -> dict[str, str | HexStr | TxReceipt]: deploy_incentives_pool_fn = self.incentives_pools_deployment_functions.get( incentives_type, @@ -145,7 +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 + self, ual: UAL, incentives_type: ParanetIncentivizationType | None = None ) -> Address: parsed_ual = parse_ual(ual) knowledge_asset_storage, knowledge_asset_token_id = ( @@ -265,7 +265,7 @@ def is_voter( self, ual: UAL, address: Address | None = None, - incentives_type: ParanetIncentivizationType = None, + incentives_type: ParanetIncentivizationType | None = None, ) -> bool: incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value @@ -285,7 +285,7 @@ def is_voter( def calculate_claimable_miner_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = None, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value @@ -304,7 +304,7 @@ def calculate_claimable_miner_reward_amount( def calculate_all_claimable_miner_rewards_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = None, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value @@ -359,7 +359,7 @@ def claim_miner_reward( def calculate_claimable_operator_reward_amount( self, ual: UAL, - incentives_type: ParanetIncentivizationType = None, + incentives_type: ParanetIncentivizationType | None = None, ) -> int: incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value @@ -378,7 +378,7 @@ def calculate_claimable_operator_reward_amount( def claim_operator_reward( self, ual: UAL, - incentives_type: ParanetIncentivizationType = None, + incentives_type: ParanetIncentivizationType | None = None, ) -> dict[str, str | HexStr | TxReceipt]: incentives_type = incentives_type or ( ParanetIncentivizationType.NEUROWEB.value