Credit Accounts

Query and manage credit accounts using SDK services.

For Solidity credit operations, see Credit Operations.

Creating a Service

Use createCreditAccountService for credit account operations:

import { GearboxSDK, createCreditAccountService } from '@gearbox-protocol/sdk';

const sdk = await GearboxSDK.attach({ client, marketConfigurators: [] });

// Create service (310 = V3.1)
const service = createCreditAccountService(sdk, 310);

Querying Credit Accounts

Get All Accounts for a Credit Manager

const accounts = await service.getCreditAccounts(
  { creditManager: cmAddress },
  sdk.currentBlock
);

for (const account of accounts) {
  console.log(`Account: ${account.addr}`);
  console.log(`  Owner: ${account.owner}`);
  console.log(`  Debt: ${account.debt}`);
  console.log(`  Health Factor: ${account.healthFactor}`);
}

Filter by Owner

Account Data Structure

Each credit account includes:

Field
Type
Description

addr

address

Credit Account contract address

owner

address

Account owner

creditManager

address

Parent Credit Manager

debt

uint256

Total debt (principal + interest)

healthFactor

uint256

Current HF (10000 = 1.0)

tokens

TokenInfo[]

Token balances and values

isLiquidatable

boolean

Whether account can be liquidated

Reading Account State

Health Factor

Token Balances

Debt Breakdown

Market Discovery

Find the market for a credit manager:

Opening a Credit Account

Closing a Credit Account

Complete Example

Next Steps

For architectural background, see Credit Suite Architecture.

Last updated