DelayedFeeCalculator
Last updated
Last updated
Inherits: IDelayedFeeCalculator, BaseFeeCalculator
To protect vault owners from inaccurate submissions, the DelayedFeeCalculator uses a dispute period and pending snapshot system that only accepts submitted values after the dispute period has passed. Each vault accrues fees independently but a shared protocol fee recipient accrues protocol level fees from all vaults
All fees are calculated in the numeraire token's decimals
Dispute period for vault snapshot
uint256 public immutable DISPUTE_PERIOD;
A mapping of vault addresses to their associated state
mapping(address vault => VaultSnapshot vaultSnapshot) internal _vaultSnapshots;
constructor(address owner_, Authority authority_, uint256 disputePeriod) BaseFeeCalculator(owner_, authority_);
function registerVault() external override;
Submit a new snapshot for fee calculation
function submitSnapshot(address vault, uint160 averageValue, uint128 highestProfit, uint32 timestamp)
external
onlyVaultAccountant(vault);
Parameters
vault
address
The address of the vault
averageValue
uint160
The average value during the period since last snapshot to this snapshot timestamp
highestProfit
uint128
The highest profit achieved up to the snapshot timestamp
timestamp
uint32
The timestamp of the snapshot
Process fee accrual for a vault
function accrueFees(address vault) external returns (uint256 protocolFeesEarned, uint256 vaultFeesEarned);
Parameters
vault
address
The address of the vault
Returns
protocolFeesEarned
uint256
tvlFeesEarned The earned TVL fees for the vault and the protocol
vaultFeesEarned
uint256
performanceFeesEarned The earned performance fees for the vault and the protocol
function previewFees(address vault, uint256 feeTokenBalance) external view override returns (uint256, uint256);
Get the fee state for a vault
function vaultFeeState(address vault) external view returns (VaultSnapshot memory, VaultAccruals memory);
Parameters
vault
address
The vault address to get fee state for
Returns
<none>
VaultSnapshot
The vault snapshot containing average value and highest profit
<none>
VaultAccruals
The vault accruals containing fees and accrued amounts
Called before claiming fees
Can be overridden by child contracts to add custom logic
function _beforeClaimFees() internal override;
Called before claiming protocol fees
Can be overridden by child contracts to add custom logic
function _beforeClaimProtocolFees() internal override;
Accrues fees for a vault based on its pending snapshot
Updates the vault's state including lastFeeAccrual, lastHighestProfit, and accruedFees
Deletes pending snapshot if dispute period has passed
function _accrueFees(
VaultSnapshot storage vaultSnapshot,
VaultAccruals storage vaultAccruals,
uint256 lastFeeAccrualCached
) internal returns (uint256 protocolFeesEarned, uint256 vaultFeesEarned);
Parameters
vaultSnapshot
VaultSnapshot
The storage pointer to the vault's state
vaultAccruals
VaultAccruals
The storage pointer to the vault's accruals
lastFeeAccrualCached
uint256
The last fee accrual timestamp cached to avoid re-reading from storage
Returns
protocolFeesEarned
uint256
The earned protocol fees
vaultFeesEarned
uint256
The earned vault fees
Calculates performance fees for both vault and protocol
Returns zero fees if no new profit has been made
function _calculatePerformanceFees(uint256 vaultPerformanceFeeRate, uint256 newHighestProfit, uint256 oldHighestProfit)
internal
view
returns (uint256, uint256);
Parameters
vaultPerformanceFeeRate
uint256
The performance fee rate for the vault
newHighestProfit
uint256
The highest profit in the pending snapshot
oldHighestProfit
uint256
The highest profit in the previous snapshot
Returns
<none>
uint256
vaultPerformanceFee The performance fee for the vault
<none>
uint256
protocolPerformanceFee The performance fee for the protocol
Calculates TVL fees for both vault and protocol
function _calculateTvlFees(
uint256 vaultTvlFeeRate,
uint256 averageValue,
uint256 snapshotTimestamp,
uint256 lastFeeAccrual
) internal view returns (uint256, uint256);
Parameters
vaultTvlFeeRate
uint256
The TVL fee rate for the vault
averageValue
uint256
The average value of the vault
snapshotTimestamp
uint256
The timestamp of the snapshot
lastFeeAccrual
uint256
The timestamp of the last fee accrual
Returns
<none>
uint256
vaultTvlFee The earned TVL fee for the vault
<none>
uint256
protocolTvlFee The earned TVL fee for the protocol