Skip to main content

sdk.earn

Earn module for depositing into yield vaults, tracking positions, and withdrawing. For a guided walkthrough, see Earn.

getVaults

List the yield vaults available to the environment.

Returns

  • [EarnVaultSummary] — Vaults available to the environment, ordered as the API returns them

Example

getVaultDetails

Get full details for one vault, including its contract address and the underlying asset’s decimals.

Parameters

  • vaultId (String) — Opaque vault identifier, from getVaults

Returns

  • EarnVaultDetails — Vault metadata including assetDecimals and contractAddress

Example

getVaultPosition

Read a wallet’s position in a vault.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address that owns the position

Returns

  • EarnVaultPosition — shares and assets, both in raw token units. Show assets; it grows as yield accrues

Example

getVaultRewards

Read the rewards a wallet has accrued through a vault.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address that owns the rewards

Returns

  • [EarnVaultReward] — Accrued rewards, empty when the wallet has none. Each reward carries accrued in raw units and its own tokenDecimals

getVaultPerformance

Read a wallet’s Morpho-indexed earnings in one vault.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address that owns the position

Returns

  • EarnVaultPerformance — netEarningsAssets in raw token units and returnOnCapital as a decimal, nil when the position has too little history
Indexed values trail the chain head, so getVaultPosition remains the live source of truth for the position’s value. Supports Morpho vaults only; other providers throw an EarnError with statusCode 400.

getEarnings

Read a wallet’s aggregate earnings across every vault it holds on one EVM chain.

Parameters

  • chainId (Int) — EVM chain ID the earnings are aggregated on, for example 8453 for Base
  • ownerAddress (String) — Wallet address the earnings belong to

Returns

  • EarnEarnings — totalAssetsUsd and totalPnlUsd totals plus a per-vault vaults breakdown. Positions whose provider does not report a cost basis carry nil PNL fields
Covers Morpho and Aave positions on EVM chains only. Solana vault positions are not included; use getVaultPosition for those.

deposit

Request an unsigned deposit payload.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address funding the deposit
  • amount (String) — Human-readable amount in the vault asset ("12.5"), with a leading digit ("0.01", not ".01")
  • receiverAddress (String?, optional) — Wallet that receives the vault shares. Defaults to ownerAddress

Returns

  • EarnVaultActionResponse — Carries the signingPayload to pass to execute

withdraw

Request an unsigned withdrawal payload.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address that owns the shares
  • amount (String) — Human-readable amount in the vault asset
  • receiverAddress (String?, optional) — Wallet that receives the withdrawn assets. Defaults to ownerAddress

Returns

  • EarnVaultActionResponse — Carries the signingPayload to pass to execute

claim

Request an unsigned payload claiming every reward the wallet has accrued in a vault.

Parameters

  • vaultId (String) — Opaque vault identifier
  • ownerAddress (String) — Wallet address that owns the rewards

Returns

  • EarnVaultActionResponse — Carries the signingPayload to pass to execute
Throws an EarnError whose nothingToClaim is true when there is nothing to claim.

execute

Sign and broadcast a payload returned by deposit, withdraw, or claim.

Parameters

  • payload (EarnSigningPayload) — The signingPayload from a vault action response
  • wallet (BaseWallet) — Wallet to sign with. Its chain must match the payload’s chainName
  • sponsored (Bool?, optional) — How fees are paid. true requires gas sponsorship and throws EarnSponsorError when unavailable, false always pays from the wallet, nil sponsors when the environment enables it
  • onStepChange ((EarnExecutionStep) -> Void, optional) — Reports .approval before an ERC-20 approval is sent and .transaction before each vault transaction
  • onTransactionStepChange ((EarnTransactionStepChange) -> Void, optional) — Solana only: reports each transaction’s ordinal, total, and label as it begins

Returns

  • String — The vault transaction hash (the last signature on Solana)

Example

An EVM payload sends its ERC-20 approval first when it carries one. A Solana payload signs, sends, and confirms its transactions one at a time in ordinal order and throws an EarnSolanaStepError when a step cannot complete, which may leave earlier transactions already confirmed.

Error types

EarnError

Thrown when an Earn API call or execution fails. statusCode carries the HTTP status when the failure came from the API, and nothingToClaim is true for a claim with no claimable rewards (HTTP 422).

EarnSolanaStepError

Thrown when a transaction in a multi-transaction Solana action cannot complete. Carries code (expired, failed, or sendFailed), the stopped transaction’s ordinal, and the sequence total. Transactions before ordinal already confirmed on-chain.

EarnSponsorError

Thrown when sponsored: true was required but sponsorship was unavailable or the sponsored transaction failed.
Last modified on October 23, 2026