# XDC Network: Deprecated Modules Documentation

## Executive Summary

**Status as of January 31, 2026:**
- **XDCx DEX Engine**: ⛔ **DEPRECATED** (Disabled at block 80,370,900 - October 2nd, 2024)
- **Lending Protocol**: ⛔ **DEPRECATED** (Disabled at block 80,370,900 - October 2nd, 2024)

Both modules were officially deprecated via hardfork on XDC Mainnet. No new transactions can be processed, but historical transaction support is required for chain replay.

---

## 1. Deprecation Timeline

### Key Block Numbers (Mainnet)

| Constant | Block Number | Date | Description |
|----------|--------------|------|-------------|
| `TIPXDCX` | 38,383,838 | ~2022 | XDCx DEX enabled |
| `TIPXDCXLending` | 38,383,838 | ~2022 | Lending protocol enabled |
| `TIPXDCXCancellationFee` | 38,383,838 | ~2022 | Cancellation fee feature |
| `TIPXDCXMinerDisable` | 80,370,000 | Oct 2, 2024 | Mining new XDCx orders disabled |
| `TIPXDCXReceiverDisable` | 80,370,900 | Oct 2, 2024 | Receiving XDCx transactions disabled |

### Current State

| Metric | Value |
|--------|-------|
| Current Mainnet Block | ~98,705,964 |
| Blocks Since Deprecation | ~18,335,064 |
| Time Since Deprecation | ~4 months |

---

## 2. XDCx DEX Engine

### 2.1 What It Was

The XDCx DEX Engine was a protocol-level decentralized exchange built into XDC Network, featuring:

- On-chain order book management
- Atomic swap settlement
- Relayer network for order relay
- Trading state trie (separate from account state)

### 2.2 Code Location (v2.6.8)

```
/root/xdposchain-ref/
├── XDCx/
│   ├── XDCx.go                 (~25KB) - Main DEX engine
│   ├── order_processor.go      (~42KB) - Order matching logic
│   ├── order_processor_test.go (~18KB) - Tests
│   ├── token.go                (~2KB)  - Token utilities
│   └── tradingstate/           - Trading state trie
├── XDCxDAO/                    - Database access layer
└── contracts/XDCx/             - Simulation contracts
```

### 2.3 Key Addresses

| Contract | Address |
|----------|---------|
| Trading State | `0x0000000000000000000000000000000000000092` |
| XDCx Listing | `0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53` |
| Relayer Registration | `0x16c63b79f9C8784168103C0b74E6A59EC2de4a02` |

### 2.4 Deprecation Logic

From `params/config.go`:
```go
func (c *ChainConfig) IsTIPXDCXReceiver(num *big.Int) bool {
    return isForked(common.TIPXDCX, num) && !isForked(common.TIPXDCXReceiverDisable, num)
}

func (c *ChainConfig) IsXDCxDisable(num *big.Int) bool {
    return isForked(common.TIPXDCXMinerDisable, num)
}
```

**Translation:**
- `IsTIPXDCXReceiver(block)` returns `true` ONLY for blocks 38,383,838 to 80,370,899
- After block 80,370,900, XDCx transactions are completely rejected

---

## 3. Lending Protocol

### 3.1 What It Was

The XDCxLending protocol enabled:

- Collateralized lending/borrowing
- Interest rate calculation
- Liquidation mechanics
- Lending order book management

### 3.2 Code Location (v2.6.8)

```
/root/xdposchain-ref/
├── XDCxlending/
│   ├── XDCxlending.go          (~40KB) - Main lending engine
│   ├── order_processor.go      (~73KB) - Lending order logic
│   ├── order_processor_test.go (~15KB) - Tests
│   └── lendingstate/           - Lending state trie
```

### 3.3 Key Addresses

| Contract | Address |
|----------|---------|
| Lending State | `0x0000000000000000000000000000000000000093` |
| Lending Registration | `0x7d761afd7ff65a79e4173897594a194e3c506e57` |

### 3.4 Deprecation

The Lending Protocol follows the same deprecation pattern as XDCx DEX - disabled at block 80,370,900.

---

## 4. Historical Transaction Support

### 4.1 Why It Matters

For full chain replay (syncing from genesis), the node must correctly process historical XDCx and Lending transactions that occurred between blocks 38,383,838 and 80,370,899.

### 4.2 How v2.6.8 Handles It

From `core/state_processor.go`:
```go
// Only process if within active XDCx window
if *to == common.TradingStateAddrBinary && config.IsTIPXDCXReceiver(blockNumber) {
    return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
}

if *to == common.XDCXLendingAddressBinary && config.IsTIPXDCXReceiver(blockNumber) {
    return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
}
```

**Key Insight:** XDCx/Lending transactions were processed as "empty transactions" - they:
- Consume gas
- Update nonces
- Don't modify EVM state (changes were in separate trading/lending state tries)

### 4.3 Historical Transaction Volume

**Estimated** (exact numbers require chain analysis):
- Active period: ~42 million blocks (38.4M → 80.4M)
- Trading pairs listed: Several hundred
- Total XDCx transactions: Relatively low adoption

---

## 5. Porting Recommendation

### 5.1 Recommended Approach: **SKIP FULL PORT** ✅

| Factor | Analysis |
|--------|----------|
| **Complexity** | Very high (~180KB of code) |
| **Current Usage** | Zero (deprecated) |
| **Future Usage** | None planned |
| **Historical Support** | Minimal stub required |

### 5.2 What We Need for Mainnet Compatibility

**Minimal Implementation (Already Done):**

1. **Stub XDCx module** (`/Users/anilchinchawale/go-ethereum/XDCx/XDCx.go`)
   - Basic interface for compilation
   - No actual order processing

2. **Stub Lending module** (`/Users/anilchinchawale/go-ethereum/XDCxlending/XDCxlending.go`)
   - Basic interface for compilation
   - No actual lending logic

3. **Transaction handling in state processor**
   - Recognize XDCx addresses (0x92, 0x93)
   - Process as empty transactions during historical window
   - Reject after deprecation block

### 5.3 Implementation Checklist

| Requirement | Status | Notes |
|-------------|--------|-------|
| XDCx/Lending addresses defined | ✅ | In `common/types.go` |
| IsTIPXDCXReceiver() function | ✅ | In `params/config.go` |
| Empty transaction handling | 🔄 | In `core/state_processor.go` |
| Stub modules for interface | ✅ | Basic stubs exist |
| Full order processing | ⏭️ SKIP | Not needed |
| Trading state trie | ⏭️ SKIP | Not needed |
| Lending state trie | ⏭️ SKIP | Not needed |

---

## 6. Code Changes Required

### 6.1 For Historical Compatibility (Required)

Add to `core/state_processor.go`:

```go
// Handle deprecated XDCx transactions (historical blocks only)
if to != nil {
    // XDCx Trading transactions (blocks 38.4M - 80.4M)
    if *to == common.TradingStateAddrBinary && config.IsTIPXDCXReceiver(blockNumber) {
        return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
    }
    
    // XDCx Lending transactions (blocks 38.4M - 80.4M)  
    if *to == common.XDCXLendingAddressBinary && config.IsTIPXDCXReceiver(blockNumber) {
        return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
    }
}

// Legacy transaction type checks
if tx.IsTradingTransaction() && config.IsTIPXDCXReceiver(blockNumber) {
    return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
}

if tx.IsLendingFinalizedTradeTransaction() && config.IsTIPXDCXReceiver(blockNumber) {
    return ApplyEmptyTransaction(config, statedb, blockNumber, blockHash, tx, usedGas)
}
```

### 6.2 For New Transactions (Reject)

After deprecation block, these transactions should be rejected at the mempool level:

```go
func (pool *TxPool) validateTx(tx *types.Transaction) error {
    // Reject deprecated XDCx transactions
    if pool.chainconfig.IsXDCxDisable(pool.chain.CurrentBlock().Number()) {
        if tx.IsTradingTransaction() || tx.IsLendingTransaction() {
            return ErrXDCxDeprecated
        }
    }
    // ... rest of validation
}
```

---

## 7. Risk Assessment

### 7.1 Skipping Full Port

| Risk | Likelihood | Impact | Mitigation |
|------|------------|--------|------------|
| Historical sync failure | Low | High | Implement empty tx handling |
| State root mismatch | Low | High | Test against v2.6.8 node |
| Future XDCx revival | Very Low | Medium | Can port later if needed |

### 7.2 Porting Full Implementation

| Risk | Likelihood | Impact | Mitigation |
|------|------------|--------|------------|
| Significant delay | High | High | Estimated 4-6 weeks |
| Integration bugs | Medium | High | Extensive testing needed |
| Maintenance burden | High | Medium | Dead code in codebase |

---

## 8. Conclusion

### Final Recommendation

**DO NOT PORT** full XDCx DEX and Lending implementation.

**DO IMPLEMENT:**
1. ✅ Stub modules (already done)
2. 🔄 Empty transaction handling for historical blocks
3. 🔄 Transaction rejection for post-deprecation blocks
4. ✅ Address constants and hardfork flags

### Justification

1. **XDCx and Lending are officially deprecated** - no new activity possible
2. **Extremely high complexity** - 180KB+ of specialized code
3. **Zero future usage** - explicitly disabled via hardfork
4. **Minimal historical support** - empty transaction handling sufficient
5. **Resource efficiency** - 4-6 weeks saved for higher-priority work

### Updated Pending Work List

| Component | Priority | Complexity | Recommendation |
|-----------|----------|------------|----------------|
| ~~XDCx DEX Engine~~ | ~~Medium~~ | ~~High~~ | **SKIP** (Deprecated) |
| ~~Lending Protocol~~ | ~~Medium~~ | ~~High~~ | **SKIP** (Deprecated) |
| Performance Tuning | **High** | Medium | **DO** |
| Snap Sync for XDC | **High** | Medium | **DO** |
| Historical XDCx handling | Medium | Low | **DO** (minimal) |

---

## References

- XDC v2.6.8 Source: `/root/xdposchain-ref/` on server
- Deprecation Hardfork: Block 80,370,900 (October 2, 2024)
- Constants: `common/constants.mainnet.go`
- Config: `params/config.go`

---

*Document Version: 1.0*  
*Created: January 31, 2026*  
*Author: XDC Development Team*
