- Checks existing vault share allowance
- Detects smart contract wallets (Safe, EIP-4337, EIP-7702)
- Returns the appropriate authorization result
Import
Usage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
yieldType | YieldType | Yes | Yield strategy (CORE, TREASURY, FRONTIER) |
wantAsset | Address | Yes | Token address to receive upon withdrawal |
withdrawAmount | string | Yes | Vault shares to withdraw (decimal string) |
userAddress | Address | Yes | Owner of vault shares |
chainId | ChainId | Yes | Blockchain network ID |
forceMethod | "approval" | "allowance_check" | No | Override auto routing behavior |
Return Type
Returns a discriminated unionWithdrawAuthorizationResult:
WithdrawAuthMethod.APPROVAL
Returned when approval is needed (insufficient allowance, smart wallet detected in auto mode, orforceMethod: "approval").
WithdrawAuthMethod.ALREADY_APPROVED
Returned when existing allowance is sufficient.Type Guards
Use type guards for type-safe handling:Smart Wallet Behavior
In auto mode, smart contract wallets (Safe, EIP-4337, EIP-7702) are routed toAPPROVAL with approve tx data so they can batch approve + withdraw atomically.
getCode. This covers:
- Safe (Gnosis Safe) multi-sig wallets
- EIP-4337 smart accounts (e.g., Biconomy, ZeroDev, Alchemy)
- EIP-7702 delegated EOAs
- Privy embedded wallets (when using smart wallets)
Force Method Overrides
UseforceMethod for deterministic behavior:
Examples
- Complete Viem Flow
- Smart Wallet Batching
Comparison with Deposit Authorization
prepareWithdrawalAuthorization() mirrors the deposit flow’s prepareDepositAuthorization():
| Feature | Deposit Auth | Withdrawal Auth |
|---|---|---|
| Methods | PERMIT, APPROVAL, ALREADY_APPROVED | APPROVAL, ALREADY_APPROVED |
| Permit Support | Yes (EIP-2612) | No |
| Smart Wallet Auto-Detect | Yes | Yes |
| Force Method | forceMethod: "permit" | "approval" | forceMethod: "approval" | "allowance_check" |
Error Handling
| Error | Description | Resolution |
|---|---|---|
No vault found for asset | Invalid yield type, chain, or asset combination | Verify parameters match an existing vault |
Failed to check withdrawal approval | On-chain multicall failed | Check RPC connectivity and retry |
Related
- prepareDepositAuthorization - Deposit authorization (equivalent for deposits)
- prepareWithdrawal - Unified withdrawal wrapper
- prepareWithdrawOrderTxData - Low-level withdrawal tx builder
- prepareApproveWithdrawOrderTxData - Manual approval
- Withdrawals Guide - Complete withdrawal integration guide
- Smart Wallets Guide - Smart wallet integration patterns