mezoAgent 0.4.2__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mezoAgent-0.4.2.dist-info → mezoAgent-0.5.0.dist-info}/METADATA +1 -1
- mezoAgent-0.5.0.dist-info/RECORD +14 -0
- mezo_agent/__init__.py +4 -2
- mezo_agent/config.py +22 -2
- mezo_agent/parsing.py +35 -1
- mezo_agent/token_balance_tool.py +32 -0
- mezo_agent/utils.py +29 -0
- mezoAgent-0.4.2.dist-info/RECORD +0 -12
- {mezoAgent-0.4.2.dist-info → mezoAgent-0.5.0.dist-info}/WHEEL +0 -0
- {mezoAgent-0.4.2.dist-info → mezoAgent-0.5.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
mezo_agent/__init__.py,sha256=naG5ZIXKDWTRlqdx2oi1zJcRZpJBO9ugVkW0MaPkZuk,497
|
2
|
+
mezo_agent/characters.py,sha256=wub7y9BrAAdAKWwcNAdgrvhRi2zHMaZNzTr2y3qtbsw,515
|
3
|
+
mezo_agent/chat.py,sha256=ZtNurUDV7UzJjbFyU96DNGy37hO3gl0osn19mRu7ER8,859
|
4
|
+
mezo_agent/config.py,sha256=LgMTntnzXrY7giGXy6JZqhPwPxxMpWWOgc2Ah6g3Y48,3017
|
5
|
+
mezo_agent/parsing.py,sha256=6g0U4x8nQaOkwIPon1UlKlnVX6-S2Tf4LKqdY1ZGyiY,4000
|
6
|
+
mezo_agent/swap_musd_btc.py,sha256=Co-XcfK73spm94VC6qzGY0VYoGwsMDKKHM8ToGh2JxU,4289
|
7
|
+
mezo_agent/token_balance_tool.py,sha256=GQsZnM6zwIdCL5fRISd_KAdc8RNVOTa0LYHPhPIdW1g,1304
|
8
|
+
mezo_agent/transaction.py,sha256=YpfWrkEaf0YGM_Kc4cFwlT9GmBGZkeJHWm0VGHs9Gks,4199
|
9
|
+
mezo_agent/utils.py,sha256=Kdq3YRj6fOnAmDjI6vktvOvN0vAR8U7TgoTGqcA2KcI,973
|
10
|
+
mezo_agent/data/new_router.json,sha256=A8U-NVfe1F-hDyR90_SuH8jDAxmzyyHWdJW62j9TZsc,26756
|
11
|
+
mezoAgent-0.5.0.dist-info/METADATA,sha256=ZfVWkIcivB8L4OlUGNFpwhg-SQXFqHp8wkFg-Ugh4W0,273
|
12
|
+
mezoAgent-0.5.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
13
|
+
mezoAgent-0.5.0.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
|
14
|
+
mezoAgent-0.5.0.dist-info/RECORD,,
|
mezo_agent/__init__.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
from .transaction import mezo_agent_transaction_btc, mezo_agent_musd_transaction
|
2
2
|
from .swap_musd_btc import mezo_agent_swap_musd_btc
|
3
|
-
from .chat import mezo_character_chat
|
3
|
+
from .chat import mezo_character_chat
|
4
4
|
from .characters import get_character_prompt
|
5
|
+
from .token_balance_tool import mezo_agent_token_balance_tool
|
5
6
|
|
6
7
|
__all__ = [
|
7
8
|
"mezo_agent_transaction_btc",
|
8
9
|
"mezo_agent_musd_transaction",
|
9
10
|
"mezo_agent_swap_musd_btc",
|
10
|
-
"mezo_character_chat",
|
11
|
+
"mezo_character_chat",
|
12
|
+
"mezo_agent_token_balance_tool",
|
11
13
|
"get_character_prompt"
|
12
14
|
]
|
mezo_agent/config.py
CHANGED
@@ -3,6 +3,8 @@ import json
|
|
3
3
|
from dotenv import load_dotenv
|
4
4
|
from web3 import Web3
|
5
5
|
import importlib.resources as pkg_resources
|
6
|
+
import requests
|
7
|
+
|
6
8
|
# Load environment variables
|
7
9
|
load_dotenv()
|
8
10
|
|
@@ -25,6 +27,9 @@ if not PRIVATE_KEY:
|
|
25
27
|
RPC_URL = "https://rpc.test.mezo.org"
|
26
28
|
web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
|
27
29
|
|
30
|
+
#Graph endpoint
|
31
|
+
GRAPH_URL = "https://api.goldsky.com/api/public/project_cm48lsrzo0axx01tna6rb1ee9/subgraphs/exchange-v2-mezo/1.0.0/gn"
|
32
|
+
|
28
33
|
# Create Account Object
|
29
34
|
account = web3_instance.eth.account.from_key(PRIVATE_KEY)
|
30
35
|
sender_address = account.address
|
@@ -32,13 +37,28 @@ sender_address = account.address
|
|
32
37
|
# mUSD Contract Setup using approve/allowance ABI
|
33
38
|
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
34
39
|
ERC20_ABI = json.loads(
|
35
|
-
'[{"constant": false, "inputs": [{"name": "
|
40
|
+
'[{"constant": false, "inputs": [{"name": "recipient", "type": "address"}, {"name": "amount", "type": "uint256"}],'
|
41
|
+
'"name": "transfer", "outputs": [{"name": "", "type": "bool"}], "stateMutability": "nonpayable", "type": "function"},'
|
42
|
+
'{"constant": false, "inputs": [{"name": "spender", "type": "address"}, {"name": "amount", "type": "uint256"}],'
|
36
43
|
'"name": "approve", "outputs": [{"name": "", "type": "bool"}], "stateMutability": "nonpayable", "type": "function"},'
|
37
44
|
'{"constant": true, "inputs": [{"name": "owner", "type": "address"}, {"name": "spender", "type": "address"}],'
|
38
45
|
'"name": "allowance", "outputs": [{"name": "remaining", "type": "uint256"}], "stateMutability": "view", "type": "function"}]'
|
39
46
|
)
|
40
47
|
musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
|
41
48
|
|
49
|
+
#Query graph for token info
|
50
|
+
def query_graph(query: str) -> dict:
|
51
|
+
"""
|
52
|
+
Queries the Goldsky GraphQL API for blockchain data.
|
53
|
+
:param query: GraphQL query string.
|
54
|
+
:return: JSON response as a dictionary.
|
55
|
+
"""
|
56
|
+
response = requests.post(GRAPH_URL, json={"query": query})
|
57
|
+
if response.status_code == 200:
|
58
|
+
return response.json()
|
59
|
+
else:
|
60
|
+
raise Exception(f"GraphQL query failed with status code {response.status_code}")
|
61
|
+
|
42
62
|
# Wrapped BTC and Swap Router setup
|
43
63
|
WRAPPED_BTC_ADDRESS = "0xA460F83cdd9584E4bD6a9838abb0baC58EAde999"
|
44
64
|
ROUTER_ADDRESS = "0xC2E61936a542D78b9c3AA024fA141c4C632DF6c1"
|
@@ -47,4 +67,4 @@ ROUTER_ADDRESS = "0xC2E61936a542D78b9c3AA024fA141c4C632DF6c1"
|
|
47
67
|
with pkg_resources.open_text("mezo_agent.data", "new_router.json") as f:
|
48
68
|
router_abi = json.load(f)
|
49
69
|
|
50
|
-
router_contract = web3_instance.eth.contract(address=ROUTER_ADDRESS, abi=router_abi)
|
70
|
+
router_contract = web3_instance.eth.contract(address=ROUTER_ADDRESS, abi=router_abi)
|
mezo_agent/parsing.py
CHANGED
@@ -62,4 +62,38 @@ def extract_swap_details(prompt: str):
|
|
62
62
|
try:
|
63
63
|
return swap_output_parser.parse(response.content)
|
64
64
|
except Exception as e:
|
65
|
-
return f"Failed to extract swap details: {str(e)}"
|
65
|
+
return f"Failed to extract swap details: {str(e)}"
|
66
|
+
|
67
|
+
#parsing for balance check tool
|
68
|
+
|
69
|
+
balance_response_schema = [
|
70
|
+
ResponseSchema(name="token_symbol", description="The token symbol to check the balance for (e.g., 'MUSD').")
|
71
|
+
]
|
72
|
+
|
73
|
+
balance_output_parser = StructuredOutputParser.from_response_schemas(balance_response_schema)
|
74
|
+
|
75
|
+
balance_prompt_template = PromptTemplate(
|
76
|
+
template="""Output a JSON object with the following key:
|
77
|
+
- token_symbol: (string) The token symbol for which to check the balance (e.g., "MUSD").
|
78
|
+
|
79
|
+
Extract this detail from the following query:
|
80
|
+
{input}
|
81
|
+
|
82
|
+
Your output must be a valid JSON object with no additional text.
|
83
|
+
""",
|
84
|
+
input_variables=["input"],
|
85
|
+
)
|
86
|
+
|
87
|
+
def extract_balance_details(prompt: str):
|
88
|
+
"""
|
89
|
+
Parses a balance query and extracts the token symbol.
|
90
|
+
|
91
|
+
:param prompt: User input asking for a token balance.
|
92
|
+
:return: Dictionary containing the token symbol or an error message.
|
93
|
+
"""
|
94
|
+
try:
|
95
|
+
formatted_prompt = balance_prompt_template.format(input=prompt)
|
96
|
+
response = balance_output_parser.parse(formatted_prompt)
|
97
|
+
return response
|
98
|
+
except Exception as e:
|
99
|
+
return f"❌ Failed to extract balance details: {str(e)}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
from langchain.tools import tool
|
2
|
+
from mezo_agent.config import web3_instance, sender_address, extract_balance_details, ERC20_ABI
|
3
|
+
from mezo_agent.utils import get_token_address_by_symbol
|
4
|
+
|
5
|
+
@tool
|
6
|
+
def mezo_agent_token_balance_tool(balance_prompt: str) -> str:
|
7
|
+
"""
|
8
|
+
Queries the wallet balance for a specified token on Mezo Matsnet.
|
9
|
+
|
10
|
+
:param balance_prompt: User query containing the token symbol.
|
11
|
+
:return: Token balance for the sender's address.
|
12
|
+
"""
|
13
|
+
details = extract_balance_details(balance_prompt)
|
14
|
+
|
15
|
+
if isinstance(details, str): # Handle extraction errors
|
16
|
+
return details
|
17
|
+
|
18
|
+
token_symbol = details.get("token_symbol")
|
19
|
+
if not token_symbol:
|
20
|
+
return "❌ Could not extract token symbol for balance query."
|
21
|
+
|
22
|
+
try:
|
23
|
+
# Get the contract address dynamically
|
24
|
+
token_address = get_token_address_by_symbol(token_symbol)
|
25
|
+
token_contract = web3_instance.eth.contract(address=token_address, abi=ERC20_ABI)
|
26
|
+
|
27
|
+
# Fetch balance
|
28
|
+
balance_wei = token_contract.functions.balanceOf(sender_address).call()
|
29
|
+
balance = web3_instance.from_wei(balance_wei, "ether")
|
30
|
+
return f"✅ {token_symbol.upper()} Balance: {balance}"
|
31
|
+
except Exception as e:
|
32
|
+
return f"❌ Failed to fetch balance: {str(e)}"
|
mezo_agent/utils.py
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
from mezo_agent.config import web3_instance, query_graph
|
2
|
+
|
3
|
+
def get_token_address_by_symbol(symbol: str) -> str:
|
4
|
+
"""
|
5
|
+
Fetches the token contract address dynamically from the Goldsky subgraph.
|
6
|
+
:param symbol: Token symbol (e.g., 'MUSD', 'WBTC').
|
7
|
+
:return: Ethereum checksum address of the token.
|
8
|
+
"""
|
9
|
+
if symbol.lower() == "btc":
|
10
|
+
symbol = "wtbtc"
|
11
|
+
|
12
|
+
query_all = '''
|
13
|
+
{
|
14
|
+
tokens(first: 100) {
|
15
|
+
id
|
16
|
+
symbol
|
17
|
+
}
|
18
|
+
}
|
19
|
+
'''
|
20
|
+
data = query_graph(query_all)
|
21
|
+
tokens = data.get("data", {}).get("tokens", [])
|
22
|
+
matching_tokens = [t for t in tokens if t["symbol"].lower() == symbol.lower()]
|
23
|
+
|
24
|
+
if matching_tokens:
|
25
|
+
token_address = matching_tokens[0]["id"]
|
26
|
+
return web3_instance.to_checksum_address(token_address)
|
27
|
+
else:
|
28
|
+
available_symbols = [t["symbol"] for t in tokens]
|
29
|
+
raise Exception(f"Token '{symbol}' not found. Available: {', '.join(available_symbols)}")
|
mezoAgent-0.4.2.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
mezo_agent/__init__.py,sha256=PRFZfcq8B68pQI2toci1ACM_SPcu7suy9D3OD8IvZeI,450
|
2
|
-
mezo_agent/characters.py,sha256=wub7y9BrAAdAKWwcNAdgrvhRi2zHMaZNzTr2y3qtbsw,515
|
3
|
-
mezo_agent/chat.py,sha256=ZtNurUDV7UzJjbFyU96DNGy37hO3gl0osn19mRu7ER8,859
|
4
|
-
mezo_agent/config.py,sha256=1PWeaHdQPKqKPraE-tM81CwRKeBiCbz5C_8iZTEiCgo,2148
|
5
|
-
mezo_agent/parsing.py,sha256=rolPVE8r_RS6BqKe25r1nyZQ47rvTPG2Hv09Kxxfv4c,2821
|
6
|
-
mezo_agent/swap_musd_btc.py,sha256=Co-XcfK73spm94VC6qzGY0VYoGwsMDKKHM8ToGh2JxU,4289
|
7
|
-
mezo_agent/transaction.py,sha256=YpfWrkEaf0YGM_Kc4cFwlT9GmBGZkeJHWm0VGHs9Gks,4199
|
8
|
-
mezo_agent/data/new_router.json,sha256=A8U-NVfe1F-hDyR90_SuH8jDAxmzyyHWdJW62j9TZsc,26756
|
9
|
-
mezoAgent-0.4.2.dist-info/METADATA,sha256=YEbcKgTvvW13zDdNJKRz47odDmCOX73-Bl_KTa3Qn_k,273
|
10
|
-
mezoAgent-0.4.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
11
|
-
mezoAgent-0.4.2.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
|
12
|
-
mezoAgent-0.4.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|