> ## Documentation Index
> Fetch the complete documentation index at: https://developers.paxoslabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# calculateDepositFee

> Calculate deposit fees for a given amount from the on-chain fee module

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.

<Info>
  Returns zero fees with `hasFees: false` for accounts without a deposit fee module configured. No RPC call is made in that case.
</Info>

## Import

```ts theme={null}
import { calculateDepositFee } from '@paxoslabs/amplify-sdk'
```

## Usage

```ts theme={null}
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

| Parameter       | Type      | Required | Description                                 |
| --------------- | --------- | -------- | ------------------------------------------- |
| `vaultName`     | `string`  | Yes      | Account name from `getVaultsByConfig()`     |
| `chainId`       | `ChainId` | Yes      | Blockchain network ID                       |
| `assetAddress`  | `Address` | Yes      | Deposit token contract address              |
| `depositAmount` | `string`  | Yes      | Amount as decimal string (e.g., `"1000.0"`) |

```ts theme={null}
interface CalculateDepositFeeParams {
  vaultName: string
  chainId: ChainId
  assetAddress: Address
  depositAmount: string
}
```

## Return Type

```ts theme={null}
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

```tsx theme={null}
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 Pattern       | Description                   | Resolution                       |
| --------------------------- | ----------------------------- | -------------------------------- |
| `"No vault found"`          | No account matches parameters | Verify vaultName, asset, chainId |
| `"Failed to read fee data"` | On-chain fee read failed      | Check RPC connectivity           |
| `"SDK not initialized"`     | SDK not initialized           | Call `initAmplifySDK()` first    |

## Related

* [getDepositCap](./getDepositCap) — Read the supply cap for an account
* [Deposit Workflow](/v0.5.3/intro/products/earn/developers/api/deposit-workflow) — Execute deposits
