# SSU Atomic Settlement Flow

## Overview

SSU atomic settlement uses Synthetic Settlement Units for cross-border settlement with atomic execution guarantees. This flow documents the complete SSU-based settlement process.

## Prerequisites

- SSU exists and is active
- Sufficient SSU balance
- Source and destination banks registered
- Atomic settlement service operational

## Visual Flow Diagram

```
┌─────────────┐
│ SSU         │
│ Settlement  │
│  Request    │
└──────┬──────┘
       │
       │ 1. Verify SSU
       ▼
┌─────────────────────────┐
│ Verify SSU & Balance   │
│  - SSU lookup           │
│  - Balance check        │
└──────┬──────────────────┘
       │
       │ 2. Create Transaction
       ▼
┌─────────────────────────┐
│ Create SSU Transaction  │
│  - Transaction ID       │
│  - Settlement type      │
└──────┬──────────────────┘
       │
       │ 3. Execute Atomic Swap
       ▼
┌─────────────────────────┐
│ Execute Atomic Swap     │
│  - Verify commitments   │
│  - Execute on both sides│
└──────┬──────────────────┘
       │
       │ 4. Complete
       ▼
┌─────────────┐
│ Settlement  │
│  Complete   │
└─────────────┘
```

## Step-by-Step Process

### Step 1: Verify SSU
1. Lookup SSU by ID
2. Verify SSU is active
3. Check SSU balance
4. Verify sufficient balance

**Code Reference**: `src/core/settlement/ssu/ssu-service.ts:99-126`

### Step 2: Create Transaction
1. Create SSU transaction record
2. Set transaction type: `settle`
3. Link to source and destination banks
4. Store transaction ID

**Code Reference**: `src/core/settlement/ssu/ssu-transaction.service.ts`

### Step 3: Execute Atomic Swap
1. Create commitments for both sides
2. Verify commitments match
3. Execute swap atomically
4. Verify execution success

**Code Reference**: `src/core/settlement/isn/atomic-settlement.service.ts`

## Error Handling

- SSU not found: Return error
- Insufficient balance: Return error
- Atomic swap failure: Rollback, mark failed

## Integration Points

- SSU Service: `src/core/settlement/ssu/ssu-service.ts`
- Atomic Settlement Service: `src/core/settlement/isn/atomic-settlement.service.ts`

## Performance Metrics

- Total End-to-End: < 150ms target
- Throughput: 5,000+ settlements/second

---

**Related Flows**:
- [SSU Mint Burn Flow](./ssu-mint-burn-flow.md)
- [Atomic Settlement Flow](./atomic-settlement-flow.md)

