♾️1.2 Limit Orders
Last updated
Last updated
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.
Makers place limit orders by specifying a yield curve which is a curve that associates with each term a non-negative rate
The yield curve consists of a set of points specified by the lender-associated
to a given term
a certain rate (they can be negative because of the price hooks explained later)
This effectively defines a piece-wise function in the temporal range on-chain and the taker submitting a market order can pick any and the result is computed by interpolating linearly.
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 set of points mentioned above, the lenders can also provide a set of of points that work as multipliers for the 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.
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:
This allows to compute the corresponding rate to that lender yield curve as follows
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.
finally, before finalizing the operation, a collateral check is performed to check that the borrower's collateral ratio is above the opening threshold
The filling of Borrowing Limit Orders is symmetric to the filling of Lending Limit Orders.
So renaming into as a bias term, each point of the yield is automatically computed as follows:
When , 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.
an amount to borrow
a lender and
a tenor
Of course, it is required that since outside of that interval, the lender does not want to lend.
the borrower emits a bond in favor of the lender for face value that matures at time
the amount is withdrawn from the Lender L reserves and sent to the borrower