Skip to content

Instantly share code, notes, and snippets.

@GalloDaSballo
Last active August 25, 2023 19:47
Show Gist options
  • Save GalloDaSballo/27ddbf6cb06d8fe8368d2611c4eecc40 to your computer and use it in GitHub Desktop.
Save GalloDaSballo/27ddbf6cb06d8fe8368d2611c4eecc40 to your computer and use it in GitHub Desktop.
8 Units of Coll to Deny Liquidations
6 Units of Repaid Debt
Rational to Repay at least superficially (not looking at CDP at risk and upcoming price drawdown)
def get_debt(coll, cr):
return coll / cr * 100
def get_cr(coll, debt):
return coll / debt * 100
## Figure out the cost of the swap
COST_SWAP = 30 ## Either Pool, or Mint Fee
SAFE_COLL = 200
SAFE_CR = 200
SAFE_DEBT = get_debt(SAFE_COLL, SAFE_CR)
print("SAFE_DEBT", SAFE_DEBT)
RISKY_CR = 110
SYSTEM_CR = 126
def round(at_risk_percent):
print("")
print("")
print("at_risk_percent", at_risk_percent)
at_risk_coll = SAFE_COLL * at_risk_percent / 100
at_risk_debt = get_debt(at_risk_coll, RISKY_CR)
print("at_risk_coll", at_risk_coll)
print("at_risk_debt", at_risk_debt)
total_coll = SAFE_COLL + at_risk_coll
total_debt = SAFE_DEBT + at_risk_debt
attacker_coll = 0
attacker_debt = 0
## At Risk Assumption
## We want to find the % of over leverage to make it profitable
while get_cr(total_coll, total_debt) > SYSTEM_CR:
attacker_coll += 10
attacker_debt = get_debt(attacker_coll, RISKY_CR)
total_coll = SAFE_COLL + at_risk_coll + attacker_coll
total_debt = SAFE_DEBT + at_risk_debt + attacker_debt
print("attacker_coll", attacker_coll)
print("attacker_debt", attacker_debt)
print("get_cr(total_coll, total_debt)", get_cr(total_coll, total_debt))
print("")
print("liquidation profit %", at_risk_coll / 10 / attacker_coll * 100)
## Find cost to Flashloan and grief the RM Liquidations
current_cr = get_cr(total_coll, total_debt)
target_cr = current_cr * 101 / 100 ## 1% increase for simplification
fl_coll = 0
while get_cr(total_coll, total_debt) < target_cr:
fl_coll += 1
total_coll = SAFE_COLL + at_risk_coll + attacker_coll + fl_coll
total_debt = SAFE_DEBT + at_risk_debt + attacker_debt
print("fl_coll", fl_coll)
print("get_cr(total_coll, total_debt", get_cr(total_coll, total_debt))
print("as % of coll", fl_coll / total_coll * 100)
print("If 3BPS cost", fl_coll * 3 / 10_000)
print("If 9BPS cost", fl_coll * 9 / 10_000)
print("If 50BPS cost", fl_coll * 50 / 10_000)
print("Additional 1% closing fee for same block", fl_coll * 1 / 100)
print("If Its in millions", 1e6 * fl_coll * 1 / 100) ## Need to be higher imo
print("If Its in millions", 1e6 * fl_coll * 10 / 100) ## Need to be higher imo
fl_repaid_debt = 0
## Reset
total_coll = SAFE_COLL + at_risk_coll + attacker_coll
total_debt = SAFE_DEBT + at_risk_debt + attacker_debt
while get_cr(total_coll, total_debt) < target_cr:
fl_repaid_debt += 1
total_coll = SAFE_COLL + at_risk_coll + attacker_coll
total_debt = SAFE_DEBT + at_risk_debt + attacker_debt - fl_repaid_debt
print("fl_repaid_debt", fl_repaid_debt)
print("get_cr(total_coll, total_debt", get_cr(total_coll, total_debt))
print("as % of coll", fl_repaid_debt / total_coll * 100)
print("If 3BPS cost", fl_repaid_debt * 3 / 10_000)
print("If 9BPS cost", fl_repaid_debt * 9 / 10_000)
print("If 50BPS cost", fl_repaid_debt * 50 / 10_000)
print("Additional 1% closing fee for same block", fl_repaid_debt * 1 / 100)
print("If Its in millions", 1e6 * fl_repaid_debt * 1 / 100) ## Need to be higher imo
print("If Its in millions", 1e6 * fl_repaid_debt * 10 / 100) ## Need to be higher imo
MIN_MAX_RISK = 5 ## 5%
MAX_RISK = 55 ## 50% cmon
STEP = 5
def main():
for risk in range(MIN_MAX_RISK, MAX_RISK, STEP):
round(risk)
main()
@GalloDaSballo
Copy link
Author

SAFE_DEBT 100.0

at_risk_percent 5
at_risk_coll 10.0
at_risk_debt 9.090909090909092
attacker_coll 500
attacker_debt 454.54545454545456
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 0.2
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 10
at_risk_coll 20.0
at_risk_debt 18.181818181818183
attacker_coll 490
attacker_debt 445.45454545454544
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 0.40816326530612246
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 15
at_risk_coll 30.0
at_risk_debt 27.27272727272727
attacker_coll 480
attacker_debt 436.3636363636363
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 0.625
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 20
at_risk_coll 40.0
at_risk_debt 36.36363636363637
attacker_coll 470
attacker_debt 427.27272727272725
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 0.851063829787234
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 25
at_risk_coll 50.0
at_risk_debt 45.45454545454545
attacker_coll 460
attacker_debt 418.1818181818182
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 1.0869565217391304
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 30
at_risk_coll 60.0
at_risk_debt 54.54545454545454
attacker_coll 450
attacker_debt 409.09090909090907
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 1.3333333333333335
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 35
at_risk_coll 70.0
at_risk_debt 63.63636363636363
attacker_coll 440
attacker_debt 400.0
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 1.5909090909090908
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 40
at_risk_coll 80.0
at_risk_debt 72.72727272727273
attacker_coll 430
attacker_debt 390.90909090909093
get_cr(total_coll, total_debt) 125.96774193548386

liquidation profit % 1.8604651162790697
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419354
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249427
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 45
at_risk_coll 90.0
at_risk_debt 81.81818181818183
attacker_coll 420
attacker_debt 381.8181818181818
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 2.142857142857143
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

at_risk_percent 50
at_risk_coll 100.0
at_risk_debt 90.9090909090909
attacker_coll 410
attacker_debt 372.7272727272727
get_cr(total_coll, total_debt) 125.96774193548387

liquidation profit % 2.4390243902439024
fl_coll 8
get_cr(total_coll, total_debt 127.38709677419355
as % of coll 1.1142061281337048
If 3BPS cost 0.0024
If 9BPS cost 0.0072
If 50BPS cost 0.04
Additional 1% closing fee for same block 0.08
If Its in millions 80000.0
If Its in millions 800000.0
fl_repaid_debt 6
get_cr(total_coll, total_debt 127.32311705249431
as % of coll 0.8450704225352111
If 3BPS cost 0.0018
If 9BPS cost 0.0054
If 50BPS cost 0.03
Additional 1% closing fee for same block 0.06
If Its in millions 60000.0
If Its in millions 600000.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment