The Core Problem

Not all crypto traders are created equal. A whale moving 500 ETH through your DEX aggregator generates 100x more revenue than a casual swapper doing $50 trades. Yet most DeFi projects broadcast the same marketing message to every wallet address that touches their protocol. This one-size-fits-all approach wastes budget on low-value users and misses opportunities to retain high-value traders.

DeFiKit needed a way to automatically score every wallet that interacts with partner DEXs, prioritise high-value traders for premium outreach, and trigger personalised marketing sequences -- all without exposing sensitive trading data or requiring manual segmentation.

The Solution: Serverless Wallet Scoring Engine

DeFiKit's Automated Wallet Scoring engine runs entirely on Cloudflare Workers with D1 and KV. It ingests on-chain swap events from partner DEXs, computes a composite score from six dimensions, and routes each wallet into a marketing tier. The entire pipeline processes 10,000+ events per minute with p99 latency under 200ms.

Scoring Dimensions

| Dimension | Weight | Data Source |

|---|---|---|

| Transaction Volume (30d) | 30% | On-chain DEX events |

| Trade Frequency | 20% | Daily active trade count |

| Asset Diversity | 15% | Unique token pairs traded |

| Retention Length | 15% | Days since first interaction |

| Gas Spent | 10% | Total gas fees paid |

| Referral Network | 10% | Invited traders still active |

Architecture Overview

The pipeline follows a stream-processing pattern familiar to data engineers but implemented entirely on Cloudflare's edge:

1. **Ingestion Worker** -- Listens for webhook events from partner DEX smart contracts. Each swap event carries wallet address, token pair, volume, and timestamp.

2. **Scoring Worker** -- Reads the last 30 days of activity from D1 for each wallet. Computes the six dimension scores using pure SQL aggregate queries. KV caches scores for 5 minutes to reduce D1 reads on frequently queried wallets.

3. **Tier Router** -- Maps numeric scores to marketing tiers: Platinum (80+), Gold (60-79), Silver (40-59), Bronze (below 40). Each tier maps to a different Telegram notification cadence and offer set.

4. **Campaign Trigger** -- On score change events (a wallet moves from Silver to Gold), enqueues an automated campaign into DeFiKit's notification pipeline.

Worker Implementation

The scoring function is deliberately simple -- no ML model hosting, no Python runtime. A weighted sum on SQL results:

```sql

-- Score computation (run on Cloudflare D1)

SELECT

wallet_address,

ROUND(

COALESCE(volume_30d, 0) * 0.30 +

COALESCE(trade_freq, 0) * 0.20 +

COALESCE(asset_diversity, 0) * 0.15 +

COALESCE(retention_days, 0) * 0.02 +

COALESCE(gas_score, 0) * 0.10 +

COALESCE(referral_score, 0) * 0.10

, 0) AS composite_score

FROM wallet_metrics

WHERE wallet_address = ?

```

Each dimension is normalised to a 0-100 scale using percentile-based bucketing, computed once daily by a cron-triggered Worker. The percentile bucketing ensures that a wallet scoring 80 in volume on a quiet day means the same as an 80 on a high-volume day -- the score is relative to the current user base, not absolute.

Handling Edge Cases

The scoring engine handles several edge cases that naive implementations miss:

- **New wallets with no history** -- Default to Bronze tier with a 7-day grace period. If the wallet makes a first trade above a configurable threshold within the grace period, it auto-upgrades to Silver. This prevents new high-value users from receiving no marketing at all.

- **Wallet address rotation attacks** -- Some traders use fresh wallets for every trade to avoid MEV bots. The scoring engine tracks a device fingerprint hash from the frontend (optional, user-consented) to correlate wallets from the same user. Without this, rotating traders appear as multiple Bronze wallets.

- **Dusting attacks** -- Tiny amounts sent to thousands of wallets can artificially inflate trade frequency. The engine ignores transactions below $1 equivalent and requires at least two trades above $10 to count as active.

- **Score staleness** -- If a wallet has no activity for 14 days, the score decays by 10% per week. A Platinum wallet that goes dormant for 90 days drops to Silver. This prevents sending premium offers to churned users.

Results After 8 Weeks

DeFiKit deployed the scoring engine across three partner DEXs with a combined base of 12,400 active wallets per month:

- **Top-tier conversion:** Platinum-wallet retention improved by 37% after introducing personalised Telegram alerts for high-value trade opportunities

- **Budget efficiency:** Marketing spend shifted 68% toward Gold and Platinum tiers, reducing cost-per-retained-trader by 42%

- **Automated engagement:** 2,300+ automated campaign triggers fired within the first month, each one a personalised message based on the trader's actual activity

- **False positive rate:** Only 3.2% of Bronze-tier wallets upgraded to Silver within 14 days, validating that the scoring correctly identified low-engagement users

- **Infra cost:** The entire scoring pipeline costs $18.70/month at current traffic levels -- D1 reads at $0.001/million rows, Workers requests at $0.30/million

Comparison: Before vs After

| Metric | Before (Blast Marketing) | After (Wallet Scoring) |

|---|---|---|

| Retention (30d) | 22% | 37% |

| Cost per retained trader | $14.20 | $8.23 |

| Personalised messages sent | 0 (batch only) | 2,300+ |

| Low-value wallet wastage | 64% of budget | 18% of budget |

| Onboarding time for high-value traders | 3-5 days manual | < 2 hours automated |

Key Takeaways

- Serverless ML scoring is practical without a model server -- SQL-based weighted scores on Cloudflare D1 handle 10K+ events/minute

- Wallet scoring transforms generic DeFi marketing into targeted, behaviour-driven outreach with measurable ROI

- The scoring engine doubles as a churn predictor: wallets dropping from Gold to Silver are automatically enrolled in re-engagement sequences

- Edge case handling (new wallets, address rotation, dust attacks, staleness) is critical for production accuracy

- DeFiKit's architecture proves that marketing automation in crypto can be fully on-chain without compromising user privacy or requiring centralised user profiles