@pioneer-platform/pioneer-discovery-service 0.2.1 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @pioneer-platform/pioneer-discovery-service
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @pioneer-platform/default-mongo-v2@1.7.1
9
+
3
10
  ## 0.2.1
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,459 @@
1
+ # DApp Investigation Worker
2
+
3
+ ## Overview
4
+
5
+ The DApp Investigator is a deep analysis worker that runs as part of the Pioneer Discovery Service to comprehensively investigate dApps before whitelisting them.
6
+
7
+ ## Investigation Areas
8
+
9
+ ### 1. Contract Verification
10
+
11
+ **What we check:**
12
+ - Are smart contracts verified on block explorers?
13
+ - Etherscan, BSCScan, Polygonscan verification status
14
+ - Source code availability
15
+ - Security audit status (CertiK, Trail of Bits, OpenZeppelin)
16
+ - Audit recency and findings
17
+
18
+ **Data Sources:**
19
+ - Etherscan API
20
+ - BSCScan API
21
+ - Polygonscan API
22
+ - CertiK Security Oracle
23
+ - DeFi Safety scores
24
+
25
+ ### 2. Social Media Presence
26
+
27
+ **What we check:**
28
+ - Twitter: Handle, followers, verification, activity
29
+ - Discord: Server size, activity level
30
+ - GitHub: Repository stats, stars, contributors, commit frequency
31
+ - Telegram: Group size, admin activity
32
+ - Medium/Blog: Technical documentation quality
33
+
34
+ **Red Flags:**
35
+ - No social presence
36
+ - Inactive accounts
37
+ - Recently created accounts
38
+ - Bought followers
39
+ - No community engagement
40
+
41
+ ### 3. Metrics & Usage
42
+
43
+ **What we check:**
44
+ - Total Value Locked (TVL) from DeFiLlama
45
+ - Daily Active Users (DAU)
46
+ - Transaction volume
47
+ - Fee generation
48
+ - User retention
49
+ - Growth trends
50
+
51
+ **Data Sources:**
52
+ - DeFiLlama
53
+ - Dune Analytics
54
+ - The Graph
55
+ - On-chain data
56
+
57
+ ### 4. Security History
58
+
59
+ **What we check:**
60
+ - Past security incidents
61
+ - Exploit history
62
+ - Bug bounty program
63
+ - Response to vulnerabilities
64
+ - Recovery procedures
65
+
66
+ **Data Sources:**
67
+ - Rekt News
68
+ - Immunefi
69
+ - CertiK incidents
70
+ - SlowMist Hacked database
71
+ - BlockSec alerts
72
+
73
+ ### 5. Team Transparency
74
+
75
+ **What we check:**
76
+ - Public team members
77
+ - LinkedIn profiles
78
+ - Previous project experience
79
+ - KYC verification (CertiK, Assure)
80
+ - Team size and roles
81
+ - Developer activity
82
+
83
+ **Scoring:**
84
+ - Anonymous team: +20 risk
85
+ - Public team: -10 risk
86
+ - KYC verified: -10 risk
87
+ - Experienced team: -15 risk
88
+
89
+ ## Risk Score Calculation
90
+
91
+ Risk scores range from 0 (safe) to 100 (high risk):
92
+
93
+ ### Starting Point
94
+ - Base score: 50 (neutral)
95
+
96
+ ### Adjustments
97
+
98
+ **Reduce Risk (-):**
99
+ - Contract verified: -20
100
+ - Strong social presence: -10
101
+ - High TVL (>$1M): -15
102
+ - Bug bounty program: -5
103
+ - Public team: -10
104
+ - KYC verified: -10
105
+
106
+ **Increase Risk (+):**
107
+ - No contract verification: +10
108
+ - No social presence: +15
109
+ - Security incident: +25 per incident
110
+ - Anonymous team: +20
111
+ - Recent creation (<30 days): +15
112
+
113
+ ### Examples
114
+
115
+ **Safe DApp (Risk: 15)**
116
+ ```
117
+ Base: 50
118
+ - Contract verified: -20
119
+ - Strong social: -10
120
+ - High TVL: -15
121
+ - Public team: -10
122
+ = 50 - 55 = 0 (clamped to minimum)
123
+ ```
124
+
125
+ **Risky DApp (Risk: 85)**
126
+ ```
127
+ Base: 50
128
+ + Not verified: +10
129
+ + No social: +15
130
+ + 1 incident: +25
131
+ = 50 + 50 = 100
132
+ ```
133
+
134
+ ## Whitelist Criteria
135
+
136
+ A dApp is recommended for whitelisting if:
137
+
138
+ 1. **Risk score < 30**
139
+ 2. **Either:**
140
+ - Contract verified, OR
141
+ - TVL > $1M
142
+ 3. **Has social presence** (Twitter, Discord, or GitHub)
143
+ 4. **No major security incidents**
144
+
145
+ ## Investigation Flow
146
+
147
+ ### Phase 1: Contract Verification (30s)
148
+
149
+ ```typescript
150
+ // Check Etherscan
151
+ const etherscan = await axios.get(
152
+ `https://api.etherscan.io/api?module=contract&action=getsourcecode&address=${address}`
153
+ );
154
+
155
+ if (etherscan.data.result[0].SourceCode) {
156
+ findings.contractVerification = {
157
+ verified: true,
158
+ auditor: etherscan.data.result[0].AuditorName,
159
+ auditDate: etherscan.data.result[0].AuditDate,
160
+ };
161
+ }
162
+ ```
163
+
164
+ ### Phase 2: Social Analysis (45s)
165
+
166
+ ```typescript
167
+ // Check GitHub
168
+ const github = await axios.get(
169
+ `https://api.github.com/repos/${org}/${repo}`
170
+ );
171
+
172
+ findings.socialPresence.github = {
173
+ repos: 1,
174
+ stars: github.data.stargazers_count,
175
+ lastCommit: github.data.pushed_at,
176
+ };
177
+
178
+ // Check Twitter (via scraping or paid API)
179
+ // Check Discord (via bot or public stats)
180
+ ```
181
+
182
+ ### Phase 3: Metrics Fetch (30s)
183
+
184
+ ```typescript
185
+ // Query DeFiLlama
186
+ const protocols = await axios.get(
187
+ 'https://api.llama.fi/protocols'
188
+ );
189
+
190
+ const match = protocols.data.find(p =>
191
+ p.name.toLowerCase() === dapp.name.toLowerCase()
192
+ );
193
+
194
+ if (match) {
195
+ findings.metrics = {
196
+ tvl: match.tvl,
197
+ source: 'DeFiLlama',
198
+ };
199
+ }
200
+ ```
201
+
202
+ ### Phase 4: Security Check (60s)
203
+
204
+ ```typescript
205
+ // Check Rekt News database
206
+ // Check Immunefi for bounties
207
+ // Check CertiK for incidents
208
+ // Check SlowMist Hacked list
209
+
210
+ findings.security = {
211
+ incidents: [],
212
+ bugBounty: false,
213
+ };
214
+ ```
215
+
216
+ ### Phase 5: Team Check (45s)
217
+
218
+ ```typescript
219
+ // Scrape team page
220
+ // Check LinkedIn
221
+ // Verify KYC badges
222
+
223
+ findings.team = {
224
+ public: false,
225
+ kyc: false,
226
+ experience: 'unknown',
227
+ };
228
+ ```
229
+
230
+ **Total Time: ~3-4 minutes per dApp**
231
+
232
+ ## Batch Processing
233
+
234
+ To avoid overwhelming the system:
235
+
236
+ - **Process 10 dApps per run** (configurable)
237
+ - **1 second delay** between dApps
238
+ - **Only investigate stale dApps** (not checked in 7 days)
239
+ - **Non-blocking** (doesn't slow down other discovery phases)
240
+
241
+ ```typescript
242
+ // Get stale dApps
243
+ const allDapps = await discoveryDB.getDappsNeedingCheck(24 * 7); // 7 days
244
+
245
+ // Limit batch size
246
+ const dappsToInvestigate = allDapps.slice(0, 10);
247
+
248
+ // Process with delays
249
+ for (const dapp of dappsToInvestigate) {
250
+ await investigateDApp(dapp);
251
+ await sleep(1000); // 1 second delay
252
+ }
253
+ ```
254
+
255
+ ## Investigation Results
256
+
257
+ ### High Quality DApp Example
258
+
259
+ ```json
260
+ {
261
+ "dappId": "uniswap-v3",
262
+ "dappName": "Uniswap V3",
263
+ "investigationComplete": true,
264
+ "findings": {
265
+ "contractVerification": {
266
+ "verified": true,
267
+ "auditor": "Trail of Bits",
268
+ "auditDate": "2021-03-15",
269
+ "auditUrl": "https://github.com/Uniswap/v3-core/blob/main/audits/"
270
+ },
271
+ "socialPresence": {
272
+ "twitter": {
273
+ "handle": "@Uniswap",
274
+ "followers": 1200000,
275
+ "verified": true,
276
+ "lastPost": "2024-01-15T10:30:00Z"
277
+ },
278
+ "discord": {
279
+ "serverSize": 50000,
280
+ "active": true
281
+ },
282
+ "github": {
283
+ "repos": 15,
284
+ "stars": 8500,
285
+ "lastCommit": "2024-01-14",
286
+ "contributors": 45
287
+ }
288
+ },
289
+ "metrics": {
290
+ "tvl": 3500000000,
291
+ "dailyActiveUsers": 25000,
292
+ "transactionVolume": 1000000000,
293
+ "source": "DeFiLlama"
294
+ },
295
+ "security": {
296
+ "incidents": [],
297
+ "bugBounty": true,
298
+ "bugBountyUrl": "https://immunefi.com/bounty/uniswap/"
299
+ },
300
+ "team": {
301
+ "public": true,
302
+ "kyc": true,
303
+ "experience": "Hayden Adams - experienced DeFi builder"
304
+ }
305
+ },
306
+ "riskScore": 5,
307
+ "recommendWhitelist": true,
308
+ "investigatedAt": 1705338000000
309
+ }
310
+ ```
311
+
312
+ ### Suspicious DApp Example
313
+
314
+ ```json
315
+ {
316
+ "dappId": "anon-swap-123",
317
+ "dappName": "AnonSwap",
318
+ "investigationComplete": true,
319
+ "findings": {
320
+ "contractVerification": {
321
+ "verified": false
322
+ },
323
+ "socialPresence": {},
324
+ "metrics": {},
325
+ "security": {
326
+ "incidents": [
327
+ {
328
+ "date": "2024-01-10",
329
+ "type": "rug-pull",
330
+ "severity": "critical",
331
+ "description": "Liquidity removed by deployer"
332
+ }
333
+ ],
334
+ "bugBounty": false
335
+ },
336
+ "team": {
337
+ "public": false,
338
+ "kyc": false
339
+ }
340
+ },
341
+ "riskScore": 95,
342
+ "recommendWhitelist": false,
343
+ "investigatedAt": 1705338000000
344
+ }
345
+ ```
346
+
347
+ ## Integration with Discovery Service
348
+
349
+ ### Automatic Updates
350
+
351
+ Investigation results automatically update the discovery database:
352
+
353
+ ```typescript
354
+ // Update dapp record
355
+ await discoveryDB.updateDapp(result.dappId, {
356
+ scamScore: result.riskScore / 100, // Convert to 0-1
357
+ whitelist: result.recommendWhitelist,
358
+ lastChecked: result.investigatedAt,
359
+ });
360
+
361
+ // Log to report
362
+ if (result.recommendWhitelist) {
363
+ discoveryReporter.addLog('INFO', `✅ Whitelisted: ${result.dappName}`);
364
+ }
365
+
366
+ if (result.riskScore > 70) {
367
+ discoveryReporter.addLog('WARN', `⚠️ High risk: ${result.dappName}`);
368
+ }
369
+ ```
370
+
371
+ ### Pioneer Server Integration
372
+
373
+ The pioneer-server dapps controller can query investigation results:
374
+
375
+ ```typescript
376
+ // In pioneer-server/src/controllers/dapps.controller.ts
377
+ const dapp = await discoveryDB.getDapp(dappId);
378
+
379
+ return {
380
+ id: dapp.id,
381
+ name: dapp.name,
382
+ url: dapp.url,
383
+ whitelist: dapp.whitelist,
384
+ riskScore: dapp.scamScore * 100,
385
+ investigation: dapp.metadata, // Full findings
386
+ };
387
+ ```
388
+
389
+ ## Free Data Sources
390
+
391
+ ### Currently Used
392
+
393
+ 1. **DeFiLlama** - TVL and protocol data (free, no API key)
394
+ 2. **GitHub API** - Repository stats (free tier: 60 req/hour)
395
+ 3. **Etherscan/BSCScan** - Contract verification (free tier: 5 req/sec)
396
+
397
+ ### Planned
398
+
399
+ 4. **CoinGecko API** - Market data and social links
400
+ 5. **The Graph** - On-chain queries
401
+ 6. **Dune Analytics** - Usage metrics
402
+ 7. **Immunefi API** - Bug bounty info
403
+ 8. **CertiK API** - Audit data
404
+ 9. **Rekt News** - Incident history
405
+
406
+ ## Future Enhancements
407
+
408
+ - [ ] ML model for scam detection
409
+ - [ ] Automated contract analysis (Slither, Mythril)
410
+ - [ ] User reputation integration
411
+ - [ ] Community voting on dApps
412
+ - [ ] Real-time incident alerts
413
+ - [ ] Automated whitelist/blacklist updates
414
+ - [ ] Integration with Web3 security tools
415
+ - [ ] NFT project investigation
416
+ - [ ] DAO governance analysis
417
+ - [ ] Bridge security assessment
418
+
419
+ ## Monitoring
420
+
421
+ Check discovery service logs for investigator status:
422
+
423
+ ```bash
424
+ # View investigation logs
425
+ tail -f /var/log/pioneer/discovery-service.log | grep dapp-investigator
426
+
427
+ # Expected output
428
+ [dapp-investigator] 🔍 Starting deep investigation of 10 dApps...
429
+ [dapp-investigator] Investigating: Uniswap V3
430
+ [dapp-investigator] ✅ WHITELIST RECOMMENDED: Uniswap V3
431
+ [dapp-investigator] Investigating: SuspiciousDex
432
+ [dapp-investigator] ⚠️ HIGH RISK: SuspiciousDex (score: 85)
433
+ [dapp-investigator] Investigation complete: 10 dApps analyzed
434
+ ```
435
+
436
+ ## Performance
437
+
438
+ - **Investigation time**: ~3-4 minutes per dApp
439
+ - **Batch size**: 10 dApps per run
440
+ - **Total run time**: ~30-40 minutes per discovery cycle
441
+ - **Memory usage**: Minimal (<100MB)
442
+ - **Network**: Moderate (multiple API calls per dApp)
443
+
444
+ ## Error Handling
445
+
446
+ The investigator is designed to be fault-tolerant:
447
+
448
+ - **API failures**: Continue with available data
449
+ - **Timeouts**: Skip to next dApp after 30s
450
+ - **Rate limits**: Respect and backoff
451
+ - **Missing data**: Use defaults, don't fail
452
+ - **Network issues**: Retry with exponential backoff
453
+
454
+ ## See Also
455
+
456
+ - [Price Discovery](./PRICE-DISCOVERY.md)
457
+ - [Discovery Service README](./README.md)
458
+ - [Discord Integration](../../pioneer-server/DISCORD-INTEGRATION.md)
459
+