FIAT DAO
  • Introduction
    • ๐Ÿš€Getting Started
    • ๐Ÿ”—Quick Links
    • โœ‹FAQs
      • Protocol FAQ
      • App FAQ
  • Protocol
    • ๐ŸŒ…FIAT I
      • Position Management
      • Liquidations
      • Borrow Rates
      • Formulas
    • ๐ŸบCollateral Vaults
      • Element Finance pToken
      • Notional Finance fCash
      • Yield Protocol fyToken
    • ๐Ÿ”ฎOracles
      • Delphi II
      • Delphi I
        • Implementations
          • Notional Finance fCash
          • Yield Protocol fyToken
          • Chainlink Underlier Feed
          • Chainlink + Curve LP Token Feed
        • Oracle
        • Relayer
    • ๐ŸงฐSDK
    • ๐Ÿ“ŠSubgraph
    • ๐Ÿ’พProtocol Deployment
    • ๐Ÿ›๏ธGovernance Deployment
Powered by GitBook
On this page
  • Borrow Formulas
  • Leverage Formulas
  • Trade Formulas
Edit on GitHub
  1. Protocol
  2. FIAT I

Formulas

PreviousBorrow RatesNextCollateral Vaults

Last updated 2 years ago

Borrow Formulas

interestPerYear to interestPerSecond

isecond=(iyear)131622400i_\text{second} = (i_{year})^\frac{1}{31622400}isecondโ€‹=(iyearโ€‹)316224001โ€‹

with both iyeari_{year}iyearโ€‹ and isecondi_{second}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).

Find a sample calculation here.

interestPerSecond to interestPerYear

iyear=(isecond)31622400i_\text{year} = (i_{second})^{31622400}iyearโ€‹=(isecondโ€‹)31622400

with both iyeari_{year}iyearโ€‹ and isecondi_{second}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).

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}imaturityโ€‹={(isecondโ€‹)Tโˆ’t1e18โ€‹ifย t<Telseโ€‹

where ttt is the current block.timestamp and TTT is the collateral assetโ€™s maturityboth expressed in seconds.

normalDebt to debt

d=dnโˆ—rate1e18d = \frac{d_n*\text{rate}}{1e^{18}}d=1e18dnโ€‹โˆ—rateโ€‹

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}dnโ€‹={ratedโˆ—1e18โ€‹โˆžโ€‹ifrate>0elseโ€‹

normalDebt to debtAtMaturity

collateralizationRatio

Max.debt for a given collateralizationRatio and collateral amount

Min. collateral for a given collateralizationRatio and debt amount

Leverage Formulas

Min. collateralizationRatio for a levered deposit

Max. collateralizationRatio for a levered deposit

flashloan amount for a levered deposit

Min. collateralizationRatio for a levered withdrawal

Max. collateralizationRatio for a levered withdrawal

flashloan amount for a levered withdrawal

Estimated underlier for a levered withdrawal

profitAtMaturity for a levered deposit

yieldToMaturity for a levered deposit

yieldToMaturity to annualYield

Trade Formulas

Minimal amountOut for a max slippagePercentage

where it is assumed that rateโ‰ฅ1e18rate \geq 1e^{18}rateโ‰ฅ1e18.

The following correction has to be performed on the resulting amount dnd_ndnโ€‹ 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}dnโ€‹={dnโ€‹+1dnโ€‹โ€‹ifย 1e18dnโ€‹โˆ—rateโ€‹<delseย โ€‹

dm=dnrate+imaturityโˆ’118118d_m = d_n\frac{\text{rate} + i_{\text{maturity}} - 1^{18}}{1^{18}}dmโ€‹=dnโ€‹118rate+imaturityโ€‹โˆ’118โ€‹

r={pโˆ—cdifd>0โˆželser = \begin{cases} \frac{p*c}{d} &\text{if}\quad d>0 \\ \infty &\text{else} \end{cases}r={dpโˆ—cโ€‹โˆžโ€‹ifd>0elseโ€‹

dmax={pโˆ—crifr>0โˆželsed_\text{max} = \begin{cases} \frac{p*c}{r} &\text{if}\quad r>0 \\ \infty &\text{else} \end{cases}dmaxโ€‹={rpโˆ—cโ€‹โˆžโ€‹ifr>0elseโ€‹

cmin={rโˆ—dpifp>0โˆželsec_\text{min} = \begin{cases} \frac{r*d}{p} &\text{if}\quad p>0 \\ \infty &\text{else} \end{cases}cminโ€‹={prโˆ—dโ€‹โˆžโ€‹ifp>0elseโ€‹

rmin=pโˆ—xfโ†’u1e18xuโ†’c1e18r_{\text{min}}=\frac{\frac{p*x_{\text{fโ†’u}}}{1e^{18}}x_{\text{uโ†’c}}}{1e^{18}}rminโ€‹=1e181e18pโˆ—xfโ†’uโ€‹โ€‹xuโ†’cโ€‹โ€‹

where xfโ†’ux_{fโ†’u}xfโ†’uโ€‹ and xuโ†’cx_{uโ†’c}xuโ†’cโ€‹ are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.

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}rmaxโ€‹={dpโˆ—(c+1e18xuโ†’cโ€‹uโ€‹)โ€‹โˆžโ€‹ifย d>0elseโ€‹

where uuu is the deposited underlier amount and xucx_{uc}xucโ€‹ is the underlying/collateral exchange rate including price impact and slippage.

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}}}f=1e18rโˆ’1e18pxfโ†’uโ€‹โ€‹xuโ†’cโ€‹pโˆ—(c+1e18xuโ†’cโ€‹uโ€‹)โˆ’rdโ€‹

where uuu is the deposited underlier amount and xfโ†’ux_{fโ†’u}xfโ†’uโ€‹and xuโ†’cx_{uโ†’c}xuโ†’cโ€‹ are the FIAT/underlying and underlying/collateral exchange rates including price impact and slippage.

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}rminโ€‹={dp(cโˆ’ฮ”c)โ€‹โˆžโ€‹ifฮ”c<cย ANDย d>0elseโ€‹

where ccc and ddd are the position collateral and debt, and ฮ”c\Delta cฮ”c is the withdrawn collateral amount.

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}rmaxโ€‹={dโˆ’ฮ”cxcโ†’uโ€‹xuโ†’fโ€‹p(cโˆ’ฮ”c)โ€‹โˆžโ€‹ifฮ”c<cย ANDย d>0elseโ€‹

where ccc is the position collateral and ฮ”c\Delta cฮ”c the withdrawn collateral amount.

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}f=โŽฉโŽจโŽงโ€‹dโˆ’rp(cโˆ’ฮ”c)โ€‹drevertโ€‹ifc>ฮ”cifย elsec=ฮ”celseโ€‹

where ccc and ddd are the position collateral and debt, and ฮ”c\Delta cฮ”c is the withdrawn collateral amount. It is thus assumed that ฮ”cโ‰คc\Delta c \leq cฮ”cโ‰คc and d>0d>0d>0 as the computation would otherwise yield an invalid result.

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}}w=1e18(ฮ”cโˆ’xcโ†’uโ€‹xuโ†’fโ€‹fโˆ—1e18โ€‹1e18โ€‹)xcโ†’uโ€‹โ€‹

where ฮ”c\Delta cฮ”c is the withdrawn collateral amount, fff is the flashloan amount used for the withdrawal, and xuโ†’fx_{uโ†’f}xuโ†’fโ€‹ and xcโ†’ux_{cโ†’u}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=1e18x_{uโ†’c} = 1e^{18}xuโ†’cโ€‹=1e18.

g=wโˆ’ug = w - ug=wโˆ’u

where www is the estimated underlier amount withdrawn at maturity (i.e. with an input of xcu=1e18x_{cu} = 1e^{18}xcuโ€‹=1e18 and ฮ”c=c\Delta c = cฮ”c=c) and uuu 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}xcuโ€‹=1e18.

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}ymaturityโ€‹={u(u+g)1e18โ€‹โˆ’1e18โˆžโ€‹ifu>0elseโ€‹

where uuu is the deposited underlier amount and ggg is the estimated profitAtMaturity.

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}yyearโ€‹={(1e18+ymaturityโ€‹)Tโˆ’t31622400โ€‹โˆ’1e180โ€‹ifย t<Telseโ€‹

as=a(1e18โˆ’spercentage)1e18a_s = \frac{a(1e^{18}-s_\text{percentage})}{1e^{18}}asโ€‹=1e18a(1e18โˆ’spercentageโ€‹)โ€‹

where aaa is the estimated amountOut without accounting for slippage.

๐ŸŒ