Token A → DEX1 → Token C → DEX2 → Token B (2+ hops)
Total Order: 10,000 USDC → Token X
Strategy 1: Single Venue
10,000 USDC → DEX1 → 5% slippage = 9,500 Token X
Strategy 2: Split Across 2 Venues
5,000 USDC → DEX1 → 2% slippage = 4,900 Token X
5,000 USDC → DEX2 → 2% slippage = 4,900 Token X
Total = 9,800 Token X (better outcome)
Swap USDC for DAI
Max Slippage: 100 BPS (1%)
If actual slippage would exceed 100 BPS → Transaction reverts
User protection against unexpected price movement
Router A: 999 successful swaps, 1 failure = 99.9% success
Router B: 900 successful swaps, 100 failures = 90% success
Router C: 10 successful swaps, 10 failures = 50% success
Routing prioritizes Router A, uses B as fallback, C disabled
check → effect → interaction pattern
State locked during execution
Prevents recursive malicious calls
Protects user funds and contract state
Flash Loan Attack Scenario:
1. Attacker borrows large token amount
2. Artificially moves price
3. Creates favorable swap conditions
4. Attempts swap through MonBridge
TWAP Protection:
- Historical price averaging detects unnatural movement
- Swap rejected if price deviates from TWAP too much
- Attack fails, attacker loses loan
User wants: 10,000 SHIB → USDC
SHIB is fee-on-transfer (2% fee)
Without MonBridge:
Send 10,000 SHIB → Contract applies 2% fee → Only 9,800 SHIB received
Swap fails or results in wrong amounts
With MonBridge:
Detects fee-on-transfer mechanism
Routes through compatible venue
Accounts for 2% fee in amounts
Swap succeeds with correct output
User Swap: 1,000 USDC → DAI
Expected Output: 1,000 DAI (assuming 1:1 price)
Fee Divisor: 1000 (means 0.1% fee)
Protocol Fee: 1,000 USDC * 0.1% = 1 USDC
Result:
- MonBridge Routes: 999 USDC through DEX
- User Receives: ~999 DAI (after DEX fees)
- MonBridge Accumulates: 1 USDC to treasury
User swaps ETH → Token
Fee collected in ETH
Stored in protocol contract: feeAccumulatedETH
User swaps Token A → Token B
Fee collected in Token A
Stored in mapping: feeAccumulated[tokenA]
Each Router Tracked:
├─ isActive: Currently enabled
├─ lastSuccessfulSwap: Timestamp of last success
├─ failureCount: Consecutive failures
└─ totalVolume: Cumulative volume routed
During Swap Execution:
1. Attempt through primary router
2. If fails:
- Increment failure counter
- Log failure timestamp
- If failures exceed threshold → Disable router
3. Try next available router
4. Continue until successful or all routers exhausted