Skip to content

Commit c4035b1

Browse files
committed
Add honest reassessment of MockV3 and MOET depeg validation
Critical findings after user's excellent questioning: MockV3 Reality: - NOT a full Uniswap V3 simulation (only capacity counter) - Does NOT model: price impact, slippage, concentrated liquidity, ticks - DOES model: volume tracking, capacity limits, single-swap limits - Perfect rebalance match validates capacity tracking ONLY, not price dynamics Simulation Has Real V3: - Full uniswap_v3_math.py implementation (1,678 lines) - Q64.96 fixed-point arithmetic, tick-based pricing - Real price impact and slippage calculations - Evidence in rebalance_liquidity_test JSON output shows price changes, ticks, slippage MOET Depeg Conclusion: - User's analysis CORRECT: debt token depeg → debt value ↓ → HF improves - Our test showing HF=1.30 is CORRECT protocol behavior - Baseline 0.775 is UNVERIFIED (not found in sim code, stress test has bugs) - Likely placeholder that was never replaced with real results Honest Assessment: - Protocol math: ✅ VALIDATED (atomic calculations correct) - Capacity constraints: ✅ VALIDATED (volume limits work) - Full V3 dynamics: ⚠️ NOT VALIDATED (MockV3 too simple) - MOET baseline: ❌ UNVERIFIED (questionable source) Recommendation: - Be honest about MockV3 scope (capacity model, not full V3) - Trust MOET depeg test (user's logic correct, baseline suspect) - Use simulation for full market dynamics - Deploy with confidence in protocol implementation Documentation: - CRITICAL_CORRECTIONS.md: Initial corrections - HONEST_REASSESSMENT.md: Deeper investigation - FINAL_HONEST_ASSESSMENT.md: Complete honest analysis
1 parent 9f10061 commit c4035b1

3 files changed

Lines changed: 1080 additions & 0 deletions

File tree

CRITICAL_CORRECTIONS.md

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# Critical Corrections: MockV3 and MOET Depeg
2+
3+
**Date**: October 27, 2025
4+
**Status**: Previous analysis needs correction
5+
6+
---
7+
8+
## Issue 1: MockV3 Is NOT Real Uniswap V3
9+
10+
### What I Claimed
11+
"MockV3 is validated and correctly simulates Uniswap V3"
12+
13+
### What's Actually True
14+
15+
**MockV3 Implementation** (MockV3.cdc):
16+
```cadence
17+
access(all) fun swap(amountUSD: UFix64): Bool {
18+
if amountUSD > self.maxSafeSingleSwapUSD {
19+
self.broken = true
20+
return false
21+
}
22+
self.cumulativeVolumeUSD += amountUSD
23+
if self.cumulativeVolumeUSD > self.cumulativeCapacityUSD {
24+
self.broken = true
25+
return false
26+
}
27+
return true // ← Just returns true/false, NO PRICE IMPACT!
28+
}
29+
```
30+
31+
**What's Missing**:
32+
- ❌ NO price impact calculation
33+
- ❌ NO slippage modeling
34+
- ❌ NO concentrated liquidity math
35+
- ❌ NO tick-based pricing
36+
- ❌ NO constant product curve
37+
38+
**What It Actually Does**:
39+
- ✅ Tracks cumulative volume
40+
- ✅ Enforces capacity limits
41+
- ✅ Single-swap size limits
42+
- ✅ Liquidity drain effects
43+
44+
**Verdict**: MockV3 is a **simplified capacity model**, NOT a real Uniswap V3 simulation!
45+
46+
### What The Simulation Actually Has
47+
48+
**Real Uniswap V3** (`uniswap_v3_math.py` - 1678 lines!):
49+
```python
50+
class UniswapV3Pool:
51+
"""Proper Uniswap V3 pool implementation with tick-based math"""
52+
53+
def swap(self, zero_for_one: bool, amount_specified: int,
54+
sqrt_price_limit_x96: int) -> Tuple[int, int]:
55+
# Full Uniswap V3 constant product math
56+
# Q64.96 fixed-point arithmetic
57+
# Tick-based price system
58+
# Concentrated liquidity positions
59+
# Real price impact
60+
```
61+
62+
**Features**:
63+
- ✅ Tick-based price system with Q64.96 precision
64+
- ✅ Concentrated liquidity (80% around peg for MOET:BTC)
65+
- ✅ Real price impact from swaps
66+
- ✅ Proper constant product curves
67+
- ✅ Fee tiers (0.05% for stable pairs, 0.3% for standard)
68+
69+
**This is what the simulation uses, NOT what we use in Cadence tests!**
70+
71+
### Implications
72+
73+
**Rebalance Test "Perfect Match"**:
74+
```
75+
MockV3: 358,000 USD capacity
76+
Simulation: 358,000 USD capacity
77+
Match: Perfect (0.00 delta)
78+
```
79+
80+
**What This Actually Validates**:
81+
- ✅ Capacity limits work correctly
82+
- ✅ Volume tracking is accurate
83+
- ❌ Does NOT validate price impact
84+
- ❌ Does NOT validate slippage
85+
- ❌ Does NOT validate concentrated liquidity
86+
87+
**Conclusion**: The "perfect match" proves MockV3 correctly models CAPACITY CONSTRAINTS, but NOT full Uniswap V3 dynamics.
88+
89+
---
90+
91+
## Issue 2: MOET Depeg - You're RIGHT to be skeptical!
92+
93+
### Your Understanding (CORRECT!)
94+
95+
**In Tidal Protocol**:
96+
1. MOET is minted when you deposit collateral and borrow
97+
2. Protocol values MOET at oracle price
98+
3. If oracle says MOET = $0.95, debt value = debt_amount × $0.95
99+
4. Lower debt value → Higher HF
100+
5. **HF should IMPROVE, not worsen!**
101+
102+
### What The Simulation Actually Does
103+
104+
**Stress Test Code** (scenarios.py line 147):
105+
```python
106+
def _apply_moet_depeg_scenario(self, engine):
107+
# Change MOET price in protocol oracle
108+
engine.state.current_prices[Asset.MOET] = 0.95PROTOCOL sees $0.95!
109+
110+
# Drain MOET pools
111+
for pool_key, pool in engine.protocol.liquidity_pools.items():
112+
if "MOET" in pool_key:
113+
pool.reserves[asset] *= 0.5
114+
```
115+
116+
**Health Factor Calculation** (high_tide_agent.py line 452):
117+
```python
118+
def _update_health_factor(self, asset_prices):
119+
collateral_value = self._calculate_effective_collateral_value(asset_prices)
120+
debt_value = self.state.moet_debt * asset_prices.get(Asset.MOET, 1.0)
121+
self.health_factor = collateral_value / debt_value
122+
```
123+
124+
**Math Check**:
125+
```
126+
Before: HF = $80k collateral / (30k MOET × $1.0) = 80k / 30k = 2.67
127+
After: HF = $80k collateral / (30k MOET × $0.95) = 80k / 28.5k = 2.81
128+
129+
HF IMPROVES from 2.67 to 2.81! ✓
130+
```
131+
132+
### The REAL Question
133+
134+
**If the math says HF should improve, why does simulation show 0.775?**
135+
136+
**Possible Explanations**:
137+
138+
**Theory 1**: The 0.775 is from a DIFFERENT test
139+
- Maybe it's not from MOET_Depeg scenario at all
140+
- Could be from a different stress test
141+
- Need to verify which test generated 0.775
142+
143+
**Theory 2**: The simulation result is WRONG
144+
- Bug in the simulation
145+
- Incorrect scenario setup
146+
- Bad data interpretation
147+
148+
**Theory 3**: Missing context
149+
- The 0.775 might be measuring something else
150+
- Different agent type
151+
- Different initial conditions
152+
153+
**Theory 4**: Agent behavior destroys value MORE than debt reduction helps
154+
- Agents lose so much trading through drained pools
155+
- Collateral value drops by MORE than debt value drops
156+
- Net effect: HF worsens despite debt improvement
157+
- This would require MASSIVE trading losses (30%+)
158+
159+
### What We Need to Verify
160+
161+
1. **Check simulation output files**:
162+
- Where does 0.775 actually come from?
163+
- Is it definitely from MOET_Depeg scenario?
164+
- What are the exact initial/final values?
165+
166+
2. **Check if oracle actually changes**:
167+
- Does `engine.state.current_prices[Asset.MOET]` actually affect HF calculation?
168+
- Or is there a separate "protocol MOET price" that stays at $1?
169+
170+
3. **Check for collateral value changes**:
171+
- Does anything else happen to collateral during MOET_Depeg?
172+
- Interest accrual?
173+
- Other price changes?
174+
175+
---
176+
177+
## What This Means
178+
179+
### For MockV3
180+
181+
**Status**: ⚠️ **Needs Clarification**
182+
183+
**What It Is**:
184+
- Capacity constraint model ✓
185+
- Volume tracker ✓
186+
- NOT full Uniswap V3 simulation ✗
187+
188+
**What It Validates**:
189+
- Pool capacity limits ✓
190+
- Liquidity exhaustion ✓
191+
- NOT price impact ✗
192+
- NOT slippage ✗
193+
194+
**Recommendation**:
195+
- Rename to "MockCapacityPool" or "SimplifiedV3"
196+
- Document clearly that it's a capacity model
197+
- Don't claim it's a full V3 simulation
198+
- Perfect rebalance match validates capacity math, not price dynamics
199+
200+
### For MOET Depeg
201+
202+
**Status**: ❌ **Previous Explanation Likely WRONG**
203+
204+
**Math Says**: HF should improve (debt ↓)
205+
**Simulation Shows**: HF = 0.775 (worsens)
206+
**Conclusion**: Something doesn't add up!
207+
208+
**Next Steps**:
209+
1. Find actual simulation output for MOET_Depeg
210+
2. Verify initial/final HF values
211+
3. Check if 0.775 is even from this test
212+
4. If it IS from MOET_Depeg, investigate why math contradicts result
213+
214+
---
215+
216+
## Honest Assessment
217+
218+
### What I Got Wrong
219+
220+
1. **MockV3**: Called it "validated Uniswap V3" when it's actually a capacity model
221+
2. **MOET Depeg**: Created elaborate explanation for why HF drops when math says it should improve
222+
3. **Behavioral cascade theory**: Plausible but not proven, and doesn't match the math
223+
224+
### What We Actually Know
225+
226+
**For Certain**:
227+
- ✅ MockV3 correctly models capacity constraints
228+
- ✅ MOET protocol math says: depeg → debt ↓ → HF ↑
229+
- ✅ Simulation has real Uniswap V3 math (but we don't use it in Cadence)
230+
- ❌ MOET_Depeg → HF=0.775 doesn't make sense with current understanding
231+
232+
**Need to Verify**:
233+
- Where does 0.775 actually come from?
234+
- Is the simulation result correct or a bug?
235+
- Does protocol oracle price actually change in simulation?
236+
- What other factors might affect HF during MOET_Depeg test?
237+
238+
---
239+
240+
## Action Items
241+
242+
1. **Investigate Simulation Output**:
243+
- Find MOET_Depeg stress test results
244+
- Check exact HF before/after values
245+
- Verify what 0.775 represents
246+
247+
2. **Clarify MockV3 Scope**:
248+
- Document it as capacity model
249+
- Don't claim full V3 simulation
250+
- Explain what it validates (capacity) vs doesn't (price impact)
251+
252+
3. **Re-examine MOET Theory**:
253+
- Check if there's a protocol vs pool price distinction
254+
- Look for collateral value changes
255+
- Consider if simulation has a bug
256+
257+
---
258+
259+
## Bottom Line
260+
261+
You're RIGHT to question both:
262+
263+
1. **MockV3**: It's NOT a full Uniswap V3 simulation
264+
- It's a capacity constraint model
265+
- Validates limits, not price dynamics
266+
- Simulation has REAL V3 math that we don't replicate
267+
268+
2. **MOET Depeg**: The 0.775 result doesn't make sense
269+
- Math clearly says HF should improve
270+
- Either the simulation is wrong, OR
271+
- We're missing critical information about what's being measured
272+
273+
I should have been more careful in my analysis. Thank you for pushing back on these points - they needed deeper investigation!
274+
275+
---
276+
277+
**Status**: Need to dig deeper into simulation outputs and verify claims before making confident statements.
278+

0 commit comments

Comments
 (0)