Skip to content

Commit aaba39a

Browse files
onakijames-droidDev User
andauthored
#744 Implement lending pool compliance module for institutions FIXED (#779)
Co-authored-by: Dev User <dev@local>
1 parent c8425b8 commit aaba39a

7 files changed

Lines changed: 1791 additions & 15 deletions

File tree

api/docs/COMPLIANCE_FEATURES.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Compliance Features Documentation
2+
3+
## Overview
4+
5+
StellarLend's compliance module provides institutional-grade KYC/AML integration, regulatory limit enforcement, compliance reporting, audit trail, and a compliance dashboard — all designed for DeFi protocols that need to meet regulatory requirements.
6+
7+
---
8+
9+
## Features
10+
11+
### 1. KYC Integration
12+
13+
- **KYC Verification**: Set, check, revoke, and list KYC verifications for addresses.
14+
- **Tiered KYC**: Supports multiple KYC tiers (1, 2, 3+) with different verification levels.
15+
- **KYC Providers**: Pluggable KYC provider integration (Jumio, Onfido, etc.).
16+
- **Jurisdiction Tracking**: Each KYC record tracks the user's jurisdiction.
17+
- **Expiry Management**: KYC verifications have configurable validity periods.
18+
19+
**Endpoints:**
20+
- `POST /api/v1/compliance/kyc` — Set KYC verification
21+
- `DELETE /api/v1/compliance/kyc` — Revoke KYC
22+
- `GET /api/v1/compliance/kyc/check?address=...` — Check KYC status
23+
- `GET /api/v1/compliance/kyc/list` — List all KYC verifications
24+
25+
### 2. AML Integration
26+
27+
- **AML Risk Scoring**: Each address receives a risk score (0-100) based on multiple factors.
28+
- **Risk Levels**: `low` (0-39), `medium` (40-69), `high` (70-89), `critical` (90-100).
29+
- **Automated Detection**:
30+
- Rapid movement detection (multiple transactions in short time)
31+
- Structuring detection (transactions just below reporting thresholds)
32+
- High-frequency transaction detection
33+
- High-risk jurisdiction detection
34+
- Sanctions list screening
35+
- **Auto SAR Filing**: Optionally auto-file SARs when risk exceeds a configurable threshold.
36+
37+
**Endpoints:**
38+
- `POST /api/v1/compliance/aml/assess/:address` — Trigger AML risk assessment
39+
- `GET /api/v1/compliance/aml/risk/:address` — Get existing AML assessment
40+
- `GET /api/v1/compliance/aml/assessments?riskLevel=...` — List assessments by risk level
41+
42+
### 3. Sanctions Screening
43+
44+
- **Internal Sanctions List**: Add/remove addresses from the internal sanctions list.
45+
- **OFAC Screening**: Screen addresses against OFAC sanctions list.
46+
- **Expiry Support**: Sanctions can have expiry dates.
47+
48+
**Endpoints:**
49+
- `POST /api/v1/compliance/sanctions` — Add sanction
50+
- `DELETE /api/v1/compliance/sanctions` — Remove sanction
51+
- `GET /api/v1/compliance/sanctions/check?address=...` — Check if address is sanctioned
52+
53+
### 4. Compliance Reporting
54+
55+
- **Comprehensive Reports**: Generate reports for any time period.
56+
- **Metrics Include**: Total transactions, flagged transactions, SAR count, sanctions matches, KYC verifications/revocations, AML alerts.
57+
- **Jurisdiction Breakdown**: Breakdown of KYC verifications by jurisdiction.
58+
- **Event Type Breakdown**: Breakdown of all compliance events by type.
59+
60+
**Endpoints:**
61+
- `GET /api/v1/compliance/report?from=...&to=...` — Get compliance report
62+
63+
### 5. Regulatory Limits
64+
65+
- **Configurable Limits**: Daily, weekly, and per-transaction limits.
66+
- **Jurisdiction-Specific Limits**: Different limits per jurisdiction.
67+
- **Non-KYC Limits**: Separate (lower) limits for non-KYC users.
68+
- **Real-Time Enforcement**: Limits checked on every transaction.
69+
70+
**Endpoints:**
71+
- `POST /api/v1/compliance/regulatory-limits/check` — Check if a transaction is within limits
72+
- `PUT /api/v1/compliance/config` — Update limit configuration
73+
- `POST /api/v1/compliance/config/jurisdiction-limits` — Set jurisdiction-specific limits
74+
75+
### 6. Compliance Audit Trail
76+
77+
- **Comprehensive Logging**: Every compliance action is logged with a timestamp.
78+
- **Hash Chain Integrity**: Events are linked via SHA-256 hash chain for tamper detection.
79+
- **Filtering**: Filter by address, event type, and limit.
80+
- **Integrity Verification**: Verify the entire audit trail has not been tampered with.
81+
82+
**Endpoints:**
83+
- `GET /api/v1/compliance/audit-trail?address=...&limit=...&eventType=...` — Get audit trail
84+
- `GET /api/v1/compliance/audit-trail/verify` — Verify audit trail integrity
85+
86+
### 7. Compliance Configuration
87+
88+
- **Dynamic Configuration**: All compliance settings can be updated at runtime.
89+
- **Configurable Settings**:
90+
- Default transaction limits
91+
- Per-jurisdiction limits
92+
- Restricted jurisdictions
93+
- KYC threshold amount
94+
- AML risk threshold
95+
- AML monitoring toggle
96+
- Auto-SAR filing toggle
97+
- KYC requirements for deposit/withdrawal
98+
- Non-KYC volume limits
99+
100+
**Endpoints:**
101+
- `GET /api/v1/compliance/config` — Get current configuration
102+
- `PUT /api/v1/compliance/config` — Update configuration
103+
- `POST /api/v1/compliance/config/jurisdiction-limits` — Set jurisdiction-specific limits
104+
- `POST /api/v1/compliance/config/restricted-jurisdictions` — Add restricted jurisdiction
105+
- `DELETE /api/v1/compliance/config/restricted-jurisdictions` — Remove restricted jurisdiction
106+
107+
### 8. Compliance Dashboard
108+
109+
- **Summary Statistics**: Total KYC verifications, sanctioned addresses, SARs, AML alerts, pending reviews, compliance rate.
110+
- **Risk Distribution**: Breakdown of addresses by risk level.
111+
- **Jurisdiction Stats**: Per-jurisdiction user count and risk scores.
112+
- **Top Flagged Addresses**: Most frequently flagged addresses.
113+
- **Regulatory Limits Overview**: Current volume usage vs. limits.
114+
- **Recent Events**: Last 20 compliance events.
115+
116+
**Endpoints:**
117+
- `GET /api/v1/compliance/dashboard` — Get compliance dashboard
118+
119+
### 9. Compliance Middleware
120+
121+
The `complianceEnforcement` middleware can be applied to any route to enforce compliance checks automatically:
122+
123+
```typescript
124+
import { complianceEnforcement } from './middleware/complianceEnforcement';
125+
126+
// Apply to specific routes
127+
app.post('/api/lending/deposit', complianceEnforcement({ requireKyc: true }), lendingController.deposit);
128+
129+
// Apply to all lending routes
130+
app.use('/api/lending', complianceEnforcement(), lendingRoutes);
131+
```
132+
133+
**Middleware Options:**
134+
- `requireKyc` — Require KYC verification for all requests
135+
- `checkAml` — Enable AML risk checking (default: true)
136+
- `skipLimits` — Skip regulatory limit checks (default: false)
137+
138+
**Middleware Checks:**
139+
1. Sanctions screening (internal + OFAC)
140+
2. KYC verification (if required)
141+
3. Jurisdiction restrictions
142+
4. Regulatory limits (daily/weekly/max-single)
143+
5. AML risk assessment (if enabled)
144+
145+
---
146+
147+
## Configuration Reference
148+
149+
```typescript
150+
interface ComplianceConfig {
151+
defaultLimits: {
152+
dailyLimit: string; // Default daily limit in stroops
153+
weeklyLimit: string; // Default weekly limit in stroops
154+
maxSingleTx: string; // Max single transaction in stroops
155+
};
156+
jurisdictionLimits: Record<string, TransactionLimits>; // Per-jurisdiction overrides
157+
restrictedJurisdictions: string[]; // Blocked jurisdictions
158+
kycThresholdAmount: string; // Amount above which KYC is required
159+
amlRiskThreshold: number; // AML risk score threshold (0-100)
160+
amlMonitoringEnabled: boolean; // Enable/disable AML monitoring
161+
autoFileSar: boolean; // Auto-file SAR for high-risk addresses
162+
autoFileSarThreshold: number; // Risk score threshold for auto-SAR
163+
requireKycForWithdrawal: boolean; // Require KYC for withdrawals
164+
requireKycForDeposit: boolean; // Require KYC for deposits
165+
maxDailyVolumeWithoutKyc: string; // Max daily volume for non-KYC users
166+
}
167+
```
168+
169+
---
170+
171+
## Database Schema
172+
173+
The compliance module uses the following database tables (see `api/db/init/02_compliance.sql`):
174+
- `sanctions_list` — Sanctioned addresses
175+
- `kyc_verifications` — KYC verification records
176+
- `compliance_events` — Compliance event log
177+
- `suspicious_activity_reports` — SAR records
178+
- `transaction_volume` — Volume tracking per address
179+
- `restricted_jurisdictions` — Restricted jurisdiction list
180+
181+
---
182+
183+
## Compliance Event Types
184+
185+
| Event Type | Description |
186+
|---|---|
187+
| `SANCTION_ADDED` | Address added to sanctions list |
188+
| `SANCTION_REMOVED` | Address removed from sanctions list |
189+
| `KYC_VERIFIED` | KYC verification set |
190+
| `KYC_REVOKED` | KYC verification revoked |
191+
| `TX_CHECKED` | Transaction compliance check |
192+
| `SAR_FILED` | SAR filed |
193+
| `SAR_STATUS_UPDATED` | SAR status updated |
194+
| `AML_ASSESSMENT` | AML risk assessment performed |
195+
| `CONFIG_UPDATED` | Configuration updated |
196+
| `JURISDICTION_LIMITS_SET` | Jurisdiction-specific limits set |
197+
| `JURISDICTION_RESTRICTED` | Jurisdiction added to restricted list |
198+
| `JURISDICTION_UNRESTRICTED` | Jurisdiction removed from restricted list |
199+
200+
---
201+
202+
## API Endpoints Summary
203+
204+
| Method | Path | Description |
205+
|---|---|---|
206+
| POST | `/api/v1/compliance/sanctions` | Add sanction |
207+
| DELETE | `/api/v1/compliance/sanctions` | Remove sanction |
208+
| GET | `/api/v1/compliance/sanctions/check` | Check sanctions |
209+
| POST | `/api/v1/compliance/kyc` | Set KYC |
210+
| DELETE | `/api/v1/compliance/kyc` | Revoke KYC |
211+
| GET | `/api/v1/compliance/kyc/check` | Check KYC |
212+
| GET | `/api/v1/compliance/kyc/list` | List KYC verifications |
213+
| POST | `/api/v1/compliance/aml/assess/:address` | Assess AML risk |
214+
| GET | `/api/v1/compliance/aml/risk/:address` | Get AML risk |
215+
| GET | `/api/v1/compliance/aml/assessments` | List AML assessments |
216+
| POST | `/api/v1/compliance/transaction/check` | Check transaction |
217+
| POST | `/api/v1/compliance/sar` | File SAR |
218+
| GET | `/api/v1/compliance/sar/:sarId` | Get SAR |
219+
| GET | `/api/v1/compliance/sar` | List SARs |
220+
| PATCH | `/api/v1/compliance/sar/:sarId/status` | Update SAR status |
221+
| GET | `/api/v1/compliance/report` | Get compliance report |
222+
| GET | `/api/v1/compliance/audit-trail` | Get audit trail |
223+
| GET | `/api/v1/compliance/audit-trail/verify` | Verify audit trail |
224+
| GET | `/api/v1/compliance/config` | Get configuration |
225+
| PUT | `/api/v1/compliance/config` | Update configuration |
226+
| POST | `/api/v1/compliance/config/jurisdiction-limits` | Set jurisdiction limits |
227+
| POST | `/api/v1/compliance/config/restricted-jurisdictions` | Add restricted jurisdiction |
228+
| DELETE | `/api/v1/compliance/config/restricted-jurisdictions` | Remove restricted jurisdiction |
229+
| GET | `/api/v1/compliance/dashboard` | Get compliance dashboard |
230+
| POST | `/api/v1/compliance/regulatory-limits/check` | Check regulatory limits |

0 commit comments

Comments
 (0)