Frontend Applications

Build dashboards, portfolio trackers, and trading UIs that display Gearbox protocol data and let users manage positions.

Overview

Frontend applications typically need to:

  1. Display pool and market data

  2. Show collateral exposure and limits

  3. Monitor credit account health

  4. Enable position management

This guide maps each requirement to specific SDK methods.


Pool Display

WHY: Users want to see pool health, yields, and utilization before depositing or borrowing.

Data Requirements

Display
SDK Source
Field

Underlying token

market.pool

underlying.symbol, underlying.address

Total supplied

market.pool

totalAssets

Available liquidity

market.pool

availableLiquidity

Utilization

Calculated

(totalAssets - availableLiquidity) / totalAssets

Supply APY

market.pool

supplyRate (RAY scaled)

Borrow APR

market.pool

baseInterestRate (RAY scaled)

Share price

market.pool

dieselRate (RAY scaled)

How to Fetch

Where Data Comes From

The SDK caches market data on initialization via GearboxSDK.attach(). This data comes from the MarketCompressor contract. For real-time updates, either:


Collateral Exposure

WHY: Users want to see what collaterals the pool is exposed to and current utilization against limits.

Data Requirements

Display
SDK Source
Field

Quoted tokens

MarketData.quotaKeeper

tokens[]

Token quota limit

quotaKeeper.tokens[]

limit

Current quoted amount

quotaKeeper.tokens[]

totalQuoted

Quota rate

quotaKeeper.tokens[]

rate (RAY scaled)

How to Fetch

For quota data, use the MarketCompressor directly:

Gotcha: Quota Limits

Before letting users open positions with a specific collateral, check that totalQuoted < limit. If the limit is reached, new positions with that collateral will fail.


Credit Manager Configuration

WHY: Users need to know debt limits, collateral requirements, and fees before opening positions.

Data Requirements

Display
SDK Source
Field

Min debt

creditManager

minDebt

Max debt

creditManager

maxDebt

Collateral tokens

creditManager

collateralTokens[]

Liquidation threshold

collateralTokens[]

liquidationThreshold (basis points)

Fees

creditManager

fees

Liquidation premium

creditManager

liquidationPremium

How to Fetch

Understanding Liquidation Threshold

The liquidation threshold (LT) determines how much each collateral contributes to the weighted collateral value:

A lower LT means the protocol values that collateral more conservatively.


Credit Account Monitoring

WHY: Users need to track their position health, collateral values, and accrued interest.

Data Requirements

Display
SDK Source
Field

Account address

CreditAccountData

addr

Owner

CreditAccountData

owner

Total debt

CreditAccountData

debt

Health factor

CreditAccountData

healthFactor (10000 = 1.0)

Is liquidatable

CreditAccountData

isLiquidatable

Token balances

CreditAccountData

tokens[]

Token values

tokens[]

balanceInUnderlying

Accrued interest

CreditAccountData

cumulativeQuotaInterest

Quota fees

CreditAccountData

quotaFees

How to Fetch

Interest Breakdown

Credit account debt consists of:

  • Principal: Original borrowed amount

  • Base interest: Accrues on principal based on pool utilization

  • Quota interest: Per-collateral rate for non-underlying tokens

  • Quota fees: Fixed fee component for quotas

Health Factor Thresholds

Display appropriate warnings based on health factor:


Price Feed Information

WHY: Users want to understand which oracles determine their collateral values.

How to Fetch


Position Management

WHY: Users take actions on their positions (add collateral, borrow, repay, etc.).

Linking to Operations

Position management uses multicalls. Link to the appropriate operation guide:

User Action
Operation Guide

Deposit collateral

Borrow more

Repay debt

Update quota

Swap collateral

Pre-Operation Data Checks

Before letting users perform operations, validate:


Real-Time Updates

WHY: UI needs to stay current as blockchain state changes.

Option 1: Poll Compressors

For most dashboards, polling every few seconds is sufficient:

Option 2: Watch Events

For specific state changes, watch contract events:

Recommendation

Use polling for:

  • General market data

  • Pool state (rates, liquidity)

  • Quota utilization

Use events for:

  • User's own account changes

  • Critical health factor alerts


Complete Example: Dashboard Component


Next Steps

Last updated