♾️3.3 Market Orders
Notation
: the exact amount of credit to be sold
: absolute rate (not the APR) obtained by applying
debtPosition.dueDate
to the buyer yield curve: the remaining time to maturity i.e.
deltaT = debtPosition.dueDate - block.timestamp
: Conditional Fragmentation Fee, can be zero or non-zero depending on specific conditions
: Actual Fragmentation Fee, equal to
fragmentationFee
in the protocol: Swap Fee defined as APR (so needs to be multiplied by a time to become an absolute rate)
: the amount of cash swapped
: the maximum amount of credit that can be traded which is equivalent to
creditPosition.credit
the amount the credit is entitled to
3.3.1 Sell Credit Market Order (borrowing market order)
The FROB Borrowing Market Order can be used for different purposes.
The mechanism is always the same:
the borrower specifies, in addition to MEV-protection parameters:
a
lender
a
tenor
an
creditPositionId
to sellan
amount
to borrowexactAmountIn
whether theamount
parameter means credit or cash
for the lender's limit order, the related
rate
is computed by applying the specifiedtenor
to the limit order yield curve soas a result of this, given the
amount
and therate
, the future value of the loan related to that specific limit order is computed by applying the linear interest rate model
If the borrower wants to take multiple loans, from N different lenders, they may do so with a multicall
by submitting N borrowing market orders.
Observation: thanks to its robust API, both existing and new credit may be sold through the SellCreditMarket
function. By passing type(uint256).max
as the creditPositionId
, the system first creates a DebtPosition/CreditPosition pair assigned to the sender, in a "mint credit" internal operation, and then sells that CreditPosition to the lender. If an existing credit position is being sold, the tenor
parameter is ignored, as it can be automatically computed from the related debt position.
3.3.1.1 To take a new fixed-rate loan
This is the primary purpose of the Sell Credit Market Order; to take a new fixed-rate loan, a borrower fills a lending limit order, and a DebtPosition, CreditPosition pair is created as a result.
3.3.1.2 To exit a loan you own
Lenders can "exit" their lending position before the due date by selling their credit to other lenders
This is possible because the FROB as an order book without any further adaptation serves 2 purposes
to price the borrowing requests and
to price the credit aka future cashflow
3.3.1.3 Technical specification
In this case, the
amountIn
is creditWith
exactAmountIn=true
Formula
Preconditions
since it is not possible to sell more credit than the
creditPosition.credit
since of course, we need to avoid the swap fee to eat the full or even exceed it, even though that's more of a theoretical issue since
the break-even is at
the order of magnitude of the fee we are considering is 0.5% APR so the break-even would be for a credit whose remaining lifetime is 200 years.
Fragmentation Fee
if then since there is no fragmentation as the full credit is swapped
if then
Explanation
The is the amount of cash the credit buyer values the amount of credit he is buying, before fees
Then fees are applied and
is charged since the swap fee is a function of the remaining lifetime of the loan and is applied to the cash side of the trade
The higher or and the lower the cash returned to the credit seller
is charged to cover the gas costs related to credit fragmentation
The higher and the lower the cash returned to the credit seller
With
exactAmountIn=false
Formula
Preconditions
Recalling the formula for
exactAmountIn=true
let's computewhich is the maximum amount of cash possible, obtained by selling the full credit and therefore assuming no fragmentation fee
Let's define so we see immediately that
and that plugging it into the formula here we obtain that by submitting we sell and therefore there is no fragmentation and it is correct not to charge the fragmentation fee
Now we see in general so what happens if i.e. the seller wants to get slightly less than the max possible?
It happens that charging the fragmentation fee would make and therefore make the trading impossible
The turning point is for meaning
for which the trader can still sell the full amount, but the amount of cash it gets is less than the previous case since but still both require selling the entire amount
This is to say that the preconditions are
or
Fragmentation Fee
Starting from they are
If then
If then
Equivalently starting from simply they are
if then since there is no fragmentation as the full credit is swapped
if then
Explanation
The is the amount of cash the credit buyer values the amount of credit he is buying, before fees
Then fees are applied and
is charged since the swap fee is a function of the remaining lifetime of the loan and is applied to the cash side of the trade
The higher and and the higher the amount to be sold to get the desired amount out
is charged to cover the gas costs related to credit fragmentation
The higher and the higher the amount to be sold to get the desired amount out
3.3.2 Buy Credit Market Order (lending market order)
There is also a FROB for borrowing bids.
The mechanism is similar to that of selling credit:
the lender specifies, in addition to MEV-protection parameters:
a
borrower
a
tenor
an
creditPositionId
to sellan
amount
to lendexactAmountIn
whether theamount
parameter means cash or credit
Observation: thanks to its robust API, here too, both existing and new credit may be bought through the BuyCreditMarket
function. By passing type(uint256).max
as the creditPositionId
, the system first creates a DebtPosition/CreditPosition pair assigned to the borrower, in a "mint credit" internal operation, and then buys that CreditPosition to the sender. If an existing credit position is being bought, both the tenor
and borrower
parameters are ignored, as these can be automatically computed from the related debt and credit positions.
The main use case has been envisioned for that is to allow borrowers to exit their positions before the due date, without forfeiting the full-term interest.
It is also possible for lenders to fill limit orders on the borrowing offer book. However, this is likely to be a less frequent arbitrage event, i.e. when borrow bids are priced higher than the market lending rate.
3.3.2.1 Technical specification
In this case, the
amountIn
is cashwith
exactAmountIn=false
Formula
We can see that
the amount of cash to send in is equal to the credit desired (exact amount out) converted into cash discounting by the rate and increased by the fragmentation fee and then
Preconditions
since it is not possible to buy more than the full credit amount
Fragmentation Fee
if then
if then
with
exactAmountIn=true
Formula
We can see that,
the amount of credit that is obtained is equal to the amount of cash sent in (exact amount in) first subtracted by the fragmentation fee and then converted into credit using the rate
Preconditions
We need to compute the and as previously explained in the
SellCreditMarket
case, but this time we use theBuyCreditMarket
formula soSo the conditions for the swap to happen are
or
Fragmentation Fee
Starting from they are
If then
If then
Equivalently starting from they are
if then since there is no fragmentation as the full credit is swapped
if then
In the case of BuyCreditMarket
, there is no swap fee in the formula since it is not paid by the credit buyer (even though he is on the active side of the trade), but by the credit seller. So the. amount of cash received by the credit seller is netCash = cash * (1 - k * \Delta T)
.
Last updated