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, YieldType } from "@paxoslabs/amplify-sdk";

const fee = await getWithdrawalFee({
  yieldType: YieldType.CORE,
  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
yieldTypeYieldTypeYesYield strategy type
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 {
  yieldType: YieldType;
  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, YieldType } from "@paxoslabs/amplify-sdk";
import { formatUnits } from "viem";

const fee = await getWithdrawalFee({
  yieldType: YieldType.CORE,
  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