Conversation
cadence/tests/transactions/position-manager/set_draw_down_sink.cdc
Outdated
Show resolved
Hide resolved
| // minHealth = 1.1: required deposit per position to reach minHealth after 50% price crash: | ||
| // effectiveCollateral = 1 000 * 0.5 * 0.8 = 400 | ||
| // effectiveDebt ≈ 615.38 | ||
| // | ||
| // Ideal health = 400 / (615.38 - required) = 1.3 | ||
| // Required MOET ≈ 307.69 MOET | ||
| // | ||
| // left 310 MOET which is enough for one position, not both |
There was a problem hiding this comment.
I don't understand why using ideal health (1.3) instead of using minHealth (1.1)
To me, liquidation happens when HF < minHealth (1.1), rather than ideal health (1.3).
In other words, It requires only 251.74 (615.38 - 400 / 1.1= 251.74) MOET (rather than 310 MOET) in order to avoid liquidation when price drops 50%.
So if we provide only 251.74 MOET to the topup source, then only one of the position can pull all of it to avoid liquidation (enough to rescue), and the other position will pull nothing, and still liquidatable.
I tried changing 310.0 in L262 to 251.74, the test case still passes, and it passes even if I changed down to 216.0, but fails when changed to 215.0, do you know why?
There was a problem hiding this comment.
Oh, I see. the minimum health factor to avoid liquidation is 1, not 1.1.
the minHealth 1.1 is when the low threshold to trigger rebalancing, not liquidation.
So 615.38 - 400 / 1.0 = 215.38, and 215.39 is the minimum to rescue just one.
FYI, this is my understanding:
For 1000 FLOW as collateral, and flow price is 0.5 MOET, then :
- to avoid rebalancing (pulling from top up source), debt must be below 363.63 (1000 * 0.5 * 0.8 / D = 1.1; D = 363.63)
- to avoid liquidation, debt must be below 400 (1000 * 0.5 * 0.8 / D = 1; D = 400)
- to avoid become bad debt (users don't care, but protocol cares), debt must be below 500 (1000 * 0.5 / D = 1; D = 500)
- to avoid become total dead debt (users don't care, but protocol cares): collateral still have collateral (FLOW > 0)
There was a problem hiding this comment.
Good catch, thanks for pointing this out! You’re right, so I’ve updated the test in comment 4268477
| // minHealth = 1.1: required deposit per position to reach minHealth after 50% price crash: | ||
| // effectiveCollateral = 1 000 * 0.5 * 0.8 = 400 | ||
| // effectiveDebt ≈ 615.38 | ||
| // | ||
| // Ideal health = 400 / (615.38 - required) = 1.3 | ||
| // Required MOET ≈ 307.69 MOET | ||
| // | ||
| // left 310 MOET which is enough for one position, not both |
There was a problem hiding this comment.
Oh, I see. the minimum health factor to avoid liquidation is 1, not 1.1.
the minHealth 1.1 is when the low threshold to trigger rebalancing, not liquidation.
So 615.38 - 400 / 1.0 = 215.38, and 215.39 is the minimum to rescue just one.
FYI, this is my understanding:
For 1000 FLOW as collateral, and flow price is 0.5 MOET, then :
- to avoid rebalancing (pulling from top up source), debt must be below 363.63 (1000 * 0.5 * 0.8 / D = 1.1; D = 363.63)
- to avoid liquidation, debt must be below 400 (1000 * 0.5 * 0.8 / D = 1; D = 400)
- to avoid become bad debt (users don't care, but protocol cares), debt must be below 500 (1000 * 0.5 / D = 1; D = 500)
- to avoid become total dead debt (users don't care, but protocol cares): collateral still have collateral (FLOW > 0)
Co-authored-by: Taras Maliarchuk <maliarchuk@gmail.com>
Closes: #280
Context
Insufficient_TopUpSource_Fundsis omitted, as such a test already exists -testRebalanceUndercollateralised_InsufficientTopUpSource())asyncUpdate()helper totest_helpers.cdcand renamed it for claritydrawDownSink