Skip to content

Commit

Permalink
Merge pull request #201 from valory-xyz/feat/tx-tool
Browse files Browse the repository at this point in the history
Implement a dummy transaction preparation tool
  • Loading branch information
0xArdi authored Mar 29, 2024
2 parents b660d04 + d49e70d commit ad73254
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 42 deletions.
1 change: 1 addition & 0 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"custom/napthaai/resolve_market_reasoning/0.1.0": "bafybeigutlttyivlf6yxdeesclv3dwxq6h7yj3varq63b6ujno3q6ytoje",
"custom/napthaai/prediction_request_rag/0.1.0": "bafybeibp3hfeywllhmepvqyah763go4i5vtvo4wwihy6h4x7sylsjm5cam",
"custom/napthaai/prediction_request_reasoning/0.1.0": "bafybeihrq7vvup2jztclucyrveb3nlgeb2pe5afgrxglgb7ji6b5jv5vtm",
"custom/valory/prepare_tx/0.1.0": "bafybeighlfdmykwbar6wuipeo66blv2vcckxyspvw2oscsjctowly5taf4",
"protocol/valory/acn_data_share/0.1.0": "bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq",
"protocol/valory/websocket_client/0.1.0": "bafybeih43mnztdv3v2hetr2k3gezg7d3yj4ur7cxdvcyaqhg65e52s5sf4",
"contract/valory/agent_mech/0.1.0": "bafybeidsau5x2vjofpcdzxkg7airwkrdag65ohtxcby2ut27tfjizgnrnm",
Expand Down
20 changes: 20 additions & 0 deletions packages/valory/customs/prepare_tx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- 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 a tool that prepares a transaction."""
14 changes: 14 additions & 0 deletions packages/valory/customs/prepare_tx/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: prepare_tx
author: valory
version: 0.1.0
type: custom
description: A tool to prepare a transaction.
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeieynbsr6aijx2totfi5iw6thjwgzko526zcs5plgvgrq2lufso2sy
prepare_tx.py: bafybeichg7r54hcaqvrxecpzssm7iqrc5kjli33m6hqlnsrojqng7jqvsa
fingerprint_ignore_patterns: []
entry_point: prepare_tx.py
callable: run
dependencies: {}
72 changes: 72 additions & 0 deletions packages/valory/customs/prepare_tx/prepare_tx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- 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 implements a tool which prepares a transaction for the transaction settlement skill.
Please note that the gnosis safe parameters are missing from the payload, e.g., `safe_tx_hash`, `safe_tx_gas`, etc.
"""

import json
from typing import Any, Dict, Optional, Tuple


# a test value
VALUE = 1
# a test address
TO_ADDRESS = "0xFDECa8497223DFa5aE2200D759f769e95dAadE01"


def prepare_tx(
prompt: str,
) -> Tuple[Optional[str], Any, Optional[Dict[str, Any]], Any]:
"""Perform native transfer."""
transaction = json.dumps(
{
"value": VALUE,
"to_address": TO_ADDRESS,
}
)
return transaction, prompt, None, None


AVAILABLE_TOOLS = {"prepare_tx": prepare_tx}


def error_response(msg: str) -> Tuple[str, None, None, None]:
"""Return an error mech response."""
return msg, None, None, None


def run(**kwargs) -> Tuple[str, Optional[str], Optional[Dict[str, Any]], Any]:
"""Run the task"""
tool = kwargs.get("tool", None)
if tool is None:
return error_response("No tool has been specified.")

prompt = kwargs.get("prompt", None)
if prompt is None:
return error_response("No prompt has been given.")

transaction_builder = AVAILABLE_TOOLS.get(tool, None)
if transaction_builder is None:
return error_response(
f"Tool {tool!r} is not in supported tools: {tuple(AVAILABLE_TOOLS.keys())}."
)

return transaction_builder(prompt)
68 changes: 26 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad73254

Please sign in to comment.