Deposit into Earn Vault
earn.deposit
Deposits assets into a vault and mints Earn shares to a recipient.
Usage
import { } from './viem.config'
const = await ..({
: 100_000_000n,
: 99_900_000n,
: 50,
: '0x0000000000000000000000000000000000000001',
})
{// assetAmount: 100_000_000n,// caller: '0x...',
// receipt: { ... },
// recipient: '0x...',
// shareAmount: 99_500_500n,
// }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})The action reads the vault's asset token, approves it, 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 Earn share output.
import { } from './viem.config'
const = await ..({
: 100_000_000n,
: 99_500_000n,
: '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 100_000_000n, shareAmount: 99_750_000n, ... }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Asynchronous Usage
earn.depositSync waits for inclusion and returns the decoded deposit event. Use earn.deposit to
return the transaction hash immediately.
import { } from 'viem/tempo'
import { } from './viem.config'
const = '0x0000000000000000000000000000000000000001'
const = await ..({
: 100_000_000n,
: 99_500_000n,
,
})
0x1234...abcd const = await ..({ }).
const { } = ...(., { })
{ assets: 100_000_000n, shares: 99_750_000n, ... }Recipes
Sweep Idle Treasury into Yield
Combine earn.getPosition with a deposit to move an account's
full idle asset balance into the vault.
import { } from './viem.config'
const = '0x0000000000000000000000000000000000000001'
const { } = await ..({ })
const = await ..({
: ,
: 12_437_500_000n, // provider quote for `assetBalance`
: 50,
,
})
{ assetAmount: 12_500_000_000n, shareAmount: 12_400_000_000n, ... }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Mint Earn Shares to a Cold Treasury
Pass recipient when an operator wallet funds the position but a treasury address should hold the
resulting Earn shares.
import { } from './viem.config'
const = await ..({
: 5_000_000_000n,
: '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
: 4_975_000_000n,
: '0x0000000000000000000000000000000000000001',
})
{ recipient: '0x8ba1...BA72', shareAmount: 4_987_500_000n, ... }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})The shares mint directly to the treasury; the operator account never holds them.
Deposit a Dollar-Denominated Amount
Pass a formatted assetAmount when your accounting system works in display units; providing
decimals skips the live decimals lookup.
import { } from './viem.config'
const = await ..({
: { : 6, : '25000' },
: 24_875_000_000n,
: '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 25_000_000_000n, ... }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnValue = {
/** Assets deposited. */
assetAmount: bigint
/** Depositing caller. */
caller: Address
/** Transaction receipt. */
receipt: TransactionReceipt
/** Earn share recipient. */
recipient: Address
/** Earn 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
Earn share recipient.
shareAmount (optional)
- Type:
bigint
Quoted Earn share output. Provide it with slippageBps, or provide shareAmountMin instead.
shareAmountMin (optional)
- Type:
bigint
Minimum Earn 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.
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.