Code Examples
Red Flag Detection
from datetime import datetime
# Example transaction data
transactions = [
{'amount': 500, 'wallet': '0xABC', 'timestamp': '2024-12-01T12:00:00Z'},
{'amount': 500, 'wallet': '0xABC', 'timestamp': '2024-12-01T12:01:00Z'},
{'amount': 1000, 'wallet': '0xDEF', 'timestamp': '2024-12-01T12:02:00Z'},
]
def detect_red_flags(transactions):
red_flags = []
# Check for rapid transactions from a single wallet
wallet_activity = {}
for tx in transactions:
wallet = tx['wallet']
wallet_activity[wallet] = wallet_activity.get(wallet, 0) + 1
for wallet, count in wallet_activity.items():
if count > 2:
red_flags.append(f"Wallet {wallet} has {count} rapid transactions.")
return red_flags
flags = detect_red_flags(transactions)
print(flags)
Predictive Model (Simplified)
from sklearn.linear_model import LogisticRegression
# Training data (simplified example)
features = [
[0.1, 0.2, 0.7], # Low risk
[0.8, 0.7, 0.9], # High risk
[0.3, 0.4, 0.5], # Medium risk
]
labels = [0, 1, 0] # 0 = Low Risk, 1 = High Risk
# Train model
model = LogisticRegression()
model.fit(features, labels)
# Predict risk
new_token = [[0.6, 0.5, 0.8]] # Example new token
prediction = model.predict(new_token)
print("High Risk" if prediction[0] == 1 else "Low/Medium Risk")
Risk Scoring Algorithm
import numpy as np
def calculate_risk_score(token_data):
# Example weights for different factors
weights = {
'holder_concentration': 0.4,
'transaction_anomalies': 0.3,
'social_presence': 0.2,
'historical_performance': 0.1
}
# Normalize factors to a 0-1 scale
normalized_factors = {
key: value / max_value
for key, (value, max_value) in token_data.items()
}
# Calculate weighted risk score
risk_score = sum(
weights[key] * normalized_factors[key]
for key in weights.keys()
) * 100 # Scale to 0-100
return round(risk_score, 2)
# Example token data
sample_token_data = {
'holder_concentration': (80, 100),
'transaction_anomalies': (70, 100),
'social_presence': (10, 100),
'historical_performance': (50, 100)
}
risk_score = calculate_risk_score(sample_token_data)
print(f"Risk Score: {risk_score}")
Last updated