ordlibrary commited on
Commit
42754c0
Β·
verified Β·
1 Parent(s): d7176d4

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +396 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Bonkbutton
3
- emoji: 😻
4
- colorFrom: indigo
5
- colorTo: green
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: bonkbutton
3
+ emoji: 🐳
4
+ colorFrom: yellow
5
+ colorTo: purple
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,396 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>BONK AI Dashboard</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap">
9
+ <style>
10
+ body {
11
+ font-family: 'Press Start 2P', 'Courier New', monospace;
12
+ background-color: #1a1a2e;
13
+ color: #ffffff;
14
+ }
15
+
16
+ .bonk-button {
17
+ background-color: #FFD700;
18
+ color: #000000;
19
+ box-shadow: 0 4px 0 #b89b00;
20
+ transition: all 0.2s;
21
+ }
22
+
23
+ .bonk-button:hover:not(:disabled) {
24
+ transform: translateY(-2px);
25
+ box-shadow: 0 6px 0 #b89b00;
26
+ }
27
+
28
+ .bonk-button:active:not(:disabled) {
29
+ transform: translateY(2px);
30
+ box-shadow: 0 2px 0 #b89b00;
31
+ }
32
+
33
+ .bonk-button:disabled {
34
+ opacity: 0.6;
35
+ cursor: not-allowed;
36
+ }
37
+
38
+ .token-card {
39
+ background: linear-gradient(135deg, #2a2d31 0%, #1e2023 100%);
40
+ border-radius: 12px;
41
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
42
+ }
43
+
44
+ .token-card.sol {
45
+ border-top: 4px solid #00ffbd;
46
+ }
47
+
48
+ .token-card.bonk {
49
+ border-top: 4px solid #FFD700;
50
+ }
51
+
52
+ .token-card.bonkai {
53
+ border-top: 4px solid #5865F2;
54
+ }
55
+
56
+ .account-item {
57
+ background-color: #2a2d31;
58
+ border-left: 4px solid #FFD700;
59
+ }
60
+
61
+ .tab-active {
62
+ color: #FFD700;
63
+ border-bottom: 4px solid #FFD700;
64
+ margin-bottom: -2px;
65
+ }
66
+
67
+ /* Custom scrollbar */
68
+ ::-webkit-scrollbar {
69
+ width: 8px;
70
+ }
71
+
72
+ ::-webkit-scrollbar-track {
73
+ background: #2a2d31;
74
+ }
75
+
76
+ ::-webkit-scrollbar-thumb {
77
+ background: #FFD700;
78
+ border-radius: 4px;
79
+ }
80
+
81
+ ::-webkit-scrollbar-thumb:hover {
82
+ background: #b89b00;
83
+ }
84
+ </style>
85
+ </head>
86
+ <body class="min-h-screen">
87
+ <div class="container mx-auto px-4 py-8 max-w-6xl">
88
+ <!-- Header -->
89
+ <header class="flex justify-between items-center mb-12">
90
+ <div class="flex items-center">
91
+ <div class="w-12 h-12 bg-yellow-400 rounded-full flex items-center justify-center mr-4">
92
+ <span class="text-black text-2xl">πŸ•</span>
93
+ </div>
94
+ <h1 class="text-2xl md:text-3xl text-yellow-400">BONK AI</h1>
95
+ </div>
96
+ <button id="connectWalletBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-6 py-3 rounded-lg transition-colors">
97
+ Connect Wallet
98
+ </button>
99
+ </header>
100
+
101
+ <!-- Wallet Connect Prompt -->
102
+ <div id="walletConnectPrompt" class="text-center mb-12 p-8 bg-gray-800 rounded-xl">
103
+ <h2 class="text-xl md:text-2xl text-yellow-400 mb-4">Connect your wallet to use the BONK Button</h2>
104
+ <p class="text-gray-300 mb-6">Clean up your Solana wallet and recover SOL with just one click!</p>
105
+ <button id="connectPromptBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-8 py-3 rounded-lg transition-colors">
106
+ Connect Wallet
107
+ </button>
108
+ </div>
109
+
110
+ <!-- Dashboard Content (hidden by default) -->
111
+ <div id="dashboardContent" class="hidden">
112
+ <!-- Tabs -->
113
+ <div class="flex border-b-2 border-gray-700 mb-8">
114
+ <button data-tab="dashboard" class="tab-active px-6 py-3 text-sm md:text-base">Dashboard</button>
115
+ <button data-tab="bonkbutton" class="px-6 py-3 text-sm md:text-base text-gray-400 hover:text-yellow-400">BONK Button</button>
116
+ <button data-tab="staking" class="px-6 py-3 text-sm md:text-base text-gray-400 hover:text-yellow-400">Staking</button>
117
+ </div>
118
+
119
+ <!-- Tab Content -->
120
+ <div id="tabContent">
121
+ <!-- Dashboard Tab -->
122
+ <div id="dashboardTab" class="tab-panel">
123
+ <h2 class="text-xl md:text-2xl text-yellow-400 mb-6">Wallet Overview</h2>
124
+
125
+ <div id="walletAddress" class="bg-gray-800 p-4 rounded-lg mb-8 font-mono text-sm overflow-x-auto">
126
+ 0x0000...0000
127
+ </div>
128
+
129
+ <!-- Balance Cards -->
130
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
131
+ <!-- SOL Balance -->
132
+ <div class="token-card sol p-6">
133
+ <div class="flex items-center mb-4">
134
+ <div class="w-10 h-10 bg-teal-400 rounded-full flex items-center justify-center mr-4">
135
+ <span class="text-black">β—Ž</span>
136
+ </div>
137
+ <h3 class="text-lg">SOL</h3>
138
+ </div>
139
+ <p id="solBalance" class="text-2xl font-bold">0.0000 SOL</p>
140
+ </div>
141
+
142
+ <!-- BONK Balance -->
143
+ <div class="token-card bonk p-6">
144
+ <div class="flex items-center mb-4">
145
+ <div class="w-10 h-10 bg-yellow-400 rounded-full flex items-center justify-center mr-4">
146
+ <span class="text-black">πŸ•</span>
147
+ </div>
148
+ <h3 class="text-lg">BONK</h3>
149
+ </div>
150
+ <p id="bonkBalance" class="text-2xl font-bold">0 BONK</p>
151
+ </div>
152
+
153
+ <!-- BONKAI Balance -->
154
+ <div class="token-card bonkai p-6">
155
+ <div class="flex items-center mb-4">
156
+ <div class="w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center mr-4">
157
+ <span class="text-black">πŸ€–</span>
158
+ </div>
159
+ <h3 class="text-lg">BONKAI</h3>
160
+ </div>
161
+ <p id="bonkaiBalance" class="text-2xl font-bold">0 BONKAI</p>
162
+ </div>
163
+ </div>
164
+
165
+ <!-- Account Stats -->
166
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
167
+ <div class="bg-gray-800 p-6 rounded-lg">
168
+ <h4 class="text-gray-400 mb-2">Token Accounts</h4>
169
+ <p id="accountCount" class="text-xl">0</p>
170
+ </div>
171
+ <div class="bg-gray-800 p-6 rounded-lg">
172
+ <h4 class="text-gray-400 mb-2">Estimated Rent</h4>
173
+ <p id="estimatedRent" class="text-xl">0.000 SOL</p>
174
+ </div>
175
+ </div>
176
+
177
+ <div class="bg-yellow-400 bg-opacity-10 border border-yellow-400 border-opacity-30 p-4 rounded-lg">
178
+ <p class="text-yellow-400 text-sm">πŸ’‘ Use the BONK Button to clean up unused token accounts and recover SOL!</p>
179
+ </div>
180
+ </div>
181
+
182
+ <!-- BONK Button Tab -->
183
+ <div id="bonkButtonTab" class="tab-panel hidden">
184
+ <div class="text-center mb-8">
185
+ <h2 class="text-xl md:text-2xl text-yellow-400 mb-2">BONK Button</h2>
186
+ <p class="text-gray-300">Clean up your wallet and recover SOL with one click!</p>
187
+ </div>
188
+
189
+ <!-- Error Message -->
190
+ <div id="errorMessage" class="bg-red-900 bg-opacity-30 border border-red-500 p-4 rounded-lg mb-6 hidden">
191
+ <p id="errorText" class="text-red-300"></p>
192
+ </div>
193
+
194
+ <!-- Scan Results -->
195
+ <div id="scanResults" class="hidden">
196
+ <h3 class="text-lg text-yellow-400 mb-4">Found <span id="closeableCount">0</span> closeable accounts:</h3>
197
+
198
+ <div id="accountsList" class="max-h-96 overflow-y-auto mb-6 space-y-2 pr-2">
199
+ <!-- Account items will be added here -->
200
+ </div>
201
+
202
+ <button id="bonkItBtn" class="bonk-button px-8 py-4 text-lg font-bold rounded-lg mx-auto block">
203
+ BONK IT!
204
+ </button>
205
+ </div>
206
+
207
+ <!-- Cleanup Complete -->
208
+ <div id="cleanupComplete" class="hidden text-center bg-yellow-400 bg-opacity-10 border border-yellow-400 border-opacity-30 p-8 rounded-lg mb-6">
209
+ <h3 class="text-xl text-yellow-400 mb-4">BONK! Wallet Cleaned Successfully!</h3>
210
+ <p class="mb-2">You've recovered approximately <span id="recoveredSol">0.000</span> SOL</p>
211
+ <p class="mb-6">Your wallet is now cleaner and more efficient!</p>
212
+ <button id="scanAgainBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-6 py-3 rounded-lg transition-colors">
213
+ Scan Again
214
+ </button>
215
+ </div>
216
+
217
+ <!-- Initial Scan Button -->
218
+ <div id="initialScan" class="text-center">
219
+ <button id="scanWalletBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-8 py-4 rounded-lg transition-colors text-lg font-bold">
220
+ Scan My Wallet
221
+ </button>
222
+ </div>
223
+ </div>
224
+
225
+ <!-- Staking Tab -->
226
+ <div id="stakingTab" class="tab-panel hidden">
227
+ <div class="text-center">
228
+ <h2 class="text-xl md:text-2xl text-yellow-400 mb-4">Coming Soon!</h2>
229
+ <p class="text-gray-300">Staking functionality will be available soon.</p>
230
+ </div>
231
+ </div>
232
+ </div>
233
+ </div>
234
+
235
+ <!-- Footer -->
236
+ <footer class="mt-16 pt-8 border-t border-gray-800 text-center text-gray-400 text-sm">
237
+ <p>BONK AI - The smart way to manage your Solana wallet</p>
238
+ <p class="mt-2">Β© 2023 BONK AI. All rights reserved.</p>
239
+ </footer>
240
+ </div>
241
+
242
+ <script>
243
+ // Mock wallet connection and data
244
+ document.addEventListener('DOMContentLoaded', function() {
245
+ // Tab switching
246
+ const tabs = document.querySelectorAll('[data-tab]');
247
+ tabs.forEach(tab => {
248
+ tab.addEventListener('click', function() {
249
+ // Update active tab
250
+ tabs.forEach(t => t.classList.remove('tab-active', 'text-yellow-400'));
251
+ tabs.forEach(t => t.classList.add('text-gray-400'));
252
+ this.classList.add('tab-active', 'text-yellow-400');
253
+ this.classList.remove('text-gray-400');
254
+
255
+ // Show corresponding content
256
+ document.querySelectorAll('.tab-panel').forEach(panel => {
257
+ panel.classList.add('hidden');
258
+ });
259
+ document.getElementById(`${this.dataset.tab}Tab`).classList.remove('hidden');
260
+ });
261
+ });
262
+
263
+ // Connect wallet buttons
264
+ const connectButtons = ['connectWalletBtn', 'connectPromptBtn'];
265
+ connectButtons.forEach(id => {
266
+ document.getElementById(id).addEventListener('click', function() {
267
+ // Mock wallet connection
268
+ document.getElementById('walletConnectPrompt').classList.add('hidden');
269
+ document.getElementById('dashboardContent').classList.remove('hidden');
270
+
271
+ // Mock wallet address
272
+ const walletAddress = '7sK...9fG';
273
+ document.getElementById('walletAddress').textContent = walletAddress;
274
+
275
+ // Mock balances
276
+ document.getElementById('solBalance').textContent = '1.2345 SOL';
277
+ document.getElementById('bonkBalance').textContent = '42,069,420 BONK';
278
+ document.getElementById('bonkaiBalance').textContent = '0 BONKAI';
279
+ document.getElementById('accountCount').textContent = '18';
280
+ document.getElementById('estimatedRent').textContent = '0.036 SOL';
281
+
282
+ // Change connect button text
283
+ connectButtons.forEach(btnId => {
284
+ document.getElementById(btnId).textContent = walletAddress;
285
+ });
286
+ });
287
+ });
288
+
289
+ // BONK Button functionality
290
+ let closeableAccounts = [];
291
+ let selectedAccounts = [];
292
+
293
+ // Scan wallet
294
+ document.getElementById('scanWalletBtn').addEventListener('click', function() {
295
+ // Show loading state
296
+ this.innerHTML = '<span class="animate-pulse">Scanning...</span>';
297
+ this.disabled = true;
298
+
299
+ // Mock API call
300
+ setTimeout(() => {
301
+ // Mock closeable accounts
302
+ closeableAccounts = [
303
+ { address: 'TokenAcc1...', mint: 'Wrapped SOL', balance: '0.5', isWrappedSol: true },
304
+ { address: 'TokenAcc2...', mint: 'USDC', balance: '0', isWrappedSol: false },
305
+ { address: 'TokenAcc3...', mint: 'BONK', balance: '0', isWrappedSol: false },
306
+ { address: 'TokenAcc4...', mint: 'SAMO', balance: '0', isWrappedSol: false },
307
+ { address: 'TokenAcc5...', mint: 'Wrapped SOL', balance: '0.2', isWrappedSol: true }
308
+ ];
309
+
310
+ // Reset scan button
311
+ this.innerHTML = 'Scan My Wallet';
312
+ this.disabled = false;
313
+
314
+ // Show results
315
+ document.getElementById('initialScan').classList.add('hidden');
316
+ document.getElementById('scanResults').classList.remove('hidden');
317
+ document.getElementById('closeableCount').textContent = closeableAccounts.length;
318
+
319
+ // Populate accounts list
320
+ const accountsList = document.getElementById('accountsList');
321
+ accountsList.innerHTML = '';
322
+
323
+ closeableAccounts.forEach(account => {
324
+ const accountItem = document.createElement('div');
325
+ accountItem.className = 'account-item p-4 rounded flex items-center';
326
+
327
+ accountItem.innerHTML = `
328
+ <input type="checkbox" class="mr-4 h-5 w-5" checked
329
+ data-address="${account.address}">
330
+ <div>
331
+ <div class="text-sm text-gray-300">${account.address}</div>
332
+ <div class="text-xs text-yellow-400 font-bold">${account.isWrappedSol ? 'Wrapped SOL' : 'Empty Token Account'}</div>
333
+ </div>
334
+ `;
335
+
336
+ accountsList.appendChild(accountItem);
337
+ });
338
+
339
+ // Select all by default
340
+ selectedAccounts = [...closeableAccounts.map(acc => acc.address)];
341
+
342
+ // Add event listeners to checkboxes
343
+ document.querySelectorAll('#accountsList input[type="checkbox"]').forEach(checkbox => {
344
+ checkbox.addEventListener('change', function() {
345
+ const address = this.dataset.address;
346
+ if (this.checked) {
347
+ if (!selectedAccounts.includes(address)) {
348
+ selectedAccounts.push(address);
349
+ }
350
+ } else {
351
+ selectedAccounts = selectedAccounts.filter(acc => acc !== address);
352
+ }
353
+
354
+ // Disable BONK button if no accounts selected
355
+ document.getElementById('bonkItBtn').disabled = selectedAccounts.length === 0;
356
+ });
357
+ });
358
+ }, 1500);
359
+ });
360
+
361
+ // BONK IT! button
362
+ document.getElementById('bonkItBtn').addEventListener('click', function() {
363
+ // Show loading state
364
+ this.innerHTML = '<span class="animate-pulse">BONKING...</span>';
365
+ this.disabled = true;
366
+
367
+ // Mock API call
368
+ setTimeout(() => {
369
+ // Hide results, show completion
370
+ document.getElementById('scanResults').classList.add('hidden');
371
+ document.getElementById('cleanupComplete').classList.remove('hidden');
372
+
373
+ // Calculate estimated SOL recovered (0.002 SOL per account)
374
+ const estimatedRecovery = selectedAccounts.length * 0.002;
375
+ document.getElementById('recoveredSol').textContent = estimatedRecovery.toFixed(3);
376
+
377
+ // Reset button
378
+ this.innerHTML = 'BONK IT!';
379
+ this.disabled = false;
380
+ }, 2000);
381
+ });
382
+
383
+ // Scan again button
384
+ document.getElementById('scanAgainBtn').addEventListener('click', function() {
385
+ document.getElementById('cleanupComplete').classList.add('hidden');
386
+ document.getElementById('initialScan').classList.remove('hidden');
387
+ document.getElementById('scanResults').classList.add('hidden');
388
+
389
+ // Reset selections
390
+ closeableAccounts = [];
391
+ selectedAccounts = [];
392
+ });
393
+ });
394
+ </script>
395
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ordlibrary/bonkbutton" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
396
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ // File: src/App.tsx import React from 'react'; import { ConnectionProvider, // File: src/index.ts import express from 'express'; import cors from 'cors'; import { Connection, PublicKey, clusterApiUrl } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; import { scanWalletRoute } from './routes/scanWallet'; import { tokenInfoRoute } from './routes/tokenInfo'; import { stakingRoute } from './routes/staking'; import { config } from './config'; const app = express(); const PORT = process.env.PORT || 3001; // Configure RPC connection const connection = new Connection( process.env.SOLANA_RPC_URL || clusterApiUrl('mainnet-beta'), 'confirmed' ); // Middleware app.use(cors()); app.use(express.json()); // Pass the connection to routes app.locals.connection = connection; // Routes app.use('/api/scan', scanWalletRoute); app.use('/api/tokens', tokenInfoRoute); app.use('/api/staking', stakingRoute); // Health check endpoint app.get('/health', (req, res) => { res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() }); }); // Start server app.listen(PORT, () => { console.log(`BONK AI API server running on port ${PORT}`); console.log(`Environment: ${process.env.NODE_ENV}`); }); // File: src/config.ts // Configuration settings for the BONK AI backend export const config = { // Token addresses tokens: { BONK: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', BONKAI: '', // To be filled when token is created WSOL: 'So11111111111111111111111111111111111111112' }, // Programs programs: { TOKEN_PROGRAM: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', BONK_AI_REGISTRY: '', // To be filled when deployed BONK_AI_STAKING: '', // To be filled when deployed }, // RPC endpoint fallbacks rpc: { mainnet: process.env.MAINNET_RPC_URL || 'https://api.mainnet-beta.solana.com', devnet: process.env.DEVNET_RPC_URL || 'https://api.devnet.solana.com' }, // Cache settings cache: { ttl: 60 * 1000, // 1 minute cache for basic data walletTtl: 5 * 60 * 1000 // 5 minutes for wallet data }, // Rate limiting rateLimit: { windowMs: 15 * 60 * 1000, // 15 minutes max: 100 // limit each IP to 100 requests per windowMs } }; // File: src/routes/scanWallet.ts import { Router, Request, Response } from 'express'; import { PublicKey } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; import { config } from '../config'; import { scanWalletForCloseableAccounts } from '../services/walletService'; const router = Router(); // Endpoint to scan wallet for closeable accounts router.get('/:walletAddress', async (req: Request, res: Response) => { try { WalletProvider } from '@solana/wallet-adapter-react'; import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; import { PhantomWalletAdapter, SolflareWalletAdapter, BackpackWalletAdapter } from '@solana/wallet-adapter-wallets'; import { WalletModalProvider } from '@solana/wallet-adapter-react-ui'; import { clusterApiUrl } from '@solana/web3.js'; import { BonkDashboard } from './components/BonkDashboard'; import { TokenProvider } from './context/TokenContext'; import { BonkThemeProvider } from './context/ThemeContext'; // Import wallet adapter styles import '@solana/wallet-adapter-react-ui/styles.css'; import './styles/global.css'; function App() { // Set network to 'mainnet-beta' for production const network = WalletAdapterNetwork.MainnetBeta; // You can also provide a custom RPC endpoint const endpoint = process.env.REACT_APP_RPC_URL || clusterApiUrl(network); // Initialize wallet adapters for common Solana wallets const wallets = [ new PhantomWalletAdapter(), new SolflareWalletAdapter(), new BackpackWalletAdapter() ]; return ( <BonkThemeProvider> <ConnectionProvider endpoint={endpoint}> <WalletProvider wallets={wallets} autoConnect> <WalletModalProvider> <TokenProvider> <div className="app-container"> <BonkDashboard /> </div> </TokenProvider> </WalletModalProvider> </WalletProvider> </ConnectionProvider> </BonkThemeProvider> ); } export default App; // File: src/components/BonkDashboard.tsx import React, { useState } from 'react'; import { useWallet } from '@solana/wallet-adapter-react'; import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'; import { BonkButton } from './BonkButton'; import { WalletOverview } from './WalletOverview'; import { StakingSection } from './StakingSection'; import { Footer } from './Footer'; import { Header } from './Header'; export const BonkDashboard: React.FC = () => { const { publicKey } = useWallet(); const [activeTab, setActiveTab] = useState('dashboard'); return ( <div className="dashboard-container"> <Header /> <div className="wallet-connect-section"> <WalletMultiButton /> {!publicKey && ( <div className="connect-prompt"> <h2>Connect your wallet to use the BONK Button</h2> <p>Clean up your Solana wallet and recover SOL with just one click!</p> </div> )} </div> {publicKey && ( <> <div className="tabs"> <button className={`tab ${activeTab === 'dashboard' ? 'active' : ''}`} onClick={() => setActiveTab('dashboard')} > Dashboard </button> <button className={`tab ${activeTab === 'bonkbutton' ? 'active' : ''}`} onClick={() => setActiveTab('bonkbutton')} > BONK Button </button> <button className={`tab ${activeTab === 'staking' ? 'active' : ''}`} onClick={() => setActiveTab('staking')} > Staking </button> </div> <div className="tab-content"> {activeTab === 'dashboard' && <WalletOverview />} {activeTab === 'bonkbutton' && <BonkButton />} {activeTab === 'staking' && <StakingSection />} </div> </> )} <Footer /> </div> ); }; // File: src/components/BonkButton.tsx import React, { useState, useCallback, useEffect } from 'react'; import { useConnection, useWallet } from '@solana/wallet-adapter-react'; import { Transaction, PublicKey, sendAndConfirmTransaction } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID, createCloseAccountInstruction, getAccount, getAssociatedTokenAddress } from '@solana/spl-token'; import '../styles/BonkButton.css'; interface TokenAccount { pubkey: PublicKey; account: { mint: PublicKey; owner: PublicKey; amount: bigint; isNative: boolean; } isWrappedSol: boolean; } interface CloseableAccount { address: PublicKey; mint: PublicKey; isWrappedSol: boolean; balance: string; } const WSOL_MINT = new PublicKey('So11111111111111111111111111111111111111112'); export const BonkButton: React.FC = () => { const { connection } = useConnection(); const { publicKey, sendTransaction } = useWallet(); const [isScanning, setIsScanning] = useState(false); const [closeableAccounts, setCloseableAccounts] = useState<CloseableAccount[]>([]); const [selectedAccounts, setSelectedAccounts] = useState<string[]>([]); const [isCleaning, setIsCleaning] = useState(false); const [cleaningComplete, setCleaningComplete] = useState(false); const [recoveredSol, setRecoveredSol] = useState(0); const [error, setError] = useState<string | null>(null); // Scan for closeable accounts const scanForCloseableAccounts = useCallback(async () => { if (!publicKey) return; setIsScanning(true); setError(null); try { // Get all token accounts owned by this wallet const tokenAccounts = await connection.getParsedTokenAccountsByOwner( publicKey, { programId: TOKEN_PROGRAM_ID } ); const closeableAccts: CloseableAccount[] = []; for (const { pubkey, account } of tokenAccounts.value) { const parsedAccount = account.data.parsed.info; const isWrappedSol = parsedAccount.mint === WSOL_MINT.toString(); const balance = parsedAccount.tokenAmount.uiAmount; // Account is closeable if it's wrapped SOL or has zero balance if (isWrappedSol || balance === 0) { closeableAccts.push({ address: pubkey, mint: new PublicKey(parsedAccount.mint), isWrappedSol, balance: balance.toString() }); } } setCloseableAccounts(closeableAccts); // Auto-select all accounts by default setSelectedAccounts(closeableAccts.map(acct => acct.address.toString())); } catch (err) { console.error('Error scanning accounts:', err); setError('Failed to scan accounts. Please try again.'); } finally { setIsScanning(false); } }, [publicKey, connection]); // Handle account selection const toggleAccountSelection = (accountAddress: string) => { setSelectedAccounts(prev => { if (prev.includes(accountAddress)) { return prev.filter(addr => addr !== accountAddress); } else { return [...prev, accountAddress]; } }); }; // Clean selected accounts (close them) const cleanSelectedAccounts = useCallback(async () => { if (!publicKey || selectedAccounts.length === 0) return; setIsCleaning(true); setError(null); try { const transaction = new Transaction(); // Add close instruction for each selected account for (const accountAddr of selectedAccounts) { const account = closeableAccounts.find( acct => acct.address.toString() === accountAddr ); if (account) { transaction.add( createCloseAccountInstruction( account.address, // token account to close publicKey, // destination for remaining SOL publicKey // account owner ) ); } } // Send transaction const signature = await sendTransaction(transaction, connection); // Wait for confirmation await connection.confirmTransaction(signature, 'confirmed'); // Calculate approximate SOL recovered (this is an estimate) // Each account closure recovers ~0.002 SOL in rent const estimatedRecovery = selectedAccounts.length * 0.002; setRecoveredSol(estimatedRecovery); setCleaningComplete(true); // Reset the closeable accounts list setCloseableAccounts([]); setSelectedAccounts([]); } catch (err) { console.error('Error closing accounts:', err); setError('Failed to close accounts. Please try again.'); } finally { setIsCleaning(false); } }, [publicKey, connection, sendTransaction, selectedAccounts, closeableAccounts]); // Reset the cleanup state to scan again const resetCleanup = () => { setCleaningComplete(false); setRecoveredSol(0); }; return ( <div className="bonk-button-container"> <div className="bonk-button-header"> <h2>BONK Button</h2> <p>Clean up your wallet and recover SOL with one click!</p> </div> {error && ( <div className="error-message"> {error} </div> )} {!cleaningComplete ? ( <> {closeableAccounts.length === 0 ? ( <button className="scan-button" onClick={scanForCloseableAccounts} disabled={isScanning || !publicKey} > {isScanning ? 'Scanning...' : 'Scan My Wallet'} </button> ) : ( <div className="accounts-section"> <h3>Found {closeableAccounts.length} closeable accounts:</h3> <div className="accounts-list"> {closeableAccounts.map((account) => ( <div key={account.address.toString()} className="account-item" > <input type="checkbox" checked={selectedAccounts.includes(account.address.toString())} onChange={() => toggleAccountSelection(account.address.toString())} /> <div className="account-info"> <span className="account-address"> {account.address.toString().slice(0, 4)}... {account.address.toString().slice(-4)} </span> <span className="account-type"> {account.isWrappedSol ? 'Wrapped SOL' : 'Empty Token Account'} </span> </div> </div> ))} </div> <button className="bonk-button" onClick={cleanSelectedAccounts} disabled={isCleaning || selectedAccounts.length === 0} > {isCleaning ? 'BONKING...' : 'BONK IT!'} </button> </div> )} </> ) : ( <div className="cleanup-complete"> <h3>BONK! Wallet Cleaned Successfully!</h3> <p>You've recovered approximately {recoveredSol.toFixed(3)} SOL</p> <p>Your wallet is now cleaner and more efficient!</p> <button className="scan-again-button" onClick={resetCleanup} > Scan Again </button> </div> )} </div> ); }; // File: src/components/WalletOverview.tsx import React, { useEffect, useState } from 'react'; import { useConnection, useWallet } from '@solana/wallet-adapter-react'; import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; import { useTokenBalances } from '../hooks/useTokenBalances'; import '../styles/WalletOverview.css'; // Known token addresses (mainnet) const BONK_TOKEN_ADDRESS = 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263'; const BONKAI_TOKEN_ADDRESS = ''; // To be filled when BONKAI is created export const WalletOverview: React.FC = () => { const { connection } = useConnection(); const { publicKey } = useWallet(); const [solBalance, setSolBalance] = useState(0); const { bonkBalance, bonkaiBalance, isLoading: isLoadingTokens } = useTokenBalances(); const [accountCount, setAccountCount] = useState(0); useEffect(() => { if (!publicKey) return; const fetchSolBalance = async () => { try { const balance = await connection.getBalance(publicKey); setSolBalance(balance / LAMPORTS_PER_SOL); } catch (error) { console.error('Error fetching SOL balance:', error); } }; const fetchAccountCount = async () => { try { const tokenAccounts = await connection.getParsedTokenAccountsByOwner( publicKey, { programId: TOKEN_PROGRAM_ID } ); setAccountCount(tokenAccounts.value.length); } catch (error) { console.error('Error fetching token accounts:', error); } }; fetchSolBalance(); fetchAccountCount(); // Set up interval to refresh balances const intervalId = setInterval(() => { fetchSolBalance(); }, 30000); // every 30 seconds return () => clearInterval(intervalId); }, [publicKey, connection]); if (!publicKey) { return <div>Please connect your wallet to view this section.</div>; } return ( <div className="wallet-overview"> <h2>Wallet Overview</h2> <div className="wallet-address"> {publicKey.toString().slice(0, 6)}...{publicKey.toString().slice(-6)} </div> <div className="balances-section"> <div className="balance-card sol"> <div className="token-icon">β—Ž</div> <div className="token-details"> <h3>SOL</h3> <p className="balance">{solBalance.toFixed(4)} SOL</p> </div> </div> <div className="balance-card bonk"> <div className="token-icon">πŸ•</div> <div className="token-details"> <h3>BONK</h3> <p className="balance"> {isLoadingTokens ? 'Loading...' : `${bonkBalance.toLocaleString()} BONK`} </p> </div> </div> <div className="balance-card bonkai"> <div className="token-icon">πŸ€–</div> <div className="token-details"> <h3>BONKAI</h3> <p className="balance"> {isLoadingTokens ? 'Loading...' : `${bonkaiBalance.toLocaleString()} BONKAI`} </p> </div> </div> </div> <div className="account-stats"> <div className="stat"> <h4>Token Accounts</h4> <p>{accountCount}</p> </div> <div className="stat"> <h4>Estimated Rent</h4> <p>~{(accountCount * 0.002).toFixed(3)} SOL</p> </div> </div> <div className="bonk-tip"> <p>πŸ’‘ Use the BONK Button to clean up unused token accounts and recover SOL!</p> </div> </div> ); }; // File: src/hooks/useTokenBalances.ts import { useState, useEffect } from 'react'; import { useConnection, useWallet } from '@solana/wallet-adapter-react'; import { PublicKey } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from '@solana/spl-token'; // Known token addresses const BONK_TOKEN_ADDRESS = new PublicKey('DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263'); const BONKAI_TOKEN_ADDRESS = ''; // To be filled when BONKAI is created export function useTokenBalances() { const { connection } = useConnection(); const { publicKey } = useWallet(); const [bonkBalance, setBonkBalance] = useState(0); const [bonkaiBalance, setBonkaiBalance] = useState(0); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState<string | null>(null); useEffect(() => { if (!publicKey) return; const fetchTokenBalances = async () => { setIsLoading(true); setError(null); try { // Fetch all token accounts const tokenAccounts = await connection.getParsedTokenAccountsByOwner( publicKey, { programId: TOKEN_PROGRAM_ID } ); // Find BONK balance const bonkAccount = tokenAccounts.value.find( ({ account }) => account.data.parsed.info.mint === BONK_TOKEN_ADDRESS.toString() ); if (bonkAccount) { const balance = bonkAccount.account.data.parsed.info.tokenAmount.uiAmount; setBonkBalance(balance); } else { setBonkBalance(0); } // Find BONKAI balance if token address is set if (BONKAI_TOKEN_ADDRESS) { const bonkaiAccount = tokenAccounts.value.find( ({ account }) => account.data.parsed.info.mint === BONKAI_TOKEN_ADDRESS ); if (bonkaiAccount) { const balance = bonkaiAccount.account.data.parsed.info.tokenAmount.uiAmount; setBonkaiBalance(balance); } else { setBonkaiBalance(0); } } } catch (err) { console.error('Error fetching token balances:', err); setError('Failed to load token balances'); } finally { setIsLoading(false); } }; fetchTokenBalances(); // Set up interval to refresh balances const intervalId = setInterval(fetchTokenBalances, 30000); // every 30 seconds return () => clearInterval(intervalId); }, [publicKey, connection]); return { bonkBalance, bonkaiBalance, isLoading, error }; } // File: src/styles/global.css body { margin: 0; font-family: 'Press Start 2P', 'Courier New', monospace; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; background-color: #202225; color: #ffffff; } .app-container { max-width: 1200px; margin: 0 auto; padding: 20px; } .dashboard-container { display: flex; flex-direction: column; gap: 24px; } .wallet-connect-section { display: flex; flex-direction: column; align-items: center; margin: 20px 0; gap: 16px; } .connect-prompt { text-align: center; max-width: 600px; margin: 24px auto; } .connect-prompt h2 { font-size: 1.5rem; margin-bottom: 16px; color: #FFD700; } .connect-prompt p { font-size: 1rem; color: #bbbbbb; } .tabs { display: flex; gap: 4px; border-bottom: 2px solid #444; margin-bottom: 24px; } .tab { padding: 12px 24px; background: none; border: none; color: #bbbbbb; font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 0.9rem; cursor: pointer; transition: all 0.2s; } .tab:hover { color: #FFD700; } .tab.active { color: #FFD700; border-bottom: 4px solid #FFD700; margin-bottom: -2px; } .tab-content { min-height: 400px; } button { font-family: 'Press Start 2P', 'Courier New', monospace; cursor: pointer; } .error-message { background-color: rgba(255, 0, 0, 0.1); border: 1px solid #ff6b6b; color: #ff6b6b; padding: 12px; border-radius: 4px; margin: 16px 0; } /* File: src/styles/BonkButton.css */ .bonk-button-container { display: flex; flex-direction: column; gap: 24px; padding: 24px; background: #2a2d31; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); } .bonk-button-header { text-align: center; margin-bottom: 24px; } .bonk-button-header h2 { color: #FFD700; font-size: 1.8rem; margin-bottom: 8px; } .bonk-button-header p { color: #bbbbbb; font-size: 0.9rem; } .scan-button, .bonk-button, .scan-again-button { padding: 16px 24px; font-size: 1rem; border: none; border-radius: 4px; transition: all 0.2s; text-transform: uppercase; font-weight: bold; margin: 0 auto; display: block; min-width: 200px; } .scan-button { background-color: #5865F2; color: white; } .scan-button:hover:not(:disabled) { background-color: #4752c4; transform: translateY(-2px); } .scan-button:disabled { background-color: #4752c4; opacity: 0.6; cursor: not-allowed; } .bonk-button { background-color: #FFD700; color: #000000; font-size: 1.2rem; padding: 20px 36px; box-shadow: 0 4px 0 #b89b00; } .bonk-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 #b89b00; } .bonk-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #b89b00; } .bonk-button:disabled { opacity: 0.6; cursor: not-allowed; } .accounts-section { display: flex; flex-direction: column; gap: 16px; } .accounts-section h3 { font-size: 1rem; color: #FFD700; margin-bottom: 16px; } .accounts-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; padding: 16px; background-color: #1e2023; border-radius: 4px; margin-bottom: 24px; } .account-item { display: flex; align-items: center; padding: 12px; background-color: #2a2d31; border-radius: 4px; gap: 12px; } .account-info { display: flex; flex-direction: column; gap: 4px; } .account-address { font-size: 0.8rem; font-family: monospace; color: #bbbbbb; } .account-type { font-size: 0.7rem; color: #FFD700; font-weight: bold; } .cleanup-complete { text-align: center; padding: 24px; background-color: rgba(255, 215, 0, 0.1); border-radius: 8px; margin: 24px 0; } .cleanup-complete h3 { color: #FFD700; font-size: 1.5rem; margin-bottom: 16px; } .cleanup-complete p { margin: 8px 0; color: #ffffff; } .scan-again-button { background-color: #5865F2; color: white; margin-top: 16px; } .scan-again-button:hover { background-color: #4752c4; }