FIAT DAO
Search…
⌃K

Formulas

Borrow Formulas

interestPerYear to interestPerSecond

​
isecond=(iyear)131622400i_\text{second} = (i_{year})^\frac{1}{31622400}
​
with both
iyeari_{year}
and
isecondi_{second}
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).
Find a sample calculation here.

interestPerSecond to interestPerYear

​
iyear=(isecond)31622400i_\text{year} = (i_{second})^{31622400}
​
with both
iyeari_{year}
and
isecondi_{second}
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).

interestPerSecond to interestToMaturity

​
imaturity={(isecond)T−tif t<T1e18elsei_{\text{maturity}} = \begin{cases} (i_{\text{second}})^{T-t} & \text{if } t < T \\ 1e^{18} &\text{else} \end{cases}
​
where
tt
is the current block.timestamp and
TT
is the collateral asset’s maturityboth expressed in seconds.

normalDebt to debt

​
d=dn∗rate1e18d = \frac{d_n*\text{rate}}{1e^{18}}
​

debt to normalDebt

​
dn={d∗1e18rateifrate>0∞elsed_n = \begin{cases} \frac{d*1e^{18}}{\text{rate}} &\text{if}\quad \text{rate}>0 \\ \infty &\text{else} \end{cases}
​
where it is assumed that
rate≥1e18rate \geq 1e^{18}
.
The following correction has to be performed on the resulting amount
dnd_n
to avoid rounding errors due to precision loss:
​
dn={dn+1if dn∗rate1e18<ddnelse d_n = \begin{cases} d_n+1 &\text{if } \frac{d_n*\text{rate}}{1e^{18}} < d \\ d_n &\text{else } \end{cases}
​

normalDebt to debtAtMaturity

​
dm=dnrate+imaturity−118118d_m = d_n\frac{\text{rate} + i_{\text{maturity}} - 1^{18}}{1^{18}}
​

collateralizationRatio

​
r={p∗cdifd>0∞elser = \begin{cases} \frac{p*c}{d} &\text{if}\quad d>0 \\ \infty &\text{else} \end{cases}
​

Max.debt for a given collateralizationRatio and collateral amount

​
dmax={p∗crifr>0∞elsed_\text{max} = \begin{cases} \frac{p*c}{r} &\text{if}\quad r>0 \\ \infty &\text{else} \end{cases}
​

Min. collateral for a given collateralizationRatio and debt amount

​
cmin={r∗dpifp>0∞elsec_\text{min} = \begin{cases} \frac{r*d}{p} &\text{if}\quad p>0 \\ \infty &\text{else} \end{cases}
​

Leverage Formulas

Min. collateralizationRatio for a levered deposit

​
rmin=p∗xf→u1e18xu→c1e18r_{\text{min}}=\frac{\frac{p*x_{\text{f→u}}}{1e^{18}}x_{\text{u→c}}}{1e^{18}}
​
where
xf→ux_{f→u}
and
xu→cx_{u→c}
are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.

Max. collateralizationRatio for a levered deposit

​
rmax={p∗(c+xu→cu1e18)dif d>0∞elser_{\text{max}}=\begin{cases} \frac{p*(c + \frac{x_{\text{u→c}}u}{1e^{18}})}{d} &\text{if } d>0 \\ \infty &\text{else} \end{cases}
​
where
uu
is the deposited underlier amount and
xucx_{uc}
is the underlying/collateral exchange rate including price impact and slippage.

flashloan amount for a levered deposit

​
f=p∗(c+xu→cu1e18)−rd1e18r−pxf→u1e18xu→cf=\frac{p*(c + \frac{x_{\text{u→c}}u}{1e^{18}}) - rd}{1e^{18}r - \frac{px_{\text{f→u}}}{1e^{18}}x_{\text{u→c}}}
​
where
uu
is the deposited underlier amount and
xf→ux_{f→u}
and
xu→cx_{u→c}
are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.

Min. collateralizationRatio for a levered withdrawal

​
rmin={p(c−Δc)difΔc<c AND d>0∞elser_{\text{min}} = \begin{cases} \frac{p(c - \Delta c)}{d} &\text{if}\quad \Delta c < c \text{ AND } d>0 \\ \infty &\text{else} \end{cases}
​
where
cc
and
dd
are the position collateral and debt, and
Δc\Delta c
is the withdrawn collateral amount.

Max. collateralizationRatio for a levered withdrawal

​
rmax={p(c−Δc)d−Δcxc→uxu→fifΔc<c AND d>0∞elser_{\text{max}} = \begin{cases} \frac{p(c-\Delta c)}{d - \Delta c x_{c\rightarrow u}x_{u\rightarrow f}} &\text{if}\quad \Delta c < c \text{ AND } d>0 \\ \infty &\text{else} \end{cases}
​
where
cc
is the position collateral and
Δc\Delta c
the withdrawn collateral amount.

flashloan amount for a levered withdrawal

​
f={d−p(c−Δc)rifc>Δcdif elsec=Δcrevertelsef = \begin{cases} d-\frac{p(c - \Delta c)}{r} &\text{if}\quad c>\Delta c \\ d &\text{if else}\quad c=\Delta c \\ \text{revert} &\text{else}\end{cases}
​
where
cc
and
dd
are the position collateral and debt, and
Δc\Delta c
is the withdrawn collateral amount. It is thus assumed that
Δc≤c\Delta c \leq c
and
d>0d>0
as the computation would otherwise yield an invalid result.

Estimated underlier for a levered withdrawal

​
w=(Δc−f∗1e18xu→f1e18xc→u)xc→u1e18w = \frac{(\Delta c - \frac{\frac{f*1e^{18}}{x_{u→f}}1e^{18}}{x_{c→u}})x_{c→u}}{1e^{18}}
​
where
Δc\Delta c
is the withdrawn collateral amount,
ff
is the flashloan amount used for the withdrawal, and
xu→fx_{u→f}
and
xc→ux_{c→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=1e18x_{u→c} = 1e^{18}
.

profitAtMaturity for a levered deposit

​
g=w−ug = w - u
​
where
ww
is the estimated underlier amount withdrawn at maturity (i.e. with an input of
xcu=1e18x_{cu} = 1e^{18}
and
Δc=c\Delta c = c
) and
uu
is the deposited underlier amount. It is further assumed that the collateral token can be redeemed for underlier tokens at a rate of
xcu=1e18x_{cu}=1e^{18}
.

yieldToMaturity for a levered deposit

​
ymaturity={(u+g)1e18u−1e18ifu>0∞elsey_{\text{maturity}} = \begin{cases} \frac{(u + g)1e^{18}}{u} - 1e^{18} &\text{if}\quad u>0 \\ \infty &\text{else} \end{cases}
​
​
where
uu
is the deposited underlier amount and
gg
is the estimated profitAtMaturity.

yieldToMaturity to annualYield

​
yyear={(1e18+ymaturity)31622400T−t−1e18if t<T0elsey_{\text{year}} = \begin{cases} (1e^{18}+y_{\text{maturity}})^{\frac{31622400}{T-t}}-1e^{18} & \text{if } t < T \\ 0 &\text{else} \end{cases}
​

Trade Formulas

Minimal amountOut for a max slippagePercentage

​
as=a(1e18−spercentage)1e18a_s = \frac{a(1e^{18}-s_\text{percentage})}{1e^{18}}
​
where
aa
is the estimated amountOut without accounting for slippage.