mezoAgent 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {mezoAgent-0.1.1.dist-info → mezoAgent-0.1.3.dist-info}/METADATA +1 -1
- mezoAgent-0.1.3.dist-info/RECORD +6 -0
- mezoTransactionTool/transaction_tools.py +29 -70
- mezoAgent-0.1.1.dist-info/RECORD +0 -6
- {mezoAgent-0.1.1.dist-info → mezoAgent-0.1.3.dist-info}/WHEEL +0 -0
- {mezoAgent-0.1.1.dist-info → mezoAgent-0.1.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
mezoTransactionTool/__init__.py,sha256=4izlG8P3PTGXZb_RvEQ3HlPMxQ1jzSINnF9nSlxnEXE,161
|
2
|
+
mezoTransactionTool/transaction_tools.py,sha256=0VxSaiMSQW067K6qw2SJR9dm-CH7obwMF0cagbEEX1g,5013
|
3
|
+
mezoAgent-0.1.3.dist-info/METADATA,sha256=nMCSfEH-FTHSDb8iEP1W2sGNtNu7ahB-ZzEGy5CZFBo,536
|
4
|
+
mezoAgent-0.1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
+
mezoAgent-0.1.3.dist-info/top_level.txt,sha256=Czoa5A8CU_I_oPKDa5OXa5H7RM4Jk94PF9mIpz2V9t4,20
|
6
|
+
mezoAgent-0.1.3.dist-info/RECORD,,
|
@@ -9,7 +9,7 @@ from langchain.output_parsers import StructuredOutputParser, ResponseSchema
|
|
9
9
|
from langchain.prompts import PromptTemplate
|
10
10
|
|
11
11
|
# ✅ Load environment variables
|
12
|
-
USER_PROJECT_DIR = os.getcwd()
|
12
|
+
USER_PROJECT_DIR = os.getcwd()
|
13
13
|
USER_ENV_PATH = os.path.join(USER_PROJECT_DIR, ".env")
|
14
14
|
|
15
15
|
if os.path.exists(USER_ENV_PATH):
|
@@ -19,17 +19,31 @@ else:
|
|
19
19
|
|
20
20
|
# ✅ Load Private Key from User's `.env`
|
21
21
|
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
|
22
|
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
23
|
+
|
22
24
|
if not PRIVATE_KEY:
|
23
25
|
print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
|
24
26
|
PRIVATE_KEY = None # Allow package to be installed but prevent transactions
|
25
27
|
|
26
|
-
# ✅
|
27
|
-
|
28
|
-
|
28
|
+
# ✅ Define RPC URL before initializing Web3
|
29
|
+
RPC_URL = "https://rpc.test.mezo.org"
|
30
|
+
web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
|
31
|
+
|
32
|
+
# ✅ Check Web3 connection
|
33
|
+
if not web3_instance.is_connected():
|
34
|
+
raise ConnectionError("❌ Failed to connect to Mezo Matsnet RPC.")
|
35
|
+
|
36
|
+
# ✅ Initialize account object using `web3_instance`
|
37
|
+
if PRIVATE_KEY:
|
38
|
+
account = web3_instance.eth.account.from_key(PRIVATE_KEY)
|
39
|
+
sender_address = account.address
|
40
|
+
else:
|
41
|
+
account = None
|
42
|
+
sender_address = None
|
29
43
|
|
30
|
-
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
44
|
+
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
31
45
|
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 =
|
46
|
+
musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
|
33
47
|
|
34
48
|
# ✅ Define Structured Output Parser for Transaction Details
|
35
49
|
response_schemas = [
|
@@ -41,7 +55,7 @@ response_schemas = [
|
|
41
55
|
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
|
42
56
|
|
43
57
|
# ✅ Define LLM Prompt for Parsing Transactions
|
44
|
-
llm = ChatOpenAI(temperature=0, openai_api_key=
|
58
|
+
llm = ChatOpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
|
45
59
|
|
46
60
|
prompt_template = PromptTemplate(
|
47
61
|
template="Extract transaction details from this request:\n{input}\n{format_instructions}",
|
@@ -65,14 +79,6 @@ def extract_transaction_details(prompt: str):
|
|
65
79
|
def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
|
66
80
|
"""
|
67
81
|
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
82
|
"""
|
77
83
|
transaction_details = extract_transaction_details(transaction_prompt)
|
78
84
|
|
@@ -87,19 +93,19 @@ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
|
|
87
93
|
return "❌ This function only supports BTC transactions."
|
88
94
|
|
89
95
|
# ✅ Convert amount to Wei (BTC uses 18 decimals on Mezo Matsnet)
|
90
|
-
amount_wei =
|
96
|
+
amount_wei = web3_instance.to_wei(amount, "ether")
|
91
97
|
|
92
98
|
# ✅ Check sender's BTC balance
|
93
|
-
sender_balance =
|
94
|
-
sender_balance_btc =
|
99
|
+
sender_balance = web3_instance.eth.get_balance(sender_address)
|
100
|
+
sender_balance_btc = web3_instance.from_wei(sender_balance, "ether")
|
95
101
|
|
96
102
|
if sender_balance < amount_wei:
|
97
103
|
return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
|
98
104
|
|
99
105
|
# ✅ Fetch nonce and gas price
|
100
|
-
nonce =
|
101
|
-
gas_price =
|
102
|
-
gas_limit =
|
106
|
+
nonce = web3_instance.eth.get_transaction_count(sender_address)
|
107
|
+
gas_price = web3_instance.eth.gas_price
|
108
|
+
gas_limit = web3_instance.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
|
103
109
|
|
104
110
|
tx = {
|
105
111
|
"to": recipient,
|
@@ -113,55 +119,8 @@ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
|
|
113
119
|
try:
|
114
120
|
# ✅ Sign and send the transaction
|
115
121
|
signed_tx = account.sign_transaction(tx)
|
116
|
-
tx_hash =
|
122
|
+
tx_hash = web3_instance.eth.send_raw_transaction(signed_tx.raw_transaction)
|
117
123
|
return f"✅ BTC Transaction Successful! Hash: {tx_hash.hex()}"
|
118
124
|
|
119
125
|
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)}"
|
126
|
+
return f"❌ BTC Transaction Failed: {str(e)}"
|
mezoAgent-0.1.1.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
mezoTransactionTool/__init__.py,sha256=4izlG8P3PTGXZb_RvEQ3HlPMxQ1jzSINnF9nSlxnEXE,161
|
2
|
-
mezoTransactionTool/transaction_tools.py,sha256=jvVtD0T72-XR5BlBxZEMV_LMD_u4m2Y00X3Qybo6SXQ,6488
|
3
|
-
mezoAgent-0.1.1.dist-info/METADATA,sha256=xbeDFoJsEQDQBYJK60GjATHq55qXOrjN3o0INUJwjM0,536
|
4
|
-
mezoAgent-0.1.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
-
mezoAgent-0.1.1.dist-info/top_level.txt,sha256=Czoa5A8CU_I_oPKDa5OXa5H7RM4Jk94PF9mIpz2V9t4,20
|
6
|
-
mezoAgent-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|