# Worldwide AML Pattern Language (WAPL)

## Overview

WAPL is the global AML pattern recognition language used by DBIS to detect illicit transfers, identify layering, smurfing, structuring, flag cross-border velocity anomalies, detect SSU manipulation, and identify DeFi laundering schemes.

## Pattern Syntax

### Example Pattern: Circular FX Laundering

```
pattern CIRCULAR_FX:
  if occurs(
     FX_trade[X].pair == FX_trade[Y].pair.reverse &&
     abs(FX_trade[X].amount - FX_trade[Y].amount) < tolerance &&
     entity_link(X.entity, Y.entity) == true
  ) raise_alert("Circular FX pattern detected")
```

### Example Pattern: High-Velocity CBDC Layering

```
pattern CBDC_LAYERING:
  if velocity(wallet) > threshold &&
     hops(wallet) > 4 &&
     transaction_type == "micro-split":
     raise_alert("CBDC layering risk")
```

## Machine-Learning Enhanced Patterns

WAPL integrates:
- Graph embeddings
- Anomaly detection
- Statistical signatures
- Behavioral clustering

## API Endpoints

### Initialize WAPL
```http
POST /api/v1/wapl/initialize
```

### Get Patterns
```http
GET /api/v1/wapl/patterns
GET /api/v1/wapl/patterns/:patternCode
```

### Match Patterns
```http
POST /api/v1/wapl/match/:transactionId
```

### Get Alerts
```http
GET /api/v1/wapl/alerts?status=PENDING
```

### Create Pattern
```http
POST /api/v1/wapl/patterns
```

## Usage Example

```typescript
import { waplService } from '@/core/compliance/wapl';

// Initialize WAPL
await waplService.initialize();

// Match transaction against patterns
const matches = await waplService.matchPatterns(transactionId);

// Get alerts
const alerts = await waplService.getAlerts('PENDING');
```

## Database Models

- `WAPLPattern`: Pattern definitions
- `PatternMatch`: Pattern match results
- `PatternAlert`: Generated alerts

