Fee Calculations
Functions for calculating various fees in the protocol.
multiVaultEntryFeeAmountβ
Calculate entry fee for a deposit.
Parametersβ
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bytes32, bigint] | VaultId, assets | Yes |
Returnsβ
Promise<bigint> // Entry fee amount
Exampleβ
import { multiVaultEntryFeeAmount } from '@0xintuition/protocol'
import { parseEther, formatEther } from 'viem'
const depositAmount = parseEther('1')
const entryFee = await multiVaultEntryFeeAmount(
{ address, publicClient },
{ args: [vaultId, depositAmount] }
)
console.log('Entry fee:', formatEther(entryFee))
console.log('Net deposit:', formatEther(depositAmount - entryFee))
multiVaultExitFeeAmountβ
Calculate exit fee for a redemption.
Parametersβ
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bytes32, bigint] | VaultId, assets | Yes |
Returnsβ
Promise<bigint> // Exit fee amount
Exampleβ
import { multiVaultExitFeeAmount } from '@0xintuition/protocol'
const expectedAssets = parseEther('10')
const exitFee = await multiVaultExitFeeAmount(
{ address, publicClient },
{ args: [vaultId, expectedAssets] }
)
console.log('Exit fee:', formatEther(exitFee))
console.log('Net withdrawal:', formatEther(expectedAssets - exitFee))
multiVaultProtocolFeeAmountβ
Calculate protocol fee.
Parametersβ
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bytes32, bigint] | VaultId, assets | Yes |
Returnsβ
Promise<bigint> // Protocol fee amount
Exampleβ
import { multiVaultProtocolFeeAmount } from '@0xintuition/protocol'
const protocolFee = await multiVaultProtocolFeeAmount(
{ address, publicClient },
{ args: [vaultId, depositAmount] }
)
console.log('Protocol fee:', formatEther(protocolFee))
multiVaultAtomDepositFractionAmountβ
Calculate atom deposit fraction for triple creation.
Parametersβ
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bigint] | Total assets | Yes |
Returnsβ
Promise<bigint> // Atom deposit fraction
Exampleβ
import { multiVaultAtomDepositFractionAmount } from '@0xintuition/protocol'
const totalAssets = parseEther('1')
const atomFraction = await multiVaultAtomDepositFractionAmount(
{ address, publicClient },
{ args: [totalAssets] }
)
console.log('Atom deposit fraction:', formatEther(atomFraction))
console.log('Remaining for triple:', formatEther(totalAssets - atomFraction))
Use Case Exampleβ
// Calculate total fees before depositing
const calculateTotalFees = async (vaultId: string, depositAmount: bigint) => {
const entryFee = await multiVaultEntryFeeAmount(
{ address, publicClient },
{ args: [vaultId, depositAmount] }
)
const protocolFee = await multiVaultProtocolFeeAmount(
{ address, publicClient },
{ args: [vaultId, depositAmount] }
)
const totalFees = entryFee + protocolFee
const netDeposit = depositAmount - totalFees
return {
depositAmount: formatEther(depositAmount),
entryFee: formatEther(entryFee),
protocolFee: formatEther(protocolFee),
totalFees: formatEther(totalFees),
netDeposit: formatEther(netDeposit),
feePercentage: (Number(totalFees) / Number(depositAmount) * 100).toFixed(2) + '%',
}
}
const fees = await calculateTotalFees(vaultId, parseEther('1'))
console.log(fees)