# Autonomous Liquidity Provision System (ALPS)

## Overview

ALPS is the autonomous liquidity engine of DBIS, providing real-time liquidity injections without human intervention. It includes real-time liquidity monitoring, predictive stress module, automated stabilization executor, and GLP interface.

## Architecture

ALPS includes:
- **Real-time liquidity monitor**: Monitors SXLR (Sovereign Liquidity Ratio) for all sovereigns
- **Predictive stress module**: Predicts liquidity stress events
- **Automated stabilization executor**: Executes injections/withdrawals automatically
- **GLP interface**: Integrates with Global Liquidity Pool

## Liquidity Injection Algorithm

```
if (liquidity_ratio < threshold)
   amount = required_liquidity - current_liquidity
   inject(amount)
```

Inputs:
- SXLR (Sovereign Liquidity Ratio)
- SRI risk levels
- FX volatility indices
- CBDC flow constraints

## Autonomous Liquidity Withdrawal

Reverse mechanism triggers when:
- Excess liquidity → inflation risk
- Settlement congestion decreases
- FX bands stabilize

## API Endpoints

### Run Autonomous Engine
```http
POST /api/v1/alps/run
```

### Monitor Liquidity
```http
GET /api/v1/alps/monitor
GET /api/v1/alps/monitor/:sovereignBankId
```

### Predict Stress Events
```http
POST /api/v1/alps/stress/predict
GET /api/v1/alps/stress?sovereignBankId=xxx
```

### Get Actions
```http
GET /api/v1/alps/actions?sovereignBankId=xxx&actionType=INJECTION
```

### Manual Injection/Withdrawal
```http
POST /api/v1/alps/inject
POST /api/v1/alps/withdraw
```

## Usage Example

```typescript
import { alpsService } from '@/core/treasury/alps';

// Run autonomous engine
await alpsService.runAutonomousEngine();

// Monitor liquidity
const ratios = await alpsService.monitorLiquidity();

// Predict stress events
const events = await alpsService.predictStressEvents();
```

## Database Models

- `AutonomousLiquidityAction`: Injection/withdrawal records
- `LiquidityStressEvent`: Predicted stress events
- `SovereignLiquidityRatio`: SXLR tracking

