Princeton University, Princeton, NJ, USA and
https://sites.google.com/view/mahsabastankhah/home?authuser=0
<EMAIL_ADDRESS>Princeton University, Princeton, NJ, USA and
https://sites.google.com/view/virajnadkarni/home<EMAIL_ADDRESS>Hong
Kong University of Science and Technology (Guangzhou), Guangdong, China and
https://xuechao2.github.io/<EMAIL_ADDRESS>Princeton University,
Princeton, NJ, USA and https://sites.google.com/view/cjin/home
<EMAIL_ADDRESS>Princeton University, Princeton, NJ, USA and
https://www.princeton.edu/~kulkarni/<EMAIL_ADDRESS>Princeton
University, Princeton, NJ, USA and https://ece.princeton.edu/people/pramod-
viswanath<EMAIL_ADDRESS>Mahsa Bastankhah, Viraj Nadkarni, Chi Jin,
Sanjeev Kulkarni, and Pramod Viswanath Theory of computation Market equilibria

# Thinking Fast and Slow: Data-Driven Adaptive DeFi Borrow-Lending Protocol

Mahsa Bastankhah  Viraj Nadkarni  Xuechao Wang  Chi Jin  Sanjeev Kulkarni
Pramod Viswanath

###### Abstract

Decentralized finance (DeFi) borrowing and lending platforms are crucial to
the decentralized economy, involving two main participants: lenders who
provide assets for interest and borrowers who offer collateral exceeding their
debt and pay interest. Collateral volatility necessitates over-
collateralization to protect lenders and ensure competitive returns.
Traditional DeFi platforms use a fixed interest rate curve based on the
utilization rate (the fraction of available assets borrowed) and determine
over-collateralization offline through simulations to manage risk. This method
doesn’t adapt well to dynamic market changes, such as price fluctuations and
evolving user needs, often resulting in losses for lenders or borrowers. In
this paper, we introduce an adaptive, data-driven protocol for DeFi borrowing
and lending. Our approach includes a high-frequency controller that
dynamically adjusts interest rates to maintain market stability and
competitiveness with external markets. Unlike traditional protocols, which
rely on user reactions and often adjust slowly, our controller uses a
learning-based algorithm to quickly find optimal interest rates, reducing the
opportunity cost for users during periods of misalignment with external rates.
Additionally, we use a low-frequency planner that analyzes user behavior to
set an optimal over-collateralization ratio, balancing risk reduction with
profit maximization over the long term. This dual approach is essential for
adaptive markets: the short-term component maintains market stability,
preventing exploitation, while the long-term planner optimizes market
parameters to enhance profitability and reduce risks. We provide theoretical
guarantees on the convergence rates and adversarial robustness of the short-
term component and the long-term effectiveness of our protocol. Empirical
validation confirms our protocol’s theoretical benefits.

###### keywords:

Defi borrow-lending, adaptive market design, decentralized finance

##  1 Introduction

Lending in DeFi Decentralized Finance (DeFi) has revolutionized lending and
borrowing by eliminating centralized intermediaries. The main paradigm shift
has been around moving away from opaque financial entities such as banks, that
use proprietary models and data to match deposits with borrowers [4], to
transparent pools with published algorithms to change interest rates, and
borrowing conditions. Major DeFi lending platforms like Aave [2] and Compound
[6] function through these liquidity pools, where lenders provide capital that
borrowers can access. These protocols ensure that borrowers pledge enough
collateral to cover their debt, along with an additional safety buffer.

Stable utilization The simplest variable of interest that any lending protocol
seeks to control is the supply-demand ratio of the pool, referred to as
“utilization.” The objective is to maintain a stable utilization around a
designated “optimal utilization” threshold. A coarse rule of thumb is that
when the utilization is low, interest rates remain low to encourage borrowing
[10]. As utilization increases, interest rates rise to balance demand with
supply and to prevent excessively high utilization, which could restrict
lenders’ ability to withdraw their funds, thus rendering the market less
attractive.

Collateral factor Besides the interest rate, other parameters like the over-
collateralization ratio, also known as the “collateral factor,” govern the
long-term risks and profits of the market [13]. In particular, the cash flow
that any lender gets from the protocol is at risk of liquidation, and in the
more severe cases, default. This risk can be minimized by demanding a large
amount of collateral from borrowers, which makes the risk vanishingly small
while making the lending market incredibly inefficient and unattractive for
borrowers, especially if the asset used as the collateral does not suffer
frequent price fluctuations. Thus, the collateral factor needs to be
determined based on a careful analysis of recent historic behavior of the
collateral asset price, and the risk appetite of the lender.

Shortcomings of existing approaches Present DeFi platforms fix the interest
rate as a static function of the utilization [9, 7]. Choosing utilization as
the primary indicator of both supply/demand dynamics and market
risk/attractiveness and employing a fixed interest rate curve to manage these
aspects is very arbitrary and manually determined. Furthermore, traditional
DeFi borrowing and lending markets set the collateral factor through a
comprehensive process involving community proposals and review phases [1, 5].
However, this method is notably slow and struggles to adapt quickly to rapid
market changes, potentially leading to losses and excessive risks due to the
delayed adjustment of parameters in response to market fluctuations and
experiencing long periods of extreme low liquidity or market inefficiencies.
For instance, the authors of [25] have found that the markets for DAI and USDC
frequently exhibit periods of extreme low liquidity with utilization exceeding
80% and 90%, respectively, which further highlights the inadequacy of current
interest rate models.

Need for adaptivity and fairness In this study, we propose an adaptive,
automated, and data-driven approach for designing a borrowing/lending
protocol. We begin by modeling the behaviors of borrowers and lenders based on
their incentives in a principled manner and examine how external factors alter
these behaviors over time. We then define market equilibrium (Definition 2.2),
where the market remains stable within a broader external market, and rates
offered by our protocol do not allow borrowers or lenders to gain an advantage
over external market rates. Achieving equilibrium is crucial in a market with
conflicting interests, as instability tends to disproportionately benefit one
group over another, reducing overall fairness and attractiveness of the market
[11]. If a protocol cannot dynamically adjust to achieve equilibrium, it risks
losing liquidity and users. Market stability must be promptly restored after
disruptions, which may be caused by changes in external market conditions or
shifts in price distributions that affect the market’s risk and profit
structure.

Thinking fast - convergence to equilibrium  Traditional stationary-curve
borrowing/lending markets depend on user interactions to push towards
equilibrium—for instance, high interest rates prompt borrowers to repay loans,
reducing utilization and interest rates. However, this process is slow and
often results in impermanent loss [8], especially for users with less
flexibility in managing their assets. In order to address this problem, our
protocol includes an “interest rate controller” submodule that learns the
equilibrium interest rate from user behaviors, providing a faster convergence
rate, even in the presence of uninformed users who lack precise information on
competitive rates. Unlike traditional methods, our approach does not solely
rely on user actions but actively learns from them to accurately assess and
adapt to market conditions. Moreover, we provide an adversarial robust version
of our interest rate controller as well which learns the equilibrium interest
rate as long as the adversary controls less than 50% of the borrowing demand.

Thinking slow - adapting to the broader market In addition to promptly
restoring stability following market disruptions, it is essential for a
protocol to adaptively optimize hyperparameters that enhance long-term system
efficiency and manage risk. Our protocol features a long-term planner that
uses the collateralization ratio as a control variable to adapt to market
changes and stabilize the market at a desired level (Section 3.2). The
collateralization ratio is critical for managing long-term risks and rewards
in the system. This ratio has a complex relationship with user behavior and
the overall risk and profitability of the market, which we explore in detail
in our paper (Section 4). The objectives of the protocol within this long-term
planner can be defined in many different ways; In this paper our focus is on
maintaining long-term utilization at a target level and controlling default,
however more complex objective functions could be implemented to address
specific market needs or objectives. Our approach provides a general framework
for designing adaptive markets with heterogeneous users who may have varying
incentives.

Evaluation Additionally, we implemented our protocol and tested it with
simulated borrowers and lenders, empirically comparing its performance against
fixed-curve baselines. We evaluated the correctness of our theoretical
guarantees in practice and demonstrated that our interest rate controller can
quickly learn the equilibrium interest rate after each market disruption,
regardless of borrowers’ and lenders’ elasticity. In contrast, the baseline
protocol fails to find the equilibrium interest rate when user elasticity is
low due to its reliance on user reactions to push the market toward
equilibrium. Moreover, we showed that in the presence of major market changes,
our protocol’s collateral factor planner adaptively activates. By learning new
price and market parameters, it sets the collateral factor to maintain
utilization near a predefined optimal level in the long term.

###  1.1 Related Work

Lending in DeFi  Various models on lender and borrower behavior and their
equilibria have been explored. [19] assume parametrized supply and demand
curves based on interest rates, approximating the curve around equilibrium to
recommend rates, but they ignore external markets and default risk
minimization. [33] consider external markets, measuring protocol efficiency by
interest rate differences, but their models lack long-term decision-making and
liquidation considerations. [17] examines Nash equilibrium in a model with
independent quality shocks, showing that exogenous asset prices yield one
equilibrium, while protocol-influenced prices cause oscillation and propose
ad-hoc contract adjustments. Empirical studies on lender/borrower behavior
[23, 24, 35] inform our parameter values. [37] discusses borrower trading
strategies with market makers. Adversarial attacks on lending protocols have
also been highlighted [16, 18, 15].

Adaptive DeFi protocols Several recent works in the mechanism design of
financial systems have been advocating for the use of automated adaptivity
[41]. The presence of impermanent loss and arbitrage loss in the design of
market makers has also spawned multiple works in adaptive market making [22,
30, 31]. We seek to bring similar automated methods to lending in DeFi.
Platforms such as Morpho [12] and Ajna [3] provide lenders and borrowers more
flexibility when it comes to equilibrium interest rate discovery via an order-
book like structure. However, such protocols require constant monitoring on
the part of the participants for fairness and optimality. Our objective is to
bring these notions of fairness/optimality to more passive pool-based lending
protocols.

Control The methods used in this work are based on optimal control and
filtering literature using the least squares method [26]. This method has been
used in the estimation of underlying dynamics, given a noisy access to
measurements [28, 40]. Several recent works have provided extensions of this
algorithm to ensure adversarial robustness [14, 38, 29], which use hard
thresholding and concentration inequalities to weed out adversarial data.

##  2 Problem Formulation

###  2.1 Market Actors

The DeFi borrowing and lending market includes four key participants: lenders,
borrowers, liquidators, and the protocol, here called $\mathcal{P}$. These
actors interact within a shared pool. This subsection briefly clarifies each
participant’s role and the mechanisms protocols use to regulate their
interactions.

Liquidators To prevent defaults during price declines, the protocol employs
_liquidation_. This occurs when a borrower’s _loan-to-value_ ratio (debt-to-
collateral value) exceeds a threshold liquidation threshold ($LT$), set
between $0$ and $1$ and higher than the initial loan-to-value ratio $c$. When
this threshold is surpassed, liquidators can claim a portion of the borrower’s
collateral to repay the debt, reducing the loan-to-value ratio. Liquidators
receive a fee $LI$ from the borrower’s collateral. Liquidations enhance system
safety but are unfavorable for borrowers due to the incentive fee. This
prompts borrowers to increase their collateral preemptively. Despite
liquidation mechanisms, defaults can occur if collateral prices drop abruptly
or if liquidators lack sufficient incentives to act.

Protocol The protocol must adjust parameters $\\{r_{t},c_{t},LT_{t},LI_{t}\\}$
over time to stabilize the pool. Objectives include stabilizing loan supply
and demand by setting an interest rate $r_{t}$ and optimizing parameters to
minimize defaults and liquidations while maintaining an ideal utilization
rate. Our paper focuses on creating a competitive DeFi protocol with efficient
rates, not on revenue maximization. The openness of DeFi protocols and minimal
fees should ensure that the most competitive protocol eventually dominates the
market.

Asset pools The lending pool consists of two assets: a stable asset,
$\mathcal{A}_{l}$, provided by lenders for interest, and a volatile asset,
$\mathcal{A}_{c}$, used by borrowers as collateral. Borrowers can only borrow
a fraction collateral factor ($c$) of their collateral, set by the protocol.
At timeslot $t$, the overall pool’s assets of type $\mathcal{A}_{l}$,
considering both lent-out funds and available liquidity, are denoted by
$L_{t}$. Note that $L_{t}$ increases over time as lenders accrue interest on
the lent-out portion. The asset of a particular lender $i$ is represented by
$L_{t}(i)$.

Borrowers and lenders The interest rate $r_{t}$ is set by the protocol at each
block. Borrowers pay this rate, but lenders earn interest only on the utilized
fraction $U_{t}$ of their deposit, defined as $U_{t}=\frac{B_{t}}{L_{t}}$,
where $B_{t}$ represents the overall debt across all borrowers, and $B_{t}(i)$
represents the debt of borrower $i$. The debt amount also increases over time
due to accrued interest. The quantity of the overall collateral posted by all
borrowers is denoted by $C_{t}$, and $C_{t}(i)$ denotes the collateral of
borrower $i$. Hence, $p_{t}\cdot C_{t}$ determines the value of the collateral
in terms of the lent-out asset, $\mathcal{A}_{l}$ (for a thorough list of the
notations and their description refer to Appendix D). When borrowers repay,
they return the loan plus interest and retrieve their collateral. Lenders
receive interest based on the protocol rate and fund utilization. Defaults can
affect the final interest rate for lenders. If collateral value drops below
the debt, the protocol cannot compel repayment of the insolvent debt,
resulting in a loss that impacts the lenders’ interest rate.

###  2.2 Environment model

##### Asset price model

We operate within discrete time intervals, denoted as $\Delta$, each
corresponding to one blocktime. We use a discrete price model to monitor the
collateral asset’s price from one block to the next. For simplicity, we assume
the lent-out asset is a stablecoin with a relatively stable price, while the
collateral asset’s price follows an exogenous geometric Brownian motion with
volatility $\sigma$. We assume constant volatility over short periods of time,
with occasional sporadic jumps, but no fluctuations from one timeslot to the
next. In particular, we assume that the price volatility is constant within
timescales denoted by $T_{m}>1$ ($m$ for market, denoting the timeframe within
which the market is stable) which consists of multiple timeslots and can
change arbitrarily every $T_{m}$ timeslots.

Geometric Brownian price The price at time $t$, denoted as $p_{t}$, follows a
Geometric Brownian motion with drift $\mu_{\text{price}}$ and volatility
$\sigma$. The initial price $p_{0}$ is the starting point, for notation
simplicity we normalize and consider $\Delta=1$ and hence formally, the model
is:

$p_{t}=p_{t-1}\exp\left(\mu+\sigma\varepsilon_{t}\right),\quad\varepsilon_{t}\sim\mathcal{N}(0,1)$
(1)

where $\varepsilon_{t}$ is the innovation term for the volatility.

##### External market competition

We assume the existence of an external competitor market which offers risk-
free borrow rate $r_{o}^{b}$ and risk-free lend rate $r_{o}^{l}$. These rates
are constant during each market period $T_{m}$ and can change arbitrarily
between periods. This assumption accounts for the competition and the broader
market within which our protocol operates. $r_{o}^{l}$ and $r_{o}^{b}$ might
represent the existence of complex alternatives rather than simple risk-free
rates. In Appendix B.1, we discuss interpreting these parameters based on
real-world strategies and competitors in the Defi ecosystem. Throughout the
paper, we abstract these concepts into $r_{o}^{l}$ and $r_{o}^{b}$.

###  2.3 Protocol behaviour and pool logic

In this section, we establish the structure of a decentralized borrowing-
lending protocol, denoted by $\mathcal{P}$. The protocol fulfills two primary
roles: 1) $\mathcal{P}$ sets the pool’s parameters for each block, denoted as
$\\{r_{t},c_{t},LT_{t},LI_{t}\\}$, by transmitting a transaction to the
underlying blockchain. These parameters govern the pool’s logic. 2)
$\mathcal{P}$ updates the state variables $L_{t}$, $B_{t}$, and $C_{t}$ every
block to apply interest rate accumulation and liquidation or default due to
price fluctuations.

Handling default At the beginning of each timeslot $t$, $\mathcal{P}$ receives
the latest price of $\mathcal{A}_{c}$, $p_{t}$, from an oracle. The protocol
calculates potential defaults accrued in the last timeslot for each user. The
default for borrower $i$ at timeslot $[t-1,t]$ is:

$\pi_{t-1}^{i}(p_{t})\coloneqq\max\left\\{0,B_{t-1}(i)-C_{t-1}(i)\cdot
p_{t}\right\\}$ (2)

The overall default, normalized by $L_{t-1}$, is:

$\pi_{t-1}(p_{t})\coloneqq\frac{1}{L_{t-1}}\sum_{i\in\mathrm{borrowers}}\max\left\\{0,B_{t-1}(i)-C_{t-1}(i)\cdot
p_{t}\right\\}$ (3)

The protocol seizes the remaining collateral of defaulted positions, exchanges
it for $\mathcal{A}_{l}$, and sets the debt of defaulted borrowers to zero.
The gained $\mathcal{A}_{l}$ assets are added back to the pool. Moreover the
underwater debt is deduced from the lender’s deposit accordingly:

$L_{t}(i)=L_{t-1}(i)-\pi_{t-1}(p_{t})\cdot
L_{t-1}(i),\quad\forall\,i\in\mathrm{Lenders}$ (4)

For a more thorough explanation of why we handle defaults in this way rather
than using a safety reserve similar to most of the current working Defi
borrow-lending platforms refer to Appendix A.

Interest update The debt of non-defaulted borrowers is updated by:

$B_{t}(i)=B_{t-1}(i)\cdot\left(1+r_{t-1}\right),\quad\forall\,i\in\mathrm{Borrowers}$

The interest rate on the utilized portion of the pool applies to the lenders
as well:

$L_{t}(i)=L_{t}(i)\cdot\left(1+r_{t-1}\,\frac{B_{t-1}}{L_{t-1}}\right),\quad\forall\,i\in\mathrm{Lenders}$

Liquidation $\mathcal{P}$ tracks borrow positions exceeding the liquidation
threshold. A position $i$ is eligible for liquidation if
$LT_{t-1}<\frac{B_{t}(i)}{C_{t}(i)\cdot p_{t}}<1$. Liquidators reduce the
user’s debt by purchasing collateral, restoring the loan-to-value ratio below
$LT_{t-1}$. The debt and collateral after liquidation are updated accordingly.
The minimum liquidation amount that reduces the user’s loan-to-value below
$LT_{t-1}$ is

$\lambda_{t-1}^{i}(p_{t})\coloneqq\max\left\\{0,\frac{B_{t}(i)-LT_{t-1}\cdot
C_{t}(i)\cdot p_{t}}{1-LT_{t-1}(1+LI_{t-1})}\right\\}$

Setting new parameters $\mathcal{P}$ sets new parameters for the next
timeslot: $\\{r_{t},c_{t},LT_{t},LI_{t}\\}$. These parameters determine the
interest rate, maximum loan-to-value, and liquidation parameters for the next
timeslot.

Admitting new users The protocol accepts all new lend and repay requests.
Borrow requests are accepted only if they adhere to the maximum
collateralization factor $c_{t}$ and there is sufficient $\mathcal{A}_{l}$ in
the pool to satisfy the request. Additionally, it processes withdrawal
requests from lenders as long as the withdrawal amount does not exceed the
available $\mathcal{A}_{l}$ in the pool.

###  2.4 User behavior model

In this section, we establish the model that a rational user would use to
interact with the protocol.

Continuum of users We consider a continuum of lenders and borrowers, each
controlling a single unit of demand or supply. In each timeslot, lenders can
deposit or withdraw their unit, and borrowers can borrow, repay, or adjust
their loan-to-value ratio by sending a transaction to the smart contract.

####  2.4.1 Lender

Utility function We assume that a continuum lender with one unit of supply,
planning for the next timeslot, will calculate the following utility function
at time $t$ to decide whether to deposit into the pool or, if already
deposited, to withdraw and invest in another external alternative offering
$r_{o}^{l}$.

$\text{Utility}_{t}^{l}\coloneqq
r_{t}U_{t}-\mathbb{E}\left[\pi_{t}(p_{t+1})\right]-r_{o}^{l}$ (5)

where the expectation is over the price at timeslot $t+1$ price. The first
term in 5 represents the interest earned by the lender on the utilized portion
of their deposit. Although the interest rate is compounded, we approximate it
linearly for simplicity. The second term denotes the normalized defaulted debt
deducted from the lender’s deposit. Finally, we subtract the external interest
rate $r_{o}^{l}$ to account for the lender’s opportunity cost.

Lending dynamics We now describe the dynamics by which lenders add or withdraw
their deposits based on utility. We introduce a new parameter $\eta_{l}$,
which reflects the average elasticity of lenders at time $t$. This value can
change over time (not faster than $T_{m}$) and is unknown to the protocol. We
assume that the relative rate at which lenders deposit or withdraw from the
pool is governed by the following model:

$\displaystyle\frac{L_{t+1}-L_{t}}{L_{t}}$
$\displaystyle=\eta_{l}\cdot\text{Utility}_{t}^{l}+\varepsilon_{t}$
$\displaystyle=\eta_{l}\cdot\left(r_{t}U_{t}-\mathbb{E}[\pi_{t}(p_{t+1})]-r_{o}^{l}\right)+\varepsilon_{t},\qquad\varepsilon_{t}\overset{\text{i.i.d}}{\sim}\mathcal{N}(0,\zeta^{2})$
(6)

The noise term accounts for the behavior of uninformed or less informed users.

####  2.4.2 Borrower

From observing the real lending markets, we identify two types of DeFi
borrowers, financing and leveraged trading borrowers (see Appendix B.2 for
more details).

Financing borrowers The first type borrows an asset to use elsewhere, gaining
value by leveraging it, e.g., for yield farming or real-world purposes. This
group’s value from the borrowed asset is represented as $r_{o}^{b}$, measured
as an interest rate. The utility function of a borrower of this type
controlling one unit of demand, considering the opportunity cost of locked
collateral, is

$\displaystyle\text{Utility}_{t}^{b,1}\coloneqq
r_{o}^{b}-r_{t}+\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$
$\displaystyle-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot LI_{t}$
$\displaystyle+C_{t}(i)\cdot\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]$
(7)

This includes inherent value ($r_{o}^{b}$), interest rate ($-r_{t}$), default
value ($\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$), liquidation cost
($-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot LI_{t}$), and
opportunity cost of locked collateral
$\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]$.

Leveraged trading borrowers The second type aims to take a long position on
$\mathcal{A}_{c}$. They borrow $\frac{1}{p_{t}}$ units of $\mathcal{A}_{c}$
from an external provider $\mathcal{Z}$, add more collateral to meet the over-
collateralization requirement $c_{t}$ , and borrow one unit of
$\mathcal{A}_{l}$ from $\mathcal{P}$, then exchange it for $\mathcal{A}_{c}$
to repay $\mathcal{Z}$. This borrowing strategy is studies in details in [37].
Their utility function is:

$\text{Utility}_{t}^{b,2}=-r_{t}+\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot
LI_{t}+\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]$ (8)

This includes interest rate ($-r_{t}$), default value
($\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$), liquidation cost
($-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot LI_{t}$), and gain
from a price change of the $\frac{1}{p_{t}}$ investment in $\mathcal{A}_{c}$
which was possible through interacting with $\mathcal{P}$
i.e.,($\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]$. Refer to Appendix
B.2 for more details.

Borrowing dynamics Assuming $\alpha$ fraction of borrowers are type 1 and the
rest type 2, the rate of borrowing or repaying is a linear function of
borrower’s elasticity $\eta_{b}$ and their average utility plus noise:

$\displaystyle\frac{B_{t+1}-B_{t}}{B_{t}}$
$\displaystyle=\eta_{b}\cdot\big{(}\alpha\cdot\text{Utility}_{t}^{b,1}+(1-\alpha)\cdot\text{Utility}_{t}^{b,2}\big{)}+\varepsilon_{t}$
$\displaystyle=\eta_{b}\cdot\bigg{(}\alpha\cdot
r_{o}^{b}-r_{t}+\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot
LI_{t}$ $\displaystyle+\alpha\cdot
C_{t}(i)\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]+(1-\alpha)\cdot\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]\bigg{)}+\varepsilon_{t},$
(9)

where $\varepsilon_{t}\overset{\text{i.i.d}}{\sim}\mathcal{N}(0,\zeta^{2})$.

Collateralization strategy Throughout this paper, we assume that $\mathcal{P}$
efficiently sets the buffer between the collateral factor and the liquidation
threshold to ensure that the expected liquidation,
$\mathbb{E}[\lambda_{t}^{i}(p_{t+1})]$, for a borrower $i$ who maintains the
posted collateral factor, is negligible. This assumption differs from the
current borrowing and lending platforms, which experience significant
liquidations even among borrowers who adhere to the posted collateral factor.
However, we believe that a competent borrowing and lending protocol should set
risk parameters to minimize this risk. In Section 3.2, we explain how we
determine the liquidation threshold and collateral factor to ensure that the
expected liquidations remain negligible. Moreover, throughout this paper, we
assume that the liquidation incentive, $LI_{t}$, is set sufficiently high by
the protocol to encourage the borrowers to maintain the collateral factor,
$c_{t}$, and avoid liquidations.

######  Lemma 2.1 (Maximum loan-to-value adoption).

Consider the following conditions:

  * •

The collateral factor, $c_{t}$, and the liquidation threshold, $LT_{t}$, are
chosen such that for a given $LT_{t}$, $c_{t}$ is the maximum collateral
factor that ensures the expected liquidation, $\mathbb{E}[\lambda_{t}^{i}]$,
is approximately zero for a user $i$ who maintains $c_{t}$.

  * •

The liquidation incentive, $LI_{t}$, is set high enough to incentivize
rational borrowers to avoid liquidation by ensuring that
$\frac{B_{t}(i)}{C_{t}(i)p_{t}}\leq c_{t}$.

Then rational borrowers will adopt the maximum loan to value allowed by the
protocol i.e., $c_{t}$.

Hence from now on, we assume that $\mathbb{E}[\lambda_{t}^{i}]$ for a rational
continuum borrower is negligible and for ease of notation, we denote it by
$\lambda(c_{t},LT_{t})$.

####  2.4.3 Liquidator

We assume that the liquidation incentive $LI$ is set at a level that
consistently incentivizes liquidators, ensuring their prompt engagement and
immediate liquidation up to the limit allowed by $\mathcal{P}$. Additionally,
since we use an exogenous price model for collateral, phenomena like
liquidation spirals studied in previous works [27] are not considered in our
analysis.

###  2.5 Equilibrium analysis

In this section, we will formally define the concept of equilibrium in the
borrow-lending framework we established. And we will analytically identify the
set of equilibria of this market when users follow the behaviour outlined in
2.4.

######  Definition 2.2 (Market equilibrium).

A lending pool governed by protocol $\mathcal{P}$ parameterized by
$\\{r_{t},c_{t},LT_{t},LI_{t}\\}$, and lender’s and borrower’s behavior
respectively governed by 2.4.1, and 2.4.2 is in equilibrium if and only if:

$\mathbb{E}\left[\frac{B_{t+1}-B_{t}}{B_{t}}\right]=0\quad\text{and}\quad\mathbb{E}\left[\frac{L_{t+1}-L_{t}}{L_{t}}\right]=0$

where the expectation is over the noise term in the user behavior model.

######  Lemma 2.3 (Simplified default and price change terms ).

In the presence of rational continuum lenders and rational continuum borrowers
who follow collateral factor $c_{t}$ (due to Lemma 2.1) we have:

$\displaystyle\pi{}(c_{t})$
$\displaystyle\coloneqq\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$
$\displaystyle=\Phi\left(\frac{\log(c_{t})-\mu}{\sigma}\right)-\frac{\exp{(\frac{\sigma^{2}}{2}+\mu)}}{c_{t}}\cdot\Phi\left(\frac{-\mu+\log(c_{t})-\sigma^{2}}{\sigma}\right)$
(10) $\mathbb{E}\left[\pi_{t}(p_{t+1})\right]=U_{t}\pi(c_{t})$ (11)
$C_{t}(i)\mathbb{E}\left[\mathbbm{1}_{p_{t+T_{u}}-p_{t}<0}(p_{t+T_{u}}-p_{t})\right]=\frac{1}{c_{t}}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)$
(12)
$\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]=e^{\mu+\frac{\sigma^{2}}{2}}-1$

Where $\phi(.)$ and $\Phi(.)$ denote the PDF and CDF, respectively, of the
standard normal distribution.

Throughout the rest of the paper, we denote the expected default for one unit
of debt by $\pi{}(c_{t})$. Conceptually, Lemma 2.3 implies that if the pool’s
loan-to-value ratio is maintained close to $c_{t}$ in each timeslot, the
probability of default remains memoryless. This is due to the Brownian motion
of price, where the price ratio between consecutive timeslots follows a
stationary distribution. Therefore, the probability that the next timeslot’s
price falls below the default threshold is stationary and memoryless, changing
only when the price distribution itself changes.

######  Theorem 2.4.

Let the lender behavior be described by Equation 2.4.1, the borrower behavior
by Equation 2.4.2 (for $\eta_{b}>0$), and the assumptions of Lemma 2.1 hold. A
protocol with parameters $\\{r_{t},c_{t},LI_{t},LT_{t}\\}$, achieves a non-
trivial equilibrium if and only if $r_{t}=r^{*}$:

$\displaystyle r^{*}$
$\displaystyle=\alpha\,r_{o}^{b}+\pi(c_{t})+\frac{\alpha}{c_{t}}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)+(1-\alpha)\left(e^{\mu+\frac{\sigma^{2}}{2}}-1\right)$
(13)

Furthermore, if $\eta_{l}>0$, then the unique equilibrium utilization is:

$U^{*}=\begin{cases}\frac{r_{o}^{l}}{r^{*}-\pi(c_{t})}&\text{if
}r^{*}>\pi(c_{t})\\\ 1&\text{otherwise}\end{cases}$ (14)

Equilibrium dynamics In order to achieve the equilibrium point, The protocol
first should find the equilibrium interest rate, $r^{*}$, and set
$r_{t}=r^{*}$ to prevent borrowers from leaving or joining the system. Once
$r^{*}$ is set, if the utilization $U_{t}$ is above $U^{*}$, lenders’ utility
is positive, so they keep lending until $U_{t}$ reaches $U^{*}$, stabilizing
the system. Conversely, if $U_{t}$ is below $U^{*}$, lenders’ utility is
negative, causing them to withdraw until $U_{t}=U^{*}$. At this point, lenders
are indifferent between the pool and external competitors and remain fixed.
The equilibrium utilization is $U^{*}=1$ if, regardless of utilization,
lenders’ utility under $r_{t}=r^{*}$ remains non-positive. Consequently, they
withdraw fully, yielding $U^{*}=1$, and they remain trapped in an unfavorable
equilibrium where they prefer external rates but since their fund is being
borrowed, they cannot leave the system.

###  2.6 Protocol objectives and evaluation metrics

In this section, we define three key metrics to evaluate a borrow-lending
protocol. The protocols considered follow the behavior outlined in 2.3. Each
protocol selects a deterministic or randomized interest rate function
$r_{t}:\mathcal{H}_{1}^{t}\to\mathbb{R}^{+}$, a collateral factor function
$c_{t}:\mathcal{H}_{1}^{t}\to[0,1]$ and a liquidation threshold function
$LI_{t}:\mathcal{H}_{1}^{t}\to[0,1]$ mapping the pool’s history to an interest
rate, a collateral factor and a liquidation threshold.

#### Rate of equilibrium convergence

The importance of stability Achieving market equilibrium is crucial for any
DeFi application, as equilibrium points represent the market’s most
competitive state. At equilibrium, no participant is overpaid or underpaid,
ensuring all users are equally satisfied with $\mathcal{P}$ as with any
external alternative. In two-sided markets like borrow-lending, the time to
achieve stability can disproportionately benefit one side. Setting interest
rates below what borrowers are willing to pay results in lenders receiving
less than in a competitive market. Conversely, if interest rates exceed the
equilibrium rate, borrowers pay more than in a stable market. The more elastic
user benefits at the expense of the less elastic user, who incurs an
impermanent loss.

Adapting to market changes Adapting to market changes allows the protocol to
stabilize the pool when user behavior or price volatility changes. As these
parameters change over time, the protocol must respond dynamically to maintain
system stability within a reasonable timeframe. In the borrow-lending market
framework, each time user behavior parameters (e.g.,
$r_{o}^{b},r_{o}^{l},\alpha$) or price volatility ($\sigma$) change, the
market stabilizes at a new $r^{*}$ (refer to Theorem 2.4). One objective of
$\mathcal{P}$ is to rapidly identify and set this new equilibrium rate. We
formalize this concept as the rate of convergence, using it as a metric to
evaluate our protocol against non-learning baselines.

######  Definition 2.5 (Rate of equilibrium convergence).

Consider a stable borrow-lending pool with the interest rate $r_{t}=r^{*}$,
where $r^{*}$ is the equilibrium interest rate determined by Equation C.3. At
time $t+1$, user behavior models adapt to new parameters
$\\{\bar{\eta_{l}},\bar{r}_{o}^{l},\bar{\eta_{b}},\bar{r}_{o}^{b},\alpha\\}$,
and price volatility changes to $\bar{\sigma}$. Let $r_{\tau}$ represent the
interest rate set by $\mathcal{P}$ at time $\tau>t$, and let $\bar{r}^{*}$
denote the new equilibrium interest rate for the updated market parameters. We
define the _rate of equilibrium convergence_ of $\mathcal{P}$, denoted by
$\mathcal{R}_{\mathcal{P}}(\delta,\tau)$, as the infimum of functions
$f(\delta,\tau)$, such that there exists some $\mathtt{T}(\delta)$ for which,
with probability $1-\delta$,

$|r_{\tau}-\bar{r}^{*}|<f(\delta,\tau),\quad\forall\,\tau>\mathtt{T}(\delta),$

for any initial and secondary set of parameters in the user model and price
model. Probabilities are calculated on the randomness of the protocol and the
noise in the user behavior model.

#### Equilibrium Optimality Index

Protocol long-term objectives Any Defi borrow-lending market aims to meet
specific long-term objectives. For instance, the pool should maintain
utilization at an optimal level; Because low utilization reduces capital
efficiency, requiring the protocol to pay higher interest rates to lenders,
and high utilization can make it difficult for lenders to withdraw and
borrowers to secure loans. Moreover, expected defaults and liquidations are
risk metrics that the protocol aims to control. These objectives operate on a
different timescale than the interest rate adjustments discussed in the
convergence rate. For instance, we care about the average utilization or
expected default over a long period rather than their local values in each
timeslot. To address this, we define a metric called optimality index, which
evaluates the desirability of the system’s equilibriums during the timeslots
when the pool has reached its equilibrium, denoting the set of these timeslots
by $\mathcal{T}_{e}$.

######  Definition 2.6 (Optimality Index).

The Optimality Index of a protocol, denoted by $OI_{\mathcal{P}}$, is defined
as follows:

$OI_{\mathcal{P}}\coloneqq\frac{1}{|\mathcal{T}_{e}|}\sum_{t\in\mathcal{T}_{e}}\mathbb{E}\left[-(U_{t}-U_{\text{opt}})^{2}-\gamma\,\big{(}U_{t}\,\pi(c_{t})+\lambda(c_{t},LT_{t})\big{)}\right],$
(15)

The expectation is taken over the protocol’s randomness and user behavior.
$U_{\text{opt}}$ and $\lambda$ are constant parameters.

While the first term in the $OI_{\mathcal{P}}$ ensures that utilization is
kept near a desired point, the second term acts as a regularization term,
controlling the expected default and liquidation. Our definition of Optimality
Index evaluates a specific notion of optimality, but it is just one of many
possible definitions. Our protocol design methodology can be applied to other
objective functions beyond Function 15. In this paper, we showcase our ideas
for this specific objective function and discuss how to extend the methodology
to other objectives.

#### Adversarial robustness

Protocols in DeFi are always susceptible to adversarial behavior that can be
used to manipulate an adaptive algorithm to respond in a suboptimal manner.
This behavior is usually observed when some borrower/lender agents interact
with protocols outside of $\mathcal{P}$ in conjunction with $\mathcal{P}$ to
achieve a profit. This can involve oracle manipulations attacks used to run
away with valuable assets while providing worthless collateral, or attacks
that move interest rates in the opposite direction of the equilibrium rates.
We focus on the latter type of adversarial behavior in this work. Moving
interest rates away from equilibrium leads to market inefficiencies. Further,
undue hikes in these rates can be used to trigger unexpected liquidations for
profit.

We thus propose that the susceptibility of $\mathcal{P}$ to adversarial
manipulation should also be measured. To do that, we first assume that a
fraction $\beta$ of the population of lenders/borrowers are adversarial. Thus,
$\mathcal{P}$ will face an adversarial lender/borrower for an approximately
$\beta$ fraction of time slots. In those time slots, the adversary can
manipulate the borrow/lend reserves arbitrarily. Let $T_{\beta}$ denote the
set of time slots that the protocol faces an adversary.

We measure how susceptible a protocol is to adversarial manipulation using the
following metric.

######  Definition 2.7 (Adversarial Susceptibility).

The adversarial susceptibility of a protocol, denoted by $AS_{\mathcal{P}}$,
is defined as follows:

$AS_{\mathcal{P}}\coloneqq\mathbb{E}\left[\sum_{t\in\mathcal{T}_{e}}r_{\mathcal{P}}^{t}-r_{\mathcal{P}|T_{\beta}}^{t}\right].$

The expectation is taken over the protocol’s randomness, user/adversarial
behavior, where $r_{\mathcal{P}}^{t}$ denotes the interest rate recommended by
the protocol and $r_{\mathcal{P}|T_{\beta}}^{t}$ is the same, when the indices
of adversarial actions are known.

Since an adversary can manipulate the protocol arbitrarily, the above measure
signifies how adept the protocol is in weeding out historical data that has
been manipulated, thus ensuring a cleaner convergence to the true interest
rate equilibrium.

###  2.7 Baseline

For the baseline, we consider protocols akin to Compound, which utilize a
piecewise linear interest rate curve to ensure stability. These protocols
dynamically adjust interest rates at each block according to the model:

$R_{t}=\begin{cases}R_{0}+\frac{U_{t}}{U_{\text{opt}}}R_{\text{slope1}},&\text{if
}U_{t}\leq U_{\text{opt}}\\\
R_{0}+R_{\text{slope1}}+\left(\frac{U_{t}-U_{\text{opt}}}{1-U_{\text{opt}}}\right)R_{\text{slope2}},&\text{if
}U_{t}>U_{\text{opt}}\end{cases}$

In contrast to our proposed approach, these platforms generally set collateral
factors and other market parameters through offline simulations that attempt
to forecast near-future market conditions. Parameters are selected based on
simulation outcomes and are subject to decentralized governance voting. Since
this phase happens in an offline and opaque manner by centralized companies,
we cannot compare this aspect of their protocol with ours.

Limited user elasticity assumption Due to the piecewise linear nature of the
interest rate as a function of utilization, these protocols achieve market
stability only when either borrowers or lenders, but not both, exhibit
elasticity [21]. To see why this is the case, note that according to Theorem
2.4, if borrowers are elastic ($\eta_{b}>0$), the equilibrium interest rate
can be uniquely determined. And if lenders are elastic too, the equilibrium
utilization is determined by Equation 14 which is not a linear function of
$r^{*}$, hence a piecewise linear interest rate curve cannot satisfy the
equilibrium conditions if both sides are elastic. Traditional DeFi platforms
typically monitor the pool to identify the more elastic side of the market
(usually borrowers) and design the curve accordingly.

##  3 Fast-slow thinker protocol

In this section, we outline a design for the interest rate and collateral
factor function of $\mathcal{P}$ that aims to achieve both the best possible
convergence rate and the optimal optimality index. The protocol has the
following two components.

Interest rate online controller A least squares estimator detects market
disruptions that lead to instability and learns the equilibrium interest rate
from borrowers’ reactions, setting it agilely.

Risk parameters planner The long-term parameter planner consists of three
parts: 1) A user behavior parameter estimator, which estimates the user
behaviour model parameters that are required to optimize the optimality index.
2) An optimization module, which selects the optimal collateral factor to
maximize optimality index, assuming negligible expected liquidation. 3) A
liquidation threshold determination module, which sets the liquidation
threshold as a function of the collateral factor to ensure zero expected
liquidation.

The canonical scenario we use to evaluate our protocol is the following: at
the beginning of the timeslot $t$, one or some of the market parameters (e.g.,
$\sigma,r_{o}^{l},r_{o}^{b},\alpha$) change to a new level and remain constant
for a period $T_{m}$. The protocol must adapt to these new parameters by
setting the equilibrium interest rate and the optimal collateral factor that
maximizes the optimality index when the pool reaches equilibrium. Refer to
Figure 1 for a visual representation of the protocol and its interaction with
the pool.

###  3.1 Online interest rate controller

Linear regression We model the problem of finding $r^{*}$ using the linear
regression method, where the borrow/repay rate depends on the difference
$r_{t}-r^{*}$ (motivating factor for borrowers) and $\eta_{b}$ (borrower
elasticity), with an added noise component; And use this model to estimate
$r^{*}$ adaptively. Here is the linear regression problem formulation:

$\displaystyle\frac{B_{t+1}-B_{t}}{B_{t}}$
$\displaystyle=\eta_{b}\cdot\bigg{(}\alpha\,r_{o}^{b}-\,r_{t}+\pi(c_{t})+\frac{\alpha}{c_{t}}\,\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(\frac{p_{t+1}-p_{t}}{p_{t}})\right]+$
$\displaystyle(1-\alpha)\cdot\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]\bigg{)}$
$\displaystyle\overset{\ref{eq:equilibrium-rate}}{=}\eta_{b}(r^{*}-r_{t})$
$\mathbf{\Delta
B}=\mathbf{P}_{b}^{t}\cdot\mathbf{\Theta}_{b}+\bm{\varepsilon}$ (16)

where:

  * •

$\mathbf{\Delta
B}=\left[\frac{B_{1}-B_{0}}{B_{0}},\frac{B_{2}-B_{1}}{B_{1}},\ldots,\frac{B_{t+1}-B_{t}}{B_{t}}\right]^{T}$
is the vector of normalized changes.

  * •

$\mathbf{P}_{b}^{t}$ is the matrix of pool variables that affect borrower’s
behaviour:

$(\mathbf{P}_{b}^{t})^{\top}=\begin{bmatrix}1&1&\cdots&1\\\
r_{0}&r_{1}&\cdots&r_{t}\end{bmatrix}$

  * •

$\mathbf{\Theta}_{b}=[\eta_{b}\,r^{*}\;,-\eta_{b}]^{T}$ is the parameter
vector

  * •

$\bm{\varepsilon}=[\varepsilon_{0},\varepsilon_{1},\ldots,\varepsilon_{t}]^{T}$
is the noise vector.

The interest rate controller algorithm, outlined in 1, activates when $\Delta
B_{t}$ exceeds a threshold $\delta$, indicating $r_{t}\neq r^{*}$. The
algorithm collects $\mathbf{\Delta B}$ and $\mathbf{P}_{b}^{t}$ to estimate
$\mathbf{\hat{\Theta}}_{b}$, setting $r_{t}$ as the estimated $\hat{r}^{*}$
according to
$\hat{r}^{*}=-\frac{\mathbf{\hat{\Theta}}_{b}(0)}{\mathbf{\hat{\Theta}}_{b}(1)}$.

Exploration noise We cannot use vanilla LSE in this setting and simply output
$r_{t}=\hat{r}^{*}=-\frac{\mathbf{\hat{\Theta}}_{b}(0)}{\mathbf{\hat{\Theta}}_{b}(1)}$
because feeding back the estimated $\hat{r}^{*}$ to the protocol may cause the
rows of the $\mathbf{P}_{b}{}$ matrix to become very close to each other. This
happens when the estimator outputs an $r_{t}$ that has been seen before,
leading to redundant data points. Consequently, the theoretical guarantee of
LSE to converge to the correct $\mathbf{\Theta}_{b}^{*}$ as the number of data
points increases is impaired. To mitigate this problem, with a small
probability, we sample a random interest rate. Finally, after running for a
few iterations and accumulating a sufficiently large number of samples, the
estimator stops and outputs the estimated $r^{*}$.

####  3.1.1 Theoretical analysis

######  Theorem 3.1 (LSE convergence rate).

Assuming $\eta_{b}>0$, the interest rate controller described in Algorithm 1
with stopping time $\tau$ (taking $\tau$ samples), satisfies the following:

$\mathcal{R}_{\mathcal{P}}(\delta,\tau)\sim\mathcal{O}\left(\frac{\log{\frac{1}{\delta}}}{\sqrt{\tau}}\right).$

Moreover, if $\eta_{b}$ is known:
$\mathbb{E}\left[r_{\tau}\right]=r^{*},\;\forall\tau$

######  Theorem 3.2 (Baseline convergence rate).

Under a piece-wise linear interest rate function

  * •

In the presence of elastic borrowers and inelastic lenders, we have:

$\displaystyle\mathbb{E}\left[r_{\tau}\right]=r^{*}+D(1-K\,\eta_{b})^{\tau},\qquad
0<1-K\,\eta_{b}<1$ $\displaystyle\mathcal{R}_{\mathcal{P}}(\delta,\tau)\sim
o\left(\frac{1}{\sqrt{\delta}}\right).$

where $K,D$ are constants determined from the specifications of the interest
rate curve.

  * •

If lenders are elastic as well, the protocol never stabilizes with rate
$r^{*}$.

Our interest rate controller provides an unbiased estimation of the
equilibrium interest rate, with the estimation variance decreasing over time.
In contrast, the baseline algorithm is a biased estimator of the equilibrium
rate, becoming unbiased only as $\tau\to\infty$; And the rate of convergence
of the average error to zero is proportional to $\eta_{b}$, as the baseline
protocol relies heavily on user actions to adjust the rate toward equilibrium
rather than actively learning from user behavior. Additionally, the baseline
algorithm maintains a constant error relative to the equilibrium rate due to
the noise in user behavior and its inability to filter out this noise.

1:Initialize: $t\leftarrow 0$, $\delta\leftarrow$ stability threshold,
$t_{\text{sleep}}\leftarrow$ sleep time, $\nu$ exploration probability

2:while True do

3: if $\frac{B_{t}-B_{t-1}}{B_{t-1}}<\delta$ then

4: Sleep for $t_{\text{sleep}}$

5: Reset matrices $\mathbf{\Delta B}$ and $\mathbf{P}_{b}$

6: else

7: Add the new row $[1,r_{t-1}]$ to $\mathbf{P}_{b}^{t-2}$ to construct
$\mathbf{P}_{b}^{t-1}$ and

8: Add the new column $[\frac{B_{t}-B_{t-1}}{B_{t-1}}]$ to $\mathbf{\Delta B}$

9: Perform least squares estimation to find
$\mathbf{\hat{\Theta}}_{b}\leftarrow({(\mathbf{P}_{b}^{t-1})}^{T}\mathbf{P}_{b}^{t-1})^{-1}\,(\mathbf{P}_{b}^{t-1})^{T}\,\mathbf{\Delta
B}$

10: Parse $\mathbf{\hat{\Theta}}_{b}$ as
$[\hat{\eta_{b}}\hat{r}^{*},-\hat{\eta_{b}}]$ and extract $\hat{r}^{*}$ and
set $r_{t}=\hat{r}^{*}$

11: With probability $\nu$, choose a random
$r_{t}\in[r_{\text{min}},r_{\text{max}}]$

12: end if

13: $t\leftarrow t+1$

14:end while

15:end algorithm

Algorithm 1 Interest rate controller, utilizing a least squares optimization
approach

###  3.2 Risk parameters planner

Determining the liquidation threshold First, we examine the conditions that
ensure zero expected liquidation. These conditions provide the planner with
the necessary bounds for setting the liquidation threshold.

######  Lemma 3.3.

The expected liquidation incurred at time $t+1$, given that the loan-to-value
ratio at time $t$ is $c_{t}$, can be expressed as

$\displaystyle\lambda(c_{t},LT_{t})$ $\displaystyle\coloneqq
E[\lambda_{t}^{i}(p_{t+1})]$
$\displaystyle=\frac{1}{1-LT_{t}}\left(\Phi\left(\frac{\ln\left(\frac{c_{t}}{LT_{t}}\right)-\mu+\sigma^{2}}{\sigma}\right)-\frac{LT_{t}}{c_{t}}e^{\mu+\sigma^{2}}\Phi\left(\frac{\ln\left(\frac{c_{t}}{LT_{t}}\right)-\mu-\sigma^{2}}{\sigma}\right)\right)$

where $\Phi$ denotes the cumulative distribution function of the standard
normal distribution.

To maintain the expected liquidation below a small threshold (nearly zero),
this lemma provides bounds on $LT_{t}$ and $\frac{c_{t}}{LT_{t}}$. These
bounds are used by the planner to set $LT_{t}$ and constrain $c_{t}$. With
negligible expected liquidation, the optimality index is simplified to include
only the utilization error and the default term.

######  Corollary 3.4.

Given a fixed set of parameters $r_{o}^{l},r_{o}^{b},\sigma,\mu$ and assuming
that $\lambda(LT_{t},c_{t})\approx 0$, the maximization problem of
$OI_{\mathcal{P}}$ with respect to $c_{t}$ can be formulated as follows:

$\displaystyle\max_{c_{t}}OI_{\mathcal{P}}$
$\displaystyle=\min_{c_{t}}\left(\frac{r_{o}^{l}}{b+\frac{a}{c_{t}}}-U_{\text{opt}}\right)^{2}+\gamma\frac{r_{o}^{l}}{b+\frac{a}{c_{t}}}\Phi\left(\frac{\log(c_{t})-\mu}{\sigma}\right)$
(17)
$\displaystyle\quad-\gamma\frac{r_{o}^{l}}{b+\frac{a}{c_{t}}}\frac{\exp\left(\frac{\sigma^{2}}{2}+\mu\right)}{c_{t}}\cdot\Phi\left(\frac{-\mu+\log(c_{t})-\sigma^{2}}{\sigma}\right)$
(18)

where
$a\coloneqq\alpha\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)$
and $b\coloneqq\alpha
r_{o}^{b}+(1-\alpha)\left(e^{\mu+\frac{\sigma^{2}}{2}}-1\right)$.

We can derive this corollary by substituting the default, expected price fall,
and price change terms from Lemma 2.3 into the definition of optimality index
stated in Definition 2.6.

Figure 1: Protocol Overview. The interest rate controller observes borrower
actions to estimate $r^{*}$ and set $r_{t}=\hat{r}^{*}$. The collateral factor
planner includes a parameter estimator and an optimizer: the estimator finds
$r_{o}^{l}$, $r_{o}^{b}$, and $\sigma$, while the optimizer uses these
estimates to determine the optimal collateral factor for the market.

Estimator and optimizer construction The estimator module, described in
Algorithm 2, uses a least squares estimator to analyze user behavior. It
integrates outputs from the interest rate controller to determine the
parameters $r_{o}^{l}$ and $r_{o}^{b}$. Additionally, it learns the empirical
price volatility $\sigma$ and drift $\mu$ from the recent price history. The
optimizer component, detailed in Algorithm 3, utilizes these parameters to
tackle the optimization problem presented in Corollary 3.4 and output the
optimal collateral factor. To construct the estimator submodule, we model the
lender’s behavior using a linear regression approach, analogous to that of the
borrower’s behavior.This relationship is formulated as follows:

$\displaystyle\frac{L_{t+1}-L_{t}}{L_{t}}$
$\displaystyle=\eta_{l}\cdot\left(r_{t}U_{t}-U_{t}\,\pi{}(c_{t})-r_{o}^{l}\right)+\varepsilon_{t}$
(19)

where $\pi{}(c_{t})$ is defined as per the simplifications in Lemma 2.3. The
linear regression model for this behavior is represented by:

$\mathbf{\Delta L}=\mathbf{P}_{l}\cdot\mathbf{\Theta}_{l}+\bm{\varepsilon},$
(20)

with:

  * •

$\mathbf{\Delta
L}=\left[\frac{L_{1}-L_{0}}{L_{0}},\frac{L_{2}-L_{1}}{L_{1}},\ldots,\frac{L_{t+1}-L_{t}}{L_{t}}\right]^{T}$
capturing the normalized changes in lenders’ supply.

  * •

$\mathbf{P}_{l}=\begin{bmatrix}1&-U_{0}\,\pi(c_{0})+r_{0}U_{0}\\\
1&-U_{1}\,\pi(c_{1})+r_{1}U_{1}\\\ \vdots&\vdots\\\
1&-U_{t}\,\pi(c_{t})+r_{t}U_{t}\end{bmatrix}$ as the matrix of pool variables
at each time step.

  * •

$\mathbf{\Theta}_{l}=[-\eta_{l}\,r_{o}^{l},\eta_{l}]^{T}$ representing the
parameter vector.

  * •

$\bm{\varepsilon}=[\varepsilon_{0},\varepsilon_{1},\ldots,\varepsilon_{t}]^{T}$
as the vector of noise terms.

Refer to Algorithm 2 and 3 to find a detailed description of the planner.

Algorithm 2 $\hat{r}_{o}^{l},\hat{r}_{o}^{b}$ \- Estimator, auxiliary to the
optimizer procedure

1:Initialize: $t\leftarrow 1$,
$\mathbf{\hat{\Theta}}_{l}^{0}\leftarrow\mathbf{0}$, and read
$L_{0},U_{0},r_{0},c$ from the pool, $\delta_{l}\leftarrow$ stability
threshold

2:Initialize: $t_{\text{sleep}}\leftarrow$ sleep time,
$\delta_{\theta}\leftarrow$ least square convergence threshold,
$T_{\text{optimizer}}\leftarrow$ the minimum time interval between successive
executions of the optimizer. $\alpha\leftarrow$ fraction of first type
borrowers

3:while True do

4: if $\frac{L_{t}-L_{t-1}}{L_{t-1}}<\delta_{l}$ then

5: Reset $\mathbf{\Delta L},\mathbf{P}_{l}$

6: Sleep for $t_{\text{sleep}}$

7: else

8: Calculate $\sigma,\mu$ empirically from the recent price history and use
them to calculate $\pi{}(c_{t})$

9: Add the new row $[1,-U_{t-1}\,\pi(c_{t})+r_{t-1}U_{t-1}]$ to
$\mathbf{P}_{l}$ and $[\frac{L_{t}-L_{t-1}}{L_{t-1}}]$ to $\mathbf{\Delta L}$

10: Perform least squares estimation to find
$\mathbf{\hat{\Theta}}_{l}^{t}\leftarrow({\mathbf{P}_{l}}^{T}\mathbf{P}_{l})^{-1}\,\mathbf{P}_{l}^{T}\,\mathbf{\Delta
L}$

11: Parse $\mathbf{\hat{\Theta}}_{l}^{t}$ as
$[-\hat{\eta_{l}}\,\hat{r}_{o}^{l}\,,\,\hat{\eta_{l}}]^{T}$ and extract
$\hat{r}_{o}^{l}$

12: Read the latest $\hat{r}^{*}$ from Algorithm 1, and extract
$\hat{r}_{o}^{b}$ as follows:

13:
$\alpha\,\hat{r}_{o}^{b}\leftarrow\hat{r}^{*}-{\pi}(c_{t})-\frac{\alpha}{c_{t}}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)-(1-\alpha)\left(e^{\mu+\frac{\sigma^{2}}{2}}-1\right)$

14: if
$|\mathbf{\hat{\Theta}}_{l}^{t}-\mathbf{\hat{\Theta}}_{l}^{t-1}|<\delta_{\theta}$
then

15: $c\leftarrow$ Optimizer($\hat{r}_{o}^{l},\hat{r}_{o}^{b},\sigma$)

16: Reset $\mathbf{\Delta L},\mathbf{P}_{l}$

17: sleep for $T_{\text{optimizer}}$

18: end if

19: end if

20: $t\leftarrow t+1$

21:end while

22:end algorithm

Algorithm 3 Optimizer module

1:procedure Optimizer($\hat{r}_{o}^{l},\hat{r}_{o}^{b},\sigma$)

2: Initialize: $\alpha\leftarrow$ fraction of first type borrowers,
$U_{\text{opt}}\leftarrow$ desired utilization level, initial guess for
collateral factor $c(0)\overset{\text{U}}{\sim}[0,1]$, $\gamma\leftarrow$
default regularization factor, $\kappa\leftarrow$ learning rate, $i\leftarrow
0$ the gradient descent iterator, $\delta\leftarrow$ gradient descent stop
theshold.

3: Set $a=\alpha\left(\exp\left(\mu-\frac{\sigma^{2}}{2}\right)-1\right)$ and
$b=\alpha\,\hat{r}_{o}^{b}+(1-\alpha)\left(\exp\left(\mu+\frac{\sigma^{2}}{2}\right)-1\right)$

4:
$\Psi(c)\coloneqq\left(\left(\frac{\hat{r}_{o}^{l}}{b+\frac{a}{c}}-U_{\text{opt}}\right)^{2}+\gamma\,\frac{\hat{r}_{o}^{l}}{b+\frac{a}{c}}\,\Phi\left(\frac{\log(c)-\mu}{\sigma}\right)-\lambda\frac{r_{o}^{l}}{b+\frac{a}{c}}\frac{\exp{(\frac{\sigma^{2}}{2}+\mu)}}{c}\cdot\Phi\left(\frac{-\mu+\log(c)-\sigma^{2}}{\sigma}\right)\right)$

5: while $|\Psi\left(c(i)\right)-\Psi\left(c(i-1)\right)|>\delta$ do

6: $i\leftarrow i+1$

7: $c(i)\leftarrow c({i-1})-\kappa\,\frac{d\,\Psi(c)}{d\,c}|_{c=c(i-1)}$

8: end while

9: return $c(i)$

10:end procedure

###  3.3 Adversarial Robustness

In this section, we employ a gradient descent-based approach to perform robust
linear regression, adapting the Torrent-GD method from the robust regression
literature [14]. This method leverages the resilience of gradient descent to
sparse corruptions and is highly efficient for large datasets, and helps us
get an improved short-term algorithm for optimizing Adversarial
Susceptibility.

Algorithm description The Torrent-GD modification to Algorithm 1 proceeds by
updating the regression coefficients iteratively, reducing the influence of
corrupt data points effectively. The update rule for the regression
coefficients $\mathbf{\hat{\Theta}}_{b}$ at each iteration $t$ is given by:

$\mathbf{\hat{\Theta}}_{b}(t+1)=\mathbf{\hat{\Theta}}_{b}(t)-\kappa\nabla
L_{S}(\mathbf{\hat{\Theta}}_{b}(t)),$ (21)

where $\kappa$ is the learning rate and $\nabla
L_{S}(\mathbf{\hat{\Theta}}_{b}(t))$ represents the gradient of the loss
function computed only over the subset of data points $S$ believed to be
uncorrupted. This subset is dynamically determined in each iteration based on
the residual errors.

Gradient calculation The gradient of the loss function with respect to the
regression coefficients is computed as:

$\nabla
L_{S}(w)=(\mathbf{P}_{b}{}^{S})^{T}(\mathbf{P}_{b}{})^{S}\mathbf{\hat{\Theta}}_{b}-\mathbf{\Delta
B}_{S},$ (22)

where $\mathbf{P}_{b}{}^{S}$ and $\mathbf{\Delta B}_{S}$ are the features and
responses of the uncorrupted subset, respectively.

Active set update The active set $S$, which includes indices of the data
points assumed to be uncorrupted, is updated using a hard thresholding
operator that selects the points with the smallest residuals:

$S^{(t+1)}=\text{HT}\left(r^{(t)},k\right),$ (23)

where $r^{(t)}=\mathbf{\Delta B}-\mathbf{P}_{b}\mathbf{\hat{\Theta}}_{b}(t)$
represents the residuals at iteration $t$, and $k$ is a threshold parameter
controlling the number of points included in $S$, and the hard thresholding
operator HT for a vector $v\in\mathbb{R}^{n}$ and a threshold $\tau$ is
defined as follows:

$\text{HT}(v_{i},\tau)=\begin{cases}v_{i}&\text{if }|v_{i}|\geq\tau,\\\
0&\text{otherwise}.\end{cases}$

This operation retains only the components of $v$ that are greater than or
equal to the threshold $\tau$ in absolute value, effectively zeroing out
smaller coefficients.

Convergence guarantees The convergence of Torrent-GD is guaranteed under
conditions that the noise and corruptions are sparse [14]. The algorithm can
tolerate arbitrary adversarial corruptions as long as $\beta<50\%$.

###  3.4 Blockchain implementation

To implement this protocol on a blockchain, we can utilize an optimistic
Rollup solution like Arbitrum or Optimism. The core idea behind these Rollups
is that the computation is performed off-chain by a Rollup validator. Only the
state update data is posted on the blockchain, allowing challengers to
validate the state update with the list of user transactions and challenge the
validators in case of discrepancies. Therefore, in an optimistic scenario, no
computation is performed on-chain.

Computational overhead Our online algorithm and the parameter estimator
modules each have a computational complexity of $\mathcal{O}(W)$, where $W$ is
the sliding window used to collect and retain data for estimation. In
practice, using $W\approx 50$ was sufficient in our implementation when the
user’s elasticity is not awfully low (An elasticity of approximately $10$ is
sufficient when the noise standard deviation does not exceed $1$). The
optimizer module, in general, can be computationally infeasible since its
objective function is not necessarily convex. However, since the range of
possible collateral factors is limited, we can discretize the possible values
into approximately 100 levels and find the optimal collateral factor through
brute force. The calculation of the objective function itself is not
computationally intensive.
Gas fee estimation Even the Roll-up solution might necessitate running the
computation on-chain in case of a dispute, therefore we need to estimate the
on-chain computation cost. To estimate the gas cost for updating the
protocol’s slow and fast parts, we consider the least squares estimator (LSE)
update of Algorithm 1 and 2. This update requires approximately $12W$
multiplications and $10W$ additions, where $W$ is the length of the history
window. Given the gas costs (5 gas per multiplication and 3 gas per addition
based on [20]), for $W=50$, we require $4500$ gas for multiplications and
additions. Additionally, storing new rows of $\mathbf{P}_{b}$ and
$\mathbf{\Delta B}$ costs $20,000$ gas per 32-byte storage, totaling $40,000$
gas. Thus, the overall gas needed for the LSE update and storing new rows is
$44,500$ gas. The slow planner additionally needs to store a table of the
optimality index values for different collateral factors and volatilities.
Discretizing each into 100 and 10 values respectively, the storage cost for
this table is $20,000\times 1000=20,000,000$ gas. Additionally, storing a
table of the CDF of Gaussian variables to calculate expected defaults and
liquidations requires $20,000\times 100=2,000,000$ gas for a reasonable
discretization with $100$ points. While more opcodes are involved in each
interest rate and collateral factor update, they mainly consist of single
arithmetic operations or multiple data storage, making the cost manageable.

###  3.5 Limitations

User behaviour model We build upon a specific model of lender and borrower
behavior, assuming that no single user controls a significant portion of the
supply or demand. However, prior research has shown that this assumption might
be unrealistic for many current platforms [32, 39]. In these scenarios,
rational user strategies would differ from those assumed in our model. While
our model manages to capture the main factors driving both sides of the market
in borrow-lending platforms, it fails to adapt to markets where a few entities
control the majority of the funds. Furthermore, we assume that liquidators are
always available to liquidate positions when protocols permit. However, real
data indicates that this is not always the case, especially when the
collateral asset lacks liquidity, resulting in considerable slippage when
reselling the collateral [32].

Price distribution Our choice of price model does not necessarily accurately
describe the actual price distribution. However, as long as the price
distribution belongs to a parameterized family of distributions with
parameters that change slowly over time, the protocol can learn risk terms
from user behavior, similar to our designed protocol. However, it may be
challenging to analytically infer the price distribution parameters from user
actions or to analytically relate the price distribution to key risk metrics,
such as expected default or price fall.

Risk neutralily In defining our utility functions, we assume users are risk-
neutral and perceive their utility as the sum of profit minus expected risk,
accurately calculating expectations over the price distribution. However, this
may not be realistic. Our protocol learns the projection of user behavior onto
our specific linear utility function and identifies parameters that best
describe this behavior. For more complex user behavior, neural networks can be
used to learn a vector representation of user behavior end-to-end. These user
representation vectors are then fed to the interest rate controller and
collateral factor planner, which are replaced by Deep Reinforcement Learning
agents. These agents learn the optimal strategy based on feedback from their
reward function. A key challenge is designing reward functions that best meet
the protocol’s needs.

Adversarial robustness The adversarial resistance model we use for the LSE
algorithm may be inadequate for permissionless blockchains. In such
blockchains, any participant, including miners who organize and submit
transactions, can act as adversaries. These adversaries can run the regression
algorithm off-chain with different sets of transactions and find the set and
the order that benefits them the most. Our current notion of adversarial
robustness only protects against adversaries who control less than 50% of the
funds and occasionally send transactions that deviate from the system’s
assumed supply and demand dynamics i.e., producing outlier data points.

Single equilibrium point Our borrower behavior model assumes that there is
always a single, unique interest rate that all borrowers are willing to pay,
and that this equilibrium interest rate is known to all borrowers with some
noise. However, in reality, this assumption may not hold true. Different
groups of borrowers may have varying perceptions of the interest rate they are
willing to pay. As a result, the system could have multiple equilibrium
points, each attracting a different subgroup of borrowers.

##  4 Evaluation

In this section, we test the interest rate controller and collateral factor
planner described in section 3 and demonstrate their robustness to the change
of market and user behaviours, moreover, we compare our interest rate
controller with that of the baseline.

###  4.1 Interest rate controller

Set-up In this experiment, we start a borrow-lending pool with an initial
borrow supply of $7\times 10^{11}$ and an initial lend supply of $10^{12}$.
Both the elasticity of borrowing and lending are set to 50, and the standard
deviation of the borrowed and supply dynamic noise is 0.1. We assume very low
price volatility, as it does not affect the determination of the equilibrium
interest rate in this experiment. Every 100 time slots, we change $r_{o}^{b}$
and allow the interest rate controller to adjust to the new equilibrium
interest rate based on borrowers’ behavior. During the exploration phases, the
interest rate is randomly selected between $r_{min}=1$ and $r_{max}=20$
(outliers in figure 2(a)).

Tracking The equilibrium interest rate As shown in Figure 2(a), the LSE-based
controller adapts to the equilibrium interest rate consistently across
different user elasticities with a nearly identical convergence rate, aligning
with our theoretical guarantees. In contrast, the baseline controller, which
sets the interest rate as a piecewise linear function of utilization, heavily
relies on elasticity. It struggles to adapt to the new equilibrium interest
rate in low elasticity scenarios and performs slightly better as elasticity
increases.

Borrowers drain due to wrong rate While the performance of the baseline
controller improves as borrower’s elasticity increases, the consequences of
misadjustment are more severe, causing significant borrower capital to leave
the system when the interest rate is too high and to flood the system when it
is too low. Figure 2(b) illustrates how the borrowed value changes with market
conditions. The LSE-based controller consistently finds the stable interest
rate, resulting in minimal market disruption whenever changes occur. In
contrast, the baseline controller’s inability to quickly find the correct rate
causes substantial borrower exit from the system. This issue worsens with
increased borrower elasticity due to higher repayment rates. Thus, even in
high elasticity markets, the baseline controller is ineffective in preventing
excessive capital inflows or outflows due to interest rate misadjustments.

(a) The LSE-based controller adapts to the new equilibrium interest rate
quickly. In contrast, the piecewise linear interest rate curve fails to track
the equilibrium interest rate when the borrower’s elasticity is low.

(b) The LSE controller prevents the exit of borrower capital by setting a
competitive interest rate, unlike the baseline controller.

Figure 2: Comparing the LSE-based interest rate controller and the piecewise
linear curve.

###  4.2 Collateral factor planner

We conducted an experiment to evaluate the performance of our collateral
factor planner. The optimality index is defined as in Definition 2.6 with
$\lambda=0$ and $U_{\text{opt}}=0.5$. Initially, the system starts with an
unoptimized collateral factor of $c=0.95$. At timeslot $t=200$, the optimizer
activates and sets a new collateral factor of $c=0.84$, which adjusts the
utilization to the desired level of $0.5$ soon after that (the pace of
reaching the equilibrium is a function of lenders’ elasticity). At timeslot
$t=3000$, a change in price volatility disrupts the system. By timeslot
$t=3200$, the estimator accurately detects the new volatility and triggers the
optimizer. The optimizer then sets a new collateral factor of $c=0.64$, which
stabilizes the utilization around $0.5$ once again. This entire process is
automated. The resulting utilization curve is shown in Figure 3.

Figure 3:

##  5 Conclusion and discussion

Modelling deFi borrow-lending user behavior In this paper, we present a first-
principles model of the behavior and incentives of borrowers and lenders in a
DeFi market. We consider their alternative strategies and analyze how to
achieve market equilibrium in the presence of price volatility. We mention
empirical evidence on the validity of our model.

Two-level protocol design We propose a data-driven, borrow-lending protocol
that sets the interest rate and over-collateralization ratio adaptively. By
monitoring user reactions and learning from their behavior, our protocol
determines a competitive interest rates and optimal collateral factors. The
protocol consists of two components, 1) Fast interest rate controller: This
component reacts online to user behavior, ensuring competitive interest rates
and preventing over- or underpaying users. It has theoretical guarantees for
fast convergence to the equilibrium interest rate. 2) Slow collateral factor
planner: This component uses accurate market condition estimates to adjust the
collateral factor, maintaining utilization at a desired level while
controlling default risk. Overall, our protocol ensures rapid convergence to
the equilibrium interest rate and optimal tuning of the collateral factor to
achieve a desired equilibrium.

Implementation We implement our protocol and test its performance using
simulated users, including uninformed ones. We compare our protocol with a
baseline that uses piecewise linear functions to set interest rates based on
utilization. Our protocol demonstrates superior performance compared to the
baseline in practice.

## References

  * [1] Aave finance governance.  https://app.aave.com/governance/.  Accessed: 2023-05.
  * [2] Aave whitepaper.  https://github.com/aave/aave-protocol/blob/master/docs/Aave_Protocol_Whitepaper_v1_0.pdf.  Accessed: 2024-02.
  * [3] Ajna whitepaper.  https://www.ajna.finance/pdf/Ajna_Protocol_Whitepaper_01-11-2024.pdf.  Accessed: 2023-05.
  * [4] Capital planning at large bank holding companies: Supervisory expectations and range of current practice.  https://www.federalreserve.gov/bankinforeg/stress-tests/ccar/august-2013-estimation-methodologies-for-losses-revenues-and-expenses.htm.  Accessed: 2023-05.
  * [5] Compound finance governance.  https://compound.finance/governance.  Accessed: 2023-05.
  * [6] Compound whitepaper.  https://compound.finance/documents/Compound.Whitepaper.pdf.  Accessed: 2024-02.
  * [7] Impermanent loss in defi lending.  https://docs.compound.finance/interest-rates/.  Accessed: 2023-05.
  * [8] Impermanent loss in defi lending.  https://www.coindesk.com/learn/defi-lending-3-major-risks-to-know/.  Accessed: 2023-05.
  * [9] Interest rate curve in aave.  https://docs.aave.com/risk/liquidity-risk/borrow-interest-rate.  Accessed: 2023-05.
  * [10] Interest rates in decentralised finance.  https://www.banque-france.fr/en/publications-and-statistics/publications/interest-rates-decentralised-finance#:~:text=The%20setting%20of%20interest%20rates%20in%20DeFI&text=The%20formula%20is%20simple%3A%20the,interest%20rates%20cannot%20be%20negative. Accessed: 2023-05.
  * [11] Market distortion.  https://www.investopedia.com/terms/m/marketdistortion.asp.  Accessed: 2023-05.
  * [12] Morpho whitepaper.  https://whitepaper.morpho.xyz/.  Accessed: 2023-05.
  * [13] Navigating risks in defi lending.  https://medium.com/intotheblock/navigating-risks-in-defi-lending-a034dbf83b54.  Accessed: 2023-05.
  * [14] Kush Bhatia, Prateek Jain, and Purushottam Kar.  Robust regression via hard thresholding, 2015.  arXiv:1506.02428.
  * [15] Sylvain Carre and Franck Gabriel.  Security and efficiency in defi lending.  Université Paris-Dauphine Research Paper, (4307207), 2023.
  * [16] Tarun Chitra, Peteris Erins, and Kshitij Kulkarni.  Attacks on dynamic defi interest rate curves.  arXiv preprint arXiv:2307.13139, 2023.
  * [17] Jonathan Chiu, Emre Ozdenoren, Kathy Yuan, and Shengxing Zhang.  On the fragility of defi lending.  Available at SSRN 4328481, 2022.
  * [18] Samuel N Cohen, Marc Sabate-Vidales, Lukasz Szpruch, and Mathis Gontier Delaunay.  The paradox of adversarial liquidation in decentralised lending.  Available at SSRN 4540333, 2023.
  * [19] Samuel N Cohen, Leandro Sánchez-Betancourt, and Lukasz Szpruch.  The economics of interest rate models in decentralised lending protocols.  Available at SSRN, 2023.
  * [20] ethereum.org.  Opcodes for the evm, 2024.  URL: https://ethereum.org/en/developers/docs/evm/opcodes/.
  * [21] Gauntlet.  Arfc aave v3 interest rate curve recommendations from gauntlet, 2023.  Accessed: 2024-05-20.  URL: https://governance.aave.com/t/arfc-aave-v3-interest-rate-curve-recommendations-from-gauntlet-2023-04-27/12921.
  * [22] Mohak Goyal, Geoffrey Ramseyer, Ashish Goel, and David Mazières.  Finding the right curve: Optimal design of constant function market makers, 2023.  arXiv:2212.03340.
  * [23] Gauntlet Research Group.  Aave market risk analysis.  URL: https://gauntlet.network/reports/aave.
  * [24] Gauntlet Research Group.  Compound market risk analysis.  URL: https://assets-global.website-files.com/648bdc0d4b8ce322f27da0af/651f146b6a1c8cc78e6c9cac_Gauntlet%20-%20Compound%20Market%20Risk%20Assessment.pdf.
  * [25] Lewis Gudgeon, Sam Werner, Daniel Perez, and William J Knottenbelt.  Defi protocols for loanable funds: Interest rates, liquidity and market efficiency.  In Proceedings of the 2nd ACM Conference on Advances in Financial Technologies, pages 92–112, 2020.
  * [26] Thomas Kailath.  Linears Systems.  Prentice-Hall, 1980.
  * [27] Ariah Klages-Mundt and Andreea Minca.  (in) stability for the blockchain: Deleveraging spirals and stablecoin attacks.  2021\.
  * [28] Arthur D Kuo.  A least-squares estimation approach to improving the precision of inverse dynamics computations.  1998\.
  * [29] Brian McWilliams, Gabriel Krummenacher, Mario Lucic, and Joachim M Buhmann.  Fast and robust least squares estimation in corrupted linear models.  Advances in Neural Information Processing Systems, 27, 2014.
  * [30] Jason Milionis, Ciamac C. Moallemi, and Tim Roughgarden.  Automated market making and arbitrage profits in the presence of fees, 2023.  arXiv:2305.14604.
  * [31] Viraj Nadkarni, Jiachen Hu, Ranvir Rana, Chi Jin, Sanjeev Kulkarni, and Pramod Viswanath.  Zeroswap: Data-driven optimal market making in defi.  arXiv preprint arXiv:2310.09413, 2023.
  * [32] Kaihua Qin, Liyi Zhou, Pablo Gamito, Philipp Jovanovic, and Arthur Gervais.  An empirical study of defi liquidations: Incentives, risks, and instabilities.  In Proceedings of the 21st ACM Internet Measurement Conference, pages 336–350, 2021.
  * [33] Thomas J Rivera, Fahad Saleh, and Quentin Vandeweyer.  Equilibrium in a defi lending market.  Available at SSRN 4389890, 2023.
  * [34] Anne Sabourin.  Lecture notes on ordinary least squares.  2021\.
  * [35] Kanis Saengchote.  Decentralized lending and its users: Insights from compound.  Journal of International Financial Markets, Institutions and Money, 87:101807, 2023.  URL: https://www.sciencedirect.com/science/article/pii/S1042443123000756, doi:10.1016/j.intfin.2023.101807.
  * [36] Kanis Saengchote.  Decentralized lending and its users: Insights from compound.  Journal of International Financial Markets, Institutions and Money, 87:101807, 2023.
  * [37] Lukasz Szpruch, Jiahua Xu, Marc Sabate-Vidales, and Kamel Aouane.  Leveraged trading via lending platforms.  Available at SSRN, 2024.
  * [38] Yue Xing, Ruizhi Zhang, and Guang Cheng.  Adversarially robust estimate and risk analysis in linear regression.  In International Conference on Artificial Intelligence and Statistics, pages 514–522. PMLR, 2021.
  * [39] Aviv Yaish, Maya Dotan, Kaihua Qin, Aviv Zohar, and Arthur Gervais.  Suboptimality in defi.  Cryptology ePrint Archive, 2023.
  * [40] Xiao Zhang and Feng Ding.  Adaptive parameter estimation for a general dynamical system with unknown states.  International Journal of Robust and Nonlinear Control, 30(4):1351–1372, 2020.
  * [41] Stephan Zheng, Alexander Trott, Sunil Srinivasa, David C. Parkes, and Richard Socher.  The AI economist: Optimal economic policy design via two-level deep reinforcement learning.  CoRR, abs/2108.02755, 2021.  URL: https://arxiv.org/abs/2108.02755, arXiv:2108.02755.

##  Appendix A Supplementary explanation on the protocol logic

###### A Comment on Handling Defaults

Unlike most lending platforms, our protocol does not use a reserve pool to
cover defaults. Traditional DeFi lending protocols charge borrowers higher
interest rates to build a reserve for defaults. Instead, our protocol directly
deducts defaults from lenders’ revenue each timeslot, removing risk for the
protocol. Both approaches manage default risk: traditional models collect
reserves continuously, while our model applies the adjustment explicitly. Our
approach can still be used if a protocol aims to mitigate risk by collecting a
reserve pool. The expected default we calculate can serve as a metric to
charge borrowers more, thus avoiding direct deductions from lenders’ revenue.

##  Appendix B Supporting evidence for our user model

In this section, we discuss our lender and borrower model in more detail and
explain why we believe it closely reflects Defi borrow-lending platform user
behavior. Moreover, we provide evidence from previous works and technical
reports from Aave and Compound to support the variables introduced in our
model. Additionally, we provide empirical estimates of these variables based
on real-world data [36, 21].

###  B.1 Lender

###### What does $r_{o}^{l}$ correspond to in the real world?

In our model, we represent competition with the external market using two
parameters: $r_{o}^{l}$ for lenders and $r_{o}^{b}$ for borrowers. For
lenders, although there is no explicit risk-free interest rate outside the
market representing $r_{o}^{l}$, they have various alternative strategies if
they decide to allocate part of their portfolio to the asset
$\mathcal{A}_{l}$. These alternatives include:

  * •

Participating in yield farming by providing liquidity to decentralized
exchanges like Uniswap or SushiSwap.

  * •

Staking tokens in Proof-of-Stake networks like Ethereum 2.0.

  * •

Using automated investment platforms like Yearn Finance to optimize yields
across different protocols.

  * •

Depositing stablecoins like USDC, DAI, or USDT in high-yield savings accounts
on platforms like Anchor Protocol.

  * •

Participating in stablecoin-specific liquidity pools on Curve Finance.

  * •

Using fixed-rate lending protocols like Notional Finance for predictable
returns.

Different lenders may have varying levels of knowledge about these
alternatives and may or may not consider the benefits of native tokens from
platforms like Compound and Aave. Regardless, each lender expects a minimum
interest rate $r_{o}^{l}$ below which they will withdraw their funds. This
$r_{o}^{l}$ can be zero or even negative for some users due to the other types
of rewards that these Defi platforms provide such as interest rate on the
native token. The $r_{o}^{l}$ in our model can be interpreted as the weighted
average of $r_{o}^{l}$ values for all users, weighted by their deposit
amounts.

We assume lenders are incentivized by a linear function of the interest rate.
However, this might not always be accurate, as lenders could expect higher
future interest rates and tolerate current lower rates to avoid transaction
fees. Since we allow $r_{o}^{l}$ to change arbitrarily over time, our model
can accommodate these affects. For instance, high transaction fees
disincentivizing withdrawals will result in a lower $r_{o}^{l}$ for those
lenders, which will be reflected in the lender’s behavior.

###### Elasticity

Aave and Compound have conducted empirical studies on the elasticity of
lenders and borrowers by analyzing their reactions to changes in interest rate
curves and other parameters. These studies typically measure elasticity by
observing the quantity of assets moved by users following any change and the
speed of their reactions. This data is then used to perform counterfactual
analyses of proposed changes [21].

In our model, we represent users’ elasticity with parameters $\eta_{b}$ and
$\eta_{l}$, assuming these parameters can change over time but not rapidly
(only on the order of $T_{m}$). This approach aligns with previous findings
that show users’ elasticity can vary over time and in different occasions
[21], with some users even displaying zero elasticity in certain cases. By
making the rate of borrow-lend change a linear function of elasticity, our
quantitative model effectively incorporates these dynamics.

###  B.2 Borrower

######  Recursive Borrowing and Leveraged Yield Farming

Saengchote notes that a significant portion of loan demand on the Compound
protocol comes from a practice called _leveraged yield farming_[36]. In this
strategy, users repeatedly borrow and deposit the same asset to earn native
token rewards, which are shared among all active lenders and borrowers by the
protocol. These rewards can sometimes be so high that they offset the interest
paid by borrowers, resulting in a positive net value for them. However, our
model does not consider this strategy. Instead, we focus on user incentives in
a simple borrow-lending market, excluding protocol-specific factors like
borrowing or deposit rewards. Now we provide more details and explanations on
our borrower model:

####  B.2.1 Financing Borrowers

We represent the value these borrowers receive from the borrowed asset as
$r_{o}^{b}$. Similar to $r_{o}^{l}$, $r_{o}^{b}$ is measured as an interest
rate and helps assess the profit that $\mathcal{P}$ provides by offering
liquidity.

These borrowers are exposed to the risk of locked collateral, meaning that if
the collateral were not locked, they could sell it at the first sign of price
decay. With the collateral locked in the pool, they cannot do this, so any
price drop must be accounted for in their utility function as the opportunity
cost of having their collateral locked.

We define the utility function for a typical borrower of this type, indexed by
$i$, who holds $C_{t}(i)$ collateral:

$\displaystyle\text{Utility}_{t}^{b,1}(i)\coloneqq$ $\displaystyle
r_{o}^{b}-r_{t}+\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$ (24)
$\displaystyle-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot LI_{t}$
$\displaystyle+C_{t}(i)\cdot\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]$

This utility function can be broken down as follows: 1\. Inherent Value
($r_{o}^{b}$): Represents the annualized value of one unit of liquidity to the
borrower. 2\. Interest Rate ($-r_{t}$): The annualized interest rate the
borrower must pay. 3\. Default Value
($\mathbb{E}\left[\pi^{i}(p_{t+T_{u}})\right]$): If default occurs, the
borrower can escape with the defaulted value. 4\. Liquidation Cost
($-\mathbb{E}\left[\lambda^{i}(p_{t+1})\right]\cdot LI_{t}$): Represents the
liquidation fee that is deducted from the user’s collateral if liquidation
occurs. 5\. Opportunity Cost
($C_{t}(i)\cdot\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]$):
Accounts for the opportunity cost of having collateral locked in the contract
when the price drops.

This opportunity cost is based on an alternative strategy where the collateral
could be sold at the first sign of price decline. Note that we only subtract
this penalty term if the price drops and don’t add a corresponding gain for a
price rise since this type of borrower already holds a profile of
$\mathcal{A}_{c}$. Thus, their profit from price appreciation remains
unaffected by the protocol but differs in the event of a price fall due to
limited reaction speed.

Empirical Validation The empirical results found by Saengchote validate our
model’s inclusion of a punishment term for expected price falls in the
borrower’s utility function. They analyzed borrow positions from the Compound
protocol from July 2019 to June 2020 and observed that loan demand has a
negative correlation with the past 30-day standard deviation of ETH for USDC,
USDT, and TUSD. This correlation is stronger in stablecoin-to-cryptocurrency
pools compared to cryptocurrency-to-cryptocurrency pools, which experience
less relative volatility [36].

####  B.2.2 Leveraged Trading Borrowers

Each borrower of this type seeks to open a leveraged position in
$\mathcal{A}_{c}$ worth $\$1$ at time $t$. Their strategy is as follows: they
borrow $\frac{1}{p_{t}}$ units of $\mathcal{A}_{c}$ (worth $\$1$) from an
external provider $\mathcal{Z}$, then add additional collateral in the amount
of $\$\left(\frac{1}{c_{t}}-1\right)$ to secure a loan of 1 unit of
$\mathcal{A}_{l}$ from $\mathcal{P}$. Since the maximum loan-to-value ratio
allowed by $\mathcal{P}$ is $c_{t}$, the borrower must provide collateral
worth $\$\frac{1}{c_{t}}$, equivalent to $\frac{1}{c_{t}\cdot p_{t}}$ units of
$\mathcal{A}_{c}$.

Next, they immediately exchange the borrowed $1$ $\mathcal{A}_{l}$ for
$\frac{1}{p_{t}}$ units of $\mathcal{A}_{c}$ through an exchange to repay
their debt to $\mathcal{Z}$. This results in a leveraged position of
$\frac{1}{p_{t}}$ units of $\mathcal{A}_{c}$ in $\mathcal{P}$, from which they
will profit if the price of $\mathcal{A}_{c}$ rises. Their rationale is that
$\mathcal{A}_{c}$ will appreciate in value, making their position in
$\mathcal{P}$ advantageous. These borrowers have been studied extensively in
[37].

The utility function for this group is defined as follows:

$\text{Utility}_{t}^{b,2}(i)=-r_{t}+\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]-\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]\cdot
LI_{t}+\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]$ (25)

Where all the expectations are over $p_{t+1}$.

The utility function of these borrowers resembles that of the first group but
lacks the $r_{o}^{b}$ term because these borrowers do not derive inherent
value from $\mathcal{A}_{l}$. Instead, they immediately swap it for
$\mathcal{A}_{c}$, as their primary interest in $\mathcal{P}$ is to take a
long position on $\mathcal{A}_{c}$.

Unlike the first group, these borrowers receive positive utility from an
increase in $\mathcal{A}_{c}$’s price because they did not own this amount of
$\mathcal{A}_{c}$ before engaging with $\mathcal{P}$. They can only invest in
$\frac{1}{p_{t}}$ units of $\mathcal{A}_{c}$ after joining $\mathcal{P}$.
While the first type of borrowers already holds a profile of $\mathcal{A}_{c}$
and therefore doesn’t gain utility from price increases, the second group can
only establish this profile through $\mathcal{P}$, so all gains from investing
in $\mathcal{A}_{c}$ should be reflected in their utility function to capture
the full profit and risk.

##  Appendix C Proofs

###  C.1 Proof of lemma 2.1

######  Proof C.1.

We denote user $i$’s loan-to-value ratio at time $t$ as $ltv_{t}^{i}$, and
assume $ltv_{t}^{i}<c_{t}$. Since the borrowed amount per user is always 1
unit, we have:

$\frac{1}{C_{t}(i)p_{t}}=ltv_{t}^{i}\quad\Rightarrow\quad
C_{t}(i)=\frac{1}{p_{t}\cdot ltv_{t}^{i}}.$

We can rewrite the utility function for a type 2 borrower by substituting
$C_{t}(i)$, yielding:

$\pi^{i}(p_{t+1})=\max\\{0,B_{t}(i)-C_{t}(i)p_{t+1}\\}=\max\\{0,1-\frac{p_{t+1}}{p_{t}\cdot
ltv_{t}^{i}}\\}.$

This allows us to express the type 2 borrower’s utility function as:

$\text{Utility}_{t}^{b,2}(i)=-r_{t}+\max\\{0,1-\frac{p_{t+1}}{p_{t}\cdot
ltv_{t}^{i}}\\}-\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right].$

Since only the default term depends on $ltv_{t}^{i}$, a rational user will:

$ltv_{t}^{i}=\arg\max_{ltv}\mathbb{E}\left[\max\\{0,1-\frac{p_{t+1}}{p_{t}\cdot
ltv}\\}\right].$

Breaking down the expression:

$ltv_{t}^{i}=\arg\max_{ltv}$

Expanding further:

$ltv_{t}^{i}=\arg\max_{ltv}\int_{0}^{p_{t}\cdot
ltv}\left(1-\frac{p}{p_{t}\cdot ltv}\right)f(p)\,dp.$

This simplifies to:

$ltv_{t}^{i}=\arg\max_{ltv}$

The expression above is the sum of two functions that both increase with
$ltv$, for any known $p_{t}$ and price distribution of $p_{t+1}$. Thus, the
optimal $ltv$ is the maximum allowed by the protocol, $c_{t}$.

Next, we analyze the utility function for a type 1 borrower. We write the
utility function as a function of $ltv_{t}^{i}$, ignoring the liquidation cost
term:

$\text{Utility}_{t}^{b,1}(i)=r_{o}^{b}-r_{t}+\mathbb{E}\left[\max\\{0,1-\frac{p_{t+1}}{p_{t}\cdot
ltv_{t}^{i}}\\}\right]+\frac{1}{p_{t}\cdot
ltv_{t}^{i}}\cdot\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right].$

Since the first two terms are independent of $ltv_{t}^{i}$, a rational type 1
borrower will:

$ltv_{t}^{i}=\arg\max_{ltv}\mathbb{E}\left[\max\\{0,1-\frac{p_{t+1}}{p_{t}\cdot
ltv}\\}\right]+\frac{1}{p_{t}\cdot
ltv}\cdot\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right].$

The first term is identical to that analyzed for type 2 borrowers. The second
term is also an increasing function of $ltv$ because
$\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(p_{t+1}-p_{t})\right]<0$.
Therefore, the overall function is increasing in $ltv$, and the optimal $ltv$
is the maximum allowed by the protocol, $c_{t}$.

###  C.2 proof of lemma 2.3

##### Expected Default

######  Proof C.2.

We first simplify:

$\displaystyle\pi_{t}(p_{t+1})$
$\displaystyle=\frac{1}{L_{t}}\sum_{i\in\mathrm{Borrowers}}\max\left\\{0,B_{t}(i)-C_{t}(i)\cdot
p_{t+1}\right\\}$ (26) $\displaystyle\overset{\text{Lemma
\ref{lemma:collateral-
strategy}}}{=}\frac{1}{L_{t}}\sum_{i\in\mathrm{Borrowers}}\max\\{0,1-\frac{p_{t+1}}{c_{t}\cdot
p_{t}}\\}$ (27)
$\displaystyle=\frac{B_{t}}{L_{t}}\cdot\max\\{0,1-\frac{p_{t+1}}{c_{t}\cdot
p_{t}}\\}=U_{t}\,\max\\{0,1-\frac{p_{t+1}}{c_{t}\cdot p_{t}}\\}$ (28)

And similarly:

$\pi_{t}^{i}=\max\\{0,1-\frac{p_{t+1}}{c_{t}\cdot p_{t}}\\}$

Let $X=\frac{p_{t+1}}{p_{t}}$ be a random variable where $\log(X)$ follows a
normal distribution with mean $\mu$ and variance $\sigma^{2}$, making $X$ a
log-normally distributed variable. The probability density function (PDF) of
$X$ is given by:

$f_{X}(x)=\frac{1}{x\sigma\sqrt{2\pi}}\exp\left(-\frac{(\log(x)-\mu)^{2}}{2\sigma^{2}}\right),\quad
x>0.$

We seek to compute the expectation: (for ease of notation we use $c$ instead
of $c_{t}$ )

$\mathbb{E}\left[\max\left\\{0,1-\frac{X}{c}\right\\}\right].$

This expectation can be split into two integrals based on the value of $X$:

$\mathbb{E}\left[\max\left\\{0,1-\frac{X}{c}\right\\}\right]=\int_{0}^{c}\left(1-\frac{x}{c}\right)f_{X}(x)\,dx.$

Let us define $u=\frac{x}{c}$, then $x=uc$ and $dx=cdu$. Substituting and
adjusting the limits gives:

$\int_{0}^{1}\left(1-u\right)f_{X}(uc)c\,du.$

Using the transformation $x=uc$ in the PDF of $X$, we can write:

$f_{X}(uc)=\frac{1}{uc\sigma\sqrt{2\pi}}\exp\left(-\frac{(\log(uc)-\mu)^{2}}{2\sigma^{2}}\right).$

Thus, the expectation becomes:

$\mathbb{E}\left[\max\left\\{0,1-\frac{X}{c}\right\\}\right]=\int_{0}^{1}(1-u)\frac{1}{u\sigma\sqrt{2\pi}}\exp\left(-\frac{(\log(u)+\log(c)-\mu)^{2}}{2\sigma^{2}}\right)du.$

we explore the steps involved in simplifying this integral, which incorporates
the probability density function of a log-normally distributed variable,
transformed via scaling.

Given the complex integral:

$\int_{0}^{1}(1-u)\frac{1}{u\sigma\sqrt{2\pi}}\exp\left(-\frac{(\log(u)+\log(c)-\mu)^{2}}{2\sigma^{2}}\right)du,$

we aim to simplify it using substitution and properties of the normal
distribution.

Transform the integral by substituting $v=\log(u)$, hence $u=e^{v}$ and
$du=e^{v}dv$. This converts the integral into:

$\int_{-\infty}^{0}(1-e^{v})\frac{1}{\sigma\sqrt{2\pi}}\exp\left(-\frac{(v+\log(c)-\mu)^{2}}{2\sigma^{2}}\right)dv=\Phi\left(\frac{\log(c)-\mu}{\sigma}\right)$

Considering $v=\log(u)$, and $v+\log(c)-\mu$ follows a normal distribution, we
leverage the cumulative distribution function (CDF) of the normal
distribution. This CDF evaluation simplifies the integral:

$\Phi\left(\frac{\log(c)-\mu}{\sigma}\right)-\frac{\exp{(\frac{\sigma^{2}}{2}+\mu)}}{c}\cdot\Phi\left(\frac{-\mu+\log(c)-\sigma^{2}}{\sigma}\right)$

##### Expected Price fall

######  Proof C.3.

Let $X=\log\left(\frac{p_{t+1}}{p_{t}}\right)$. Then
$X\sim\mathcal{N}(\mu,\sigma^{2})$. Since
$X=\log\left(\frac{p_{t+1}}{p_{t}}\right)$, we have $p_{t+1}=p_{t}e^{X}$. The
condition $p_{t+1}<p_{t}$ is equivalent to $e^{X}<1$, which implies $X<0$.

$\mathbb{E}[p_{t+1}-p_{t}\mid p_{t+1}<p_{t}]=\mathbb{E}[p_{t}e^{X}-p_{t}\mid
X<0]=p_{t}\mathbb{E}[e^{X}-1\mid X<0]$ $\mathbb{E}[e^{X}-1\mid
X<0]=\mathbb{E}[e^{X}\mid X<0]-1$

For a normal random variable $X\sim\mathcal{N}(\mu,\sigma^{2})$, the
conditional expectation $\mathbb{E}[e^{X}\mid X<0]$ can be found using the
fact that $e^{X}$ is log-normally distributed.

The expectation of a truncated log-normal variable $e^{X}$ given $X<0$ can be
derived using the cumulative distribution function (CDF) and the probability
density function (PDF) of the normal distribution. Specifically,

$\mathbb{E}[e^{X}\mid X<0]=\frac{\int_{-\infty}^{0}e^{x}f_{X}(x)\,dx}{P(X<0)}$

where $f_{X}(x)$ is the PDF of $X\sim\mathcal{N}(\mu,\sigma^{2})$.

The PDF of $X$ is

$f_{X}(x)=\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{-\frac{(x-\mu)^{2}}{2\sigma^{2}}}$

When we condition on $X<0$, the PDF becomes

$f_{X\mid
X<0}(x)=\frac{f_{X}(x)}{P(X<0)}=\frac{f_{X}(x)}{\Phi\left(\frac{0-\mu}{\sigma}\right)}$

where $\Phi(\cdot)$ is the CDF of the standard normal distribution.

The numerator of the conditional expectation is

$\int_{-\infty}^{0}e^{x}f_{X}(x)\,dx=\int_{-\infty}^{0}e^{x}\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{-\frac{(x-\mu)^{2}}{2\sigma^{2}}}\,dx$

Combine the exponential terms:

$=\int_{-\infty}^{0}\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{x-\frac{(x-\mu)^{2}}{2\sigma^{2}}}\,dx=\int_{-\infty}^{0}\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{-\frac{x^{2}-2\mu
x+\mu^{2}-2\sigma^{2}x}{2\sigma^{2}}}\,dx$

Simplify the exponent:

$=\int_{-\infty}^{0}\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{-\frac{x^{2}-2(\mu+\sigma^{2})x+\mu^{2}}{2\sigma^{2}}}\,dx=e^{\mu+\frac{\sigma^{2}}{2}}\int_{-\infty}^{0}\frac{1}{\sqrt{2\pi\sigma^{2}}}e^{-\frac{(x-(\mu+\sigma^{2}))^{2}}{2\sigma^{2}}}\,dx$

This integral represents the CDF of a normal distribution:

$=e^{\mu+\frac{\sigma^{2}}{2}}\Phi\left(\frac{0-(\mu+\sigma^{2})}{\sigma}\right)$

The denominator is the probability $P(X<0)$:

$P(X<0)=\Phi\left(\frac{0-\mu}{\sigma}\right)$

$\mathbb{E}[e^{X}\mid
X<0]=\frac{e^{\mu+\frac{\sigma^{2}}{2}}\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}$

$\mathbb{E}[e^{X}-1\mid
X<0]=e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1$

$\frac{1}{p_{t}\cdot c}\mathbb{E}[p_{t+1}-p_{t}\mid
p_{t+1}<p_{t}]=\frac{1}{p_{t}\cdot
c}p_{t}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)$

$\frac{1}{c}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)$

##### Price change expectaion

######  Proof C.4.

Using the linearity of expectation:

$\mathbb{E}\left[\frac{p_{t+1}}{p_{t}}-1\right]=\mathbb{E}\left[e^{X}-1\right]$

This can be expanded as:

$\mathbb{E}\left[e^{X}-1\right]=\mathbb{E}[e^{X}]-\mathbb{E}[1]$

Substituting the values from the last proof:

$\mathbb{E}\left[e^{X}-1\right]=e^{\mu+\frac{\sigma^{2}}{2}}-1$

###  C.3 Proof of theorem 2.4

First we equate the borrower’s utility function to zero to ensure
$\mathbb{E}\left[\frac{B_{t+1}-B_{t}}{B_{t}}\right]=0$, this yields the
equilibrium interest rate:

$\displaystyle r^{*}$ $\displaystyle=(\alpha\cdot
r_{o}^{b}+\pi(c_{t})+\frac{\alpha}{c_{t}}\,\mathbb{E}\left[\mathbbm{1}_{p_{t+1}-p_{t}<0}(\frac{p_{t+1}-p_{t}}{p_{t}})\right]$
$\displaystyle+(1-\alpha)\cdot\mathbb{E}\left[\frac{p_{t+1}-p_{t}}{p_{t}}\right]\bigg{)}$
$\displaystyle=\alpha\,r_{o}^{b}+\pi(c_{t})+\frac{\alpha}{c_{t}}\left(e^{\mu+\frac{\sigma^{2}}{2}}\frac{\Phi\left(\frac{-\mu-\sigma^{2}}{\sigma}\right)}{\Phi\left(\frac{-\mu}{\sigma}\right)}-1\right)+(1-\alpha)\left(e^{\mu+\frac{\sigma^{2}}{2}}-1\right)$

If this rate is non-positive, this means that the pool has no non-trivial
equilibrium in this market condition and under this $c_{t}$, otherwise the
above rate is the unique equilibrium interest rate of the market.

Now, we assess the utility of the lender in the equilibrium interest rate:

$\text{Utility}_{t}^{l}=r^{*}U_{t}-\pi(c_{t})-r_{o}^{l}$

There are two cases:

  * •

1) $(r^{*}-r_{o}^{l})>\pi(c_{t})$: In this case there is a $U^{*}<1$ that
satisfies $\text{Utility}_{t}^{l}=0$ and this utilization is
$U^{*}=\frac{r_{o}^{l}}{r^{*}-\pi(\sigma)}$.

  * •

2) 1) $(r^{*}-r_{o}^{l})\leq\pi(c_{t})$: In this case, when the equilibrium
rate is set, lenders have nonpositive utility hence they withdraw until the
pool depletes and the utilization hits $1$.

###  C.4 Proof of theorem 3.1

We borrow from the rich literature of Ordinary Least Square estimator [34].
First, we note that LSE is an unbiased estimator so for any $\tau$:

$\mathbf{\hat{\Theta}}_{b}^{\tau}(0)=\eta_{b}r^{*}+\epsilon_{0}$

If we assume that $\eta_{b}$ is known (which is a realistic assumption if
$\eta_{b}$ changes slower than $r^{*}$), $\mathbf{\hat{\Theta}}_{b}^{\tau}(0)$
also provides an unbiased estimator of $r^{*}$:

$\hat{r}^{*}=r^{*}+\frac{\epsilon_{0}}{\eta_{b}}$

Now for the convergence rate, we state a special case of proposition 7 of
lecture note [34]:

######  Lemma C.5.

Suppose that the noise is Gaussian. Denote by $\hat{\lambda}_{\tau}$ the
smallest eigenvalue of
$\,\frac{1}{\tau}{(\mathbf{P}_{b}^{\tau})}^{T}\mathbf{P}_{b}^{\tau}$ and
suppose that $\hat{\lambda}_{\tau}>0$ for all $n\geq 1$. Then, for
$k\in\\{0,1\\}$, $\tau\geq 1$ and $\delta>0$, it holds with probability
$1-\delta$,

$\max_{k=0,1}\left|\mathbf{\hat{\Theta}}_{b}^{\tau}(k)-\mathbf{\Theta}_{b}^{*}(k)\right|\leq\sqrt{\frac{2\zeta^{2}\log(6/\delta)}{\tau\,\hat{\lambda}_{\tau}}}.$

Where $\mathbf{\hat{\Theta}}_{b}^{\tau}(k)$ is the $k$th element of estimated
$\mathbf{\Theta}_{b}$ at time $\tau$ and $\zeta$ is the noise variance.

The exploration process incorporated in Algorithm 1 ensures the fact that
there is a sub-matrix of
$\,\frac{1}{\tau}{(\mathbf{P}_{b}^{\tau})}^{T}\mathbf{P}_{b}^{\tau}$ of at
least size $\tau\,\nu$ with all independent rows which guarantees LSE
converges.

###  C.5 Proof of theorem 3.2

Let’s consider a piecewise linear interest rate function with one corner, for
ease of analysis let’s assume the operating point of the system is before the
edge hence yielding a linear function $r_{t}=R_{0}+R_{s}\,U_{t}$.

We consider the case that only the borrower is elastic hence
$r_{t}=R_{0}+R^{\prime}_{s}\,B_{t}$ where
$R^{\prime}_{s}\coloneqq\frac{R_{s}}{L_{t}}$ and $L_{t}$ is fixed due to the
lenders’ in-elasticity. Now we write the borrower behavior dynamics to find
the convergence rate of the protocol to $r^{*}$ when the market is unstable,
we consider a slightly different borrower’s behavior in which the absolute
borrow/repay rate is proportional to the borrower’s utility, even this will
change the borrower’s dynamic slightly but does not affect the final result,

$\displaystyle\frac{B_{t+1}-B_{t}}{\Delta}$
$\displaystyle=\eta_{b}(r^{*}-r_{t})$
$\displaystyle=\eta_{b}\left(r^{*}-\left(R_{0}+R^{\prime}_{s}\,B_{t}\right)\right)$

We rewrite this discrete diffenrtial equation as the general form :

$f(t+1)-f(t)=af(t)+b+\epsilon_{t}$

Where $f(t)\coloneqq B_{t}$ and $a\coloneqq-\Delta\,\eta_{b}\,R^{\prime}_{s}$
and $b\coloneqq\eta_{b}\,\Delta\,(r^{*}-R_{0})$ and $\epsilon_{t}$ is a
guassian noise with mean $0$ and variance $\zeta^{2}\Delta^{2}$ To find
$f(t+1)$, we rearrange the equation:

$f(t+1)=(1+a)f(t)+b+\epsilon$

Iteratively expanding $f(t)$ for a few steps to understand the pattern, we
find:

$f(1)=(1+a)f(0)+b+\epsilon_{0}$
$f(2)=(1+a)f(1)+b+\epsilon_{1}=(1+a)^{2}f(0)+(1+a)b+b+(1+a)\epsilon_{0}+\epsilon_{1}$

The general form at time $t$ can be written using a recursive expansion:

$f(t)=(1+a)^{t}f(0)+\sum_{k=0}^{t-1}(1+a)^{k}b+\sum_{k=0}^{t-1}(1+a)^{t-1-k}\epsilon_{k}$

Simplifying the sum for $b$, we use the geometric series sum formula:

$\sum_{k=0}^{t-1}(1+a)^{k}=b\left(\frac{(1+a)^{t}-1}{a}\right)\quad\text{for
}a\neq-1$

Combining all components, the complete solution to the equation is:

$f(t)=(1+a)^{t}\left(f(0)+\frac{b}{a}\right)-\frac{b}{a}+\sum_{k=0}^{t-1}(1+a)^{t-1-k}\epsilon_{k}$

This function converges when $1+a=1-\Delta\,\eta_{b}\,R^{\prime}_{s}$ is
between zero and 1, in this case:

$\mathbb{E}\left[\lim_{t\to\infty}B_{t}\right]=\frac{-b}{a}=\frac{r^{*}-R_{0}}{R^{\prime}_{s}}\implies\mathbb{E}\left[\lim_{t\to\infty}r_{t}\right]=R_{0}+R_{s}^{\prime}\mathbb{E}\left[\lim_{t\to\infty}B_{t}\right]=r^{*}$

$\displaystyle\mathbb{E}\left[r_{t}\right]$
$\displaystyle=R_{0}+R^{\prime}_{s}(1+a)^{t}\left(f(0)+\frac{b}{a}\right)-R_{s}^{\prime}\frac{b}{a}$
(29)
$\displaystyle=R_{0}+R_{s}^{\prime}\frac{r^{*}-R_{0}}{R_{s}^{\prime}}+(1+a)^{t}\left(R_{s}^{\prime}f(0)-(r^{*}-R_{0})\right)$
(30)
$\displaystyle=r^{*}+(1-\Delta\,\eta_{b}\,R_{s}^{\prime})^{t}\left(R_{s}^{\prime}B_{0}-(r^{*}-R_{0})\right)$
(31)

which means that in infinity, the average of the interest rate will be the
same as the equilibrium interest rate, Now we assess the variance of this
process:

$\text{Var}[B_{t}]=\text{Var}\left[\sum_{k=0}^{t-1}(1+a)^{t-1-k}\epsilon_{k}\right]=\sum_{k=0}^{t-1}(1+a)^{2t-2-2k}\,\zeta^{2}\,\Delta^{2}=\zeta^{2}\Delta^{2}\frac{1-(1+a)^{2t}}{1-(1+a)^{2}}$

In order to find $\mathcal{R}_{\mathcal{P}}(\delta,\tau)$ we need to find the
variance of $r_{t}$:

$\text{Var}\left[r_{t}\right]={R^{\prime}_{s}}^{2}\,\text{Var}[B_{t}]={R^{\prime}_{s}}^{2}\,\zeta^{2}\Delta^{2}\frac{1-(1+a)^{2t}}{1-(1+a)^{2}}$

We use Markov’s Inequality to bound $\mathcal{R}_{\mathcal{P}}(\delta,\tau)$:

hence we can equate
$\frac{{R^{\prime}_{s}}^{2}\,\zeta^{2}\Delta^{2}\frac{1-(1+a)^{2t}}{1-(1+a)^{2}}}{\kappa^{2}}=\delta$
and write with probability more than $\delta$ we have:

$|r_{t}-r^{*}|\leq\kappa=\sqrt{\frac{{R^{\prime}_{s}}^{2}\zeta^{2}\Delta^{2}\frac{1-(1+a)^{2t}}{1-(1+a)^{2}}}{\delta}}=K\sqrt{\frac{1-(1-\Delta\,\eta_{b}\,R^{\prime}_{s})^{t}}{\delta}}\sim
o(\frac{1}{\sqrt{\delta}})$

Where $K$ is a constant.

Now we consider the case where both lenders and borrowers are elastic, in this
case, the equilibrium rate and utilization follow Equation C.3 and Equation
14. This clearly shows that the equilibrium utilization is not a linear
function of $r^{*}$, hence when setting the arbitrary $r_{t}=r^{*}$, the
implied utilization by the piece-wise linear curve cannot be the equilibrium
utilization of Equation 14. this means that at that point, lenders still refer
to lend more or repay and change the utilization which will change the
interest rate as well.

###  C.6 Proof of Lemma 3.3

First, we aim to find the liquidation $\gamma$, we know that liquidation only
happens if loan to value i.e., $\frac{1}{\frac{p_{t+1}}{p_{t}\cdot c}}>LT$,
hence if we define $X\coloneqq\frac{p_{t+1}}{p_{t}}$, the indicator term
$\mathbbm{1}_{X<\frac{c}{LT}}$ will appear. Furthermore, $\gamma$ is the
minimum value that satisfies $\frac{1-\gamma}{\frac{p_{t+1}}{p_{t}\cdot
c}-\gamma}\leq LT$, solving for the minimum $\gamma$ will result in the term
specified in the lemma statement.

We aim to find the expected value of the variable

$Y=\frac{1-\frac{LT}{c}X}{1-LT}\mathbbm{1}_{X<\frac{c}{LT}},$

where $X$ is log-normally distributed with parameters $\mu$ and $\sigma$. This
implies that $\ln(X)\sim\mathcal{N}(\mu,\sigma^{2})$.

The expected value $E[Y]$ can be expressed as:

$E[Y]=E\left[\frac{1-\frac{LT}{c}X}{1-LT}\mathbbm{1}_{X<\frac{c}{LT}}\right].$

Simplifying, we get:

$E[Y]=\frac{1}{1-LT}E\left[\left(1-\frac{LT}{c}X\right)\mathbbm{1}_{X<\frac{c}{LT}}\right].$

This expectation can be written as an integral over the probability density
function (pdf) of $X$:

$E[Y]=\frac{1}{1-LT}\int_{0}^{\frac{c}{LT}}\left(1-\frac{LT}{c}x\right)f_{X}(x)\,dx,$

where $f_{X}(x)=\frac{1}{x\sigma\sqrt{2\pi}}e^{-\frac{(\ln
x-\mu)^{2}}{2\sigma^{2}}}$.

Changing the variable of integration, let $u=\ln x$. Then $du=\frac{1}{x}dx$,
so $dx=e^{u}du$. The limits of integration change as follows: \- When $x=0$,
$u\to-\infty$ \- When $x=\frac{c}{LT}$, $u=\ln\left(\frac{c}{LT}\right)$

Thus, the expectation becomes:

$E[Y]=\frac{1}{1-LT}\int_{-\infty}^{\ln\left(\frac{c}{LT}\right)}\left(1-\frac{LT}{c}e^{u}\right)\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}e^{u}\,du.$

Simplifying the integrand:

$E[Y]=\frac{1}{1-LT}\int_{-\infty}^{\ln\left(\frac{c}{LT}\right)}\frac{1}{\sigma\sqrt{2\pi}}\left(e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}e^{u}-\frac{LT}{c}e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}e^{2u}\right)\,du.$

Separate the integral:

$E[Y]=\frac{1}{1-LT}\left(\int_{-\infty}^{\ln\left(\frac{c}{LT}\right)}\frac{e^{u}}{\sigma\sqrt{2\pi}}e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}\,du-\frac{LT}{c}\int_{-\infty}^{\ln\left(\frac{c}{LT}\right)}\frac{e^{2u}}{\sigma\sqrt{2\pi}}e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}\,du\right).$

Evaluate the integrals using the properties of the normal distribution. The
first integral is:

$I_{1}=\int_{-\infty}^{\ln\left(\frac{c}{LT}\right)}\frac{e^{u}}{\sigma\sqrt{2\pi}}e^{-\frac{(u-\mu)^{2}}{2\sigma^{2}}}\,du=\Phi\left(\frac{\ln\left(\frac{c}{LT}\right)-\mu+\sigma^{2}}{\sigma}\right),$

where $\Phi$ is the cumulative distribution function (CDF) of the standard
normal distribution.

The second integral is:

$I_{2}=e^{\mu+\sigma^{2}}\Phi\left(\frac{\ln\left(\frac{c}{LT}\right)-\mu-\sigma^{2}}{\sigma}\right).$

Combining these results, we get:

$E[Y]=\frac{1}{1-LT}\left(\Phi\left(\frac{\ln\left(\frac{c}{LT}\right)-\mu+\sigma^{2}}{\sigma}\right)-\frac{LT}{c}e^{\mu+\sigma^{2}}\Phi\left(\frac{\ln\left(\frac{c}{LT}\right)-\mu-\sigma^{2}}{\sigma}\right)\right).$

##  Appendix D Notation Table

Notation |  Description
---|---
$\mathcal{A}_{l}$ |  Lent out asset (assumed to be stable coin)
$\mathcal{A}_{c}$ |  Collateral assset
$T_{m}$ |  Market timeframe, denoting the timeframe within which the market is stable
$p_{t}$ |  Price at time $t$
$\mu$ |  Drift of the price
$\sigma$ |  Volatility of the price
$r_{l}^{o}$ |  Risk-free lend rate offered by an external competitor
$r_{b}^{o}$ |  Risk-free borrow rate offered by an external competitor
$\mathcal{P}$ |  Decentralized borrowing-lending protocol
$r_{t}$ |  Interest rate at time $t$
$c_{t}$ |  Collateral factor at time $t$
$c$ |  Collateral factor in general
$LT_{t}$ |  Liquidation threshold at time $t$
$LT$ |  Liquidation threshold in general
$LI_{t}$ |  Liquidation Incentive at time $t$
$L_{t}$ |  State variable representing total supply at time $t$
$B_{t}$ |  State variable representing total borrowings at time $t$
$C_{t}$ |  State variable representing total collateral at time $t$
$U_{t}$ |  State variable representing utilization at time $t$
$\pi_{t}^{i}(p_{t+1})$ |  Default value for borrower $i$ from timeslot $t$ to $t+1$ given that the price is $p_{t+1}$ at time $t+1$.
$\pi_{t-1}(p_{t})$ |  Normalized overall pool default value from timeslot $t$ to $t+1$ given that the price is $p_{t+1}$ at time $t+1$.
$\pi(c_{t})$ |  $\mathbb{E}\left[\pi_{t}^{i}(p_{t+1})\right]$, Expectation over $p_{t+1}$.
$L_{t}(i)$ |  Supply of user $i$ at timeslot $t$
$B_{t}(i)$ |  Borrowings of user $i$ at timeslot $t$
$C_{t}(i)$ |  Collateral of user $i$ at timeslot $t$
$\lambda_{t}^{i}(p_{t+1})$ |  Liquidation incurred by user $i$ from timeslot $t$ to $t+1$, given the price to be $p_{t+1}$ at time $t+1$
$\lambda(c_{t},LT_{t})$ |  $\mathbb{E}\left[\lambda_{t}^{i}(p_{t+1})\right]$, Expectation over $p_{t+1}$
$\text{Utility}_{t}^{l}$ |  Utility function of a continuum lender possessing one unit of supply at time $t$
$\text{Utility}_{t}^{b,1}$ |  Utility function of a financing continuum borrower with one unit of demand at time $t$
$\text{Utility}_{t}^{b,2}$ |  Utility function of a leveraged trading continuum borrower with one unit of demand at time $t$
$\eta_{l}$ |  Elasticity of the lenders
$\eta_{b}$ |  Elasticity of the borrowers
$\alpha$ |  Fraction of the financing borrowers to total
$\beta$ |  Maximum fraction of demand/supply being controlled by adversaries
$\gamma$ |  Default regularization factor in the optimality index definition
$\kappa$ |  Learning rate
Table 1: Notations and Descriptions