# ♾️1.2 Limit Orders

There are 2 types of limit orders

Lending Limit Orders (credit buy limit orders), representing an intent to lend money, in a certain time range and a certain rates range

Borrowing Limit Orders (credit sell limit orders), representing an intent to borrow money, in a certain time range and a certain rate range

In terms of liquidity

Lending Limit Orders are associated with an amount of token that can be lent out, USDC in this case and

Borrowing Limit Orders are associated with the borrower's collateral, to back the loan if the order is matched

The collateral backing a loan is automatically calculated and assigned pro rata so there is no direct collateral to loan assignment or collateralized debt position.

## 1.2.1 Limit Order Structure - Yield Curve

Makers place limit orders by specifying a yield curve $\rho(t) : \mathbb{R} \rightarrow \mathbb{R}^{+}$ which is a curve that associates with each term a non-negative rate

The yield curve consists of a set of ${(t_{i}, r_{i})}_{i=1,...,n}$ points specified by the lender-associated

to a given $t_{i}$ term

a certain $r_{i} \in \mathbb{R}$ rate (they can be negative because of the price hooks explained later)

This effectively defines a piece-wise function in the $(t_{0}, t_{n-1})$ temporal range on-chain and the taker submitting a market order can pick any $t \in (t_{0}, t_{n-1})$ and the result is computed by interpolating linearly.

## 1.2.2 Rate Hooks

Market interest rates constantly fluctuate and to support lenders in updating their yield curves more effectively a "price hook" mechanism is provided: on top of the ${(t_{i}, r_{i})}~{i=1,...,n}$* *set of points mentioned above, the lenders can also provide a set of ${m_{i}}~{i=1,...,n}$ of points that work as multipliers for the $R_{b}$ current market borrow rate.

We use an oracle that calculates off-chain the median of Aave's borrow variable rates over time as a proxy for the market rate.

So renaming $r_{i}$ into $\Delta r_{i}$ as a bias term, each point of the yield is automatically computed as follows:

$r_{i} = \Delta r_{i} + m_{i} A$

When $r_{i} < 0$, ie, when the user-defined curve can't be met, the calculation reverts. The reason is that adding any on-chain logic to user preferences, such as rounding to zero, cannot be fully expected. It might be the case that it's not even straightforward to fully accommodate such flooring, e.g. it's not a smooth function, which can alter user-side strategies, possibly leading to user losses.

## 1.2.3 Filling limit orders

**1.2.3.1 Filling **Lending Limit Orders** (credit buy limit orders)**

**1.2.3.1 Filling**Lending Limit Orders

**(credit buy limit orders)**

In filling a Lending Limit Order, the lender expects

some cash gets out of his account, since it is sent to the borrower and

to acquire some credit in exchange

This mechanism can be used for 2 purposes

standard lending and

selling existing credit

In fact, if the borrower is also a lender, he can use this mechanism to sell some of his credit to another lender in exchange for some cash.

This leads to a broader and more general terminology where

the lender is a "credit buyer" and

the borrower is a "credit seller" as he can sell both

a new credit he emits in the form of overcollateralized debt and

a credit he already owns, since he can also be a lender

The pricing of the credit is implicitly present in the Lending Limit Order as the rate associated with the due date chosen by the borrower, aka credit seller.

The way a Lending Limit Order is filled is

the credit seller/buyer chooses:

an amount $A$ to borrow

a lender $L$ and

a tenor $\Delta T$

This allows to compute the corresponding rate to that lender yield curve as follows

$r = \rho_{L}(\Delta T)$

Of course, it is required that $\Delta T \in (t_{0}, t_{n-1})$ since outside of that interval, the lender does not want to lend.

**Observation:** in the current implementation, the rate is not a function of the amount borrowed so there is no "slippage" in borrowing from a single lender, although there can be "slippage" if a large amount is borrowed since it would require borrowing from multiple lenders at different rates.

This is exactly what happens in a standard 2D order book when a large order consumes the liquidity of a bucket and the buckets at different prices close the initial one.

the borrower emits a bond in favor of the lender for $V = A (1 + r)$ face value that matures at $T$ time

the amount $A$ is withdrawn from the Lender L reserves and sent to the borrower

finally, before finalizing the operation, a collateral check is performed to check that the borrower's collateral ratio is above the opening threshold

**1.2.3.2 Filling Borrowing Limit Orders**

**1.2.3.2 Filling Borrowing Limit Orders**

The filling of Borrowing Limit Orders is symmetric to the filling of Lending Limit Orders.

Last updated