♾️3.3 Market Orders
Last updated
Last updated
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
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 sell
an amount
to borrow
exactAmountIn
whether the amount
parameter means credit or cash
for the lender's limit order, the related rate
is computed by applying the specified tenor
to the limit order yield curve so
as a result of this, given the amount
and the rate
, 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
In this case, the amountIn
is credit
With exactAmountIn=true
Formula
Preconditions
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
Explanation
Then fees are applied and
With exactAmountIn=false
Formula
Preconditions
Recalling the formula for exactAmountIn=true
let's compute
which is the maximum amount of cash possible, obtained by selling the full credit and therefore assuming no fragmentation fee
This is to say that the preconditions are
Fragmentation Fee
Explanation
Then fees are applied and
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 sell
an amount
to lend
exactAmountIn
whether the amount
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.
In this case, the amountIn
is cash
with 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
Fragmentation Fee
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
So the conditions for the swap to happen are
Fragmentation Fee
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)
.
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
if then since there is no fragmentation as the full credit is swapped
if then
The is the amount of cash the credit buyer values the amount of credit he is buying, before fees
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
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
or
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
The is the amount of cash the credit buyer values the amount of credit he is buying, before fees
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
since it is not possible to buy more than the full credit amount
if then
if then
We need to compute the and as previously explained in the SellCreditMarket
case, but this time we use the BuyCreditMarket
formula so
or
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