DocumentationOpen App
On this pageConnect SDK

Monitor

Check a Credit Account's health factor, then inspect the balances, oracle prices, liquidation thresholds, and quotas that determine it.

Connect SDK

Follow Connect SDK first. The snippets below use the already-connected instance as sdk.

Find your leveraged position

Read the leveraged positions owned by your wallet address, owner. Use the onchain source here so the position and the market data below come from RPC:

TypeScript
const positions = await sdk.positions.onchain.list({ wallet: owner, filter: { kind: "strategy" }, });

positions.data contains the leveraged positions. Check positions.meta.chains for read status, block, and timestamp. A failed read does not mean there are no leveraged positions.

With the strategy filter, each entry in positions.data is a StrategyPosition:

FieldTypeMeaning
kind"strategy"Identifies a leveraged position
namestringStrategy name
chainIdnumberChain where the position exists
creditAccountAddressYour position's Credit Account address
creditManagerAddressCredit Manager governing the position
underlyingTokenUnderlyingTokenAsset used to denominate debt and total value; the unwrapped asset for RWA markets
targetCollateralToken | nullStrategy's target collateral token, or null when no target is identified
collateralsPositionCollateral[]Held token balances, allocated quotas, and pending withdrawals
totalValueTokenAmountTotal value of the account's holdings in the market underlying
totalDebtTokenAmountDebt principal plus accrued interest and fees
leveragenumberTotal value divided by equity: 4 means 4×
healthFactornumberHealth factor in basis points: 12500 means 1.25
borrowApynumberAnnual base borrowing cost including the protocol interest fee, in basis points: 520 means 5.2%
borrowRateBorrowRateBreakdown | undefinedBorrowing cost broken down into base and quota costs
timeToLiquidationbigint | null | undefinedEstimated milliseconds to HF 1 at a fixed borrowing rate and collateral value—no collateral yield or appreciation. Not a guaranteed safe period. null if the rate is zero or HF is already ≤ 1
liquidationPricebigint | null | undefinedImmediate price-change threshold for HF 1, using current balances, debt, and LTs. Underlying per collateral token, scaled by 10 ** 8. Excludes future accrual and quota caps. null unless exactly one non-dust, non-underlying asset is held
errorstring | undefinedIncomplete or failed valuation; balances may be available while valued fields are unreliable

TokenAmount contains token, value, and valueUsd. value is a bigint in that token's base units; valueUsd is a dollar value or null when unavailable. Equity is totalValue.value - totalDebt.value; the position does not have a netValue field. Backend-only fields such as historical APYs and PnL are not included in this onchain read.

Select the account to inspect:

TypeScript
import type { StrategyPosition } from "@gearbox-protocol/sdk/model"; const selectedIndex = 0; // Index of your position in the returned list const position = positions.data[selectedIndex] as StrategyPosition;

Check health factor

Health factor is the collateral value counted for solvency divided by total debt value:

HF=∑iCiD,Ci={min⁡(BiPiLi,  QiPu),quota-bearing collateralBiPiLi,collateral without a quota cap\mathrm{HF} = \frac{\sum_i C_i}{D}, \qquad C_i = \begin{cases} \min(B_i P_i L_i,\; Q_i P_u), & \text{quota-bearing collateral} \\ B_i P_i L_i, & \text{collateral without a quota cap} \end{cases}
  • BiB_i is the token balance in whole-token units.
  • PiP_i is its oracle price; PuP_u is the underlying token's oracle price.
  • LiL_i is its liquidation threshold as a fraction, such as 0.90.9 for 90%.
  • QiQ_i is its allocated quota in whole underlying-token units.
  • DD is total debt, including accrued interest and fees, valued using PuP_u.

Prices must use the same currency. A quota caps the LT-weighted value, not the raw collateral value. An inactive quota contributes zero. The formula describes eligible collateral; the SDK also applies integer rounding and token eligibility and dust rules. Safe-price checks can use lower prices than the main oracle prices.

The SDK reports healthFactor as ⌊10000×HF⌋\lfloor 10000 \times \mathrm{HF} \rfloor: 12500 means 1.25, and below 10000 the account is liquidatable. With zero debt, the SDK returns the sentinel 65535 instead of dividing by zero.

A falling HF can come from a lower token balance or oracle price, a lower liquidation threshold, a binding quota, or growing debt. Inspect these components to distinguish the cause.

Collateral yield can increase balances or the token's oracle price and improve HF, but only while the resulting contribution is not capped by quota. Borrowing interest and quota costs increase debt and reduce HF over time. A change in quota affects HF only when it changes the collateral value counted for solvency.

Inspect collateral

Each entry in position.collaterals describes one held token:

FieldTypeMeaning
collateral.tokenTokenHeld token, including address, symbol, and decimals
collateral.valuebigintBalance in that token's base units
collateral.valueUsdnumber | nullDollar value, or null when unavailable
quota.valuebigintAllocated quota in market underlying base units, not collateral token units
withdrawalsDelayedReceivedAsset[]Pending delayed withdrawals associated with this collateral

The account can hold several tokens. Inspect every collateral entry, not just targetCollateral. A redemption phantom is reported as the held token; its pending underlying proceeds are described by withdrawals.

Prices and liquidation thresholds are available from the selected account's market. They are not fields of PositionCollateral. Select one held token:

TypeScript
const chain = sdk.onchain.chain(position.chainId); const suite = chain.marketRegister.findCreditManager(position.creditManager); const collateralIndex = 0; // Index of the collateral to inspect const token = position.collaterals[collateralIndex].collateral.token.address; const price = suite.market.priceOracle.mainPrice(token); // USD per token, 8 decimals const lt = suite.creditManager.liquidationThresholds.get(token); // Basis points: 9000 = 90%

mainPrice() throws if the price is unavailable; lt is undefined if the threshold is missing. Neither case is a successful valuation. Use collateral.valueUsd above for the held balance's dollar value.

Read the position and its market data together. After refreshing chain state, read the position again rather than combining old balances with new prices or thresholds.

Actions and their effect on HF

ActionEffect on HFRequirements and dependenciesSide effects
RepayIncreases HF by reducing debt while retaining collateralUnderlying tokens held in your wallet, or the supported unwrapped asset for an RWA market; partial repayment must respect minimum debtSpends wallet funds and reduces future debt interest; partial repayment does not automatically reduce quotas
Adjust leverageIncreasing leverage generally lowers HF; decreasing leverage generally raises itAvailable swap or redemption paths; increasing leverage also requires borrowing and quota capacitySlippage, price impact, and fees; deleveraging can require delayed settlement
DepositApproximately preserves HF when keeping current leverageWallet funds; increases position size by adding collateral and borrowing more, requiring routes and available capacitySlippage and fees can change HF; increases exposure, debt, and potentially quota costs
WithdrawApproximately preserves HF for a proportional partial withdrawalDecreases position net value by selling assets and repaying debt; requires an available withdrawal routeSlippage and fees; may trigger delayed operations, during which debt continues accruing costs
Add collateralCan increase HF at fixed debt; no increase if the added value is excluded or already capped by quotaThe position's collateral token held in your wallet; sufficient quota for its value to count where requiredCommits more wallet funds without increasing debt; a direct token transfer has no swap slippage, but any associated quota increase can add costs
Withdraw collateralLowers HF if it removes value counted for solvency; may leave HF unchanged while the remaining value still exceeds the quota capA directly withdrawable token and sufficient remaining collateral coverageReturns tokens without reducing debt; reduces equity and generally increases leverage; a direct transfer has no swap slippage
Increase quotaRaises HF only while quota caps the token's LT-weighted valueActive quota market and available quota capacityMore quota increases quota interest expense and may incur a quota-increase fee; the applicable quota rate can also change over time
Decrease quotaLeaves HF unchanged until quota falls below the token's LT-weighted value; further reduction lowers HFRemaining quota must provide sufficient collateral coverageReduces quota interest expense without changing balances or repaying debt

HF effects assume unchanged prices and liquidation thresholds. Deposit and withdraw preserve leverage by default, but quota caps and execution costs can prevent exact HF preservation. Preview the proposed action to check its actual effect before executing it.

Source