Skip to main content
Calculates the value of account shares in a quote asset using the on-chain exchange rate from the Accountant contract via getRateInQuote(quoteAsset). The share balance can come from two sources:
  • userAddress — reads balanceOf(userAddress) on the BoringVault on-chain
  • shareAmount — uses the provided amount directly (skips balanceOf)
When both are provided, shareAmount takes precedence. At least one must be specified.

Import

import { getShareValue } from '@paxoslabs/amplify-sdk'

Usage

import { getShareValue, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

// Look up a user's position value by wallet address
const result = await getShareValue({
  vaultName: vault.name,
  chainId: 1,
  quoteAssetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  userAddress: '0x1234...5678',
})

console.log(result.shareBalance) // bigint — shares held
console.log(result.value) // bigint — worth in USDC units
console.log(result.exchangeRate) // bigint — rate from accountant

// Or value a known share amount directly
const preview = await getShareValue({
  vaultName: vault.name,
  chainId: 1,
  quoteAssetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  shareAmount: '100.0',
})

Parameters

ParameterTypeRequiredDescription
vaultNamestringYesAccount name from getVaultsByConfig()
chainIdChainIdYesBlockchain network ID
quoteAssetAddressAddressYesToken to value shares in (e.g., USDC)
userAddressAddressNoWallet address to read balanceOf for
shareAmountstringNoExplicit share amount (overrides balanceOf when set)
At least one of userAddress or shareAmount must be provided.
interface GetShareValueParams {
  vaultName: string
  chainId: ChainId
  quoteAssetAddress: Address
  userAddress?: Address
  shareAmount?: string
}

Return Type

interface ShareValueResult {
  /** Share balance used for the calculation */
  shareBalance: bigint
  /** Value of shares in quote-asset units */
  value: bigint
  /** Exchange rate from getRateInQuote */
  exchangeRate: bigint
  /** Decimals of the BoringVault share token */
  shareDecimals: number
  /** Decimals of the quote asset */
  quoteAssetDecimals: number
}

Example: Portfolio Value Display

import { getShareValue, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'
import { formatUnits } from 'viem'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

const result = await getShareValue({
  vaultName: vault.name,
  chainId: 1,
  quoteAssetAddress: usdcAddress,
  userAddress: connectedWalletAddress,
})

const shares = formatUnits(result.shareBalance, result.shareDecimals)
const value = formatUnits(result.value, result.quoteAssetDecimals)
console.log(`You hold ${shares} vault shares worth $${value}`)

Error Handling

Error Message PatternDescriptionResolution
"Either userAddress or shareAmount must be provided"Neither param givenPass at least one
"No vault found"No account matches parametersVerify vaultName, asset, chainId
"SDK not initialized"SDK not initializedCall initAmplifySDK() first