Account Management
The account module provides comprehensive lending account functionality, including account information queries, health factor calculations, token merging, and other operations.
Core Features
- Account Information Query: Retrieve detailed information about user lending accounts
- Health Factor Calculation: Calculate and monitor account health factors
- Token Management: Merge and manage tokens in accounts
- Dynamic Health Factor: Simulate the impact of operations on health factors
API Reference
getLendingState
Get user's lending account information. You can filter by specific market(s). See documentation for details.
We standardized the precision of the borrowBalance and supplyBalance, with all decimal places
set to 9.
Usage Example
import { getLendingState } from '@naviprotocol/lending'
// Get lending state from all markets
const lendingState = await getLendingState('0x...')
// Get lending state from specific market(s)
const mainMarketState = await getLendingState('0x...', {
markets: ['main'] // Optional: filter by market(s)
})
// Get lending state from multiple markets
const multipleMarketsState = await getLendingState('0x...', {
markets: ['main', 0] // Can use string or number identifiers
})Result Example
[{
assetId: 19,
borrowBalance: '1979162', // The precision is fixed at 9, not the decimal part of the token.
supplyBalance: '0', // The precision is fixed at 9, not the decimal part of the token.
market: 'main', // Market identifier
emodeId: 1, // Optional EMode ID if the position is in EMode
pool: {
coinType: '375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT',
id: 19,
...
}
}]Return Fields
assetId: Asset identifierborrowBalance: Current borrow balance (precision fixed at 9)supplyBalance: Current supply balance (precision fixed at 9)market: Market identifier (e.g., "main")emodeId: Optional EMode ID if the position is in EModepool: Pool information object
Parameters
address: User address or Account Cap object IDoptions(optional):markets: Array of market identifiers to filter by (if not specified, returns data from all markets)env: Environment configuration ('dev' or 'prod')client: Sui client instancecacheTime: Cache time in millisecondsdisableCache: Whether to disable cache
For a more structured way to manage positions with automatic value calculations, EMode support, and overview statistics, see the Position Management documentation.
getTransactions
Get user's transaction history under the NAVI protocol. See documentation for details.
Usage Example
import { getTransactions } from '@naviprotocol/lending'
const transactionResult = await getTransactions('0x...', {
cursor: ''
})Result Example
{
"cursor": "7dmAzBcvd6BcX5msm1UFJns1KdMyqWKfMfqmr6n7ZHEx::0",
"data": [
{
"type": "supply",
"status": "success",
"coinChanges": [],
"timestamp": "1751358720243",
"digest": "BVpGDpt9nmb1TkTnh65QmqedXt2gYqkVMhhkBE1uraWG"
},
{
"type": "supply",
"status": "success",
"coinChanges": [
{
"symbol": "xBTC",
"amount": "-93199"
}
],
"timestamp": "1751026542701",
"digest": "GboAWeq8Lt73MUyUrrqsyURqsZRb4XqbBSvP3qHbcbEy"
},
{
"type": "withdraw",
"status": "success",
"coinChanges": [
{
"symbol": "USDC",
"amount": "100000000"
}
],
"timestamp": "1751026504653",
"digest": "9SyEYiMissMXHptiHYHhdTwAbQVscj56kHfVJAq37qLt"
},
{
"type": "supply",
"status": "success",
"coinChanges": [
{
"symbol": "xBTC",
"amount": "-2889"
}
],
"timestamp": "1751025731403",
"digest": "2B7Y2hp2VV4ahB1bRXSRXHNCDbCSUfviUEKxLuZfR1Ec"
},
{
"type": "withdraw",
"status": "success",
"coinChanges": [
{
"symbol": "USDC",
"amount": "1000000"
}
],
"timestamp": "1750782315024",
"digest": "5wn29nowrm8LfRj6RgdyWzRa1fBZNjtjViooFhejffks"
},
{
"type": "withdraw",
"status": "success",
"coinChanges": [
{
"symbol": "USDC",
"amount": "1000000"
}
],
"timestamp": "1750782116159",
"digest": "25zWhQimN7A2UhjMerM3PTsayKpkp7fnrJzgWG4JRxoq"
},
{
"type": "withdraw",
"status": "success",
"coinChanges": [
{
"symbol": "USDC",
"amount": "1000000"
}
],
"timestamp": "1750781750357",
"digest": "Atw8Q7eLJdpkZRxjkqjjqqvpHNZoscRJkXvLbxsQNCUq"
},
{
"type": "repay",
"status": "success",
"coinChanges": [
{
"symbol": "wUSDC",
"amount": "-3024"
}
],
"timestamp": "1749542703573",
"digest": "4ADWEhNgnsYzV44qjEgeuSs8T8ZVaesMDB2D1QiH6DVX"
},
{
"type": "withdraw",
"status": "success",
"coinChanges": [
{
"symbol": "wUSDC",
"amount": "6886783"
}
],
"timestamp": "1749542675879",
"digest": "3i9qfjrtCvSEd7P8wZQoDc994J7TFTS4wgVdZTsGFLrQ"
},
{
"type": "repay",
"status": "success",
"coinChanges": [
{
"symbol": "wUSDC",
"amount": "-1000000"
}
],
"timestamp": "1749542600488",
"digest": "7dmAzBcvd6BcX5msm1UFJns1KdMyqWKfMfqmr6n7ZHEx"
}
]
}getHealthFactor
Get the current health factor of an account. See documentation for details.
Usage Example
import { getHealthFactor } from '@naviprotocol/lending'
const healthFactor = await getHealthFactor('0x...')Result Example
1.8getSimulatedHealthFactor
Simulate the impact of operations on health factors to predict account status after operations. See documentation for details.
Usage Example
import { getSimulatedHealthFactor } from '@naviprotocol/lending'
const healthFactor = await getSimulatedHealthFactor('0x...', '0x2::sui::SUI', [
{ type: PoolOperator.Supply, amount: 1000000000 }
])Result Example
2.1getCoins
Get the list of tokens in a user's account. See documentation for details.
Usage Example
import { getCoins } from '@naviprotocol/lending'
const coins = await getCoins(
'0x...', // User address
{
coinType: '0x2::sui::SUI' // Optional token type filter
}
)Result Example
[
{
"coinObjectId": "0x1",
"balance": "1000000000",
"coinType": "0x2::sui::SUI",
"digest": "0x...",
"version": "123456"
}
]mergeCoinsPTB
Merge multiple tokens in a programmable transaction block. See documentation for details.
Usage Example
import { mergeCoinsPTB } from '@naviprotocol/lending'
import { Transaction } from '@mysten/sui/transactions'
const tx = new Transaction()
const mergedCoin = mergeCoinsPTB(
tx,
[
{ coinObjectId: '0x1', balance: '1000000000', coinType: '0x2::sui::SUI' },
{ coinObjectId: '0x2', balance: '2000000000', coinType: '0x2::sui::SUI' }
], // Token list
{
balance: 2500000000, // Optional split balance
useGasCoin: true // Whether to use tx.gas
}
)getHealthFactorPTB
Get health factor in a programmable transaction block. See documentation for details.
Usage Example
import { getHealthFactorPTB } from '@naviprotocol/lending'
const healthFactorResult = await getHealthFactorPTB(tx, '0x...')getSimulatedHealthFactorPTB
Get dynamic health factor in a programmable transaction block. See documentation for details.
Usage Example
import { getSimulatedHealthFactorPTB } from '@naviprotocol/lending'
// Basic usage
const healthFactorResult = await getSimulatedHealthFactorPTB(
tx,
'0x...',
assetIdentifier, // Asset identifier
estimatedSupply, // Estimated supply amount
estimatedBorrow, // Estimated borrow amount
isIncrease
)
// With market option
const healthFactorResultWithMarket = await getSimulatedHealthFactorPTB(
tx,
'0x...',
assetIdentifier,
estimatedSupply,
estimatedBorrow,
isIncrease,
{
market: 'main' // Optional: market identifier
}
)Parameters
tx: Transaction objectaddress: User addressassetIdentifier: Asset identifierestimatedSupply: Estimated supply amountestimatedBorrow: Estimated borrow amountisIncrease: Whether the operation increases the positionoptions(optional):market: Market identifierenv: Environment configuration ('dev' or 'prod')