Skip to content
LogoLogo

Redeem Earn Shares

earn.redeem

Redeems an exact number of Earn shares for assets sent to a recipient.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : 100_000_000n,
  : 50,
  : '0x0000000000000000000000000000000000000001',
})
{
// assetAmount: 99_500_000n,// caller: '0x...', // receipt: { ... }, // recipient: '0x...', // shareAmount: 100_000_000n, // }

When only slippageBps is provided, the action gets a live earn.getRedeemQuote and derives the minimum asset output. The transaction approves the Earn shares and redeems them atomically.

Use an Existing Quote

Pass assetAmount with slippageBps when you already have a recent asset quote.

import {  } from './viem.config'
 
const  = await ..({
  : 99_750_000n,
  : 100_000_000n,
  : 50,
  : '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 99_500_000n, shareAmount: 100_000_000n, ... }

Asynchronous Usage

earn.redeemSync waits for inclusion and returns the decoded redemption event. Use earn.redeem to return the transaction hash immediately.

import {  } from './viem.config'
 
const  = await ..({
  : 99_000_000n,
  : 100_000_000n,
  : '0x0000000000000000000000000000000000000001',
})
0x1234...abcd

Recipes

Exit the Full Position

Combine earn.getPosition with the redemption to burn every Earn share the account holds.

import {  } from './viem.config'
 
const  = '0x0000000000000000000000000000000000000001'
 
const {  } = await ..({  })
 
const  = await ..({
  : ,
  : 50,
  ,
})
{ assetAmount: 100_250_000n, shareAmount: 99_500_000n, ... }

Fund a Payroll Account from Yield

Pass recipient to pay the redeemed assets straight to a disbursement address ahead of a payroll run.

import {  } from './viem.config'
 
const  = await ..({
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
  : 52_000_000_000n,
  : 50,
  : '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 52_130_000_000n, recipient: '0x742d...bEbb', ... }

The redemption still burns shares from the sending account; only the asset payout is redirected.

Return Value

type ReturnValue = {
  /** Assets paid out. */
  assetAmount: bigint
  /** Redeeming caller. */
  caller: Address
  /** Transaction receipt. */
  receipt: TransactionReceipt
  /** Asset recipient. */
  recipient: Address
  /** Earn shares burned. */
  shareAmount: bigint
}

The asynchronous action returns the transaction hash instead.

Parameters

assetAmount (optional)

  • Type: bigint

Quoted asset output. Provide it with slippageBps to avoid a live quote.

assetAmountMin (optional)

  • Type: bigint

Minimum assets to accept. It must be greater than zero and cannot be combined with assetAmount or slippageBps.

recipient (optional)

  • Type: Address
  • Default: account.address

Asset recipient.

shareAmount

  • Type: bigint | { decimals?: number | undefined; formatted: string }

Earn shares to redeem. A bigint uses base units; a formatted value uses the share token's decimals unless decimals is provided.

slippageBps (optional)

  • Type: number

Slippage tolerance below the provided or live quote, in basis points. For example, 50 means 0.5%.

vault

  • Type: Address

Vault address.

account (optional)

  • Type: Account | Address

Account that will be used to send the transaction.

feePayer (optional)

  • Type: Account | boolean

Fee payer for the transaction (TIP-1 gas sponsorship).

Pass true to defer the fee token to an external fee payer (e.g. a relay), or a local Account to co-sign the transaction as the fee payer.

feeToken (optional)

  • Type: Address | bigint

Fee token for the transaction.

Can be an unpaused USD-denominated TIP-20 token address or ID.

gas (optional)

  • Type: bigint

Gas limit for the transaction.

keyAuthorization (optional)

  • Type: KeyAuthorization

Signed key authorization to include with the transaction, authorizing an access key to act for the sending account.

maxFeePerGas (optional)

  • Type: bigint

Max fee per gas for the transaction.

maxPriorityFeePerGas (optional)

  • Type: bigint

Max priority fee per gas for the transaction.

nonce (optional)

  • Type: number

Nonce for the transaction.

nonceKey (optional)

  • Type: 'expiring' | 'random' | bigint

Nonce key for the transaction (TIP-1009 2D nonces).

Use 'expiring' to select an expiring nonce, which enables concurrent transaction submission without nonce ordering. Use 'random' to select a random key.

throwOnReceiptRevert (optional)

  • Type: boolean
  • Default: true

Whether a Sync action throws when the receipt reports a revert.

validAfter (optional)

  • Type: number

Unix timestamp after which the transaction can be included.

validBefore (optional)

  • Type: number

Unix timestamp before which the transaction must be included.