How I built
previewLeverageβ a read-only preview engine that calculates leveraged lending position metrics across Suilend, Navi, and Scallop, without executing any on-chain transaction.Team: curg-13 | SDK: defidash-sdk
Why Preview Before Leverage?
In DeFi lending, leverage means borrowing against your collateral to amplify your position. A 2x leverage on $100 of SUI gives you $200 total exposure β potentially doubling your returns, but also your risk.
Before users click “Confirm”, they need to know:
- How much will be borrowed via flash loan?
- What’s the liquidation price?
- What’s the expected annual return (Net APY)?
- How far can the price drop before liquidation?
That’s what previewLeverage computes β entirely off-chain, using real-time protocol data.
| |
Glossary: Lending Protocol Concepts
If you’re a developer without DeFi background, here’s what you need to know. I’m also studying these concepts in depth β check the Lending Protocol Study series for worked examples:
- Day 1: DeFi λ λ©μ ν΅μ¬ κ°λ κ³Ό μν€ν μ² β Pool-based μ€κ°, Share-Based Accounting, Scaled Balance ν¨ν΄
- Day 2: Compound V2 Deep Diveμ Aave V3 μν€ν μ² β Fresh ν¨ν΄, Mantissa μ°μ°, λΉνΈλ§΅ μ€ν λ¦¬μ§ μ΅μ ν
LTV (Loan-to-Value)
LTV is the maximum percentage of your collateral’s value that you can borrow.
$$\text{LTV} = \frac{\text{Borrowed Value}}{\text{Collateral Value}}$$If SUI has a 70% LTV on Suilend, depositing $100 of SUI lets you borrow up to $70 of USDC. Each protocol sets different LTV ratios per asset β riskier assets get lower LTV.
| Protocol | SUI LTV | XBTC LTV |
|---|---|---|
| Suilend | 70% | 60% |
| Navi | 75% | 67% |
| Scallop | 85% | 75% |
For more details on how Health Factor works with LTV, see Lending Protocol Study Day 1 β the “Share-Based Accounting” section explains why each protocol tracks collateral differently.
Liquidation Threshold (LT)
Liquidation Threshold is the LTV level at which your position gets liquidated. It’s always higher than the borrow LTV, creating a safety buffer.
| |
When the market price drops and your position’s actual LTV exceeds the liquidation threshold, a liquidator can repay part of your debt and claim your collateral at a discount.
Liquidation mechanics are a deep topic β the Lending Protocol Study series covers Compound V2’s
liquidateBorrowFresh()and Aave V3’s architecture in detail.
Max Multiplier
Derived directly from LTV:
$$\text{Max Multiplier} = \frac{1}{1 - \text{LTV}}$$With 70% LTV β max 3.33x leverage. With 85% LTV β max 6.67x. This is a hard protocol limit β you physically cannot borrow more than what the collateral factor allows.
Flash Loan
A flash loan is an uncollateralized loan that must be borrowed and repaid within a single atomic transaction. If you don’t repay, the entire transaction reverts as if it never happened.
In our leverage strategy, the flow is:
- Flash loan USDC from Scallop
- Swap USDC β deposit asset (e.g., SUI)
- Deposit all collateral to lending protocol
- Borrow USDC from protocol (using deposited collateral)
- Repay flash loan
All 5 steps happen in one Sui Programmable Transaction Block (PTB). If step 5 fails, everything reverts.
For more on why Sui’s PTB model is ideal for this β see DefiDash Journal Day 1 where we compare PTB-based atomic leverage vs EVM Flash Loan patterns.
Supply APY & Borrow APY
- Supply APY: What you earn by depositing assets. Composed of base interest + reward tokens (e.g., sSUI, DEEP).
- Borrow APY: What you pay for borrowing. Some protocols give borrowing incentives (rebates).
- Net APY: The leveraged return on your equity.
With 2x leverage: if supply APY > borrow APY, your returns are amplified. If not, you’re paying more than you earn (negative Net APY).
The interest rate models behind these APYs (JumpRateModel, utilization curves) are covered in Lending Protocol Study Day 1 and Day 2. Especially the Mantissa-based fixed-point arithmetic in Day 2 is directly relevant to how we parse on-chain rate data.
Liquidation Price
The asset price at which your position hits the liquidation threshold:
$$\text{Liquidation Price} = \frac{\text{Total Debt}}{\text{Total Collateral Amount} \times \text{Liquidation Threshold}}$$For a $100 SUI position at 2x leverage on Suilend (LT = 75%):
- Debt = $100, Total collateral = ~52.6 SUI (at $3.80)
- Liquidation Price = $100 / (52.6 Γ 0.75) β $2.53
- That’s a ~33% price drop buffer from current price
How It’s Built
Architecture
| |
Multi-Protocol Adapter Pattern
Each lending protocol (Suilend, Navi, Scallop) implements the ILendingProtocol interface, and the preview engine queries them through a unified API:
| |
The same previewLeverage call works across all three protocols β just change the protocol parameter:
| |
This adapter pattern follows the same principle as Aave V3’s modular architecture β separation of concerns with a thin routing layer. The Day 2 study covers how Aave V3 uses
delegatecall + Library patternto achieve a similar pluggable design.
Data Sources
| Data | Source | Notes |
|---|---|---|
| Asset price | 7k Protocol getTokenPrice | Real-time DEX aggregated price |
| LTV / LT | Protocol on-chain state | Suilend RateLimiterConfig, Navi ReserveData, Scallop risk_models |
| Supply/Borrow APY | Protocol SDK + on-chain query | Includes reward token APY |
| Flash loan fee | Scallop FLASHLOAN_FEES_TABLE | Currently 0% for USDC |
| Swap slippage | 7k Protocol quote() | Real-time DEX routing |
Challenges & Bugs Fixed
Reward APY showing 3700% instead of 1.46%
Suilend stores reward coin types without the 0x prefix internally (e.g., deeb7a4...::deep::DEEP). When we passed this to the 7k price API, it returned 0. The fallback code then used the deposit asset’s price ($67,987 for LBTC) as a proxy for the reward token (DEEP at $0.027), inflating the reward APY to 3700%.
Fix: normalize the coin type with 0x prefix before price lookup, and skip the reward if price is still unavailable.
| |
Scallop risk params not accessible via SDK
Scallop’s TypeScript SDK doesn’t expose risk_models data. We had to query the on-chain risk_models dynamic fields directly using suiClient.getDynamicFieldObject() to extract LTV and liquidation threshold values.
Verified Results (2026-02-26, Mainnet)
SUI 2x Leverage
| Suilend | Navi | Scallop | |
|---|---|---|---|
| Asset LTV | 70% | 75% | 85% |
| Liq. Threshold | 75% | 70% | 90% |
| Max Multiplier | 3.33x | 4.00x | 6.67x |
| Liq. Price | $0.63 | $0.68 | $0.53 |
| Price Drop Buffer | 33% | 29% | 44% |
| Supply APY | 2.89% | 2.97% | 2.98% |
| Borrow Net APY | 3.45% | 4.57% | 5.80% |
| Net APY | 2.33% | 1.37% | 0.15% |
XBTC 2x Leverage
| Suilend | Navi | Scallop | |
|---|---|---|---|
| Asset LTV | 60% | 67% | 75% |
| Supply APY | 3.78% | 6.73% | 0.00% |
| Net APY | 4.10% | 8.88% | -5.80% |
The negative Net APY on Scallop XBTC means borrowing costs exceed supply earnings β leverage actually loses money in that case.
What’s Next
leverage()β Actually execute the leveraged position on-chaindeleverage()β Close/reduce a leveraged position (flash loan β repay debt β withdraw β swap β repay)previewDeleverage()β Preview the unwinding process- Cross-protocol position comparison dashboard
Links
- DefiDash SDK Repository
- Lending Protocol Study Day 1 β Core lending concepts (LTV, Health Factor, Share-Based Accounting)
- Lending Protocol Study Day 2 β Compound V2 internals, Aave V3 architecture
- Sui PTB Documentation β Programmable Transaction Blocks
- Suilend | Navi Protocol | Scallop β The three protocols supported
DefiDashμ μ 체 μ½λλ curg-13 μ‘°μ§μμ νμΈν μ μλ€.
