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
tokenIdandliquidity, the protocol decreasesliquidityfrom an LP position to obtainamountFromBorrowedandamountToBorrowedfor a token pair.Swap: In one swap, the protocol swaps
amountFromBorrowedtogether withmarginFromintoamountReceived. The amount is then locked in contract.Accounting: The protocol ensures enough amount is swapped, i.e.
amountReceived+amountToBorrowd+marginTois 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
liquidityin the record (alien), determine the amount to repay, i.e.amountFromAddandamountToAdd.Swap: In one swap, at least swap enough to (1) get
amountToAddand (2) leave enough foramountFromAdd.Repay: increase
liquidityback 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