earn.deposit
Deposits assets into a vault and mints vault shares to a recipient.
Usage
import { client } from './viem.config'
const result = await client.earn.depositSync({
assetAmount: 100_000_000n,
shareAmount: 99_900_000n,
slippageBps: 50,
vault: '0x0000000000000000000000000000000000000001',
})
{
// assetAmount: 100_000_000n,
// caller: '0x...',
// receipt: { ... },
// recipient: '0x...',
// shareAmount: 99_500_500n,
// }import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})The action reads and approves assetToken, then deposits it in one transaction. shareAmount is a
quote; slippageBps converts it into the minimum accepted share amount.
Set an Exact Minimum
Use shareAmountMin when you already have a minimum vault share output.
import { client } from './viem.config'
const result = await client.earn.depositSync({
assetAmount: 100_000_000n,
shareAmountMin: 99_500_000n,
vault: '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 100_000_000n, shareAmount: 99_750_000n, ... }import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})Asynchronous Usage
earn.depositSync waits for inclusion and returns the decoded deposit event. Use earn.deposit to
return the transaction hash immediately.
import { Actions } from 'viem/tempo'
import { client } from './viem.config'
const vault = '0x0000000000000000000000000000000000000001'
const hash = await client.earn.deposit({
assetAmount: 100_000_000n,
shareAmountMin: 99_500_000n,
vault,
})
0x1234...abcd
const receipt = await client.waitForTransactionReceipt({ hash })
const { args } = Actions.earn.deposit.extractEvent(receipt.logs, { vault })
{ assets: 100_000_000n, shares: 99_750_000n, ... }Return Value
type ReturnValue = {
/** Assets deposited. */
assetAmount: bigint
/** Depositing caller. */
caller: Address
/** Transaction receipt. */
receipt: TransactionReceipt
/** Vault share recipient. */
recipient: Address
/** Vault shares minted. */
shareAmount: bigint
}The asynchronous action returns the transaction hash instead.
Parameters
assetAmount
- Type:
bigint | { decimals?: number | undefined; formatted: string }
Assets to deposit. A bigint uses base units; a formatted value uses the vault asset's decimals
unless decimals is provided.
recipient (optional)
- Type:
Address - Default:
account.address
Vault share recipient.
shareAmount (optional)
- Type:
bigint
Quoted vault share output. Provide it with slippageBps, or provide shareAmountMin instead.
shareAmountMin (optional)
- Type:
bigint
Minimum vault shares to accept. It must be greater than zero and cannot be combined with
shareAmount or slippageBps.
slippageBps (optional)
- Type:
number
Slippage tolerance below shareAmount, 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.
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.