mezoAgent 0.1.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.
@@ -0,0 +1,15 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: mezoAgent
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A LangChain tool for sending BTC and mUSD transactions on Mezo Matsnet.
|
5
|
+
Home-page: https://github.com/yourusername/mezoTransactionTool
|
6
|
+
Author: Dreadwulf
|
7
|
+
Author-email: dreadwul@wtf.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.7
|
12
|
+
Requires-Dist: web3
|
13
|
+
Requires-Dist: langchain
|
14
|
+
Requires-Dist: langchain-openai
|
15
|
+
Requires-Dist: python-dotenv
|
@@ -0,0 +1,6 @@
|
|
1
|
+
mezoTransactionTool/__init__.py,sha256=4izlG8P3PTGXZb_RvEQ3HlPMxQ1jzSINnF9nSlxnEXE,161
|
2
|
+
mezoTransactionTool/transaction_tools.py,sha256=6TlJPFvqB0kSpmjAXKuhPZsJ7JvNcyWYm6TYCCC_Mtc,6488
|
3
|
+
mezoAgent-0.1.0.dist-info/METADATA,sha256=m8ciD6ojJT8StDWvzwCsHzLSc5HPIxDImbiLl1ujHr8,536
|
4
|
+
mezoAgent-0.1.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
+
mezoAgent-0.1.0.dist-info/top_level.txt,sha256=Czoa5A8CU_I_oPKDa5OXa5H7RM4Jk94PF9mIpz2V9t4,20
|
6
|
+
mezoAgent-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
mezoTransactionTool
|
@@ -0,0 +1,167 @@
|
|
1
|
+
import os
|
2
|
+
import json
|
3
|
+
from dotenv import load_dotenv
|
4
|
+
from web3 import Web3
|
5
|
+
from web3.exceptions import Web3Exception
|
6
|
+
from langchain.tools import tool
|
7
|
+
from langchain_openai import ChatOpenAI
|
8
|
+
from langchain.output_parsers import StructuredOutputParser, ResponseSchema
|
9
|
+
from langchain.prompts import PromptTemplate
|
10
|
+
|
11
|
+
# ✅ Load environment variables
|
12
|
+
USER_PROJECT_DIR = os.getcwd() # Get the directory where the script is run
|
13
|
+
USER_ENV_PATH = os.path.join(USER_PROJECT_DIR, ".env")
|
14
|
+
|
15
|
+
if os.path.exists(USER_ENV_PATH):
|
16
|
+
load_dotenv(USER_ENV_PATH)
|
17
|
+
else:
|
18
|
+
print("⚠️ Warning: No `.env` file found in your project directory! Transactions requiring signing may fail.")
|
19
|
+
|
20
|
+
# ✅ Load Private Key from User's `.env`
|
21
|
+
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
|
22
|
+
if not PRIVATE_KEY:
|
23
|
+
print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
|
24
|
+
PRIVATE_KEY = None # Allow package to be installed but prevent transactions
|
25
|
+
|
26
|
+
# ✅ Create Account Object
|
27
|
+
account = web3.eth.account.from_key(PRIVATE_KEY)
|
28
|
+
sender_address = account.address
|
29
|
+
|
30
|
+
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
31
|
+
ERC20_ABI = json.loads('[{"constant": false, "inputs": [{"name": "recipient", "type": "address"},{"name": "amount", "type": "uint256"}],"name": "transfer","outputs": [{"name": "", "type": "bool"}],"stateMutability": "nonpayable","type":"function"}]')
|
32
|
+
musd_contract = web3.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
|
33
|
+
|
34
|
+
# ✅ Define Structured Output Parser for Transaction Details
|
35
|
+
response_schemas = [
|
36
|
+
ResponseSchema(name="amount", description="The amount of cryptocurrency to transfer."),
|
37
|
+
ResponseSchema(name="currency", description="The cryptocurrency (BTC or mUSD)."),
|
38
|
+
ResponseSchema(name="recipient", description="The recipient's wallet address."),
|
39
|
+
]
|
40
|
+
|
41
|
+
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
|
42
|
+
|
43
|
+
# ✅ Define LLM Prompt for Parsing Transactions
|
44
|
+
llm = ChatOpenAI(temperature=0, openai_api_key=os.getenv("OPENAI_API_KEY"))
|
45
|
+
|
46
|
+
prompt_template = PromptTemplate(
|
47
|
+
template="Extract transaction details from this request:\n{input}\n{format_instructions}",
|
48
|
+
input_variables=["input"],
|
49
|
+
partial_variables={"format_instructions": output_parser.get_format_instructions()},
|
50
|
+
)
|
51
|
+
|
52
|
+
def extract_transaction_details(prompt: str):
|
53
|
+
"""
|
54
|
+
Uses LLM to extract structured transaction details from user input.
|
55
|
+
"""
|
56
|
+
formatted_prompt = prompt_template.format(input=prompt)
|
57
|
+
response = llm.invoke(formatted_prompt)
|
58
|
+
|
59
|
+
try:
|
60
|
+
return output_parser.parse(response.content)
|
61
|
+
except Exception as e:
|
62
|
+
return f"❌ Failed to extract transaction details: {str(e)}"
|
63
|
+
|
64
|
+
@tool
|
65
|
+
def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
|
66
|
+
"""
|
67
|
+
Sends BTC on Mezo Matsnet. Parses a transaction request and executes the transfer.
|
68
|
+
|
69
|
+
Example usage:
|
70
|
+
```
|
71
|
+
mezo_agent_transaction_btc("Send 0.05 BTC to 0x93a1Eadb069A791d23aAeDF3C272E2905bb63240")
|
72
|
+
```
|
73
|
+
|
74
|
+
:param transaction_prompt: Natural language transaction request.
|
75
|
+
:return: Transaction hash or failure message.
|
76
|
+
"""
|
77
|
+
transaction_details = extract_transaction_details(transaction_prompt)
|
78
|
+
|
79
|
+
if isinstance(transaction_details, str): # Handle errors
|
80
|
+
return transaction_details
|
81
|
+
|
82
|
+
amount = float(transaction_details["amount"])
|
83
|
+
currency = transaction_details["currency"].lower()
|
84
|
+
recipient = transaction_details["recipient"]
|
85
|
+
|
86
|
+
if currency != "btc":
|
87
|
+
return "❌ This function only supports BTC transactions."
|
88
|
+
|
89
|
+
# ✅ Convert amount to Wei (BTC uses 18 decimals on Mezo Matsnet)
|
90
|
+
amount_wei = web3.to_wei(amount, "ether")
|
91
|
+
|
92
|
+
# ✅ Check sender's BTC balance
|
93
|
+
sender_balance = web3.eth.get_balance(sender_address)
|
94
|
+
sender_balance_btc = web3.from_wei(sender_balance, "ether")
|
95
|
+
|
96
|
+
if sender_balance < amount_wei:
|
97
|
+
return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
|
98
|
+
|
99
|
+
# ✅ Fetch nonce and gas price
|
100
|
+
nonce = web3.eth.get_transaction_count(sender_address)
|
101
|
+
gas_price = web3.eth.gas_price
|
102
|
+
gas_limit = web3.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
|
103
|
+
|
104
|
+
tx = {
|
105
|
+
"to": recipient,
|
106
|
+
"value": amount_wei,
|
107
|
+
"gas": gas_limit,
|
108
|
+
"gasPrice": gas_price,
|
109
|
+
"nonce": nonce,
|
110
|
+
"chainId": 31611, # Mezo Testnet Chain ID
|
111
|
+
}
|
112
|
+
|
113
|
+
try:
|
114
|
+
# ✅ Sign and send the transaction
|
115
|
+
signed_tx = account.sign_transaction(tx)
|
116
|
+
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
|
117
|
+
return f"✅ BTC Transaction Successful! Hash: {tx_hash.hex()}"
|
118
|
+
|
119
|
+
except Web3Exception as e:
|
120
|
+
return f"❌ BTC Transaction Failed: {str(e)}"
|
121
|
+
|
122
|
+
@tool
|
123
|
+
def mezo_agent_transaction_musd(transaction_prompt: str) -> str:
|
124
|
+
"""
|
125
|
+
Sends mUSD on Mezo Matsnet. Parses a transaction request and executes the transfer.
|
126
|
+
|
127
|
+
Example usage:
|
128
|
+
```
|
129
|
+
mezo_agent_transaction_musd("Transfer 100 mUSD to 0xABC123...")
|
130
|
+
```
|
131
|
+
|
132
|
+
:param transaction_prompt: Natural language transaction request.
|
133
|
+
:return: Transaction hash or failure message.
|
134
|
+
"""
|
135
|
+
transaction_details = extract_transaction_details(transaction_prompt)
|
136
|
+
|
137
|
+
if isinstance(transaction_details, str): # Handle errors
|
138
|
+
return transaction_details
|
139
|
+
|
140
|
+
amount = float(transaction_details["amount"])
|
141
|
+
currency = transaction_details["currency"].lower()
|
142
|
+
recipient = transaction_details["recipient"]
|
143
|
+
|
144
|
+
if currency != "musd":
|
145
|
+
return "❌ This function only supports mUSD transactions."
|
146
|
+
|
147
|
+
# ✅ Convert amount to Wei (mUSD uses 18 decimals)
|
148
|
+
amount_musd_wei = int(amount * 10**18)
|
149
|
+
nonce = web3.eth.get_transaction_count(sender_address)
|
150
|
+
gas_price = web3.eth.gas_price
|
151
|
+
|
152
|
+
try:
|
153
|
+
# ✅ Build the transaction for mUSD transfer
|
154
|
+
txn = musd_contract.functions.transfer(recipient, amount_musd_wei).build_transaction({
|
155
|
+
"from": sender_address,
|
156
|
+
"nonce": nonce,
|
157
|
+
"gas": 50000,
|
158
|
+
"gasPrice": gas_price,
|
159
|
+
})
|
160
|
+
|
161
|
+
signed_txn = web3.eth.account.sign_transaction(txn, PRIVATE_KEY)
|
162
|
+
tx_hash = web3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
163
|
+
|
164
|
+
return f"✅ mUSD Transaction Successful! Hash: {tx_hash.hex()}"
|
165
|
+
|
166
|
+
except Web3Exception as e:
|
167
|
+
return f"❌ mUSD Transaction Failed: {str(e)}"
|