> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# getYieldPerformance

# getYieldPerformance

Gets a wallet's earnings in a single [Earn](/docs/earn/overview) vault: how much the position has earned (`netEarningsAssets`) and its return on capital (`returnOnCapital`).

The values are indexed by Morpho rather than read on-chain, so they trail the chain head by a short delay. [`getYieldPosition`](/docs/javascript/reference/client/get-yield-position) 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 Morpho has too little history on the position to compute one.

<Note>
  `netEarningsAssets` comes back as a raw string (e.g. `"854395278"`), not a human-readable number, so values above 2^53 stay exact. Divide by the vault's `assetDecimals`, from [`getYieldDetails`](/docs/javascript/reference/client/get-yield-details), before displaying it, the same way you'd format a position's `assets`. See the example below.
</Note>

## Usage

```javascript theme={"system"}
import { getYieldPerformance } from '@dynamic-labs-sdk/client';

const performance = await getYieldPerformance({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
});

console.log(performance.netEarningsAssets, performance.returnOnCapital);
```

## Parameters

| Parameter       | Type                       | Description                                                                                        |
| --------------- | -------------------------- | -------------------------------------------------------------------------------------------------- |
| `vaultId`       | `string`                   | Opaque vault identifier, from [`listYieldVaults`](/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount`            | The wallet account whose performance in the vault is being read.                                   |
| `client`        | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple Dynamic clients.                    |

## Returns

`Promise<YieldVaultPositionPerformance>` - The position's net earnings and return on capital.

| Field               | Type             | Description                                                                                 |
| ------------------- | ---------------- | ------------------------------------------------------------------------------------------- |
| `vaultId`           | `string`         | Opaque vault identifier.                                                                    |
| `ownerAddress`      | `string`         | The wallet address the performance was read for.                                            |
| `netEarningsAssets` | `string`         | Net earnings in raw underlying-token units. Divide by `assetDecimals` before display.       |
| `returnOnCapital`   | `number \| null` | Time-weighted, non-annualized return as a decimal. `null` when there is too little history. |

## Examples

### Format earnings for display

```javascript theme={"system"}
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,
  };
}
```

## React

`useGetYieldPerformance` is a query hook that stays disabled until `walletAccount` is defined, safe to render before a wallet is connected.

```tsx theme={"system"}
import { useGetYieldDetails, useGetYieldPerformance } from '@dynamic-labs-sdk/react-hooks';
import type { WalletAccount } from '@dynamic-labs-sdk/client';
import { formatUnits } from 'viem';

function Earnings({
  vaultId,
  walletAccount,
}: {
  vaultId: string;
  walletAccount: WalletAccount | undefined;
}) {
  const { data: details } = useGetYieldDetails({ vaultId });
  const { data: performance, isLoading } = useGetYieldPerformance({
    vaultId,
    walletAccount,
  });

  if (isLoading || !details) {
    return <p>Loading earnings...</p>;
  }

  const earnings = formatUnits(
    BigInt(performance?.netEarningsAssets ?? '0'),
    details.assetDecimals
  );

  return <p>Earnings: {earnings} {details.assetSymbol}</p>;
}
```

## Related

* [`getYieldPosition`](/docs/javascript/reference/client/get-yield-position) - The wallet's current balance in the vault
* [`getYieldEarnings`](/docs/javascript/reference/client/get-yield-earnings) - The wallet's earnings across all vaults on a chain
* [`getYieldDetails`](/docs/javascript/reference/client/get-yield-details) - Vault details, including `assetDecimals`
