Overview
We provide an illustration to the protocol logic in https://excalidraw.com/#json=TcmwLn2W4K9H_UlCExFXa,J_yKjXNaowF0gYL8uvPruA
The basic flow of opening a leverage position in LAMM contains 3 steps:
Borrow Liquidity: input
tokenId
andliquidity
, the protocol decreasesliquidity
from an LP position to obtainamountFromBorrowed
andamountToBorrowed
for a token pair.Swap: In one swap, the protocol swaps
amountFromBorrowed
together withmarginFrom
intoamountReceived
. The amount is then locked in contract.Accounting: The protocol ensures enough amount is swapped, i.e.
amountReceived
+amountToBorrowd
+marginTo
is enough to covercollateralTo
. The leftover amount are kept as premiums.
Similarly, the basic flow of closing an LAMM position contains 3 steps:
Accounting: Based on
liquidity
in the record (alien
), determine the amount to repay, i.e.amountFromAdd
andamountToAdd
.Swap: In one swap, at least swap enough to (1) get
amountToAdd
and (2) leave enough foramountFromAdd
.Repay: increase
liquidity
back for LP and addtokensOwed
, the leftover amounts (premiums subtract owed and PnLs) are all refund to the borrower.
For more details, please refer to the illustrative figures and the notes in the link above. The same figures are provided in the sections next.
Last updated