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
assetDecimalsandcontractAddress
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 —
sharesandassets, both in raw token units. Showassets; 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
accruedin raw units and its owntokenDecimals
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 —
netEarningsAssetsin raw token units andreturnOnCapitalas a decimal,nilwhen 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
8453for Base - ownerAddress (String) — Wallet address the earnings belong to
Returns
- EarnEarnings —
totalAssetsUsdandtotalPnlUsdtotals plus a per-vaultvaultsbreakdown. Positions whose provider does not report a cost basis carrynilPNL 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
signingPayloadto pass toexecute
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
signingPayloadto pass toexecute
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
signingPayloadto pass toexecute
Throws an
EarnError whose nothingToClaim is true when there is nothing to claim.execute
Sign and broadcast a payload returned bydeposit, withdraw, or claim.
Parameters
- payload (EarnSigningPayload) — The
signingPayloadfrom 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.
truerequires gas sponsorship and throwsEarnSponsorErrorwhen unavailable,falsealways pays from the wallet,nilsponsors when the environment enables it - onStepChange ((EarnExecutionStep) -> Void, optional) — Reports
.approvalbefore an ERC-20 approval is sent and.transactionbefore each vault transaction - onTransactionStepChange ((EarnTransactionStepChange) -> Void, optional) — Solana only: reports each transaction’s
ordinal,total, andlabelas it begins
Returns
- String — The vault transaction hash (the last signature on Solana)
Example
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. Carriescode (expired, failed, or sendFailed), the stopped transaction’s ordinal, and the sequence total. Transactions before ordinal already confirmed on-chain.
EarnSponsorError
Thrown whensponsored: true was required but sponsorship was unavailable or the sponsored transaction failed.