mezoAgent 0.1.2__py3-none-any.whl → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mezoAgent
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A LangChain tool for sending BTC and mUSD transactions on Mezo Matsnet.
5
5
  Home-page: https://github.com/yourusername/mezoTransactionTool
6
6
  Author: Dreadwulf
@@ -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() # Get the directory where the script is run
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):
@@ -17,29 +17,33 @@ if os.path.exists(USER_ENV_PATH):
17
17
  else:
18
18
  print("⚠️ Warning: No `.env` file found in your project directory! Transactions requiring signing may fail.")
19
19
 
20
- # ✅ Load Private Keys from User's `.env`
20
+ # ✅ Load Private Key from User's `.env`
21
21
  PRIVATE_KEY = os.getenv("PRIVATE_KEY")
22
22
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
23
+
23
24
  if not PRIVATE_KEY:
24
25
  print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
25
26
  PRIVATE_KEY = None # Allow package to be installed but prevent transactions
26
27
 
28
+ # ✅ Define RPC URL before initializing Web3
27
29
  RPC_URL = "https://rpc.test.mezo.org"
28
-
29
- # ✅ Initialize Web3 instance
30
30
  web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
31
31
 
32
- # ✅ Check if connection is successful
32
+ # ✅ Check Web3 connection
33
33
  if not web3_instance.is_connected():
34
34
  raise ConnectionError("❌ Failed to connect to Mezo Matsnet RPC.")
35
35
 
36
- # ✅ Create Account Object
37
- account = Web3.eth.account.from_key(PRIVATE_KEY)
38
- sender_address = account.address
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
39
43
 
40
- MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
44
+ MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
41
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"}]')
42
- musd_contract = Web3.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
46
+ musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
43
47
 
44
48
  # ✅ Define Structured Output Parser for Transaction Details
45
49
  response_schemas = [
@@ -51,7 +55,7 @@ response_schemas = [
51
55
  output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
52
56
 
53
57
  # ✅ Define LLM Prompt for Parsing Transactions
54
- llm = ChatOpenAI(temperature=0, openai_api_key=os.getenv("OPENAI_API_KEY"))
58
+ llm = ChatOpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
55
59
 
56
60
  prompt_template = PromptTemplate(
57
61
  template="Extract transaction details from this request:\n{input}\n{format_instructions}",
@@ -75,14 +79,6 @@ def extract_transaction_details(prompt: str):
75
79
  def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
76
80
  """
77
81
  Sends BTC on Mezo Matsnet. Parses a transaction request and executes the transfer.
78
-
79
- Example usage:
80
- ```
81
- mezo_agent_transaction_btc("Send 0.05 BTC to 0x93a1Eadb069A791d23aAeDF3C272E2905bb63240")
82
- ```
83
-
84
- :param transaction_prompt: Natural language transaction request.
85
- :return: Transaction hash or failure message.
86
82
  """
87
83
  transaction_details = extract_transaction_details(transaction_prompt)
88
84
 
@@ -97,19 +93,19 @@ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
97
93
  return "❌ This function only supports BTC transactions."
98
94
 
99
95
  # ✅ Convert amount to Wei (BTC uses 18 decimals on Mezo Matsnet)
100
- amount_wei = Web3.to_wei(amount, "ether")
96
+ amount_wei = web3_instance.to_wei(amount, "ether")
101
97
 
102
98
  # ✅ Check sender's BTC balance
103
- sender_balance = Web3.eth.get_balance(sender_address)
104
- sender_balance_btc = Web3.from_wei(sender_balance, "ether")
99
+ sender_balance = web3_instance.eth.get_balance(sender_address)
100
+ sender_balance_btc = web3_instance.from_wei(sender_balance, "ether")
105
101
 
106
102
  if sender_balance < amount_wei:
107
103
  return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
108
104
 
109
105
  # ✅ Fetch nonce and gas price
110
- nonce = Web3.eth.get_transaction_count(sender_address)
111
- gas_price = Web3.eth.gas_price
112
- gas_limit = Web3.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
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})
113
109
 
114
110
  tx = {
115
111
  "to": recipient,
@@ -123,55 +119,8 @@ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
123
119
  try:
124
120
  # ✅ Sign and send the transaction
125
121
  signed_tx = account.sign_transaction(tx)
126
- tx_hash = Web3.eth.send_raw_transaction(signed_tx.raw_transaction)
122
+ tx_hash = web3_instance.eth.send_raw_transaction(signed_tx.raw_transaction)
127
123
  return f"✅ BTC Transaction Successful! Hash: {tx_hash.hex()}"
128
124
 
129
125
  except Web3Exception as e:
130
- return f"❌ BTC Transaction Failed: {str(e)}"
131
-
132
- @tool
133
- def mezo_agent_transaction_musd(transaction_prompt: str) -> str:
134
- """
135
- Sends mUSD on Mezo Matsnet. Parses a transaction request and executes the transfer.
136
-
137
- Example usage:
138
- ```
139
- mezo_agent_transaction_musd("Transfer 100 mUSD to 0xABC123...")
140
- ```
141
-
142
- :param transaction_prompt: Natural language transaction request.
143
- :return: Transaction hash or failure message.
144
- """
145
- transaction_details = extract_transaction_details(transaction_prompt)
146
-
147
- if isinstance(transaction_details, str): # Handle errors
148
- return transaction_details
149
-
150
- amount = float(transaction_details["amount"])
151
- currency = transaction_details["currency"].lower()
152
- recipient = transaction_details["recipient"]
153
-
154
- if currency != "musd":
155
- return "❌ This function only supports mUSD transactions."
156
-
157
- # ✅ Convert amount to Wei (mUSD uses 18 decimals)
158
- amount_musd_wei = int(amount * 10**18)
159
- nonce = Web3.eth.get_transaction_count(sender_address)
160
- gas_price = Web3.eth.gas_price
161
-
162
- try:
163
- # ✅ Build the transaction for mUSD transfer
164
- txn = musd_contract.functions.transfer(recipient, amount_musd_wei).build_transaction({
165
- "from": sender_address,
166
- "nonce": nonce,
167
- "gas": 50000,
168
- "gasPrice": gas_price,
169
- })
170
-
171
- signed_txn = Web3.eth.account.sign_transaction(txn, PRIVATE_KEY)
172
- tx_hash = Web3.eth.send_raw_transaction(signed_txn.raw_transaction)
173
-
174
- return f"✅ mUSD Transaction Successful! Hash: {tx_hash.hex()}"
175
-
176
- except Web3Exception as e:
177
- return f"❌ mUSD Transaction Failed: {str(e)}"
126
+ return f"❌ BTC Transaction Failed: {str(e)}"
@@ -1,6 +0,0 @@
1
- mezoTransactionTool/__init__.py,sha256=4izlG8P3PTGXZb_RvEQ3HlPMxQ1jzSINnF9nSlxnEXE,161
2
- mezoTransactionTool/transaction_tools.py,sha256=XlyTaqiDGxN0tyqdyJA6tIX6xq6d6hfaQe-V2XKGcAU,6814
3
- mezoAgent-0.1.2.dist-info/METADATA,sha256=9-Hi0dTMOqtYOOO8u1kjg-OGgFQTkAFxiy2CH5DP4-A,536
4
- mezoAgent-0.1.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
- mezoAgent-0.1.2.dist-info/top_level.txt,sha256=Czoa5A8CU_I_oPKDa5OXa5H7RM4Jk94PF9mIpz2V9t4,20
6
- mezoAgent-0.1.2.dist-info/RECORD,,