1.0.16 • Published 8 months ago
iloop-sdk v1.0.16
#iloop-sdk
Calculate adjust leverage
- Deposit: A token JITOSOL
- Current leverage: X
- New leverage: Y
-> New Deposit amount: A * Y/X = B
-> Total withdraw collateral: A - B = C
-> if C > 0 -> decrease leverage -> flashBorrow SOL, repay flashBorrowSOL, withdraw collateral, swap collateral to SOL, flash repay SOL
if C < 0 - increase leverage -> flash borrow SOL, swap into JitoSOL, deposit JitoSOL to reserve, borrow SOL from reserve, flash repay SOL
Calculate withdraw collateral
- total deposit A token JitoSOL
- Current leverage X
- withdraw B token
-> Actual withdraw from Reserve: B * X
-> Swap amount = B * X - B = C
Close multiply position
- Borrow A SOL
- Total deposit B SOL
-> flash borrow A SOL, repay A SOL, withdraw B JitoSOL, swap Y JitoSOL to A SOL, repay A SOL