mezoAgent 0.2.3__tar.gz → 0.3.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {mezoagent-0.2.3 → mezoagent-0.3.0}/PKG-INFO +1 -1
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezoAgent.egg-info/PKG-INFO +1 -1
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezoAgent.egg-info/SOURCES.txt +1 -0
- mezoagent-0.3.0/mezo_agent/__init__.py +2 -0
- mezoagent-0.3.0/mezo_agent/config.py +44 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezo_agent/parsing.py +30 -1
- mezoagent-0.3.0/mezo_agent/swap_musd_btc.py +0 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezo_agent/transaction.py +2 -2
- {mezoagent-0.2.3 → mezoagent-0.3.0}/setup.py +1 -1
- mezoagent-0.2.3/mezo_agent/__init__.py +0 -1
- mezoagent-0.2.3/mezo_agent/config.py +0 -46
- {mezoagent-0.2.3 → mezoagent-0.3.0}/README.md +0 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezoAgent.egg-info/dependency_links.txt +0 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezoAgent.egg-info/requires.txt +0 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/mezoAgent.egg-info/top_level.txt +0 -0
- {mezoagent-0.2.3 → mezoagent-0.3.0}/setup.cfg +0 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
import os
|
2
|
+
import json
|
3
|
+
from dotenv import load_dotenv
|
4
|
+
from web3 import Web3
|
5
|
+
|
6
|
+
# Load environment variables
|
7
|
+
load_dotenv()
|
8
|
+
|
9
|
+
# Check for keys
|
10
|
+
OpenAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
11
|
+
if not OpenAI_API_KEY:
|
12
|
+
raise ValueError("OPENAI_API_KEY not found in environment variables!")
|
13
|
+
|
14
|
+
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
|
15
|
+
if not PRIVATE_KEY:
|
16
|
+
raise ValueError("PRIVATE_KEY not found in environment variables!")
|
17
|
+
|
18
|
+
# Mezo Testnet RPC and Web3 initialization
|
19
|
+
RPC_URL = "https://rpc.test.mezo.org"
|
20
|
+
web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
|
21
|
+
|
22
|
+
# Create Account Object
|
23
|
+
account = web3_instance.eth.account.from_key(PRIVATE_KEY)
|
24
|
+
sender_address = account.address
|
25
|
+
|
26
|
+
# mUSD Contract Setup using approve/allowance ABI
|
27
|
+
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
28
|
+
ERC20_ABI = json.loads(
|
29
|
+
'[{"constant": false, "inputs": [{"name": "spender", "type": "address"}, {"name": "amount", "type": "uint256"}],'
|
30
|
+
'"name": "approve", "outputs": [{"name": "", "type": "bool"}], "stateMutability": "nonpayable", "type": "function"},'
|
31
|
+
'{"constant": true, "inputs": [{"name": "owner", "type": "address"}, {"name": "spender", "type": "address"}],'
|
32
|
+
'"name": "allowance", "outputs": [{"name": "remaining", "type": "uint256"}], "stateMutability": "view", "type": "function"}]'
|
33
|
+
)
|
34
|
+
musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
|
35
|
+
|
36
|
+
# Wrapped BTC and Swap Router setup
|
37
|
+
WRAPPED_BTC_ADDRESS = "0xA460F83cdd9584E4bD6a9838abb0baC58EAde999"
|
38
|
+
ROUTER_ADDRESS = "0xC2E61936a542D78b9c3AA024fA141c4C632DF6c1"
|
39
|
+
|
40
|
+
# Load router ABI from a JSON file packaged with mezoAgent
|
41
|
+
router_abi_path = os.path.join(os.path.dirname(__file__), "new_router_abi.json")
|
42
|
+
with open(router_abi_path, "r") as f:
|
43
|
+
router_abi = json.load(f)
|
44
|
+
router_contract = web3_instance.eth.contract(address=ROUTER_ADDRESS, abi=router_abi)
|
@@ -33,4 +33,33 @@ def extract_transaction_details(prompt: str):
|
|
33
33
|
try:
|
34
34
|
return output_parser.parse(response.content)
|
35
35
|
except Exception as e:
|
36
|
-
return f"❌ Failed to extract transaction details: {str(e)}"
|
36
|
+
return f"❌ Failed to extract transaction details: {str(e)}"
|
37
|
+
|
38
|
+
|
39
|
+
swap_response_schemas = [
|
40
|
+
ResponseSchema(name="amount", description="The amount of mUSD to swap."),
|
41
|
+
ResponseSchema(name="from_currency", description="The token to swap from (should always be 'mUSD')."),
|
42
|
+
ResponseSchema(name="to_currency", description="The token to receive (should always be 'BTC')."),
|
43
|
+
ResponseSchema(name="router_address", description="The Dumpy Swap router address for executing the swap."),
|
44
|
+
]
|
45
|
+
swap_output_parser = StructuredOutputParser.from_response_schemas(swap_response_schemas)
|
46
|
+
|
47
|
+
swap_prompt_template = PromptTemplate(
|
48
|
+
template=(
|
49
|
+
"Extract swap transaction details from this request:\n{input}\n\n"
|
50
|
+
"- The token to swap from should always be 'mUSD'.\n"
|
51
|
+
"- The token to receive should always be 'BTC'.\n"
|
52
|
+
"- The router address should always be '0xC2E61936a542D78b9c3AA024fA141c4C632DF6c1'.\n\n"
|
53
|
+
"{format_instructions}"
|
54
|
+
),
|
55
|
+
input_variables=["input"],
|
56
|
+
partial_variables={"format_instructions": swap_output_parser.get_format_instructions()},
|
57
|
+
)
|
58
|
+
|
59
|
+
def extract_swap_details(prompt: str):
|
60
|
+
formatted_prompt = swap_prompt_template.format(input=prompt)
|
61
|
+
response = llm.invoke(formatted_prompt)
|
62
|
+
try:
|
63
|
+
return swap_output_parser.parse(response.content)
|
64
|
+
except Exception as e:
|
65
|
+
return f"Failed to extract swap details: {str(e)}"
|
File without changes
|
@@ -31,7 +31,7 @@ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
|
|
31
31
|
return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
|
32
32
|
|
33
33
|
# Fetch nonce and gas price
|
34
|
-
nonce = web3_instance.eth.get_transaction_count(sender_address)
|
34
|
+
nonce = web3_instance.eth.get_transaction_count(sender_address, 'pending')
|
35
35
|
gas_price = web3_instance.eth.gas_price
|
36
36
|
gas_limit = web3_instance.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
|
37
37
|
|
@@ -77,7 +77,7 @@ def mezo_agent_musd_transaction(transaction_prompt: str) -> str:
|
|
77
77
|
|
78
78
|
try:
|
79
79
|
# Fetch nonce and gas price for the sender
|
80
|
-
nonce = web3_instance.eth.get_transaction_count(sender_address)
|
80
|
+
nonce = web3_instance.eth.get_transaction_count(sender_address, 'pending')
|
81
81
|
gas_price = web3_instance.eth.gas_price
|
82
82
|
|
83
83
|
# Estimate gas required for the token transfer
|
@@ -1 +0,0 @@
|
|
1
|
-
from .transaction import mezo_agent_transaction_btc, mezo_agent_musd_transaction
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import json
|
3
|
-
from dotenv import load_dotenv
|
4
|
-
from web3 import Web3
|
5
|
-
from web3.exceptions import Web3Exception
|
6
|
-
|
7
|
-
# ✅ Load environment variables
|
8
|
-
USER_PROJECT_DIR = os.getcwd()
|
9
|
-
USER_ENV_PATH = os.path.join(USER_PROJECT_DIR, ".env")
|
10
|
-
|
11
|
-
if os.path.exists(USER_ENV_PATH):
|
12
|
-
load_dotenv(USER_ENV_PATH)
|
13
|
-
else:
|
14
|
-
print("⚠️ Warning: No `.env` file found in your project directory! Transactions requiring signing may fail.")
|
15
|
-
|
16
|
-
# ✅ Load keys from the environment
|
17
|
-
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
|
18
|
-
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
19
|
-
|
20
|
-
if not PRIVATE_KEY:
|
21
|
-
print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
|
22
|
-
PRIVATE_KEY = None # Allow package to be installed but prevent transactions
|
23
|
-
|
24
|
-
# ✅ Define RPC URL and initialize Web3
|
25
|
-
RPC_URL = "https://rpc.test.mezo.org"
|
26
|
-
web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
|
27
|
-
|
28
|
-
if not web3_instance.is_connected():
|
29
|
-
raise ConnectionError("❌ Failed to connect to Mezo Matsnet RPC.")
|
30
|
-
|
31
|
-
# ✅ Initialize account and sender address
|
32
|
-
if PRIVATE_KEY:
|
33
|
-
account = web3_instance.eth.account.from_key(PRIVATE_KEY)
|
34
|
-
sender_address = account.address
|
35
|
-
else:
|
36
|
-
account = None
|
37
|
-
sender_address = None
|
38
|
-
|
39
|
-
# ✅ Set up contract details (for mUSD)
|
40
|
-
MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
|
41
|
-
ERC20_ABI = json.loads(
|
42
|
-
'[{"constant": false, "inputs": [{"name": "recipient", "type": "address"},'
|
43
|
-
'{"name": "amount", "type": "uint256"}],"name": "transfer","outputs": [{"name": "", "type": "bool"}],'
|
44
|
-
'"stateMutability": "nonpayable","type":"function"}]'
|
45
|
-
)
|
46
|
-
musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|