Skip to content

Conversation

failingtwice
Copy link
Contributor

A short summary of the changes.

Context

#1305


Math

  • LS = liability shares
  • TVS = total value in shares (floor)
  • B = 10000 (basis points base)
  • T = thresholdBP
  • M = B - T = mintRatio in bp.
  • X = shortfall (misleading name btw)

Vault is healthy if:

LS / TVS <= M / B

or

LS * B <= TVS * M


Rebalance does the following

LS - X

rebalance(roundUp(X))

and

TVS - Y

Normally, X == Y

BUT

because rebalance rounds UP, in the worst case scenario

Y = X + 1

thus, we can derive the post-rebalance condition:

(LS - X) * B <= (TVS - X - 1) * M

OR (using distributive property)

LS * B - X * B <= TVS * M - X * M - M

add X * M to both sides

LS * B - X * B + X * M <= TVS * M - M

subtract LS * B

- X * B + X * M <= TVS * M - M - LS * B

or factor X

X (M - B) <= TVS * M - M - LS * B

because

T = M - B

X * (-T) <= TVS * M - M - LS * B

divide both sides by -T and flip the sign

X >= (TVS * M - M - LS * B) / (-T)

move minus to numerator

X >= -(TVS * M - M - LS * B) / T

factor -1

X >= (-TVS * M + M + L * B) / T

rearrange and get the final inequality

X >= (L * B - TVS * M + M) / T

AND after all of that we need to use ceiling division because the final inequality also includes division

X >= (L * B - TVS * M + M) + (T - 1) / T


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant