-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplainerEngine.ts
More file actions
39 lines (30 loc) · 1.09 KB
/
ExplainerEngine.ts
File metadata and controls
39 lines (30 loc) · 1.09 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
import { ExplainerInput, ExplainerOutput } from './ExplainerTypes'
import { RiskPatterns } from './RiskPatterns'
export class ExplainerEngine {
static explain(input: ExplainerInput): ExplainerOutput {
const flags: string[] = []
if (RiskPatterns.UNLIMITED_APPROVAL(input.method, input.params)) {
flags.push('UNLIMITED_APPROVAL')
}
if (RiskPatterns.DELEGATECALL(input.method)) {
flags.push('DELEGATECALL')
}
if (RiskPatterns.SELF_DESTRUCT(input.method)) {
flags.push('SELF_DESTRUCT')
}
let riskLevel: ExplainerOutput['riskLevel'] = 'LOW'
if (flags.length >= 2) riskLevel = 'HIGH'
else if (flags.length === 1) riskLevel = 'MEDIUM'
const summary = this.buildSummary(input, flags)
return { summary, riskLevel, flags }
}
private static buildSummary(
input: ExplainerInput,
flags: string[]
): string {
if (flags.includes('UNLIMITED_APPROVAL')) {
return `⚠️ You are granting unlimited token access to ${input.params.spender}.`
}
return `You are calling "${input.method}" on contract ${input.contract}.`
}
}