Skip to content

withdraw ​

Withdraw an exact amount of USDC, burning the required vault shares from owner.

Signature ​

solidity
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

Parameters ​

NameTypeDescription
assetsuint256Amount of USDC to withdraw (6 decimals), after the withdrawal fee.
receiveraddressAddress that will receive the USDC.
owneraddressAddress whose vault shares will be burned.

Returns ​

NameTypeDescription
sharesuint256Amount of shares burned.

Preconditions ​

  • withdrawalsPaused() must be false.
  • assets > 0.
  • receiver and owner must be non-zero addresses.
  • If owner != msg.sender, the caller needs a vault-share allowance(owner, msg.sender) >= shares. Set this with the vault's approve (or have the owner do it).
  • owner must hold at least shares worth of vault shares (use previewWithdraw(assets) to quote).

Events emitted ​

solidity
event Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
event Transfer(address indexed from, address indexed to, uint256 value); // share burn, to = 0x0
event Approval(address indexed owner, address indexed spender, uint256 value); // only if allowance was used

Example — withdraw 500 USDC to self ​

ts
import { parseUnits } from 'viem'
import { publicClient, walletClient } from './client'
import { liteUsdVaultAbi } from './abi'
import { VAULT, USDC_DECIMALS } from './constants'

const account = walletClient.account!
const assets = parseUnits('500', USDC_DECIMALS)

const { request, result: sharesBurned } = await publicClient.simulateContract({
  account,
  address: VAULT,
  abi: liteUsdVaultAbi,
  functionName: 'withdraw',
  args: [assets, account.address, account.address],
})

console.log('Will burn', sharesBurned, 'shares')

const hash = await walletClient.writeContract(request)
await publicClient.waitForTransactionReceipt({ hash })

Notes ​

  • assets is the amount the receiver gets net of the withdrawal fee. To withdraw exactly your full balance, prefer redeem(balanceOf(account), …) — see the next page.