Skip to main content
Reads the withdrawal fee from the on-chain FeeModule contract. Performs two sequential RPC calls: reads the FeeModule address from the WithdrawQueue, then multicalls calculateOfferFees and offerFeePercentage.

Import

import { getWithdrawalFee } from '@paxoslabs/amplify-sdk'

Usage

import { getWithdrawalFee, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

const fee = await getWithdrawalFee({
  vaultName: vault.name,
  chainId: 1,
  assetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  amount: '1.0',
  offerAsset: '0x1234...5678', // vault shares
  wantAsset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  receiver: '0x5678...abcd',
})

console.log(fee.feeAmount) // bigint
console.log(fee.feePercentage) // bigint

Parameters

ParameterTypeRequiredDescription
vaultNamestringYesVault name from getVaultsByConfig()
chainIdChainIdYesBlockchain network ID
assetAddressAddressYesAsset address for vault lookup
amountstringYesWithdrawal amount as decimal string
offerAssetAddressYesVault share token address
wantAssetAddressYesToken the user wants to receive
receiverAddressYesAddress receiving the withdrawal
interface GetWithdrawalFeeParams {
  vaultName: string
  chainId: ChainId
  assetAddress: Address
  amount: string
  offerAsset: Address
  wantAsset: Address
  receiver: Address
}

Return Type

interface WithdrawalFeeResult {
  /** Fee amount in share token units */
  feeAmount: bigint
  /** Fee percentage from the FeeModule */
  feePercentage: bigint
}

Example: Fee Preview

import { getWithdrawalFee, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'
import { formatUnits } from 'viem'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

const fee = await getWithdrawalFee({
  vaultName: vault.name,
  chainId: 1,
  assetAddress: usdcAddress,
  amount: withdrawAmount,
  offerAsset: vaultShareAddress,
  wantAsset: usdcAddress,
  receiver: userAddress,
})

const feeFormatted = formatUnits(fee.feeAmount, 18)
console.log(`Withdrawal fee: ${feeFormatted} shares`)

Error Handling

Error Message PatternDescriptionResolution
"No vault found"No vault matches parametersVerify yieldType, asset, chainId
"SDK not initialized"SDK not initializedCall initAmplifySDK() first