Gets a wallet’s earnings in a single Earn vault: how much the position has earned (netEarningsAssets) and its return on capital (returnOnCapital).The values are indexed by the vault’s provider rather than read on-chain, so they trail the chain head by a short delay. getYieldPosition stays the source of truth for what a position is worth right now; use this function for earnings and PNL.returnOnCapital is a time-weighted, non-annualized decimal (for example 0.00413 means a 0.41% return). It comes back null when the provider has too little history on the position to compute one, and always for Kamino vaults, which report no time-weighted return.
This function currently supports vaults from these providers: Morpho and Kamino. For a vault from any other provider, such as an Aave vault, the call rejects because the API responds with an HTTP 400 error. Check the vault’s provider from getYieldDetails before calling it, and use the assets value from getYieldPosition to show the position’s balance.
netEarningsAssets comes back as a raw string (e.g. "854395278"), not a human-readable number, so values above 2^53 stay exact. It is negative when the position is at a loss (e.g. "-2500000"). Divide by the vault’s assetDecimals, from getYieldDetails, before displaying it, the same way you’d format a position’s assets. See the example below.
The wallet account whose performance in the vault is being read. Must be an EVM wallet account for an EVM vault, or a Solana wallet account for a Solana vault.
client
DynamicClient (optional)
The Dynamic client instance. Only required when using multiple Dynamic clients.
import { getYieldDetails, getYieldPerformance } from '@dynamic-labs-sdk/client';import { formatUnits } from 'viem';// Turns the raw `netEarningsAssets` string into a plain number like "854.39",// ready to show a user.async function loadEarnings(vaultId, walletAccount) { const [details, performance] = await Promise.all([ getYieldDetails({ vaultId }), getYieldPerformance({ vaultId, walletAccount }), ]); return { assetSymbol: details.assetSymbol, earnings: formatUnits(BigInt(performance.netEarningsAssets), details.assetDecimals), returnOnCapital: performance.returnOnCapital, };}