Skip to main content
Calculates the deposit fee for a given amount by reading the fee module’s depositTokenFeeData and ONE_HUNDRED_PERCENT on-chain. Returns both the variable (percentage-based) and flat fee components, along with the total fee and the net deposit amount after fees.
Returns zero fees with hasFees: false for accounts without a deposit fee module configured. No RPC call is made in that case.

Import

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

Usage

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

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

const fee = await calculateDepositFee({
  vaultName: vault.name,
  chainId: 1,
  assetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  depositAmount: '1000.0',
})

console.log(fee.hasFees) // boolean
console.log(fee.totalFeeAmount) // bigint — variable + flat fee
console.log(fee.depositAmountAfterFees) // bigint — net amount

Parameters

ParameterTypeRequiredDescription
vaultNamestringYesAccount name from getVaultsByConfig()
chainIdChainIdYesBlockchain network ID
assetAddressAddressYesDeposit token contract address
depositAmountstringYesAmount as decimal string (e.g., "1000.0")
interface CalculateDepositFeeParams {
  vaultName: string
  chainId: ChainId
  assetAddress: Address
  depositAmount: string
}

Return Type

interface DepositFeeResult {
  /** Whether the vault has a fee module configured */
  hasFees: boolean
  /** Deposit fee module contract address (zero address if no fees) */
  depositFeeModuleAddress: Address
  /** Variable fee percentage as raw uint256 from the contract */
  feePercentage: bigint
  /** ONE_HUNDRED_PERCENT constant from the fee module (denominator for percentage calc) */
  oneHundredPercent: bigint
  /** Flat fee in deposit-token units (raw uint256) */
  flatFee: bigint
  /** Computed variable fee: depositAmount * feePercentage / oneHundredPercent */
  variableFeeAmount: bigint
  /** Total fee: variableFeeAmount + flatFee */
  totalFeeAmount: bigint
  /** Deposit amount after total fee deduction */
  depositAmountAfterFees: bigint
  /** Decimals of the deposit asset (for display formatting) */
  assetDecimals: number
}

Example: Fee Preview UI

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

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

const fee = await calculateDepositFee({
  vaultName: vault.name,
  chainId: 1,
  assetAddress: usdcAddress,
  depositAmount: userInputAmount,
})

if (fee.hasFees) {
  const totalFee = formatUnits(fee.totalFeeAmount, fee.assetDecimals)
  const netAmount = formatUnits(fee.depositAmountAfterFees, fee.assetDecimals)
  console.log(`Deposit fee: ${totalFee} USDC`)
  console.log(`Net deposit: ${netAmount} USDC`)

  // Compute percentage for display
  if (fee.oneHundredPercent > 0n) {
    const pct = Number(fee.feePercentage * 10000n / fee.oneHundredPercent) / 100
    console.log(`Fee rate: ${pct}%`)
  }
} else {
  console.log('No deposit fees for this vault')
}

Error Handling

Error Message PatternDescriptionResolution
"No vault found"No account matches parametersVerify vaultName, asset, chainId
"Failed to read fee data"On-chain fee read failedCheck RPC connectivity
"SDK not initialized"SDK not initializedCall initAmplifySDK() first