diff --git a/operate/data/contracts/staking_token/__init__.py b/operate/data/contracts/staking_token/__init__.py deleted file mode 100644 index 4682f8155..000000000 --- a/operate/data/contracts/staking_token/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# ------------------------------------------------------------------------------ -# -# Copyright 2024 Valory AG -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ------------------------------------------------------------------------------ - -"""This module contains the support resources for the staking contract.""" diff --git a/operate/data/contracts/staking_token/contract.py b/operate/data/contracts/staking_token/contract.py deleted file mode 100644 index 384beea7a..000000000 --- a/operate/data/contracts/staking_token/contract.py +++ /dev/null @@ -1,192 +0,0 @@ -# -*- coding: utf-8 -*- -# ------------------------------------------------------------------------------ -# -# Copyright 2023-2024 Valory AG -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ------------------------------------------------------------------------------ - -"""This module contains the class to connect to the `ServiceStakingTokenMechUsage` contract.""" - -from enum import Enum - -from aea.common import JSONLike -from aea.configurations.base import PublicId -from aea.contracts.base import Contract -from aea.crypto.base import LedgerApi - - -class StakingTokenContract(Contract): - """The Service Staking contract.""" - - contract_id = PublicId.from_str("valory/staking_token:0.1.0") - - @classmethod - def get_service_staking_state( - cls, - ledger_api: LedgerApi, - contract_address: str, - service_id: int, - ) -> JSONLike: - """Check whether the service is staked.""" - contract_instance = cls.get_instance(ledger_api, contract_address) - res = contract_instance.functions.getStakingState(service_id).call() - return dict(data=res) - - @classmethod - def build_stake_tx( - cls, - ledger_api: LedgerApi, - contract_address: str, - service_id: int, - ) -> JSONLike: - """Build stake tx.""" - contract_instance = cls.get_instance(ledger_api, contract_address) - data = contract_instance.encodeABI("stake", args=[service_id]) - return dict(data=bytes.fromhex(data[2:])) - - @classmethod - def build_checkpoint_tx( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Build checkpoint tx.""" - contract_instance = cls.get_instance(ledger_api, contract_address) - data = contract_instance.encodeABI("checkpoint") - return dict(data=bytes.fromhex(data[2:])) - - @classmethod - def build_unstake_tx( - cls, - ledger_api: LedgerApi, - contract_address: str, - service_id: int, - ) -> JSONLike: - """Build unstake tx.""" - contract_instance = cls.get_instance(ledger_api, contract_address) - data = contract_instance.encodeABI("unstake", args=[service_id]) - return dict(data=bytes.fromhex(data[2:])) - - @classmethod - def available_rewards( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Get the available rewards.""" - contract_instance = cls.get_instance(ledger_api, contract_address) - res = contract_instance.functions.availableRewards().call() - return dict(data=res) - - @classmethod - def get_staking_rewards( - cls, - ledger_api: LedgerApi, - contract_address: str, - service_id: int, - ) -> JSONLike: - """Get the service's staking rewards.""" - contract = cls.get_instance(ledger_api, contract_address) - reward = contract.functions.calculateStakingReward(service_id).call() - return dict(data=reward) - - @classmethod - def get_next_checkpoint_ts( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Get the next checkpoint's timestamp.""" - contract = cls.get_instance(ledger_api, contract_address) - ts = contract.functions.getNextRewardCheckpointTimestamp().call() - return dict(data=ts) - - @classmethod - def ts_checkpoint( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the checkpoint's timestamp.""" - contract = cls.get_instance(ledger_api, contract_address) - ts_checkpoint = contract.functions.tsCheckpoint().call() - return dict(data=ts_checkpoint) - - @classmethod - def liveness_ratio( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the liveness ratio.""" - contract = cls.get_instance(ledger_api, contract_address) - liveness_ratio = contract.functions.livenessRatio().call() - return dict(data=liveness_ratio) - - @classmethod - def get_liveness_period( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the liveness period.""" - contract = cls.get_instance(ledger_api, contract_address) - liveness_period = contract.functions.livenessPeriod().call() - return dict(data=liveness_period) - - @classmethod - def get_service_info( - cls, - ledger_api: LedgerApi, - contract_address: str, - service_id: int, - ) -> JSONLike: - """Retrieve the service info for a service.""" - contract = cls.get_instance(ledger_api, contract_address) - info = contract.functions.getServiceInfo(service_id).call() - return dict(data=info) - - @classmethod - def max_num_services( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the max number of services.""" - contract = cls.get_instance(ledger_api, contract_address) - max_num_services = contract.functions.maxNumServices().call() - return dict(data=max_num_services) - - @classmethod - def get_service_ids( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the service IDs.""" - contract = cls.get_instance(ledger_api, contract_address) - service_ids = contract.functions.getServiceIds().call() - return dict(data=service_ids) - - @classmethod - def get_min_staking_duration( - cls, - ledger_api: LedgerApi, - contract_address: str, - ) -> JSONLike: - """Retrieve the service IDs.""" - contract = cls.get_instance(ledger_api, contract_address) - duration = contract.functions.minStakingDuration().call() - return dict(data=duration) diff --git a/operate/data/contracts/staking_token/contract.yaml b/operate/data/contracts/staking_token/contract.yaml deleted file mode 100644 index 2fce9ed86..000000000 --- a/operate/data/contracts/staking_token/contract.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: staking_token -author: valory -version: 0.1.0 -type: contract -description: Service staking token contract -license: Apache-2.0 -aea_version: '>=1.0.0, <2.0.0' -fingerprint: - __init__.py: bafybeicmgkagyhgwn2ktcdjbprijalbdyj26cvza4d3b7uvmehvy4mmr3i - build/StakingToken.json: bafybeid5vwardpaeeggfbp4o2ea7wdhywaeamhvyolxmhv6v2ynil4st6q - contract.py: bafybeigzb6oxpyi7eiohftxuha5t3tcvj2bekihc77ts3dwzqpfl34ev6y -fingerprint_ignore_patterns: [] -contracts: [] -class_name: StakingTokenContract -contract_interface_paths: - ethereum: build/StakingToken.json -dependencies: - open-aea-ledger-ethereum: - version: ==1.52.0 - open-aea-test-autonomy: - version: ==0.14.12 - web3: - version: <7,>=6.0.0 diff --git a/operate/services/manage.py b/operate/services/manage.py index d93e86687..abe7893b7 100644 --- a/operate/services/manage.py +++ b/operate/services/manage.py @@ -684,17 +684,29 @@ def terminate_service_on_chain_from_safe(self, hash: str, chain_id: int) -> None ic(info) + # Determine if the service is staked in a known staking program + current_staking_program = None for staking_program in STAKING[ledger_config.chain]: state = sftxb.staking_status( service_id=chain_data.token, staking_contract=STAKING[ledger_config.chain][staking_program], ) + if state in (StakingState.STAKED, StakingState.EVICTED): + current_staking_program = staking_program - print(state) + is_staked = current_staking_program is not None + # if is_staked: + # can_unstake = and not self._can_unstake_service_from_safe(hash=hash) + print(current_staking_program) + print(is_staked) import sys sys.exit(1) + + + + if ( chain_data.user_params.use_staking and not self._can_unstake_service_from_safe(hash=hash) diff --git a/operate/services/protocol.py b/operate/services/protocol.py index ea7bcda35..78e1d4e4e 100644 --- a/operate/services/protocol.py +++ b/operate/services/protocol.py @@ -63,9 +63,6 @@ from operate.data.contracts.service_staking_token.contract import ( ServiceStakingTokenContract, ) -from operate.data.contracts.staking_token.contract import ( - StakingTokenContract, -) from operate.types import ContractAddresses from operate.utils.gnosis import ( MultiSendOperation, @@ -203,48 +200,23 @@ def __init__( directory=str(DATA_DIR / "contracts" / "service_staking_token") ), ) - self.staking_token_ctr = t.cast( - StakingTokenContract, - StakingTokenContract.from_dir( - directory=str(DATA_DIR / "contracts" / "staking_token") - ), - ) + # self.staking_token_ctr = t.cast( + # StakingTokenContract, + # StakingTokenContract.from_dir( + # directory=str(DATA_DIR / "contracts" / "staking_token") + # ), + # ) def status(self, service_id: int, staking_contract: str) -> StakingState: """Is the service staked?""" - staking_state = None - - print(staking_contract) - try: - print("a") - staking_state = StakingState( - self.staking_ctr.get_instance( - ledger_api=self.ledger_api, - contract_address=staking_contract, - ) - .functions.getStakingState(service_id) - .call() + return StakingState( + self.staking_ctr.get_instance( + ledger_api=self.ledger_api, + contract_address=staking_contract, ) - print("b") - return staking_state - except Exception: - print("c") - - try: - staking_state = StakingState( - self.staking_token_ctr.get_instance( - ledger_api=self.ledger_api, - contract_address=staking_contract, - ) - .functions.getStakingState(service_id) - .call() - ) - return staking_state - except Exception: - print("EXCEPTION") - print("d") - - return staking_state + .functions.getStakingState(service_id) + .call() + ) def slots_available(self, staking_contract: str) -> bool: """Check if there are available slots on the staking contract"""