with both iyear and isecond interest accrual factors (and not interest rates) and where it is assumed that one full year consists of 31622400 seconds (366 days with 86400 seconds each).
iyear=(isecond)31622400
with both iyear and isecond interest accrual factors (and not interest rates) and where it is assumed that one full year consists of 31622400 seconds (366 days with 86400 seconds each).
imaturity={(isecond)T−t1e18if t<Telse
where t is the current block.timestamp and T is the collateral asset’s maturityboth expressed in seconds.
d=1e18dn∗rate
dn={rated∗1e18∞ifrate>0else
where it is assumed that rate≥1e18.
The following correction has to be performed on the resulting amount dn to avoid rounding errors due to precision loss:
dn={dn+1dnif 1e18dn∗rate<delse
dm=dn118rate+imaturity−118
r={dp∗c∞ifd>0else
dmax={rp∗c∞ifr>0else
cmin={pr∗d∞ifp>0else
rmin=1e181e18p∗xf→uxu→c
where xf→u and xu→c are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.
rmax={dp∗(c+1e18xu→cu)∞if d>0else
where u is the deposited underlier amount and xuc is the underlying/collateral exchange rate including price impact and slippage.
f=1e18r−1e18pxf→uxu→cp∗(c+1e18xu→cu)−rd
where u is the deposited underlier amount and xf→uand xu→c are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.
rmin={dp(c−Δc)∞ifΔc<c AND d>0else
where c and d are the position collateral and debt, and Δc is the withdrawn collateral amount.
rmax={d−Δcxc→uxu→fp(c−Δc)∞ifΔc<c AND d>0else
where c is the position collateral and Δc the withdrawn collateral amount.
f=⎩⎨⎧d−rp(c−Δc)drevertifc>Δcif elsec=Δcelse
where c and d are the position collateral and debt, and Δc is the withdrawn collateral amount. It is thus assumed that Δc≤c and d>0 as the computation would otherwise yield an invalid result.
w=1e18(Δc−xc→uxu→ff∗1e181e18)xc→u
where Δc is the withdrawn collateral amount, f is the flashloan amount used for the withdrawal, and xu→f and xc→u are the underlying/FIAT and collateral/underlying exchange rates including price impact and slippage.
Note that for a collateral asset beyond its maturity the formula remains intact with the difference that the input underlying/collateral exchange rate is fixed, i.e. xu→c=1e18.
g=w−u
where w is the estimated underlier amount withdrawn at maturity (i.e. with an input of xcu=1e18 and Δc=c) and u is the deposited underlier amount. It is further assumed that the collateral token can be redeemed for underlier tokens at a rate of xcu=1e18.
ymaturity={u(u+g)1e18−1e18∞ifu>0else
where u is the deposited underlier amount and g is the estimated profitAtMaturity.