-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit-bot-run.ts
More file actions
202 lines (174 loc) Β· 6.01 KB
/
audit-bot-run.ts
File metadata and controls
202 lines (174 loc) Β· 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* Deep audit of bot run - analyze why spam didn't trigger
*/
import 'dotenv/config'
import { readFileSync, readdirSync, statSync } from 'fs'
import { join } from 'path'
interface LogEntry {
timestamp: string
level: string
category: string
message: string
data?: any
}
function parseLogLine(line: string): LogEntry | null {
// Format: [2025-11-12T08:20:37.031Z] [INFO] [GAS] message | DATA: {...}
const match = line.match(/\[([^\]]+)\]\s+\[([^\]]+)\]\s+\[([^\]]+)\]\s+(.+?)(?:\s+\|\s+DATA:\s+(.+))?$/)
if (!match) return null
const [, timestamp, level, category, message, dataStr] = match
let data: any = undefined
if (dataStr) {
try {
data = JSON.parse(dataStr)
} catch (e) {
// Ignore parse errors
}
}
return { timestamp, level, category, message, data }
}
async function auditBotRun() {
console.log('π DEEP AUDIT OF BOT RUN\n')
console.log('='.repeat(80))
// Find latest log file
const logsDir = join(process.cwd(), 'logs')
const logFiles = readdirSync(logsDir)
.filter(f => f.endsWith('.log'))
.map(f => ({
name: f,
path: join(logsDir, f),
mtime: statSync(join(logsDir, f)).mtime
}))
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime())
if (logFiles.length === 0) {
console.log('β No log files found')
return
}
const latestLog = logFiles[0]
console.log(`π Analyzing: ${latestLog.name}\n`)
const logContent = readFileSync(latestLog.path, 'utf8')
const lines = logContent.split('\n').filter(l => l.trim())
// Parse all log entries
const entries: LogEntry[] = []
for (const line of lines) {
const entry = parseLogLine(line)
if (entry) entries.push(entry)
}
console.log(`π Total log entries: ${entries.length}\n`)
// Find initialization
const initEntries = entries.filter(e =>
e.message.includes('Time-based spam') ||
e.message.includes('Expected unlock') ||
e.message.includes('Spam starts') ||
e.message.includes('Spam ends') ||
e.message.includes('Adjusted unlock')
)
console.log('π§ INITIALIZATION:\n')
if (initEntries.length > 0) {
initEntries.forEach(e => {
console.log(` [${e.timestamp}] ${e.message}`)
if (e.data) console.log(` Data: ${JSON.stringify(e.data, null, 2)}`)
})
} else {
console.log(' β No initialization entries found!')
}
// Find spam attempts
const spamEntries = entries.filter(e =>
e.category === 'SPAM' &&
(e.message.includes('Spam sent') ||
e.message.includes('Spam transaction') ||
e.message.includes('Broadcast'))
)
console.log(`\nπ€ SPAM TRANSACTIONS:\n`)
console.log(` Total spam entries: ${spamEntries.length}`)
if (spamEntries.length > 0) {
spamEntries.slice(0, 10).forEach(e => {
console.log(` [${e.timestamp}] ${e.message}`)
if (e.data) {
console.log(` Successful RPCs: ${e.data.successfulRPCs || 'N/A'}`)
console.log(` Gas multiplier: ${e.data.gasMultiplier || 'N/A'}`)
}
})
if (spamEntries.length > 10) {
console.log(` ... and ${spamEntries.length - 10} more`)
}
} else {
console.log(' β NO SPAM TRANSACTIONS FOUND!')
}
// Find window checks
const windowChecks = entries.filter(e =>
e.message.includes('Periodic window check') ||
e.message.includes('unlockTime')
)
console.log(`\nβ° WINDOW CHECKS:\n`)
console.log(` Total window checks: ${windowChecks.length}`)
if (windowChecks.length > 0) {
const recentChecks = windowChecks.slice(-10)
recentChecks.forEach(e => {
console.log(` [${e.timestamp}] unlockTime: ${e.data?.unlockTime || 'N/A'}s, paused: ${e.data?.paused}, available: ${e.data?.available}`)
})
}
// Find errors
const errors = entries.filter(e =>
e.level === 'ERROR' ||
e.level === 'WARN' ||
e.message.includes('failed') ||
e.message.includes('error') ||
e.message.includes('Error')
)
console.log(`\nβ οΈ ERRORS/WARNINGS:\n`)
console.log(` Total: ${errors.length}`)
if (errors.length > 0) {
errors.slice(0, 10).forEach(e => {
console.log(` [${e.timestamp}] ${e.message}`)
if (e.data?.error) console.log(` Error: ${e.data.error}`)
})
}
// Check for inSpamWindow logic
const spamWindowEntries = entries.filter(e =>
e.message.includes('inSpamWindow') ||
e.message.includes('Time-based spam starts in') ||
e.message.includes('Spam window ended')
)
console.log(`\nπͺ SPAM WINDOW STATUS:\n`)
if (spamWindowEntries.length > 0) {
spamWindowEntries.forEach(e => {
console.log(` [${e.timestamp}] ${e.message}`)
})
} else {
console.log(' β No spam window status entries found!')
}
// Check nonce initialization
const nonceEntries = entries.filter(e =>
e.message.includes('nonce') ||
e.data?.nonce !== undefined
)
console.log(`\nπ’ NONCE STATUS:\n`)
if (nonceEntries.length > 0) {
const nonceInfo = nonceEntries
.filter(e => e.data?.nonce !== undefined)
.map(e => ({ time: e.timestamp, nonce: e.data.nonce }))
.slice(-5)
nonceInfo.forEach(n => {
console.log(` [${n.time}] nonce: ${n.nonce}`)
})
} else {
console.log(' β οΈ No nonce information found')
}
// Summary
console.log(`\n${'='.repeat(80)}`)
console.log('π SUMMARY:\n')
console.log(` Initialization entries: ${initEntries.length}`)
console.log(` Spam transaction attempts: ${spamEntries.length}`)
console.log(` Window checks: ${windowChecks.length}`)
console.log(` Errors/warnings: ${errors.length}`)
console.log(` Spam window status entries: ${spamWindowEntries.length}`)
if (spamEntries.length === 0) {
console.log(`\nβ CRITICAL: No spam transactions were sent!`)
console.log(` Possible causes:`)
console.log(` 1. spamStartTimestamp was never set or was null`)
console.log(` 2. inSpamWindow was never true`)
console.log(` 3. spamTransactionByTime() returned early`)
console.log(` 4. currentNonce was null and couldn't be fetched`)
}
}
auditBotRun().catch(console.error)