Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add funds recovery #136

Merged
merged 9 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ leak_report

agent/
backup_mech/
/packages/valory/skills/termination_abci/
15 changes: 8 additions & 7 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
"dev": {
"connection/valory/websocket_client/0.1.0": "bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm",
"skill/valory/contract_subscription/0.1.0": "bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4",
"agent/valory/mech/0.1.0": "bafybeiamnuotz3zj7whskv6hoieswntuobr3fowkfoh52xw4vait4b5eli",
"skill/valory/mech_abci/0.1.0": "bafybeid6pm3a3yd33hpcvcj5s4rydk623b6hmukrgs4oxnabct2zylzotm",
"contract/valory/agent_mech/0.1.0": "bafybeicshvlc2slopzidzblf2zhdcw2uuav3ntxcgqduxskjujvebikg5u",
"service/valory/mech/0.1.0": "bafybeigh5gm3yc5dsi2gjxcussokytzxqbjvpabedhdshxzgwkmdhknxom",
"agent/valory/mech/0.1.0": "bafybeib6pandgld3qtqprrvrjmptpehc65ue6m5ozbavfpjqrrb5ikjbgi",
"skill/valory/mech_abci/0.1.0": "bafybeifqcfbpwipyvlkrpttnkxnd2fv6pov3gapjhz3b3sbfbmykidrrkq",
"contract/valory/agent_mech/0.1.0": "bafybeidyfhwye3ybk3vxrceljafe2n4o43oxtmjepvexpcrwlccboi34e4",
"service/valory/mech/0.1.0": "bafybeidryu6vwlr5t5wt4ggp34wj6wezjwadetl5rk7r74e24facvcoho4",
"protocol/valory/acn_data_share/0.1.0": "bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq",
"skill/valory/task_submission_abci/0.1.0": "bafybeihluuiksi63kwp2kzn5hdbeek74bnhsctdwl72qv2xjmzqvf7j3va",
"skill/valory/task_execution/0.1.0": "bafybeianf56ypn6pjrqvj24uhmty2b5vtsewzjcrqxnrqyjsuudhyjpiue",
"skill/valory/task_submission_abci/0.1.0": "bafybeidz6os4qfq657vzne2inn76vuteohs2rfldthys37atsgcvznitvi",
"skill/valory/task_execution/0.1.0": "bafybeieup24rlnjosvbixq62f225qayflmxjohzmcopc2y5qfixohv2dlq",
"contract/valory/agent_registry/0.1.0": "bafybeiargayav6yiztdnwzejoejstcx4idssch2h4f5arlgtzj3tgsgfmu",
"protocol/valory/websocket_client/0.1.0": "bafybeih43mnztdv3v2hetr2k3gezg7d3yj4ur7cxdvcyaqhg65e52s5sf4",
"skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta"
"skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta",
"contract/valory/hash_checkpoint/0.1.0": "bafybeiap5fvi2w53e4uwxt75gjzie557hwuegf76xupimx3dvpkgfmj4ei"
},
"third_party": {
"skill/valory/transaction_settlement_abci/0.1.0": "bafybeifqase6vqfrakahogdl4h2hpxntug5ckioicfqlw2og5tn6htru3q",
Expand Down
8 changes: 4 additions & 4 deletions packages/valory/agents/mech/aea-config.yaml
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ connections:
- valory/http_server:0.22.0:bafybeie6g5hxhvdijyjlz4opquapxbsh6udzdjvlqhguwd6wp5cb5a5wuy
- valory/websocket_client:0.1.0:bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm
contracts:
- valory/agent_mech:0.1.0:bafybeicshvlc2slopzidzblf2zhdcw2uuav3ntxcgqduxskjujvebikg5u
- valory/agent_mech:0.1.0:bafybeidyfhwye3ybk3vxrceljafe2n4o43oxtmjepvexpcrwlccboi34e4
- valory/gnosis_safe:0.1.0:bafybeie7qpo4sue4i54pzsg6nx365q6d3i4sl6ygdilwldqqxwroukbkiu
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeig6evakqztiuyn67vwv63fzgqqfig4whp4qlef3w6pf7hmngrw3si
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
Expand All @@ -37,11 +37,11 @@ skills:
- valory/abstract_abci:0.1.0:bafybeieynwkrnlm6wwtufh2jsgnlprjbpmte7now5rk7fbgd5mh5yumhry
- valory/abstract_round_abci:0.1.0:bafybeifcq2nwd6m5tgxooe7436bc6lwo73xcreedmhcwauzhp5jic6jeq4
- valory/contract_subscription:0.1.0:bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4
- valory/mech_abci:0.1.0:bafybeid6pm3a3yd33hpcvcj5s4rydk623b6hmukrgs4oxnabct2zylzotm
- valory/task_execution:0.1.0:bafybeianf56ypn6pjrqvj24uhmty2b5vtsewzjcrqxnrqyjsuudhyjpiue
- valory/mech_abci:0.1.0:bafybeifqcfbpwipyvlkrpttnkxnd2fv6pov3gapjhz3b3sbfbmykidrrkq
- valory/task_execution:0.1.0:bafybeieup24rlnjosvbixq62f225qayflmxjohzmcopc2y5qfixohv2dlq
- valory/registration_abci:0.1.0:bafybeig5fb3ibz3tr4kie53venqtajnlhvh7gwt5h45rxwzakwgs6jjsjq
- valory/reset_pause_abci:0.1.0:bafybeiergfseqtmsphdimzjijxezqyyhigktvqriw2xb4dyujim6s5dr4a
- valory/task_submission_abci:0.1.0:bafybeihluuiksi63kwp2kzn5hdbeek74bnhsctdwl72qv2xjmzqvf7j3va
- valory/task_submission_abci:0.1.0:bafybeidz6os4qfq657vzne2inn76vuteohs2rfldthys37atsgcvznitvi
- valory/termination_abci:0.1.0:bafybeia73cl2vqj2uawt5lnoej3fzlhhum72i2p6ld4bbudd67lxb7f3cu
- valory/transaction_settlement_abci:0.1.0:bafybeifqase6vqfrakahogdl4h2hpxntug5ckioicfqlw2og5tn6htru3q
- valory/websocket_client:0.1.0:bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta
Expand Down
32 changes: 31 additions & 1 deletion packages/valory/contracts/agent_mech/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# ------------------------------------------------------------------------------

"""This module contains the dynamic_contribution contract definition."""

from enum import Enum
from typing import Any, Dict, List, cast

from aea.common import JSONLike
Expand Down Expand Up @@ -81,6 +81,13 @@
]


class MechOperation(Enum):
"""Operation types."""

CALL = 0
DELEGATE_CALL = 1


class AgentMechContract(Contract):
"""The scaffold contract class for a smart contract."""

Expand Down Expand Up @@ -272,3 +279,26 @@ def get_multiple_undelivered_reqs(
).get("data")
pending_tasks.extend(pending_tasks_batch)
return {"data": pending_tasks}

@classmethod
def get_exec_tx_data(
cls,
ledger_api: LedgerApi,
contract_address: str,
to: str,
value: int,
data: bytes,
operation: int,
tx_gas: int,
) -> JSONLike:
"""Get tx data"""
ledger_api = cast(EthereumApi, ledger_api)

if not isinstance(ledger_api, EthereumApi):
raise ValueError(f"Only EthereumApi is supported, got {type(ledger_api)}")

contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI(
fn_name="exec", args=[to, value, data, operation, tx_gas]
)
return {"data": bytes.fromhex(data[2:])} # type: ignore
2 changes: 1 addition & 1 deletion packages/valory/contracts/agent_mech/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeigpq5lxfj2aza6ok3fjuywtdafelkbvoqwaits7regfbgu4oynmku
build/AgentMech.json: bafybeidrlu7vpusp2tzovyf5rbnqy2jicuq3e6czizfkzswjq4rjusu72i
contract.py: bafybeihm4bmidifvp225rpxtg5xu5dyd5k65gm33jkoms2brrshvu5lige
contract.py: bafybeig65qzfwsetro4ncnb4zlmtws3dliun6q57mw3xzy7qh5s2kczj64
fingerprint_ignore_patterns: []
class_name: AgentMechContract
contract_interface_paths:
Expand Down
20 changes: 20 additions & 0 deletions packages/valory/contracts/hash_checkpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 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 agent mech contract."""
241 changes: 241 additions & 0 deletions packages/valory/contracts/hash_checkpoint/build/HashCheckpoint.json

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions packages/valory/contracts/hash_checkpoint/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 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 hash checkpoint contract definition."""
from enum import Enum
from typing import Any, Dict, List, cast

from aea.common import JSONLike
from aea.configurations.base import PublicId
from aea.contracts.base import Contract
from aea.crypto.base import LedgerApi
from aea_ledger_ethereum import EthereumApi
from web3.types import BlockIdentifier, TxReceipt


class HashCheckpointContract(Contract):
"""The scaffold contract class for a smart contract."""

contract_id = PublicId.from_str("valory/hash_checkpoint:0.1.0")

@classmethod
def get_raw_transaction(
cls, ledger_api: LedgerApi, contract_address: str, **kwargs: Any
) -> JSONLike:
"""
Handler method for the 'GET_RAW_TRANSACTION' requests.

Implement this method in the sub class if you want
to handle the contract requests manually.

:param ledger_api: the ledger apis.
:param contract_address: the contract address.
:param kwargs: the keyword arguments.
:return: the tx # noqa: DAR202
"""
raise NotImplementedError

@classmethod
def get_raw_message(
cls, ledger_api: LedgerApi, contract_address: str, **kwargs: Any
) -> bytes:
"""
Handler method for the 'GET_RAW_MESSAGE' requests.

Implement this method in the sub class if you want
to handle the contract requests manually.

:param ledger_api: the ledger apis.
:param contract_address: the contract address.
:param kwargs: the keyword arguments.
:return: the tx # noqa: DAR202
"""
raise NotImplementedError

@classmethod
def get_state(
cls, ledger_api: LedgerApi, contract_address: str, **kwargs: Any
) -> JSONLike:
"""
Handler method for the 'GET_STATE' requests.

Implement this method in the sub class if you want
to handle the contract requests manually.

:param ledger_api: the ledger apis.
:param contract_address: the contract address.
:param kwargs: the keyword arguments.
:return: the tx # noqa: DAR202
"""
raise NotImplementedError

@classmethod
def get_checkpoint_data(
cls, ledger_api: LedgerApi, contract_address: str, data: bytes
) -> JSONLike:
"""
Deliver a response to a request.

:param ledger_api: LedgerApi object
:param contract_address: the address of the token to be used
:param data: the ipfs hash
:return: the deliver data
"""
ledger_api = cast(EthereumApi, ledger_api)

if not isinstance(ledger_api, EthereumApi):
raise ValueError(f"Only EthereumApi is supported, got {type(ledger_api)}")

contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI(
fn_name="checkpoint", args=[data]
)
return {"data": data}

@classmethod
def get_latest_hash(
cls,
ledger_api: LedgerApi,
contract_address: str,
sender_address: str,
) -> JSONLike:
"""Get the Request events emitted by the contract."""
ledger_api = cast(EthereumApi, ledger_api)

if not isinstance(ledger_api, EthereumApi):
raise ValueError(f"Only EthereumApi is supported, got {type(ledger_api)}")

contract_instance = cls.get_instance(ledger_api, contract_address)
sender_address = ledger_api.api.to_checksum_address(sender_address)
latest_ipfs_hash = contract_instance.functions.latestHash(sender_address).call()
return {"data": latest_ipfs_hash}
21 changes: 21 additions & 0 deletions packages/valory/contracts/hash_checkpoint/contract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: hash_checkpoint
author: valory
version: 0.1.0
type: contract
description: Hash checkpoint contract
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeigpq5lxfj2aza6ok3fjuywtdafelkbvoqwaits7regfbgu4oynmku
build/HashCheckpoint.json: bafybeicdse6k7xbis3mdurqee7a3ghiba4hzfk4llhc3hk6q4qbfjd5rg4
contract.py: bafybeiaklk45tud5qogk6zeufwlewlgbaunux5kbahj4auf6xzkikfgwru
fingerprint_ignore_patterns: []
class_name: HashCheckpointContract
contract_interface_paths:
ethereum: build/HashCheckpoint.json
dependencies:
open-aea-ledger-ethereum:
version: ==1.41.0.post1
web3:
version: <7,>=6.0.0
contracts: []
2 changes: 1 addition & 1 deletion packages/valory/services/mech/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeif7ia4jdlazy6745ke2k2x5yoqlwsgwr6sbztbgqtwvs3ndm2p7ba
fingerprint_ignore_patterns: []
agent: valory/mech:0.1.0:bafybeiamnuotz3zj7whskv6hoieswntuobr3fowkfoh52xw4vait4b5eli
agent: valory/mech:0.1.0:bafybeib6pandgld3qtqprrvrjmptpehc65ue6m5ozbavfpjqrrb5ikjbgi
number_of_agents: 4
deployment:
agent:
Expand Down
5 changes: 4 additions & 1 deletion packages/valory/skills/mech_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ skills:
- valory/abstract_round_abci:0.1.0:bafybeifcq2nwd6m5tgxooe7436bc6lwo73xcreedmhcwauzhp5jic6jeq4
- valory/registration_abci:0.1.0:bafybeig5fb3ibz3tr4kie53venqtajnlhvh7gwt5h45rxwzakwgs6jjsjq
- valory/reset_pause_abci:0.1.0:bafybeiergfseqtmsphdimzjijxezqyyhigktvqriw2xb4dyujim6s5dr4a
- valory/task_submission_abci:0.1.0:bafybeihluuiksi63kwp2kzn5hdbeek74bnhsctdwl72qv2xjmzqvf7j3va
- valory/task_submission_abci:0.1.0:bafybeidz6os4qfq657vzne2inn76vuteohs2rfldthys37atsgcvznitvi
- valory/termination_abci:0.1.0:bafybeia73cl2vqj2uawt5lnoej3fzlhhum72i2p6ld4bbudd67lxb7f3cu
- valory/transaction_settlement_abci:0.1.0:bafybeifqase6vqfrakahogdl4h2hpxntug5ckioicfqlw2og5tn6htru3q
behaviours:
Expand Down Expand Up @@ -159,8 +159,11 @@ models:
agent_id: 3
metadata_hash: '00000000000000000000000000000000000000000000000000'
slash_cooldown_hours: 3
hash_checkpoint_address: '0x0000000000000000000000000000000000000000'
slash_threshold_amount: 10000000000000000
light_slash_unit_amount: 5000000000000000
service_owner_share: 0.1
profit_split_freq: 100
serious_slash_unit_amount: 8000000000000000
service_endpoint_base: https://dummy_service.autonolas.tech/
class_name: Params
Expand Down
12 changes: 11 additions & 1 deletion packages/valory/skills/task_execution/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,15 @@ def _handle_done_task(self, task_result: Any) -> None:
executing_task = cast(Dict[str, Any], self._executing_task)
req_id = executing_task.get("requestId", None)
mech_address = executing_task.get("contract_address", None)
tool = executing_task.get("tool", None)
response = {"requestId": req_id, "result": "Invalid response"}
self._done_task = {"request_id": req_id, "mech_address": mech_address}
task_executor = self.context.agent_address
self._done_task = {
"request_id": req_id,
"mech_address": mech_address,
"task_executor_address": task_executor,
"tool": tool,
}
if task_result is not None:
# task succeeded
deliver_msg, prompt, transaction = task_result
Expand Down Expand Up @@ -330,6 +337,8 @@ def _handle_get_task(self, message: IpfsMessage, dialogue: Dialogue) -> None:
self._prepare_task(task_data)
elif is_data_valid:
tool = task_data["tool"]
executing_task = cast(Dict[str, Any], self._executing_task)
executing_task["tool"] = tool
self.context.logger.warning(f"Tool {tool} is not valid.")
self._invalid_request = True
else:
Expand Down Expand Up @@ -358,6 +367,7 @@ def _prepare_task(self, task_data: Dict[str, Any]) -> None:
future = self._submit_task(tool_task.execute, **task_data)
executing_task = cast(Dict[str, Any], self._executing_task)
executing_task["timeout_deadline"] = time.time() + self.params.task_deadline
executing_task["tool"] = task_data["tool"]
self._async_result = cast(Optional[Future], future)

def _build_ipfs_message(
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/task_execution/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeidqhvvlnthkbnmrdkdeyjyx2f2ab6z4xdgmagh7welqnh2v6wczx4
behaviours.py: bafybeie4h4m4py7u3ah4mcotiah32umi7lb5xnxmzpvvhikushaedcglkq
behaviours.py: bafybeiahzfpgcjpvbhpfkbifrkzb6qaj2gesnkswdi2lj7yszhe27dvjtm
dialogues.py: bafybeid4zxalqdlo5mw4yfbuf34hx4jp5ay5z6chm4zviwu4cj7fudtwca
handlers.py: bafybeidbt5ezj74cgfogk3w4uw4si2grlnk5g54veyumw7g5yh6gdscywu
models.py: bafybeihc2kmymmh5oousjddbc7xujqbk5niermuqak2dhtgryukzq5wxeq
Expand All @@ -20,7 +20,7 @@ connections:
- valory/ipfs:0.1.0:bafybeigfmqvlzbp67fttccpl4hsu3zaztbxv6vd7ikzra2hfppfkalgpji
- valory/p2p_libp2p_client:0.1.0:bafybeihge56dn3xep2dzomu7rtvbgo4uc2qqh7ljl3fubqdi2lq44gs5lq
contracts:
- valory/agent_mech:0.1.0:bafybeicshvlc2slopzidzblf2zhdcw2uuav3ntxcgqduxskjujvebikg5u
- valory/agent_mech:0.1.0:bafybeidyfhwye3ybk3vxrceljafe2n4o43oxtmjepvexpcrwlccboi34e4
protocols:
- valory/acn_data_share:0.1.0:bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq
- valory/contract_api:1.0.0:bafybeialhbjvwiwcnqq3ysxcyemobcbie7xza66gaofcvla5njezkvhcka
Expand Down
Loading
Loading