Lending

Lending transaction

Let
xx
be the increase in the
XX
pool. This increase is due to the lender depositing
xx
assets in the pool.
Let
yy
be the decrease in the
YY
pool.
Let
zz
be the decrease in the
ZZ
pool.
The value of
xx
, y, and
zz
is calculated from the constant product
KK
(X+x)×(Yy)×(Zz)=K(X+x)\times(Y-y)\times(Z-z)=K
As
yy
increases,
zz
has to decrease and when
zz
increases,
yy
has to decrease. So, a user receives lower interest as the insurance increases and vice versa. Thus, lenders have the flexibility to decide their risk-reward profile at the time of lending assets to the pool.
The maximum of
yy
is when
z=0z=0
:
(X+x)×(Yymax)×(Z0)=K(X+x)\times(Y - y_{max})\times(Z-0)=K
The maximum of
zz
is when
y=0 y=0
:
(X+x)×(Y0)×(Zzmax)=K(X+x)\times(Y-0)\times(Z -z_{max}) = K
Let d be time duration from the time of user transaction to maturity time of pool in seconds
Total Bond tokens and Insurance tokens received by lenders are as follows:
Bond Principal tokens:
xx
Bond Interest tokens:
dydy
Insurance Principal tokens: z_{max}
Insurance Interest tokens= zd/2^25
There is a restriction where,
y>=ymax16y>=\frac{y_{max}}{16}
, such that there is a minimum interest per second received by lenders

Deep-dive into a Lending transaction

Alice would like to lend DAI on DAI-ETH Timeswap pool to earn interest with minimal risk. Suppose a Liquidity Provider(LP) creates the DAI-ETH pool with the following parameters and maturity of 1 year:
X=10,000X = 10,000
Y=0.0000475Y=0.0000475
(Average int rate of 15%)
Z=4.16Z = 4.16
K=1.979K=1.979
Now Alice deposits 1000 DAI to the Timeswap DAI — ETH pool 1 month before the pool maturity. So as per the AMM equation for a lending transaction:
(10000+1000)×(0.0000475y)×(4.16z)=1.979(10000+1000)\times(0.0000475-y)\times(4.16-z)=1.979
Solving for
ymaxy_{max}
,
(10000+1000)×(0.0000475ymax)×(4.160)=1.979(10000+1000)\times(0.0000475 - y_{max})\times(4.16-0)=1.979
ymax=0.00000425y_{max}= 0.00000425
=>=>
The annual interest rate that can be selected by Alice will have a range of
ymax16×dyearx\frac{y_{max}}{16}\times\frac{d_{year}}{x}
to
ymax×dyearxy_{max}\times\frac{d_{year}}{x}
(where
dyeard_{year}
is no. of sec in a year = 31556926). In this case, Alice can select APR from 0.84% to 13.41%
Solving for
zmaxz_{max}
,
(10000+1000)×(0.00004750)×(4.16zmax)=1.979(10000+1000) \times(0.0000475-0) \times(4.16-z_{max}) =1.979
zmax=0.37z_{max}=0.37
Let’s assume Alice chose to receive 10% APR with some insurance while initiating the transaction.
=>y=>y
or the interest value per second is
0.1×100031556926=0.000003160.1\times\frac{1000}{31556926}=0.00000316
Let
d=d=
2592000 (duration of 30 days from the time of tx in seconds)
Solving for Bond tokens to be received by Alice, we get
Bond Principal tokens=
x=1000x=1000
Bond lnterest tokens = dy={2592000}\times{0.00000316}=8.19
Solving for z
(10000+1000)×(0.00004750.00000316)×(4.16z)=1.979(10000+1000)\times (0.0000475-0.00000316)\times(4.16-z)=1.979
z=0.1z=0.1
Solving for Insurance tokens to be received by Alice, we get
Insurance Principal tokens= z_{max} = 0.37
Insurance Interest tokens = zd/2^25 = 0.1*2592000/33554432 = 0.077
i.e. Alice receives 1000 Bond Principal tokens, 8.19 Bond Interest tokens, 0.37 Insurance Principal tokens and 0.077 Insurance Interest tokens. In total Alice should get 1008.19 DAI after maturity and in case of default coverage of up to 0.371 ETH
Summarising:
Alice deposited 1000 DAI to the pool one month before the pool expiry and received toal 1008.19 Bond tokens (BPT+BIT) and 0.371 Insurance tokens (IPT+IIT). At the end of 1 month, she should receive 1008.19 DAI by burning her Bond tokens . However in case her bond tokens are not able to give her exact same amount of DAI, her insurance tokens will kick in to provide her a proportional percentage of coverage on insurance value which is in line with the percentage of unrealised assets from respective bond tokens