Skip to main content

Earn

Earn puts part of a private balance into an ERC-4626 yield vault. A deposit spends a private note of the vault’s asset, the Gateway calls the vault’s deposit, and the vault shares come back to you as a new private note. A redeem does the reverse: it spends share notes and credits the asset. If the vault call can’t deliver the signed minimum when it executes, the input is refunded to your private balance instead. Earn explains how the Gateway settles these operations and what stays private. Depositing and redeeming need a signed-in session. Earn runs on the root SDK only: a sdk.forChain() client rejects it with UNSUPPORTED_OPERATION.

Checking Availability

Earn needs the external call Gateway. getGatewayConfig() works before sign-in:
availability.retryable says whether canSubmit: false is expected to clear on its own.

Finding Vaults

The vaults you can use are the ERC-4626 routes in the token catalog. An asset token lists an erc4626 capability with direction: 'deposit' for each vault it can enter, and the vault’s share token lists one with direction: 'redeem'. The share token’s address is the vault address.
Some deployments also run a vault catalog with display data: APY, TVL, curators, warnings, and availability per operation. It’s optional. A deployment without it still supports deposits and redemptions, so treat a failed read as “no metadata”, not “no earn”.
APY values are fractions (0.05 is 5%). For TVL and APY charts, see Vault history charts.

Depositing

amount is net: exactly the assets that enter the vault. The Gateway fee is charged on top, so the asset balance has to cover amount + fee (see Fees). previewEarnOutput reads the vault’s previewDeposit on-chain, which is what to show before the user confirms:
The SDK reads the preview again while it builds the request and signs minOutputAmount: the preview less maxSlippageBps. A value above the deployment’s gateway.constraints.maxSlippageBps is lowered to it. If the vault would mint fewer shares than that when the request executes, the deposit settles as a refund. A vault can stop taking deposits while its route is still enabled, for example once it reaches a supply cap. Read maxDeposit for the Gateway executor, the address the vault mints shares to, and hide the deposit when it’s below the amount:

Redeeming

Shares sit in your private balance like any other token, under the vault address. amount is the number of shares to redeem, and the fee is charged in shares on top of it. To redeem everything, leave room for the fee:

Fees

The Gateway fee replaces the ordinary unshield fee. It’s charged in the input token (the asset for a deposit, shares for a redeem) on top of amount, and it’s still charged when the vault call misses its minimum and the input is refunded. result.fee reports the fee that was charged. To show the fee before submitting, price it for the Gateway executor and the vault function’s selector:
For a redeem, pass the vault address and 0xba087652. See Fees for how the operator sets the rate.

Tracking Settlement

A deposit or redeem settles in two steps: the unshield, then the credit of the output note in a later epoch. Read both with getUnshieldStatus(requestId) and wait for gateway.creditStatus, or for a failure. The top-level status only covers the first step.
A request that fails before it settles on-chain reports settlement: 'failed_before_settlement', or 'reorged' when its settlement was reorged out. A credit that doesn’t go through reports creditStatus: 'failed'. In history, an earn operation is two rows, one per step. Pass collapseGateway: true to fetchHistory to get one row per operation.

Error Handling

A refused deposit or redeem has a Gateway code. Read it with asGatewaySubmitErrorCode rather than matching on the message:
A refusal’s retryable flag follows the server’s: a paused Gateway or a failed on-chain read clears by itself, while a minimum the vault no longer meets doesn’t. GATEWAY_ONCHAIN_PREFLIGHT_FAILED means the server checked the vault call on-chain and it would revert. The error’s gatewayPreflight carries a fresh recheck with a reason and a suggestedAction. Codes that come before anything is sent: INSUFFICIENT_BALANCE when the balance doesn’t cover amount + fee, and GATEWAY_FEE_NOT_CONFIGURED when the app has no Gateway fee set up.

Approval-Only Accounts

earnDeposit and earnRedeem refuse an approval-only account with INVALID_INPUT. It proposes the operation as a plan instead:
Before the owner approves, check the package with verifyEarnApprovalPackage(owner, expectedAuthority, authRegistryState), using the AuthRegistry state that assertApprovalOnlyAccount returns. Once the owner’s approval is on-chain, submit the plan with sdk.vault.submitPrebuiltEarnApprovalPlan(plan.privatePlan), or let reconcilePendingApprovals() submit it. Before it submits an earn plan, reconcilePendingApprovals() reads the vault’s preview again. A plan whose signed minimum no longer clears would only settle as a refund, so it’s reported as stale and left for the user to propose again. See Approval plans.

Next Steps