clawrtc 1.4.0 → 1.6.0

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,234 @@
1
+ """
2
+ ClawRTC Coinbase Wallet Integration
3
+ Optional module for creating/managing Coinbase Base wallets.
4
+
5
+ Install with: pip install clawrtc[coinbase]
6
+ """
7
+
8
+ import json
9
+ import os
10
+ import sys
11
+
12
+ # ANSI colors (match cli.py)
13
+ CYAN = "\033[36m"
14
+ GREEN = "\033[32m"
15
+ RED = "\033[31m"
16
+ YELLOW = "\033[33m"
17
+ BOLD = "\033[1m"
18
+ DIM = "\033[2m"
19
+ NC = "\033[0m"
20
+
21
+ NODE_URL = "https://bulbous-bouffant.metalseed.net"
22
+
23
+ SWAP_INFO = {
24
+ "wrtc_contract": "0x5683C10596AaA09AD7F4eF13CAB94b9b74A669c6",
25
+ "usdc_contract": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
26
+ "aerodrome_pool": "0x4C2A0b915279f0C22EA766D58F9B815Ded2d2A3F",
27
+ "swap_url": "https://aerodrome.finance/swap?from=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&to=0x5683C10596AaA09AD7F4eF13CAB94b9b74A669c6",
28
+ "network": "Base (eip155:8453)",
29
+ "reference_price_usd": 0.10,
30
+ }
31
+
32
+ INSTALL_DIR = os.path.join(os.path.expanduser("~"), ".clawrtc")
33
+ COINBASE_FILE = os.path.join(INSTALL_DIR, "coinbase_wallet.json")
34
+
35
+
36
+ def _load_coinbase_wallet():
37
+ """Load saved Coinbase wallet data."""
38
+ if not os.path.exists(COINBASE_FILE):
39
+ return None
40
+ try:
41
+ with open(COINBASE_FILE) as f:
42
+ return json.load(f)
43
+ except (json.JSONDecodeError, IOError):
44
+ return None
45
+
46
+
47
+ def _save_coinbase_wallet(data):
48
+ """Save Coinbase wallet data to disk."""
49
+ os.makedirs(INSTALL_DIR, exist_ok=True)
50
+ with open(COINBASE_FILE, "w") as f:
51
+ json.dump(data, f, indent=2)
52
+ os.chmod(COINBASE_FILE, 0o600)
53
+
54
+
55
+ def coinbase_create(args):
56
+ """Create a Coinbase Base wallet via AgentKit."""
57
+ existing = _load_coinbase_wallet()
58
+ if existing and not getattr(args, "force", False):
59
+ print(f"\n {YELLOW}You already have a Coinbase wallet:{NC}")
60
+ print(f" {GREEN}{BOLD}{existing['address']}{NC}")
61
+ print(f" Network: {existing.get('network', 'Base')}")
62
+ print(f"\n To create a new one: clawrtc wallet coinbase create --force\n")
63
+ return
64
+
65
+ # Check for CDP credentials
66
+ cdp_key_name = os.environ.get("CDP_API_KEY_NAME", "")
67
+ cdp_key_private = os.environ.get("CDP_API_KEY_PRIVATE_KEY", "")
68
+
69
+ if not cdp_key_name or not cdp_key_private:
70
+ print(f"""
71
+ {YELLOW}Coinbase CDP credentials not configured.{NC}
72
+
73
+ To create a wallet automatically:
74
+ 1. Sign up at {CYAN}https://portal.cdp.coinbase.com{NC}
75
+ 2. Create an API Key
76
+ 3. Set environment variables:
77
+ export CDP_API_KEY_NAME="organizations/.../apiKeys/..."
78
+ export CDP_API_KEY_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----..."
79
+
80
+ Or link an existing Base address manually:
81
+ clawrtc wallet coinbase link 0xYourBaseAddress
82
+ """)
83
+ return
84
+
85
+ try:
86
+ from coinbase_agentkit import AgentKit, AgentKitConfig
87
+
88
+ print(f" {CYAN}Creating Coinbase wallet on Base...{NC}")
89
+
90
+ config = AgentKitConfig(
91
+ cdp_api_key_name=cdp_key_name,
92
+ cdp_api_key_private_key=cdp_key_private,
93
+ network_id="base-mainnet",
94
+ )
95
+ kit = AgentKit(config)
96
+ wallet = kit.wallet
97
+ address = wallet.default_address.address_id
98
+
99
+ wallet_data = {
100
+ "address": address,
101
+ "network": "Base (eip155:8453)",
102
+ "created": __import__("time").strftime("%Y-%m-%dT%H:%M:%SZ", __import__("time").gmtime()),
103
+ "method": "agentkit",
104
+ }
105
+ _save_coinbase_wallet(wallet_data)
106
+
107
+ print(f"""
108
+ {GREEN}{BOLD}═══════════════════════════════════════════════════════════
109
+ COINBASE BASE WALLET CREATED
110
+ ═══════════════════════════════════════════════════════════{NC}
111
+
112
+ {GREEN}Base Address:{NC} {BOLD}{address}{NC}
113
+ {DIM}Network:{NC} Base (eip155:8453)
114
+ {DIM}Saved to:{NC} {COINBASE_FILE}
115
+
116
+ {CYAN}What you can do:{NC}
117
+ - Receive USDC payments via x402 protocol
118
+ - Swap USDC → wRTC on Aerodrome DEX
119
+ - Link to your RustChain miner for cross-chain identity
120
+ - See swap info: clawrtc wallet coinbase swap-info
121
+ """)
122
+ except ImportError:
123
+ print(f"""
124
+ {RED}coinbase-agentkit not installed.{NC}
125
+
126
+ Install it with:
127
+ pip install clawrtc[coinbase]
128
+
129
+ Or: pip install coinbase-agentkit
130
+ """)
131
+ except Exception as e:
132
+ print(f"\n {RED}Failed to create wallet: {e}{NC}\n")
133
+
134
+
135
+ def coinbase_show(args):
136
+ """Show Coinbase Base wallet info."""
137
+ wallet = _load_coinbase_wallet()
138
+ if not wallet:
139
+ print(f"\n {YELLOW}No Coinbase wallet found.{NC}")
140
+ print(f" Create one: clawrtc wallet coinbase create")
141
+ print(f" Or link: clawrtc wallet coinbase link 0xYourAddress\n")
142
+ return
143
+
144
+ print(f"\n {GREEN}{BOLD}Coinbase Base Wallet{NC}")
145
+ print(f" {GREEN}Address:{NC} {BOLD}{wallet['address']}{NC}")
146
+ print(f" {DIM}Network:{NC} {DIM}{wallet.get('network', 'Base')}{NC}")
147
+ print(f" {DIM}Created:{NC} {DIM}{wallet.get('created', 'unknown')}{NC}")
148
+ print(f" {DIM}Method:{NC} {DIM}{wallet.get('method', 'unknown')}{NC}")
149
+ print(f" {DIM}Key File:{NC} {DIM}{COINBASE_FILE}{NC}")
150
+ print()
151
+
152
+
153
+ def coinbase_link(args):
154
+ """Link an existing Base address as your Coinbase wallet."""
155
+ address = getattr(args, "base_address", "")
156
+ if not address:
157
+ print(f"\n {YELLOW}Usage: clawrtc wallet coinbase link 0xYourBaseAddress{NC}\n")
158
+ return
159
+
160
+ if not address.startswith("0x") or len(address) != 42:
161
+ print(f"\n {RED}Invalid Base address. Must be 0x + 40 hex characters.{NC}\n")
162
+ return
163
+
164
+ wallet_data = {
165
+ "address": address,
166
+ "network": "Base (eip155:8453)",
167
+ "created": __import__("time").strftime("%Y-%m-%dT%H:%M:%SZ", __import__("time").gmtime()),
168
+ "method": "manual_link",
169
+ }
170
+ _save_coinbase_wallet(wallet_data)
171
+
172
+ print(f"\n {GREEN}Coinbase wallet linked:{NC} {BOLD}{address}{NC}")
173
+ print(f" {DIM}Saved to: {COINBASE_FILE}{NC}")
174
+
175
+ # Also try to link to RustChain miner
176
+ rtc_wallet_file = os.path.join(INSTALL_DIR, "wallets", "default.json")
177
+ if os.path.exists(rtc_wallet_file):
178
+ try:
179
+ with open(rtc_wallet_file) as f:
180
+ rtc = json.load(f)
181
+ print(f" {DIM}Linked to RTC wallet: {rtc['address']}{NC}")
182
+ except Exception:
183
+ pass
184
+ print()
185
+
186
+
187
+ def coinbase_swap_info(args):
188
+ """Show USDC→wRTC swap instructions and Aerodrome pool info."""
189
+ print(f"""
190
+ {GREEN}{BOLD}USDC → wRTC Swap Guide{NC}
191
+
192
+ {CYAN}wRTC Contract (Base):{NC}
193
+ {BOLD}{SWAP_INFO['wrtc_contract']}{NC}
194
+
195
+ {CYAN}USDC Contract (Base):{NC}
196
+ {BOLD}{SWAP_INFO['usdc_contract']}{NC}
197
+
198
+ {CYAN}Aerodrome Pool:{NC}
199
+ {BOLD}{SWAP_INFO['aerodrome_pool']}{NC}
200
+
201
+ {CYAN}Swap URL:{NC}
202
+ {BOLD}{SWAP_INFO['swap_url']}{NC}
203
+
204
+ {CYAN}Network:{NC} {SWAP_INFO['network']}
205
+ {CYAN}Reference Price:{NC} ~${SWAP_INFO['reference_price_usd']}/wRTC
206
+
207
+ {GREEN}How to swap:{NC}
208
+ 1. Get USDC on Base (bridge from Ethereum or buy on Coinbase)
209
+ 2. Go to the Aerodrome swap URL above
210
+ 3. Connect your wallet (MetaMask, Coinbase Wallet, etc.)
211
+ 4. Swap USDC for wRTC
212
+ 5. Bridge wRTC to native RTC at https://bottube.ai/bridge
213
+
214
+ {DIM}Or use the RustChain API:{NC}
215
+ curl -s https://bulbous-bouffant.metalseed.net/wallet/swap-info
216
+ """)
217
+
218
+
219
+ def cmd_coinbase(args):
220
+ """Handle clawrtc wallet coinbase subcommand."""
221
+ action = getattr(args, "coinbase_action", "show")
222
+
223
+ dispatch = {
224
+ "create": coinbase_create,
225
+ "show": coinbase_show,
226
+ "link": coinbase_link,
227
+ "swap-info": coinbase_swap_info,
228
+ }
229
+
230
+ func = dispatch.get(action)
231
+ if func:
232
+ func(args)
233
+ else:
234
+ print(f" Usage: clawrtc wallet coinbase [create|show|link|swap-info]")
File without changes