Skip to content
LogoLogo

earn.privateDeposit

Withdraws assets from a private Zone, deposits them into an Earn vault, and returns the vault shares to an encrypted Zone recipient.

Usage

Prepare the encrypted callback with a parent Tempo client, then submit the withdrawal with the Zone client.

import { client as parentClient } from './viem.config'
import { client as zoneClient } from './zones.config'
 
const prepared = await parentClient.earn.privateDeposit.prepare({
  assetAmount: 100_000_000n,
  gateway: '0x0000000000000000000000000000000000000001',
  recipient: zoneClient.account.address,
  recoveryRecipient: parentClient.account.address,
  shareAmountMin: 99_500_000n,
})
 
const { receipt, senderTag } = await zoneClient.earn.privateDepositSync(prepared)
{ transactionHash: '0x1234...abcd', ... }
console.log('Sender tag:', senderTag)

The synchronous action confirms the Zone withdrawal. Use earn.waitForPrivateDeposit to wait for the parent-chain vault deposit. senderTag identifies the corresponding parent-chain WithdrawalProcessed event.

Asynchronous Usage

Use earn.privateDeposit to return the Zone transaction hash immediately.

import { client as parentClient } from './viem.config'
import { client as zoneClient } from './zones.config'
 
const prepared = await parentClient.earn.privateDeposit.prepare({
  assetAmount: 100_000_000n,
  gateway: '0x0000000000000000000000000000000000000001',
  recipient: zoneClient.account.address,
  recoveryRecipient: parentClient.account.address,
  shareAmountMin: 99_500_000n,
})
 
const hash = await zoneClient.earn.privateDeposit(prepared)
0x1234...abcd

Swap-Routed Deposits

Pass assetToken when the Zone asset differs from the gateway vault asset. Set vaultAssetAmountMin to bound the gateway vault assets produced by that swap, and set the share bound independently.

import { client as parentClient } from './viem.config'
import { client as zoneClient } from './zones.config'
 
const prepared = await parentClient.earn.privateDeposit.prepare({
  assetAmount: 100_000_000n,
  assetToken: '0x0000000000000000000000000000000000000002',
  gateway: '0x0000000000000000000000000000000000000001',
  recipient: zoneClient.account.address,
  recoveryRecipient: parentClient.account.address,
  shareAmountMin: 98_500_000n,
  vaultAssetAmountMin: 99_000_000n,
})

When assetToken is the gateway vault asset, the action always requires the exact withdrawn assetAmount. For swap-routed deposits, omitting vaultAssetAmountMin preserves the zero minimum.

Return Type

type ReturnType = {
  receipt: TransactionReceipt
  senderTag: Hash
}

The asynchronous action returns the transaction hash instead.

Prepare Return Type

type PreparedZoneRequest = {
  actionId: Hex
  amount: bigint
  callbackGas: bigint
  chainId: number
  data: Hex
  fallbackRecipient: Address
  fromBlock: bigint
  memo?: Hex
  to: Address
  token: Address
  zoneId: number
}

Pass the prepared value directly to earn.privateDeposit or earn.privateDepositSync. The action checks that its parent and Zone chain IDs match the Zone client.

Prepare Parameters

actionId (optional)

  • Type: Hex
  • Default: A random bytes32 value

Correlation ID encoded in the gateway callback. Supply one when deterministic request preparation is needed.

assetAmount

  • Type: bigint

Assets withdrawn from the Zone, in base units.

assetToken (optional)

  • Type: Address
  • Default: The gateway vault asset

Asset token withdrawn from the Zone. The gateway swaps it into the vault asset when needed.

vaultAssetAmountMin (optional)

  • Type: bigint
  • Default: 0n for swap-routed deposits

Minimum gateway vault assets accepted after swapping assetToken. This bound works alongside the vault share bound. Direct vault-asset deposits always use the exact withdrawn assetAmount instead.

callbackGas (optional)

  • Type: bigint
  • Default: 10_000_000n

Gas reserved for the parent-chain gateway callback.

fallbackRecipient (optional)

  • Type: Address
  • Default: recoveryRecipient

Public recipient if the parent-chain gateway callback fails.

gateway

  • Type: Address

Gateway identifying the vault and Zone configuration.

recipient

  • Type: Address

Encrypted Zone recipient for the returned vault shares.

recoveryRecipient

  • Type: Address

Public Tempo recipient if the encrypted return deposit fails.

returnMemo (optional)

  • Type: Hex

Memo encrypted with the returned Zone deposit.

shareAmount (optional)

  • Type: bigint

Quoted vault share output. Provide it with slippageBps, or provide shareAmountMin instead.

shareAmountMin (optional)

  • Type: bigint

Minimum vault shares returned to the Zone.

slippageBps (optional)

  • Type: number

Slippage tolerance below shareAmount, in basis points. For example, 50 means 0.5%.

withdrawalMemo (optional)

  • Type: Hex

Memo attached to the Zone withdrawal.

blockNumber (optional)

  • Type: bigint

Block number to read the state from.

blockOverrides (optional)

  • Type: BlockOverrides

Block overrides to apply to the state.

blockTag (optional)

  • Type: BlockTag

Block tag to read the state from.

stateOverride (optional)

  • Type: StateOverride

State override to apply.

Transaction Parameters

account (optional)

  • Type: Account | Address

Account that will be used to send the transaction.

feeToken (optional)

  • Type: Address | bigint

Fee token for the transaction.

Can be an unpaused USD-denominated TIP-20 token address or ID. Use client.fee.validateToken({ token }) to validate a token before submitting a transaction or setting it as a fee preference.

feePayer (optional)

  • Type: Account | true

Fee payer for the transaction.

Can be a Viem Account, or true if a Fee Payer Service will be used.

gas (optional)

  • Type: bigint

Gas limit for the transaction.

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' | bigint

Nonce key for the transaction. Use 'expiring' to use expiring nonces (TIP-1009), which enables concurrent transaction submission without nonce ordering.

validBefore (optional)

  • Type: number

Unix timestamp before which the transaction must be included.

validAfter (optional)

  • Type: number

Unix timestamp after which the transaction can be included.

throwOnReceiptRevert (optional)

  • Type: boolean
  • Default: true

Whether to throw an error if the transaction receipt indicates a revert. Only applicable to *Sync actions.