-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvnet_setup.py
More file actions
186 lines (167 loc) · 6.09 KB
/
Copy pathvnet_setup.py
File metadata and controls
186 lines (167 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import os
import random
import sys
import httpx
from dotenv import load_dotenv
def main():
load_dotenv()
tenderly_api_key = os.getenv("TENDERLY_API_KEY")
if not tenderly_api_key:
print("Error: TENDERLY_API_KEY environment variable is not set", file=sys.stderr)
sys.exit(1)
tenderly_org = os.getenv("TENDERLY_ORG")
if not tenderly_org:
print("Error: TENDERLY_ORG environment variable is not set", file=sys.stderr)
sys.exit(1)
tenderly_project = os.getenv("TENDERLY_PROJECT")
if not tenderly_project:
print("Error: TENDERLY_PROJECT environment variable is not set", file=sys.stderr)
sys.exit(1)
server_wallet_address = os.getenv("SERVER_WALLET_ADDRESS")
if not server_wallet_address:
print("Error: SERVER_WALLET_ADDRESS environment variable is not set", file=sys.stderr)
sys.exit(1)
client_wallet_address = os.getenv("CLIENT_WALLET_ADDRESS")
if not client_wallet_address:
print("Error: CLIENT_WALLET_ADDRESS environment variable is not set", file=sys.stderr)
sys.exit(1)
facilitator_wallet_address = os.getenv("FACILITATOR_WALLET_ADDRESS")
if not facilitator_wallet_address:
print("Error: FACILITATOR_WALLET_ADDRESS environment variable is not set", file=sys.stderr)
sys.exit(1)
client = httpx.Client(
base_url=f"https://api.tenderly.co/api/v1/account/{tenderly_org}/project/{tenderly_project}",
headers={"X-Access-Key": tenderly_api_key},
)
# Create the virtual network
vnet_response = client.post(
"/testnet/container",
json={
"slug": f"xyz-base-{random.randint(100000, 999999)}",
"displayName": f"xyz-base-{random.randint(100000, 999999)}",
"description": "",
"visibility": "TEAM",
"tags": {"purpose": "development"},
"networkConfig": {
"networkId": "8453",
"blockNumber": "latest",
"chainConfig": {"chainId": "8453"},
"baseFeePerGas": "1",
},
"explorerConfig": {"enabled": False, "verificationVisibility": "bytecode"},
"syncState": False,
},
)
if vnet_response.status_code != 200:
print(f"Error creating virtual network: {vnet_response.status_code} {vnet_response.text}", file=sys.stderr)
sys.exit(1)
vnet_data = vnet_response.json()
vnet_id = vnet_data["container"]["id"]
endpoints = vnet_data["container"]["connectivityConfig"]["endpoints"]
rpc_uri = None
for endpoint in endpoints:
if str(endpoint["description"]).lower() == "admin endpoint":
rpc_uri = endpoint["uri"]
break
if not rpc_uri:
print("Error: Admin endpoint not found in virtual network response", file=sys.stderr)
sys.exit(1)
print(f"Virtual network created with ID: {vnet_id}")
print(f"RPC URI: {rpc_uri}")
# Add wallets
resp = client.post(
f"/testnet/{vnet_id}/accounts",
json={
"account_type": "wallet",
"address": client_wallet_address,
"display_name": "Client",
"watched": True,
},
)
if resp.status_code != 200:
print(f"Error adding client wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
print(f"Client wallet added: {client_wallet_address}")
resp = client.post(
f"/testnet/{vnet_id}/accounts",
json={
"account_type": "wallet",
"address": server_wallet_address,
"display_name": "Server",
"watched": True,
},
)
if resp.status_code != 200:
print(f"Error adding server wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
print(f"Server wallet added: {server_wallet_address}")
resp = client.post(
f"/testnet/{vnet_id}/accounts",
json={
"account_type": "wallet",
"address": facilitator_wallet_address,
"display_name": "Facilitator",
"watched": True,
},
)
if resp.status_code != 200:
print(f"Error adding facilitator wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
# Top up wallets
rcp_client = httpx.Client(
base_url=rpc_uri,
headers={"X-Access-Key": tenderly_api_key},
# RPC endpoints redirect...
follow_redirects=True,
)
# Add ETH to facilitator wallet
resp = rcp_client.post(
url="/",
json={
"method": "tenderly_addBalance",
"params": [[facilitator_wallet_address], "0x21e19e0c9bab2400000"],
"id": 4,
"jsonrpc": "2.0",
},
)
if resp.status_code != 200:
print(f"Error topping up facilitator wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
# Add USDC to client and server wallets
resp = rcp_client.post(
url="/",
json={
"method": "tenderly_addErc20Balance",
"params": [
"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
[client_wallet_address],
"0x2540be400",
],
"id": 3,
"jsonrpc": "2.0",
},
)
if resp.status_code != 200:
print(f"Error topping up client wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
print(f"Client wallet topped up: {client_wallet_address}")
resp = rcp_client.post(
url="/",
json={
"method": "tenderly_addErc20Balance",
"params": [
"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
[server_wallet_address],
"0x2540be400",
],
"id": 3,
"jsonrpc": "2.0",
},
)
if resp.status_code != 200:
print(f"Error topping up server wallet: {resp.status_code} {resp.text}", file=sys.stderr)
sys.exit(1)
print(f"Server wallet topped up: {server_wallet_address}")
print(f"Facilitator wallet topped up: {facilitator_wallet_address}")
if __name__ == "__main__":
main()